# HG changeset patch # User pacman # Date 1140819525 0 # Node ID 786628f8db887b57e18a176105133b2f77c2d872 # Parent 35c8d33614045318c79e2b8e2c5d326c8b1a237e Add a practical description of endian-independent RGB/BGR coding diff -r 35c8d3361404 -r 786628f8db88 DOCS/tech/colorspaces.txt --- a/DOCS/tech/colorspaces.txt Fri Feb 24 21:50:13 2006 +0000 +++ b/DOCS/tech/colorspaces.txt Fri Feb 24 22:18:45 2006 +0000 @@ -135,3 +135,24 @@ Depending upon the CPU being little- or big-endian, different 'in memory' and 'in register' formats will be equal (LE -> BGRA == BGR32 / BE -> ARGB == BGR32) + +Practical coding guide: + +The 4, 8, 15, and 16 bit formats are defined so that the portable way to +access them is to load the pixel into an integer and use bitmasks. + +The 24 bit formats are defined so that the portable way to access them is +to address the 3 components as separate bytes, as in ((uint8_t *)pixel)[0], +((uint8_t *)pixel)[1], ((uint8_t *)pixel)[2]. + +When a 32-bit format is identified by the four characters A, R, G, and B in +some order, the portable way to access it is by addressing the 4 components +as separate bytes. + +When a 32-bit format is identified by the 3 characters R, G, and B in some +order followed by the number 32, the portable way to access it is to load +the pixel into an integer and use bitmasks. + +When the above portable access methods are not used, you will need to write +2 versions of your code, and use #ifdef WORDS_BIGENDIAN to choose the correct +one.