Color mixing tricks
BlitzPlus Forums/BlitzPlus Programming/Color mixing tricks
| ||
Found this old code snippet in my archive. It was available in the old forums... thought maybe it would be interesting for some of the new guys...;from a read... pix=ReadPixelFast( x,y ) red=(pix Shr 16) And 255 grn=(pix Shr 8) And 255 blu=pix And 255 ;to a write (assumes r,g,b are 0..255) pix=(red Shl 16) Or (grn Shl 8) Or blu WritePixelFast x,y,pix ;Half-bright: pix=(pix Shr 1) And $7f7f7f ;Quarter-bright: pix=(pix Shr 2) And $3f3f3f ;Blend 2 pixels: pix=( (pix1 Shr 1) And $7f7f7f ) + ( (pix2 Shr 1) And $7f7f7f ) ;So, a fast half-bright loop might be: WritePixelFast x,y,(ReadPixelFast( x,y ) Shr 1) And $7f7f7f |
| ||
Handy stuff Paul. I might as well put this here for reference as well. Here is a link explaining RGB Formats I have gathered the most relevant info into this table. Hope it's right! RGB Formats *********** 16 Bit RGB555 ==================== %1111 1111 1111 1111 rrr rrgg gggb bbbb 16 Bit RGB565 ==================== %1111 1111 1111 1111 rrrr rggg gggb bbbb 24 Bit RGB888 ============================== %1111 1111 1111 1111 1111 1111 rrrr rrrr gggg gggg bbbb bbbb 32Bit ARGB8888 ======================================== %1111 1111 1111 1111 1111 1111 1111 1111 aaaa aaaa rrrr rrrr gggg gggg bbbb bbbb There is an example in Blitz+ by Mark called lock_graphics.bb (in the samples\mak folder). Worth a look. |
| ||
Very useful :) Cheers |