pebble bitmap xor or mask?

243 views Asked by At

On the Pebble watch I am trying to overwrite a bitmap layer with text so the text is written white over black areas and black over white areas.

In other environments I would do this with an XOR operation, or create a mask and perform a couple of writes after masking out what I don't want overwritten. I don't see an XOR graphics operator or a mask operator in the Pebble graphics library.

How can this be done?

I'm using C and CloudPebble.

Lynd

1

There are 1 answers

0
user4268665 On

Here is a routine to do it. The text layer must be 'under' the graphic layer, then you use layer_set_update_proc() to set the update procedure for the graphic layer to the routine below.

static void bitmapLayerUpdate(struct Layer *layer, GContext *ctx){
  GBitmap *framebuffer;
  const GBitmap *graphic = bitmap_layer_get_bitmap((BitmapLayer *)layer);
  int height;
  uint32_t finalBits;
  uint32_t *bfr, *bitmap;

  framebuffer = graphics_capture_frame_buffer(ctx);
  if (framebuffer == NULL){
    APP_LOG(APP_LOG_LEVEL_DEBUG, "capture frame buffer failed!!");
  } else {
//    APP_LOG(APP_LOG_LEVEL_DEBUG, "capture frame buffer succeeded");
  }
  height = graphic->bounds.size.h;

  for (int yindex =0; yindex < height; yindex++){
    for ( unsigned int xindex = 0; xindex < (graphic->row_size_bytes); xindex+=4){
      bfr = (uint32_t*)((framebuffer->addr)+(yindex * framebuffer->row_size_bytes)+xindex);
      bitmap = (uint32_t*)((graphic->addr)+(yindex * graphic->row_size_bytes)+xindex);
      finalBits = *bitmap ^ *bfr;
      // APP_LOG(APP_LOG_LEVEL_DEBUG, "bfr: %0x, bitmsp: %0x, finalBits: %x", (unsigned int)bfr, (unsigned int)bitmap, finalBits );

      *bfr = finalBits;
    }
  }
  graphics_release_frame_buffer(ctx, framebuffer);
}