0

I am taking Pebble example of working with APNG and trying to mask it with transparent text, so bitmap will show only thru text, but no matter what mask/composite mode I try, bitmap is shown as black-and-white (original animation is in color and shows in color if I don't draw text)

enter image description here

Here's a sample code I use in callback SP for the layer that draws text:

//creating background and text
graphics_context_set_fill_color(ctx, GColorBlack);
graphics_fill_rect(ctx, GRect(0, 0, 144, 168), 0, GCornerNone);
graphics_context_set_text_color(ctx, GColorWhite);
graphics_draw_text(ctx, "08:39", fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49), GRect(0,50,144,118), GTextOverflowModeFill, GTextAlignmentCenter, NULL);

//drawing bitmap (extracted from bitmap_sequence elsewhere) 
graphics_context_set_compositing_mode(ctx, GCompOpClear);
graphics_draw_bitmap_in_rect(ctx, s_bitmap, GRect(0,0,144,168));

Any idea how to have actual color bitmap to show thru?

1 Answer 1

1

Ok, I finally managed it but not sure if this is the best way. I basically capture framebuffer of current layer and then loop thru every pixel, copying there source bitmap byte by byte, but only when white pixels are encountered:

enter image description here

GBitmap *fb = graphics_capture_frame_buffer_format(ctx, GBitmapFormat8Bit);

uint8_t *fb_data =  gbitmap_get_data(fb);
uint8_t *anim_data =  gbitmap_get_data(s_bitmap);

for (int i=0; i < 144*168; i++) {
    if (fb_data[i] == 255) {
       fb_data[i] = anim_data[i];
    }
}

This can be optimized too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.