Java 类com.badlogic.gdx.graphics.Pixmap.Blending 实例源码

项目:teavm-libgdx    文件:PixmapEmulator.java   
private void circle(int x, int y, int radius, DrawType drawType) {
    if (blending == Blending.None) {
        context.setFillStyle(clearColor);
        context.setStrokeStyle(clearColor);
        context.setGlobalCompositeOperation("clear");
        context.beginPath();
        context.arc(x, y, radius, 0, 2 * Math.PI, false);
        fillOrStrokePath(drawType);
        context.closePath();
        context.setFillStyle(color);
        context.setStrokeStyle(color);
        context.setGlobalCompositeOperation("source-over");
    }
    context.beginPath();
    context.arc(x, y, radius, 0, 2 * Math.PI, false);
    fillOrStrokePath(drawType);
    context.closePath();
    pixels = null;
}
项目:teavm-libgdx    文件:PixmapEmulator.java   
private void line(int x, int y, int x2, int y2, DrawType drawType) {
    if (blending == Blending.None) {
        context.setFillStyle(clearColor);
        context.setStrokeStyle(clearColor);
        context.setGlobalCompositeOperation("clear");
        context.beginPath();
        context.moveTo(x, y);
        context.lineTo(x2, y2);
        fillOrStrokePath(drawType);
        context.closePath();
        context.setFillStyle(color);
        context.setStrokeStyle(color);
        context.setGlobalCompositeOperation("source-over");
    }
    context.beginPath();
    context.moveTo(x, y);
    context.lineTo(x2, y2);
    fillOrStrokePath(drawType);
    context.closePath();
}
项目:teavm-libgdx    文件:PixmapEmulator.java   
private void rectangle(int x, int y, int width, int height, DrawType drawType) {
    if (blending == Blending.None) {
        context.setFillStyle(clearColor);
        context.setStrokeStyle(clearColor);
        context.setGlobalCompositeOperation("clear");
        context.beginPath();
        context.rect(x, y, width, height);
        fillOrStrokePath(drawType);
        context.closePath();
        context.setFillStyle(color);
        context.setStrokeStyle(color);
        context.setGlobalCompositeOperation("source-over");
    }
    context.beginPath();
    context.rect(x, y, width, height);
    fillOrStrokePath(drawType);
    context.closePath();
    pixels = null;
}
项目:teavm-libgdx    文件:PixmapEmulator.java   
private void triangle(int x1, int y1, int x2, int y2, int x3, int y3, DrawType drawType) {
    if (blending == Blending.None) {
        context.setFillStyle(clearColor);
        context.setStrokeStyle(clearColor);
        context.setGlobalCompositeOperation("clear");
        context.beginPath();
        context.moveTo(x1, y1);
        context.lineTo(x2, y2);
        context.lineTo(x3, y3);
        context.lineTo(x1, y1);
        fillOrStrokePath(drawType);
        context.closePath();
        context.setFillStyle(color);
        context.setStrokeStyle(color);
        context.setGlobalCompositeOperation("source-over");
    }
    context.beginPath();
    context.moveTo(x1, y1);
    context.lineTo(x2, y2);
    context.lineTo(x3, y3);
    context.lineTo(x1, y1);
    fillOrStrokePath(drawType);
    context.closePath();
    pixels = null;
}
项目:libgdxcn    文件:FacedCubemapData.java   
@Override
public void consumeCubemapData () {
    for (int i = 0; i < data.length; i++) {
        if (data[i].getType() == TextureData.TextureDataType.Custom) {
            data[i].consumeCustomData(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i);
        } else {
            Pixmap pixmap = data[i].consumePixmap();
            boolean disposePixmap = data[i].disposePixmap();
            if (data[i].getFormat() != pixmap.getFormat()) {
                Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data[i].getFormat());
                Blending blend = Pixmap.getBlending();
                Pixmap.setBlending(Blending.None);
                tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
                Pixmap.setBlending(blend);
                if (data[i].disposePixmap()) pixmap.dispose();
                pixmap = tmp;
                disposePixmap = true;
            }
            Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
            Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(),
                pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
        }
    }
}
项目:libgdxcn    文件:MipMapGenerator.java   
private static void generateMipMapCPU (int target, Pixmap pixmap, int textureWidth, int textureHeight) {
    Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0,
        pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
    if ((Gdx.gl20 == null) && textureWidth != textureHeight)
        throw new GdxRuntimeException("texture width and height must be square when using mipmapping.");
    int width = pixmap.getWidth() / 2;
    int height = pixmap.getHeight() / 2;
    int level = 1;
    Blending blending = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);
    while (width > 0 && height > 0) {
        Pixmap tmp = new Pixmap(width, height, pixmap.getFormat());
        tmp.drawPixmap(pixmap, 0, 0, pixmap.getWidth(), pixmap.getHeight(), 0, 0, width, height);
        if (level > 1) pixmap.dispose();
        pixmap = tmp;

        Gdx.gl.glTexImage2D(target, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0,
            pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());

        width = pixmap.getWidth() / 2;
        height = pixmap.getHeight() / 2;
        level++;
    }
    Pixmap.setBlending(blending);
}
项目:BASToD    文件:SpriteManager.java   
private Texture initArmorLeft(int step, Color c) {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    int sqs = engine.getGridSquareSize();

    Pixmap p = new Pixmap(sqs, sqs + 4, Pixmap.Format.RGBA8888);
    p.setColor(c);

    //p.drawRectangle(0, 0, sqs, 3);

    int w = step * sqs / armorLeftStep;
    p.fillRectangle(0, 0, w, 3);

    Texture t = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

    return t;
}
项目:BASToD    文件:SingleScoreBar.java   
@Override
public Texture updateComponent() {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
    Color c1 = GUIResources.getInstance().getColor(player.getColor()).cpy();
    c1.a = 1f;
    p.setColor(c1);

    p.drawRectangle(0, 0, getWidth(), getHeight());

    c1.a = 0.5f;
    p.setColor(c1);
    int w = player.getScore() * (getWidth() - 2) / player.getMaxScore();
    p.fillRectangle(1, 1, w, getHeight() - 2);

    str = Integer.toString(player.getScore());

    Texture t = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

    return t;
}
项目:nvlist    文件:PixmapUtil.java   
/**
 * Takes a sub-rect {@code srcRect} from {@code src} and copies it to a sub-rect {@code dstRect} in {@code dst}.
 *
 * @param filter Determines which type of interpolation to use if the src/dst rects are a different size.
 */
public static void copySubRect(Pixmap src, Rect srcRect, Pixmap dst, Rect dstRect, Filter filter) {
    Blending oldBlend = dst.getBlending();
    Filter oldFilter = Filter.BiLinear;
    try {
        dst.setBlending(Blending.None);
        dst.setFilter(filter);

        dst.drawPixmap(src, srcRect.x, srcRect.y, srcRect.w, srcRect.h,
                dstRect.x, dstRect.y, dstRect.w, dstRect.h);
    } finally {
        dst.setBlending(oldBlend);
        dst.setFilter(oldFilter);
    }
}
项目:libgdxcn    文件:GLTexture.java   
public static void uploadImageData (int target, TextureData data, int miplevel) {
    if (data == null) {
        // FIXME: remove texture on target?
        return;
    }

    if (!data.isPrepared()) data.prepare();

    final TextureDataType type = data.getType();
    if (type == TextureDataType.Custom) {
        data.consumeCustomData(target);
        return;
    }

    Pixmap pixmap = data.consumePixmap();
    boolean disposePixmap = data.disposePixmap();
    if (data.getFormat() != pixmap.getFormat()) {
        Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), data.getFormat());
        Blending blend = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);
        tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
        Pixmap.setBlending(blend);
        if (data.disposePixmap()) {
            pixmap.dispose();
        }
        pixmap = tmp;
        disposePixmap = true;
    }

    Gdx.gl.glPixelStorei(GL20.GL_UNPACK_ALIGNMENT, 1);
    if (data.useMipMaps()) {
        MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight());
    } else {
        Gdx.gl.glTexImage2D(target, miplevel, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0,
            pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
    }
    if (disposePixmap) pixmap.dispose();
}
项目:libgdxcn    文件:FreeType.java   
/**
 * @return Pixmap representing the glyph, needs to be disposed manually.
 */
public Pixmap getPixmap(Format format) {
    Pixmap pixmap = new Pixmap(getWidth(), getRows(), Format.Alpha);
    BufferUtils.copy(getBuffer(), pixmap.getPixels(), pixmap.getPixels().capacity());
    Pixmap converted = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), format);
    Blending blending = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);
    converted.drawPixmap(pixmap, 0, 0);
    Pixmap.setBlending(blending);
    pixmap.dispose();
    return converted;
}
项目:ead    文件:BrushStrokes.java   
public void show(ModelEntity imageEntity) {
    if (!hasParent()) {
        container.addActor(this);
        Pixmap.setBlending(Blending.None);
        controller.getCommands().pushStack(MAX_COMMANDS);
        setBounds(0, 0, container.getWidth(), container.getHeight());
        mesh.initializeRenderingResources();
        setMode(Mode.DRAW);

        if (imageEntity != null) {
            toEdit = imageEntity;
            Gdx.app.postRunnable(editImage);
        }
    }
}
项目:ead    文件:BrushStrokes.java   
/**
 * Clears undo/redo history and invokes {@link MeshHelper#release()}.
 * 
 * @param release
 */
public void hide(boolean release) {
    if (hasParent()) {
        Pixmap.setBlending(Blending.SourceOver);
        remove();
        if (release) {
            release();
        }
        controller.getCommands().popStack(false);
    }
}
项目:BASToD    文件:OverlayManager.java   
public void renderDebugLoS(Vector pos) {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Dimension dimG = engine.getGridDimension();
    Dimension dimB = engine.getBoardDimension();
    Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888);

    Color ok = Color.GREEN;
    ok.a = 0.2f;
    Color nok = Color.ORANGE;
    nok.a = 0.2f;

    for (int x= 0; x < dimG.getW(); x++) {
        for (int y= 0; y < dimG.getH(); y++) {
            Vector v = new Vector(x, y);
            if (engine.lineOfSight(pos, v)) {
                drawTintedSquare(p, ok, engine.fromGridToBoard(v));
            } else {
                drawTintedSquare(p, nok, engine.fromGridToBoard(v));
            }
        }
    }

    Texture debug = new Texture(p);
    p.dispose();

    Pixmap.setBlending(bck);

    batchBegin();
    draw(debug, Engine._SP_SIDE, Engine._SP_BOTTOM);
    batchEnd();

    debug.dispose();
}
项目:BASToD    文件:OverlayManager.java   
public void renderBuildPositions() {
    if (buildPositions == null) {
        Dimension dimB = engine.getBoardDimension();

        Blending bck = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);

        Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888);

        for (Player player : engine.getPlayers()) {
            Color c = GUIResources.getInstance().getColor(player.getColor()).cpy();
            c.a = 0.2f;

            List<Vector> pos = engine.getBuildPositions(player);
            if (pos != null) {
                for (Vector v : pos) {
                    if ((Engine.PRECOMPUTE_OPEN_BUILD_POSITIONS && engine.isOpenedBuildPosition(v)) || (engine.isOpenedOnGrid(v))) {
                        Vector vb = engine.fromGridToBoard(v);
                        drawTintedSquare(p, c, vb);
                    }
                }
            }
        }

        buildPositions = new Texture(p);
        p.dispose();

        Pixmap.setBlending(bck);
    }

    batchBegin();
    draw(buildPositions, Engine._SP_SIDE, Engine._SP_BOTTOM);
    batchEnd();
}
项目:BASToD    文件:OverlayManager.java   
public void renderGrid() {
    if (grid == null) {
        Dimension dimG = engine.getGridDimension();
        Dimension dimB = engine.getBoardDimension();
        int sqs = engine.getGridSquareSize();

        Blending bck = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);

        Pixmap p = new Pixmap(dimB.getW() + 1, dimB.getH() + 1, Pixmap.Format.RGBA8888);
        Color c = Color.WHITE.cpy();
        c.a = 0.2f;
        p.setColor(c);

        for (int x = 0; x <= dimG.getW(); x++) {
            int bx = x * sqs;
            p.drawLine(bx, 0, bx, dimB.getH() - 1);
        }
        for (int y = 0; y <= dimG.getH(); y++) {
            int by = y * sqs;
            p.drawLine(0, by, dimB.getW() - 1, by);
        }

        grid = new Texture(p);
        p.dispose();

        Pixmap.setBlending(bck);
    }

    batchBegin();
    draw(grid, Engine._SP_SIDE, Engine._SP_BOTTOM);
    batchEnd();
}
项目:BASToD    文件:OverlayManager.java   
public void renderUnitOverlay(Unit selected) {
    if (selected != null) {
        if (selected instanceof Tower) {
            int shotRange = (int) (((Tower) selected).getRangeOnBoard());
            String k = selected.getPlayer().getColor() + "-" + shotRange;

            if (!towerRanges.containsKey(k)) {
                int gfxSize = shotRange * 2;

                Blending bck = Pixmap.getBlending();
                Pixmap.setBlending(Blending.None);

                Pixmap p = new Pixmap(gfxSize, gfxSize, Pixmap.Format.RGBA8888);
                Color c = GUIResources.getInstance().getColor(selected.getPlayer().getColor()).cpy();
                c.a = 0.2f;
                p.setColor(c);
                p.fillCircle(shotRange, shotRange, shotRange);
                Texture t = new Texture(p);
                p.dispose();
                Pixmap.setBlending(bck);
                towerRanges.put(k, t);
            }

            batchBegin();
            draw(towerRanges.get(k), Engine._SP_SIDE + selected.getPositionOnBoard().getX() - shotRange, Engine._SP_BOTTOM + selected.getPositionOnBoard().getY() - shotRange);
            batchEnd();
        }
    }
}
项目:BASToD    文件:UnitInfoBox.java   
public UnitInfoBox(Unit u) {
    super(u.getName() + "-InfoBox", -1, -1, 200, 100);
    this.unit = u;

    setNeedUpdate(false);
    font = GUIResources.getInstance().getFont(INFOBOX_FONT);

    moveTo(u.getPositionOnBoard().getXInt(), u.getPositionOnBoard().getYInt());

    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
    Color c1 = Color.YELLOW;
    c1.a = 1f;
    p.setColor(c1);

    p.drawRectangle(0, 0, getWidth(), getHeight());

    c1 = Color.BLACK;
    c1.a = 0.5f;
    p.setColor(c1);

    p.fillRectangle(1, 1, getWidth() - 2, getHeight() - 2);

    setBackground(new Texture(p));
    p.dispose();
    Pixmap.setBlending(bck);
}
项目:BASToD    文件:DualScoreBar.java   
@Override
public Texture updateComponent() {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
    Color c = GUIResources.getInstance().getColor(GUIResources.WHITE);

    Color c1 = GUIResources.getInstance().getColor(player1.getColor()).cpy();
    c1.a = 0.5f;
    Color c2 = GUIResources.getInstance().getColor(player2.getColor()).cpy();
    c2.a = 0.5f;

    int w = player1.getScore() * (getWidth() - 2) / (player1.getScore() + player2.getScore());

    p.setColor(c1);
    p.fillRectangle(1, 1, w, getHeight() - 2);

    p.setColor(c2);
    p.fillRectangle(w + 1, 1, getWidth() - 2 - w, getHeight() - 2);

    p.setColor(c);
    p.drawRectangle(0, 0, getWidth(), getHeight());

    str1 = Integer.toString(player1.getScore());
    str2 = Integer.toString(player2.getScore());

    Texture t = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

    return t;
}
项目:BASToD    文件:MetalBar.java   
@Override
public Texture updateComponent() {
    Blending bck = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);

    Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
    Color c1 = GUIResources.getInstance().getColor(player.getColor()).cpy();
    c1.a = 1f;
    p.setColor(c1);

    p.drawRectangle(0, 0, getWidth(), getHeight());

    c1.a = 0.5f;
    p.setColor(c1);
    int w = player.getMetal() * (getWidth() - 2) / player.getMaxMetal();
    p.fillRectangle(1, 1, w, getHeight() - 2);

    strMetal = "$ " + player.getMetal();
    strDeltaA = df.format(player.getMetalAddedMean(engine.getNow()));
    strDeltaR = df.format(-1 * player.getMetalRemovedMean(engine.getNow()));

    Texture t = new Texture(p);
    p.dispose();
    Pixmap.setBlending(bck);

    return t;
}
项目:BASToD    文件:AbstractComponent.java   
@Override
    public void start() {
        super.start();
        lastUpdateTime = 0;


        Blending bck = Pixmap.getBlending();
        Pixmap.setBlending(Blending.None);

        Pixmap p = new Pixmap(getWidth(), getHeight(), Pixmap.Format.RGBA8888);
        Color c1 = Color.BLACK.cpy();
        c1.a = 0.8f;
        p.setColor(c1);
        p.fillRectangle(0, 0, getWidth(), getHeight());


//      p.setColor(Color.WHITE);
//      int step = 8;
//      for (int d = 0; d < w; d += step) {
//          p.drawLine(x + d, h, 0, h - d);
//          p.drawLine(x + d, h - w, w, h - d);
//          p.drawLine(x + d, h, w, h - w + d);
//          p.drawLine(x + d, h - w, 0, h - w + d);
//      }

        disabled = new Texture(p);
        p.dispose();
        Pixmap.setBlending(bck);

    }
项目:ingress-indonesia-dev    文件:MipMapGenerator.java   
private static void generateMipMapCPU(Pixmap paramPixmap, int paramInt1, int paramInt2, boolean paramBoolean)
{
  Gdx.gl.glTexImage2D(3553, 0, paramPixmap.getGLInternalFormat(), paramPixmap.getWidth(), paramPixmap.getHeight(), 0, paramPixmap.getGLFormat(), paramPixmap.getGLType(), paramPixmap.getPixels());
  if ((Gdx.gl20 == null) && (paramInt1 != paramInt2))
    throw new GdxRuntimeException("texture width and height must be square when using mipmapping.");
  int i = paramPixmap.getWidth() / 2;
  int j = paramPixmap.getHeight() / 2;
  Pixmap.Blending localBlending = Pixmap.getBlending();
  Pixmap.setBlending(Pixmap.Blending.None);
  int k = 1;
  Pixmap localPixmap;
  for (Object localObject = paramPixmap; (i > 0) && (j > 0); localObject = localPixmap)
  {
    localPixmap = new Pixmap(i, j, ((Pixmap)localObject).getFormat());
    localPixmap.drawPixmap((Pixmap)localObject, 0, 0, ((Pixmap)localObject).getWidth(), ((Pixmap)localObject).getHeight(), 0, 0, i, j);
    if ((k > 1) || (paramBoolean))
      ((Pixmap)localObject).dispose();
    GLCommon localGLCommon = Gdx.gl;
    int m = localPixmap.getGLInternalFormat();
    int n = localPixmap.getWidth();
    int i1 = localPixmap.getHeight();
    int i2 = localPixmap.getGLFormat();
    int i3 = localPixmap.getGLType();
    ByteBuffer localByteBuffer = localPixmap.getPixels();
    localGLCommon.glTexImage2D(3553, k, m, n, i1, 0, i2, i3, localByteBuffer);
    i = localPixmap.getWidth() / 2;
    j = localPixmap.getHeight() / 2;
    k++;
  }
  Pixmap.setBlending(localBlending);
}
项目:gdx-texture-packer-gui    文件:FreeType.java   
public Pixmap getPixmap (Format format, Color color, float gamma) {
    int width = getWidth(), rows = getRows();
    ByteBuffer src = getBuffer();
    Pixmap pixmap;
    int pixelMode = getPixelMode();
    int rowBytes = Math.abs(getPitch()); // We currently ignore negative pitch.
    if (color == Color.WHITE && pixelMode == FT_PIXEL_MODE_GRAY && rowBytes == width && gamma == 1) {
        pixmap = new Pixmap(width, rows, Format.Alpha);
        BufferUtils.copy(src, pixmap.getPixels(), pixmap.getPixels().capacity());
    } else {
        pixmap = new Pixmap(width, rows, Format.RGBA8888);
        int rgba = Color.rgba8888(color);
        byte[] srcRow = new byte[rowBytes];
        int[] dstRow = new int[width];
        IntBuffer dst = pixmap.getPixels().asIntBuffer();
        if (pixelMode == FT_PIXEL_MODE_MONO) {
            // Use the specified color for each set bit.
            for (int y = 0; y < rows; y++) {
                src.get(srcRow);
                for (int i = 0, x = 0; x < width; i++, x += 8) {
                    byte b = srcRow[i];
                    for (int ii = 0, n = Math.min(8, width - x); ii < n; ii++) {
                        if ((b & (1 << (7 - ii))) != 0)
                            dstRow[x + ii] = rgba;
                        else
                            dstRow[x + ii] = 0;
                    }
                }
                dst.put(dstRow);
            }
        } else {
            // Use the specified color for RGB, blend the FreeType bitmap with alpha.
            int rgb = rgba & 0xffffff00;
            int a = rgba & 0xff;
            for (int y = 0; y < rows; y++) {
                src.get(srcRow);
                for (int x = 0; x < width; x++) {
                    float alpha = (srcRow[x] & 0xff) / 255f;
                    alpha = (float)Math.pow(alpha, gamma); // Inverse gamma.
                    dstRow[x] = rgb | (int)(a * alpha);
                }
                dst.put(dstRow);
            }
        }
    }

    Pixmap converted = pixmap;
    if (format != pixmap.getFormat()) {
        converted = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), format);
        converted.setBlending(Blending.None);
        converted.drawPixmap(pixmap, 0, 0);
        pixmap.dispose();
    }
    return converted;
}
项目:gdx-freetype-gwt    文件:FreeType.java   
public Pixmap getPixmap (Format format, Color color, float gamma) {
    int width = getWidth(), rows = getRows();
    ByteBuffer src = getBuffer();
    FreeTypePixmap pixmap;
    ByteBuffer changedPixels;
    int pixelMode = getPixelMode();
    int rowBytes = Math.abs(getPitch()); // We currently ignore negative pitch.
    if (color == Color.WHITE && pixelMode == FT_PIXEL_MODE_GRAY && rowBytes == width && gamma == 1) {
        pixmap = new FreeTypePixmap(width, rows, Format.Alpha);
        changedPixels = pixmap.getRealPixels();
        BufferUtils.copy(src, changedPixels, pixmap.getRealPixels().capacity());
    } else {
        pixmap = new FreeTypePixmap(width, rows, Format.RGBA8888);
        int rgba = Color.rgba8888(color);
        byte[] srcRow = new byte[rowBytes];
        int[] dstRow = new int[width];
        changedPixels = pixmap.getRealPixels();
        IntBuffer dst = changedPixels.asIntBuffer();
        if (pixelMode == FT_PIXEL_MODE_MONO) {
            // Use the specified color for each set bit.
            for (int y = 0; y < rows; y++) {
                src.get(srcRow);
                for (int i = 0, x = 0; x < width; i++, x += 8) {
                    byte b = srcRow[i];
                    for (int ii = 0, n = Math.min(8, width - x); ii < n; ii++) {
                        if ((b & (1 << (7 - ii))) != 0)
                            dstRow[x + ii] = rgba;
                        else
                            dstRow[x + ii] = 0;
                    }
                }
                dst.put(dstRow);
            }
        } else {
            // Use the specified color for RGB, blend the FreeType bitmap with alpha.
            int rgb = rgba & 0xffffff00;
            int a = rgba & 0xff;
            for (int y = 0; y < rows; y++) {
                src.get(srcRow);
                for (int x = 0; x < width; x++) {
                    float alpha;

                    // Zero raised to any power is always zero.
                    // 255 (=one) raised to any power is always one
                    // This means that we only have to calculate Math.pow() when alpha is NOT zero and NOT one
                    if ((srcRow[x] & 0xff) == 0) {
                        alpha = 0f;
                    } else if ((srcRow[x] & 0xff) == 255) {
                        alpha = 1f;
                    } else {
                        alpha = (float)Math.pow(((srcRow[x] & 0xff) / 255f), gamma); // Inverse gamma.
                    }
                    dstRow[x] = rgb | (int)(a * alpha);
                }
                dst.put(dstRow);
            }
        }
    }

    pixmap.putPixelsBack(changedPixels);
    pixmap.setPixelsNull();
    Pixmap p = pixmap;

    Pixmap converted = pixmap;
    if (pixmap.getFormat() != null && format != pixmap.getFormat()) {
        converted = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), format);
        pixmap.setBlending(Blending.None);
        converted.drawPixmap(pixmap, 0, 0);
        pixmap.dispose();
    }
    return converted;
}
项目:teavm-libgdx    文件:PixmapEmulator.java   
public static void setBlending(Blending blending) {
    PixmapEmulator.blending = blending;
    for (PixmapEmulator pixmap : pixmaps.values()) {
        pixmap.context.setGlobalCompositeOperation("source-over");
    }
}
项目:teavm-libgdx    文件:PixmapEmulator.java   
public static Blending getBlending() {
    return blending;
}
项目:libgdxcn    文件:PixmapPacker.java   
/** <p>
 * Inserts the given {@link Pixmap}. You can later on retrieve the images position in the output image via the supplied name
 * and the method {@link #getRect(String)}.
 * </p>
 * 
 * @param name the name of the image
 * @param image the image
 * @return Rectangle describing the area the pixmap was rendered to or null.
 * @throws RuntimeException in case the image did not fit due to the page size being to small or providing a duplicate name */
public synchronized Rectangle pack (String name, Pixmap image) {
    if (disposed) return null;
    if (getRect(name) != null) throw new RuntimeException("Key with name '" + name + "' is already in map");
    int borderPixels = padding + (duplicateBorder ? 1 : 0);
    borderPixels <<= 1;

    Rectangle rect = new Rectangle(0, 0, image.getWidth() + borderPixels, image.getHeight() + borderPixels);
    if (rect.getWidth() > pageWidth || rect.getHeight() > pageHeight)
        throw new GdxRuntimeException("page size for '" + name + "' to small");

    Node node = insert(currPage.root, rect);

    if (node == null) {
        newPage();
        return pack(name, image);
    }

    node.leaveName = name;
    rect = new Rectangle(node.rect);
    rect.width -= borderPixels;
    rect.height -= borderPixels;
    borderPixels >>= 1;
    rect.x += borderPixels;
    rect.y += borderPixels;
    currPage.rects.put(name, rect);

    Blending blending = Pixmap.getBlending();
    Pixmap.setBlending(Blending.None);
    this.currPage.image.drawPixmap(image, (int)rect.x, (int)rect.y);

    if (duplicateBorder) {
        int imageWidth = image.getWidth();
        int imageHeight = image.getHeight();
        // Copy corner pixels to fill corners of the padding.
        this.currPage.image.drawPixmap(image, 0, 0, 1, 1, (int)rect.x - 1, (int)rect.y - 1, 1, 1);
        this.currPage.image.drawPixmap(image, imageWidth - 1, 0, 1, 1, (int)rect.x + (int)rect.width, (int)rect.y - 1, 1, 1);
        this.currPage.image.drawPixmap(image, 0, imageHeight - 1, 1, 1, (int)rect.x - 1, (int)rect.y + (int)rect.height, 1, 1);
        this.currPage.image.drawPixmap(image, imageWidth - 1, imageHeight - 1, 1, 1, (int)rect.x + (int)rect.width, (int)rect.y
            + (int)rect.height, 1, 1);
        // Copy edge pixels into padding.
        this.currPage.image.drawPixmap(image, 0, 0, imageWidth, 1, (int)rect.x, (int)rect.y - 1, (int)rect.width, 1);
        this.currPage.image.drawPixmap(image, 0, imageHeight - 1, imageWidth, 1, (int)rect.x, (int)rect.y + (int)rect.height,
            (int)rect.width, 1);
        this.currPage.image.drawPixmap(image, 0, 0, 1, imageHeight, (int)rect.x - 1, (int)rect.y, 1, (int)rect.height);
        this.currPage.image.drawPixmap(image, imageWidth - 1, 0, 1, imageHeight, (int)rect.x + (int)rect.width, (int)rect.y, 1,
            (int)rect.height);
    }

    Pixmap.setBlending(blending);

    currPage.addedRects.add(name);
    return rect;
}
项目:ingress-indonesia-dev    文件:PixmapPacker.java   
public Rectangle pack(String paramString, Pixmap paramPixmap)
{
  int i = 1;
  Object localObject2;
  try
  {
    boolean bool = this.disposed;
    if (bool)
    {
      localObject2 = null;
      return localObject2;
    }
    if (getRect(paramString) != null)
      throw new RuntimeException("Key with name '" + paramString + "' is already in map");
  }
  finally
  {
  }
  int j = this.padding;
  if (this.duplicateBorder);
  while (true)
  {
    int k = i + j << 1;
    if ((paramPixmap.getWidth() >= k + this.pageWidth) || (paramPixmap.getHeight() >= k + this.pageHeight))
      throw new GdxRuntimeException("page size for '" + paramString + "' to small");
    Rectangle localRectangle1 = new Rectangle(0.0F, 0.0F, k + paramPixmap.getWidth(), k + paramPixmap.getHeight());
    PixmapPacker.Node localNode = insert(this.currPage.root, localRectangle1);
    if (localNode == null)
    {
      newPage();
      localObject2 = pack(paramString, paramPixmap);
      break;
    }
    localNode.leaveName = paramString;
    Rectangle localRectangle2 = new Rectangle(localNode.rect);
    localRectangle2.width -= k;
    localRectangle2.height -= k;
    int m = k >> 1;
    localRectangle2.x += m;
    localRectangle2.y += m;
    this.currPage.rects.put(paramString, localRectangle2);
    Pixmap.Blending localBlending = Pixmap.getBlending();
    Pixmap.setBlending(Pixmap.Blending.None);
    this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x, (int)localRectangle2.y);
    Pixmap.setBlending(localBlending);
    if (this.duplicateBorder)
    {
      this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x, -1 + (int)localRectangle2.y, (int)localRectangle2.x + (int)localRectangle2.width, (int)localRectangle2.y, 0, 0, paramPixmap.getWidth(), 1);
      this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x, (int)localRectangle2.y + (int)localRectangle2.height, (int)localRectangle2.x + (int)localRectangle2.width, 1 + ((int)localRectangle2.y + (int)localRectangle2.height), 0, -1 + paramPixmap.getHeight(), paramPixmap.getWidth(), paramPixmap.getHeight());
      this.currPage.image.drawPixmap(paramPixmap, -1 + (int)localRectangle2.x, (int)localRectangle2.y, (int)localRectangle2.x, (int)localRectangle2.y + (int)localRectangle2.height, 0, 0, 1, paramPixmap.getHeight());
      this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x + (int)localRectangle2.width, (int)localRectangle2.y, 1 + ((int)localRectangle2.x + (int)localRectangle2.width), (int)localRectangle2.y + (int)localRectangle2.height, -1 + paramPixmap.getWidth(), 0, paramPixmap.getWidth(), paramPixmap.getHeight());
      this.currPage.image.drawPixmap(paramPixmap, -1 + (int)localRectangle2.x, -1 + (int)localRectangle2.y, (int)localRectangle2.x, (int)localRectangle2.y, 0, 0, 1, 1);
      this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x + (int)localRectangle2.width, -1 + (int)localRectangle2.y, 1 + ((int)localRectangle2.x + (int)localRectangle2.width), (int)localRectangle2.y, -1 + paramPixmap.getWidth(), 0, paramPixmap.getWidth(), 1);
      this.currPage.image.drawPixmap(paramPixmap, -1 + (int)localRectangle2.x, (int)localRectangle2.y + (int)localRectangle2.height, (int)localRectangle2.x, 1 + ((int)localRectangle2.y + (int)localRectangle2.height), 0, -1 + paramPixmap.getHeight(), 1, paramPixmap.getHeight());
      this.currPage.image.drawPixmap(paramPixmap, (int)localRectangle2.x + (int)localRectangle2.width, (int)localRectangle2.y + (int)localRectangle2.height, 1 + ((int)localRectangle2.x + (int)localRectangle2.width), 1 + ((int)localRectangle2.y + (int)localRectangle2.height), -1 + paramPixmap.getWidth(), -1 + paramPixmap.getHeight(), paramPixmap.getWidth(), paramPixmap.getHeight());
    }
    this.currPage.addedRects.add(paramString);
    localObject2 = localRectangle2;
    break;
    i = 0;
  }
}