Ticket Created
over 4 years ago

WERETECH-9645

BufferedBitmap palette changes bitmap palette order depending on how you load an image...

Steps to reproduce:

1. Using a method as per the two scenarios below, try to load a two colour image (drawn in black and white) and set colours to fgCol and bgCol (Graphics.COLOR_ constants of your choosing).

EXPECTED RESULTS:

The image should ALWAYS replace Graphics.COLOR_BLACK in the loaded image with fgCol value and Graphics.COLOR_WHITE in the loaded image with bgCol - REGARDLESS OF WHICH METHOD IS USED.

ACTUAL RESULTS

When loaded via :bitmapResource, the palette order is unreliable and often swaps colours - presumably based on palette order in the underlying image.

EG: Loaded via :bitmapResource gets this:

But loaded via .drawBitmap gets this:

// SCENARIO 1
	// Attempts to load two colour background image and set palette to match fgCol and bgCol
	function getBgInPalette(fgCol,bgCol) {
		var toLoad = WatchUi.loadResource(Rez.Drawables.Background);
		var result;
		if(G has :BufferedBitmap) {
	    	result = new G.BufferedBitmap( 
	    			{:width=>w,
	                 :height=>h,
// Comment out :bitmapResource as will load via drawBitmap	                 
//	                 :bitmapResource=>toLoad,
	                 :palette=>[Graphics.COLOR_BLACK,
	                            Graphics.COLOR_WHITE]});       // create an off-screen buffer with a palette of two colors
	        result.getDc().drawBitmap(0,0,toLoad);
    		result.setPalette([fgCol,bgCol]);
    	} else {
    		result = toLoad;
    	}
    	return result;
	}
// SCENARIO 2
	// Attempts to load two colour background image and set palette to match fgCol and bgCol
	function getBgInPalette(fgCol,bgCol) {
		var toLoad = WatchUi.loadResource(Rez.Drawables.Background);
		var result;
		if(G has :BufferedBitmap) {
	    	result = new G.BufferedBitmap( 
	    			{:width=>w,
	                 :height=>h,
	                 :bitmapResource=>toLoad,
	                 :palette=>[Graphics.COLOR_BLACK,
	                            Graphics.COLOR_WHITE]});       // create an off-screen buffer with a palette of two colors
// Comment out drawBitmap as loaded via :bitmapResource
//	        result.getDc().drawBitmap(0,0,toLoad);
    		result.setPalette([fgCol,bgCol]);
    	} else {
    		result = toLoad;
    	}
    	return result;
	}

  • Hi, I apologize about responding so late. A ticket had been created and this has been getting looked into. 

    I did some testing of my own and it seems like using :bitmapResource=toLoad is dependent on the order in which the colors appear in the original image resource file. I created two background images with only black and white and reversed from one another and attempted all the combinations of using :bitmapResource, .drawBitmap and swapping the COLOR_BLACK and COLOR_WHITE in the bufferedbitmap palette and these were my results with fgCol being white and bgCol being blue. 

    background has black first and white second
    background2 has white first and black second
    
    background drawbitmap = blue background, white foreground
    background drawbitmap = white background, blue foreground
    background bitmapresource = white background, blue foreground
    background bitmapresource swapped palette = white background, blue foreground
    
    Background2 drawbitmap = white background, blue foreground
    bacckground2 drawbitmap swapped palette = blue background, white foreground
    background2 bitmapresource = blue background, white foreground
    background 2 bitmapresource swapped palette blue background, white foreground