Hi
I've written a piece of code which shifts some RGB colour values four bits to the left. First it stores a backup of each RGB value just incase the shift results in a zero. If a zero is produced then the original values are restored. Here is that piece of code:
redStore = scratchPalette.red; // Save a backup of the Red component
greenStore = scratchPalette.green; // Save a backup of the Green component
blueStore = scratchPalette.blue; // Save a backup of the Blue component
scratchPalette.red <<= 4; // Shift the Red value 4-bits to the left
scratchPalette.green <<= 4; // Shift the Green value 4-bits to the left
scratchPalette.blue <<= 4; // Shift the Blue value 4-bits to the left
if((scratchPalette.red) == 0) { scratchPalette.red = redStore; }
if((scratchPalette.green) == 0) { scratchPalette.green = greenStore; }
if((scratchPalette.blue) == 0) { scratchPalette.blue = blueStore; }
As you can see it's a little long winded so I thought I could make it a bit smaller and a bit more optimised by changing the code to this:
if((scratchPalette.red << 4) != 0) { scratchPalette.red <<= 4; }
if((scratchPalette.green << 4) != 0) { scratchPalette.green <<= 4; }
if((scratchPalette.blue << 4) != 0) { scratchPalette.blue <<= 4; }
Well of course, it doesn't want to work. Instead of seeing what value scratchPalette.red green and blue would have had if they had been shifted all the program sees is the value they already hold. Is there any way of fixing this??
Steve-B