Trying to mask APNG background with text

青春壹個敷衍的年華 提交于 2019-12-25 09:58:23

问题


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)

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:


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:

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.



来源:https://stackoverflow.com/questions/29154768/trying-to-mask-apng-background-with-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!