Example usage for com.badlogic.gdx.graphics Pixmap drawPixel

List of usage examples for com.badlogic.gdx.graphics Pixmap drawPixel

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics Pixmap drawPixel.

Prototype

public void drawPixel(int x, int y, int color) 

Source Link

Document

Draws a pixel at the given location with the given color.

Usage

From source file:com.agateau.pixelwheels.map.LapPositionTableIO.java

License:Open Source License

public static Pixmap createPixmap(LapPositionTable table, int width, int height) {
    NLog.i("Saving");
    Pixmap pixmap = new Pixmap(width, height, Pixmap.Format.RGBA8888);
    for (int y = 0; y < height; ++y) {
        NLog.i("Saving %d/%d", y, height);
        for (int x = 0; x < width; ++x) {
            LapPosition pos = table.get(x, y);
            int color;
            if (pos == null) {
                color = 0;/*  w  ww.  j a  v a2  s  .  c  om*/
            } else {
                int r = (int) ((1 - Math.abs(pos.getCenterDistance())) * 255);
                int g = pos.getSectionId() * 255 / table.getSectionCount();
                int b = (int) (pos.getSectionDistance() * 255);
                color = (r << 24) | (g << 16) | (b << 8) | 0xff;
            }
            pixmap.drawPixel(x, height - 1 - y, color);
        }
    }
    return pixmap;
}

From source file:com.commons.color.CustomColorPicker.java

License:Apache License

private void createColorWidgets() {
    palettePixmap = new Pixmap(100, 100, Format.RGB888);
    paletteTexture = new Texture(palettePixmap);

    barPixmap = new Pixmap(1, 360, Format.RGB888);

    for (int h = 0; h < 360; h++) {
        ColorUtils.HSVtoRGB(360 - h, 100, 100, tmpColor);
        barPixmap.drawPixel(0, h, Color.rgba8888(tmpColor));
    }// w w  w.j  ava  2s  . c o  m

    barTexture = new Texture(barPixmap);

    palette = new Palette(style, sizes, paletteTexture, 0, 0, 100, new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            sBar.setValue(palette.getV());
            vBar.setValue(palette.getS());

            updateHSVValuesFromFields();
            updatePixmaps();
        }
    });

    verticalBar = new VerticalChannelBar(style, sizes, barTexture, 0, 360, new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            hBar.setValue(verticalBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }
    });

    hBar = new ColorChannelWidget(style, sizes, "H", 360, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            verticalBar.setValue(hBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int h = 0; h < 360; h++) {
                ColorUtils.HSVtoRGB(h, sBar.getValue(), vBar.getValue(), tmpColor);
                pixmap.drawPixel(h, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    sBar = new ColorChannelWidget(style, sizes, "S", 100, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            palette.setValue(vBar.getValue(), sBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int s = 0; s < 100; s++) {
                ColorUtils.HSVtoRGB(hBar.getValue(), s, vBar.getValue(), tmpColor);
                pixmap.drawPixel(s, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    vBar = new ColorChannelWidget(style, sizes, "V", 100, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            palette.setValue(vBar.getValue(), sBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int v = 0; v < 100; v++) {
                ColorUtils.HSVtoRGB(hBar.getValue(), sBar.getValue(), v, tmpColor);
                pixmap.drawPixel(v, 0, Color.rgba8888(tmpColor));
            }

        }
    });

    rBar = new ColorChannelWidget(style, sizes, "R", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int r = 0; r < 255; r++) {
                tmpColor.set(r / 255.0f, color.g, color.b, 1);
                pixmap.drawPixel(r, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    gBar = new ColorChannelWidget(style, sizes, "G", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int g = 0; g < 255; g++) {
                tmpColor.set(color.r, g / 255.0f, color.b, 1);
                pixmap.drawPixel(g, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    bBar = new ColorChannelWidget(style, sizes, "B", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int b = 0; b < 255; b++) {
                tmpColor.set(color.r, color.g, b / 255.0f, 1);
                pixmap.drawPixel(b, 0, Color.rgba8888(tmpColor));
            }

        }
    });

    aBar = new ColorChannelWidget(style, sizes, "A", 255, true,
            new ColorChannelWidget.ColorChannelWidgetListener() {
                @Override
                public void updateFields() {
                    if (aBar.isInputValid())
                        color.a = aBar.getValue() / 255.0f;
                    updatePixmaps();
                }

                @Override
                public void draw(Pixmap pixmap) {
                    pixmap.fill();
                    for (int i = 0; i < 255; i++) {
                        tmpColor.set(color.r, color.g, color.b, i / 255.0f);
                        pixmap.drawPixel(i, 0, Color.rgba8888(tmpColor));
                    }
                }
            });
}

From source file:com.googlecode.gdxquake2.installer.ImageConverter.java

License:Open Source License

static Pixmap makeImage(image_t source) {
    Pixmap image = new Pixmap(source.width, source.height, Pixmap.Format.RGBA8888);
    int ofs = 0;//from   w w  w.j  a v  a 2 s  . c  o  m
    for (int y = 0; y < source.height; y++) {
        for (int x = 0; x < source.width; x++) {
            int rgba = (((source.pix[ofs] & 255) << 24) | ((source.pix[ofs + 1] & 255) << 16)
                    | ((source.pix[ofs + 2] & 255) << 8) | ((source.pix[ofs + 3] & 255)));
            ofs += 4;
            image.drawPixel(x, y, rgba);
        }
    }

    return image;
}

From source file:com.googlecode.gdxquake2.installer.ImageConverter.java

License:Open Source License

static Pixmap makePalletizedImage(image_t source) {
    Pixmap image = new Pixmap(source.width, source.height, Pixmap.Format.RGBA8888);
    for (int y = 0; y < source.height; ++y) {
        for (int x = 0; x < source.width; ++x) {
            int ofs = source.pix[y * source.width + x];
            if (ofs < 0) {
                ofs += 256;/*from   w  w w.j  ava2s  . c om*/
            }
            int rgba = (ofs == 255) ? 0 : QuakeImage.PALETTE_RGBA[ofs];
            image.drawPixel(x, y, rgba);
        }
    }
    return image;
}

From source file:com.kotcrab.vis.ui.contrib.widget.file.ImgScalrFileChooserIconProvider.java

License:Apache License

public Pixmap imageToPixmap(BufferedImage image) {
    final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
    final int width = image.getWidth();
    final int height = image.getHeight();
    final boolean hasAlphaChannel = image.getAlphaRaster() != null;

    Pixmap pixmap = new Pixmap(width, height, hasAlphaChannel ? Pixmap.Format.RGBA8888 : Pixmap.Format.RGB888);

    if (hasAlphaChannel) {
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel++) {

            Color.argb8888ToColor(tmpColor, pixels[pixel]);
            pixmap.drawPixel(col, row, Color.rgba8888(tmpColor));

            col++;/*  w w w.  j  a  v a2 s  .c om*/
            if (col == width) {
                col = 0;
                row++;
            }
        }
    } else {
        for (int pixel = 0, row = 0, col = 0; pixel < pixels.length; pixel++) {
            int color = pixels[pixel];
            tmpColor.r = ((color & 0x00ff0000) >>> 16) / 255f;
            tmpColor.g = ((color & 0x0000ff00) >>> 8) / 255f;
            tmpColor.b = ((color & 0x000000ff)) / 255f;
            tmpColor.a = 1f;

            pixmap.drawPixel(col, row, Color.rgba8888(tmpColor));

            col++;
            if (col == width) {
                col = 0;
                row++;
            }
        }
    }

    return pixmap;
}

From source file:com.mbrlabs.mundus.commons.terrain.SplatMap.java

License:Apache License

public void clearChannel(SplatTexture.Channel channel) {
    Pixmap pixmap = getPixmap();
    for (int smX = 0; smX < pixmap.getWidth(); smX++) {
        for (int smY = 0; smY < pixmap.getHeight(); smY++) {
            c0.set(pixmap.getPixel(smX, smY));
            if (channel == SplatTexture.Channel.R) {
                c0.set(0, c0.g, c0.b, c0.a);
            } else if (channel == SplatTexture.Channel.G) {
                c0.set(c0.r, 0, c0.b, c0.a);
            } else if (channel == SplatTexture.Channel.B) {
                c0.set(c0.r, c0.g, 0, c0.a);
            } else if (channel == SplatTexture.Channel.A) {
                c0.set(c0.r, c0.g, c0.b, 0);
            }//from w  w w  . ja  va2 s.  com
            pixmap.drawPixel(smX, smY, Color.rgba8888(c0));
        }
    }
}

From source file:com.mbrlabs.mundus.editor.tools.brushes.TerrainBrush.java

License:Apache License

private void paint() {
    Terrain terrain = terrainAsset.getTerrain();
    SplatMap sm = terrain.getTerrainTexture().getSplatmap();
    if (sm == null)
        return;/*w w w. j a va 2s  . c  o  m*/

    Vector3 terrainPos = terrain.getPosition(tVec1);
    final float splatX = ((brushPos.x - terrainPos.x) / (float) terrain.terrainWidth) * sm.getWidth();
    final float splatY = ((brushPos.z - terrainPos.z) / (float) terrain.terrainDepth) * sm.getHeight();
    final float splatRad = (radius / terrain.terrainWidth) * sm.getWidth();
    final Pixmap pixmap = sm.getPixmap();

    for (int smX = 0; smX < pixmap.getWidth(); smX++) {
        for (int smY = 0; smY < pixmap.getHeight(); smY++) {
            final float dst = MathUtils.dst(splatX, splatY, smX, smY);
            if (dst <= splatRad) {
                final float opacity = getValueOfBrushPixmap(splatX, splatY, smX, smY, splatRad) * 0.5f
                        * strength;
                int newPixelColor = sm.additiveBlend(pixmap.getPixel(smX, smY), paintChannel, opacity);
                pixmap.drawPixel(smX, smY, newPixelColor);
            }
        }
    }

    sm.updateTexture();
    splatmapModified = true;
    getProjectManager().current().assetManager.addDirtyAsset(terrainAsset);
}

From source file:com.mbrlabs.mundus.tools.brushes.TerrainBrush.java

License:Apache License

private void paint() {
    SplatMap sm = terrain.getTerrainTexture().getSplatmap();
    if (sm == null)
        return;//from   w w  w.j  a  v a  2 s  .  com

    Vector3 terrainPos = terrain.getPosition(tVec1);
    final float splatX = ((brushPos.x - terrainPos.x) / (float) terrain.terrainWidth) * sm.getWidth();
    final float splatY = ((brushPos.z - terrainPos.z) / (float) terrain.terrainDepth) * sm.getHeight();
    final float splatRad = (radius / terrain.terrainWidth) * sm.getWidth();
    final Pixmap pixmap = sm.getPixmap();

    for (int smX = 0; smX < pixmap.getWidth(); smX++) {
        for (int smY = 0; smY < pixmap.getHeight(); smY++) {
            final float dst = MathUtils.dst(splatX, splatY, smX, smY);
            if (dst <= splatRad) {
                final float opacity = getValueOfBrushPixmap(splatX, splatY, smX, smY, splatRad) * 0.5f
                        * strength;
                int newPixelColor = sm.additiveBlend(pixmap.getPixel(smX, smY), paintChannel, opacity);
                pixmap.drawPixel(smX, smY, newPixelColor);
            }
        }
    }

    sm.updateTexture();
    splatmapModified = true;
}

From source file:com.o2d.pkayjava.editor.view.ui.widget.components.color.CustomColorPicker.java

License:Apache License

private void createColorWidgets() {
    palettePixmap = new Pixmap(100, 100, Pixmap.Format.RGB888);
    paletteTexture = new Texture(palettePixmap);

    barPixmap = new Pixmap(1, 360, Pixmap.Format.RGB888);

    for (int h = 0; h < 360; h++) {
        ColorUtils.HSVtoRGB(360 - h, 100, 100, tmpColor);
        barPixmap.drawPixel(0, h, Color.rgba8888(tmpColor));
    }/* w ww.  j  a v a  2 s. c  o m*/

    barTexture = new Texture(barPixmap);

    palette = new Palette(VisUI.getSkin().get(ColorPickerStyle.class),
            VisUI.getSkin().get(com.kotcrab.vis.ui.Sizes.class), paletteTexture, 0, 0, 100,
            new ChangeListener() {
                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    //S ans V are flipped because the plate is flipped as well!
                    sBar.setValue(palette.getV());
                    vBar.setValue(palette.getS());

                    updateHSVValuesFromFields();
                    updatePixmaps();
                }
            });

    verticalBar = new VerticalChannelBar(VisUI.getSkin().get(ColorPickerStyle.class),
            VisUI.getSkin().get(com.kotcrab.vis.ui.Sizes.class), barTexture, 0, 360, new ChangeListener() {
                @Override
                public void changed(ChangeEvent event, Actor actor) {
                    hBar.setValue(verticalBar.getValue());
                    updateHSVValuesFromFields();
                    updatePixmaps();
                }
            });

    hBar = new ColorChannelWidget("H", 360, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            verticalBar.setValue(hBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int h = 0; h < 360; h++) {
                ColorUtils.HSVtoRGB(h, sBar.getValue(), vBar.getValue(), tmpColor);
                pixmap.drawPixel(h, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    sBar = new ColorChannelWidget("S", 100, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            palette.setValue(vBar.getValue(), sBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int s = 0; s < 100; s++) {
                ColorUtils.HSVtoRGB(hBar.getValue(), s, vBar.getValue(), tmpColor);
                pixmap.drawPixel(s, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    vBar = new ColorChannelWidget("V", 100, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            palette.setValue(vBar.getValue(), sBar.getValue());
            updateHSVValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int v = 0; v < 100; v++) {
                ColorUtils.HSVtoRGB(hBar.getValue(), sBar.getValue(), v, tmpColor);
                pixmap.drawPixel(v, 0, Color.rgba8888(tmpColor));
            }

        }
    });

    rBar = new ColorChannelWidget("R", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int r = 0; r < 255; r++) {
                tmpColor.set(r / 255.0f, color.g, color.b, 1);
                pixmap.drawPixel(r, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    gBar = new ColorChannelWidget("G", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int g = 0; g < 255; g++) {
                tmpColor.set(color.r, g / 255.0f, color.b, 1);
                pixmap.drawPixel(g, 0, Color.rgba8888(tmpColor));
            }
        }
    });

    bBar = new ColorChannelWidget("B", 255, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            updateRGBValuesFromFields();
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            for (int b = 0; b < 255; b++) {
                tmpColor.set(color.r, color.g, b / 255.0f, 1);
                pixmap.drawPixel(b, 0, Color.rgba8888(tmpColor));
            }

        }
    });

    aBar = new ColorChannelWidget("A", 255, true, new ColorChannelWidget.ColorChannelWidgetListener() {
        @Override
        public void updateFields() {
            if (aBar.isInputValid())
                color.a = aBar.getValue() / 255.0f;
            updatePixmaps();
        }

        @Override
        public void draw(Pixmap pixmap) {
            pixmap.fill();
            for (int i = 0; i < 255; i++) {
                tmpColor.set(color.r, color.g, color.b, i / 255.0f);
                pixmap.drawPixel(i, 0, Color.rgba8888(tmpColor));
            }
        }
    });
}

From source file:com.quadbits.gdxhelper.actors.ScreenDimActor.java

License:Apache License

@Inject
public ScreenDimActor() {
    super();/* w ww. java  2 s . c o  m*/

    // Create a 1x1 black pixmap and send it to the graphics card (create texture)
    Pixmap dimPixmap = new Pixmap(1, 1, Pixmap.Format.RGBA8888);
    dimPixmap.drawPixel(0, 0, Color.rgba8888(0, 0, 0, 1));
    dimTexture = new Texture(dimPixmap);
    dimPixmap.dispose();

    this.dimSprite = new Sprite(dimTexture);
    setSize(dimSprite.getWidth(), dimSprite.getHeight());
    alpha = 0;
}