Search in sources :

Example 1 with CGBitmapContext

use of org.robovm.apple.coregraphics.CGBitmapContext in project playn by threerings.

the class RoboCanvas method fillText.

@Override
public Canvas fillText(TextLayout layout, float x, float y) {
    RoboGradient gradient = currentState().gradient;
    RoboTextLayout ilayout = (RoboTextLayout) layout;
    if (gradient == null) {
        ilayout.fill(bctx, x, y, fillColor);
    } else {
        // draw our text into a fresh context so we can use it as a mask for the gradient
        CGBitmapContext maskContext = RoboGraphics.createCGBitmap(texWidth, texHeight);
        maskContext.clearRect(new CGRect(0, 0, texWidth, texHeight));
        // scale the context based on our scale factor
        maskContext.scaleCTM(ctx.scale.factor, ctx.scale.factor);
        // fill the text into this temp context in white for use as a mask
        setFillColor(maskContext, 0xFFFFFFFF);
        ilayout.fill(maskContext, 0, 0, fillColor);
        // now fill the gradient, using our temp context as a mask
        bctx.saveGState();
        bctx.clipToMask(new CGRect(x, y, width, height), maskContext.toImage());
        gradient.fill(bctx);
        bctx.restoreGState();
        // finally free the temp context
        maskContext.dispose();
    }
    isDirty = true;
    return this;
}
Also used : CGBitmapContext(org.robovm.apple.coregraphics.CGBitmapContext) CGRect(org.robovm.apple.coregraphics.CGRect)

Example 2 with CGBitmapContext

use of org.robovm.apple.coregraphics.CGBitmapContext in project playn by threerings.

the class RoboGLContext method updateTexture.

void updateTexture(int tex, CGImage image) {
    int width = (int) image.getWidth(), height = (int) image.getHeight();
    if (width <= 0 || height <= 0) {
        platform.log().warn("Ignoring texture update for empty image (" + width + "x" + height + ").");
        return;
    }
    CGBitmapContext bctx = RoboGraphics.createCGBitmap(width, height);
    CGRect rect = new CGRect(0, 0, width, height);
    bctx.clearRect(rect);
    bctx.drawImage(rect, image);
    updateTexture(tex, width, height, bctx.getData());
    bctx.dispose();
}
Also used : CGBitmapContext(org.robovm.apple.coregraphics.CGBitmapContext) CGRect(org.robovm.apple.coregraphics.CGRect)

Example 3 with CGBitmapContext

use of org.robovm.apple.coregraphics.CGBitmapContext in project playn by threerings.

the class RoboAbstractImage method getRgb.

@Override
public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    if (width <= 0 || height <= 0)
        return;
    int bytesPerRow = 4 * width;
    CGBitmapContext context = CGBitmapContext.create(width, height, 8, bytesPerRow, CGColorSpace.createDeviceRGB(), // PremultipliedFirst for ARGB, same as BufferedImage in Java.
    new CGBitmapInfo(CGImageAlphaInfo.PremultipliedFirst.value()));
    // since we're fishing for authentic RGB data, never allow interpolation.
    context.setInterpolationQuality(CGInterpolationQuality.None);
    draw(context, 0, 0, width, height, startX, startY, width, height);
// TODO: extract data from context.getData()
// int x = 0;
// int y = height - 1; // inverted Y
// for (int px = 0; px < regionBytes.length; px += 4) {
//   int a = (int)regionBytes[px    ] & 0xFF;
//   int r = (int)regionBytes[px + 1] & 0xFF;
//   int g = (int)regionBytes[px + 2] & 0xFF;
//   int b = (int)regionBytes[px + 3] & 0xFF;
//   rgbArray[offset + y * scanSize + x] = a << 24 | r << 16 | g << 8 | b;
//   x++;
//   if (x == width) {
//     x = 0;
//     y--;
//   }
// }
}
Also used : CGBitmapContext(org.robovm.apple.coregraphics.CGBitmapContext) CGBitmapInfo(org.robovm.apple.coregraphics.CGBitmapInfo)

Aggregations

CGBitmapContext (org.robovm.apple.coregraphics.CGBitmapContext)3 CGRect (org.robovm.apple.coregraphics.CGRect)2 CGBitmapInfo (org.robovm.apple.coregraphics.CGBitmapInfo)1