Files
Maan-On-My-Wrist-XL/src/c/palette_manip.c
T
2026-03-10 16:53:11 -04:00

41 lines
1.2 KiB
C

// TAKEN FROM https://github.com/rebootsramblings/GBitmap-Colour-Palette-Manipulator
#include "palette_manip.h"
#ifdef PBL_COLOR
int get_num_palette_colors(GBitmap *b){
GBitmapFormat format = gbitmap_get_format(b);
switch (format) {
case GBitmapFormat1Bit: return 0;
case GBitmapFormat8Bit: return 0;
case GBitmapFormat1BitPalette: return 2;
case GBitmapFormat2BitPalette: return 4;
case GBitmapFormat4BitPalette: return 16;
default: return 0;
}
}
void replace_gbitmap_color(GColor color_to_replace, GColor replace_with_color, GBitmap *im, BitmapLayer *bml){
//First determine what the number of colors in the palette
int num_palette_items = get_num_palette_colors(im);
//Get the gbitmap's current palette
GColor *current_palette = gbitmap_get_palette(im);
//Iterate through the palette finding the color we want to replace and replacing
//it with the new color
for(int i = 0; i < num_palette_items; i++){
if ((color_to_replace.argb & 0x3F)==(current_palette[i].argb & 0x3F)){
current_palette[i].argb = (current_palette[i].argb & 0xC0)| (replace_with_color.argb & 0x3F);
}
}
//Mark the bitmaplayer dirty
if(bml != NULL){
layer_mark_dirty(bitmap_layer_get_layer(bml));
}
}
#endif