I am wondering if you could help me complete an update to the dayworld map watch face. I am using David Gianforte's applite code and updating for basalt. My goal is to show the day image and when it is night to show the night image. David's code already loops through each pixel in the picture to set night pixels to black. I am very close but I am getting a garbled up image instead of night. Here is my code, any thoughts?
//put frame buffer here
//taken from http://codecorner.galanter.net/2015/03/20/pebble-time-draw-transparent-text-over-color-bitmap-background/
GBitmap *fb = graphics_capture_frame_buffer_format(ctx, GBitmapFormat8Bit);
uint8_t *fb_data = gbitmap_get_data(fb);
uint8_t *background_data = gbitmap_get_data(gbitmap_create_with_resource(RESOURCE_ID_NIGHT_PBL));
#define WINDOW_WIDTH 144
uint8_t (*fb_matrix)[WINDOW_WIDTH] = (uint8_t (*)[WINDOW_WIDTH]) fb_data;
uint8_t (*background_matrix)[WINDOW_WIDTH] = (uint8_t (*)[WINDOW_WIDTH]) background_data;
loop through x/y cordinates and if night{
fb_matrix[y][x] = background_matrix[y][x]; //This seems to be error
}
The background is perfect and the curve is in correct place but it does not accurately reflect the night image but looks like random static. Image is 144x72.
For what it is worth, here is the original code for a black and white image to flip color when if statement is true...
if ((angle < 0) ^ (0x1 & (((char *)world_bitmap->addr)[byte] >> (x % 8)))) {
// white pixel
((char *)image.addr)[byte] = ((char *)image.addr)[byte] | (0x1 << (x % 8));
} else {
// black pixel
((char *)image.addr)[byte] = ((char *)image.addr)[byte] & ~(0x1 << (x % 8));
}
At build time, the Pebble SDK tries to produce the smallest possible GBitmap
for each input image you provide in your appinfo.json
to save precious RAM at runtime. Even when running on Basalt this could mean that you end up fewer bits per pixel (e.g. GBitmapFormat4BitPalette
) where each byte on your background_data
could represent multiple pixels so that pixels don't necessarily start at byte-boundaries. You can use gbitmap_get_format()
to verify this.
If this is the reason for your problem, the simplest way (at the cost of more RAM consumption) for you would be to enforce GBitmapFormat8Bit
as your GBitmap
format by specifying pbi8
in your appinfo.json
, e.g.
"media": [
{
"type": "PBI8",
"name": "NIGHT_PBL",
"file": "night_globe.png"
}
]
This will produce a GBitmapFormat8Bit
output on Basalt and GBitmapFormat1Bit
(as before) on Aplite. Please note that you can still use the suffixes ~bw
and ~color
as described in "Platform-specific Resources" on the 3.0 migration guide to select different input files.
Also, try to avoid hard-coded numbers in your code. Instead of 144
use gbitmap_get_bounds().size.w
on fb_data
and background_data
.