Search code examples
pebble-sdk

Pebble Cloud SDK: How to force 8 bit images and not color palette?


I have a .png file that I have successfully uploaded to the Pebble Cloud SDK. If I mark the "memory format" as "best", everything works, but when I look at the pixels (to try to alter them programmatically), they use a 4 bit color palette. I would prefer not to use this.

I went back to my resource, and chose "8 bit" from the drop down menu, but now I get a compilation error:

"can't use more than two bits on a black-and-whiteplatform.". 

So, I un-targeted "aplite" as a platform, which I believe to be the black and white version. This gets me the new compilation error:

" error: 'RESOURCE_ID_SPIRO_BLACK_RED' undeclared (first use in this function)"

I'm assuming it's undeclared for "aplite", but the emulator I'm running is "chalk", so I'm not sure why it would care.

Can anyone explain the proper way to use the "8 bit" memory format? Or, more to the point, to avoid using color palettes at all?

My long-term objective is to take every non-black pixel in a simple image and change it to some random color. If I'm using a color palette, obviously this is not an option, unless I include all desired colors in the original image. (and even then, palettes currently hurt my brain. )

Edit: As a test, I made a version of my image with all 64 colors supported by Pebble. To my surprise, the image format flipped to 8 bit (in retrospect, the palettes can only support 16 different colors, so this makes sense). I'd still like to know a manual way to do this.


Solution

  • I'd suggest to use excellent library GBitmap-Colour-Palette-Manipulator. It has many useful functions, but the one you probably will be most interested in is (from the README.md):

    void replace_gbitmap_color(GColor color_to_replace, GColor replace_with_color, GBitmap *im, BitmapLayer *bml);
    

    This is function allows you to pass in a gbitmap, the color you want to replace and the target color. You also pass your BitmapLayer to this function so that it can automatically be marked dirty. This is an all in one function; it replaces the specified color and automatically updates the BitmapLayer. Pass NULL to *bml if you do not want to update a BitmapLayer (useful for gbitmaps on your action bar).

    Library let's you concentrate on your project code and takes care of low-level details. I've successfully used it in my "Big Flip Clock" watchface which was originally Aplite/bw but was easily converted to PT/Color using this library.