Code archives/Graphics/Shows the ordering of pixel data in an integer value
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This is just some code I knocked up to test the ordering of pixel color data in the integer values used with ReadPixel, WritePixel, etc. If you are using a bank to create or parse the integer color value used with ReadPixel, WritePixel etc, then the bytes that make up the pixel color data are arranged in the following order. Bank slot:- Byte 0 = Blue Byte 1 = Green Byte 2 = Red Byte 3 = Alpha If you are creating or parsing the pixel color data mathmatically then the least significant byte (blue_color_value * 2 ^ 0) holds the color blue. The next higher byte (green_color_value * 2 ^ 8) holds the color green. The next higher byte (red_color_value * 2 ^ 16) holds the color red. The most significant byte (alpha_value * 2 ^ 24) holds the alpha value. Color byte values range from zero (darkest, or least color) to 255 (lightest, or most color). The alpha value determines how opaque (visible) the pixel is. An alpha value of zero means that the pixel is invisible. An alpha value of 255 means that the pixel is fully visible. Anything in-between means that the pixel is transparent. You can also learn more about RGBA color encoding at: http://en.wikipedia.org/wiki/RGBA | |||||
Global G_int_bank = CreateBank( 4 ) Graphics 800, 600, 0, 2 image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 PokeInt G_int_bank, 0, 0 ; Clear the bank. PokeByte G_int_bank, 0, 255 ; Store 255 in slot 0. WritePixel x, y, PeekInt( G_int_bank, 0 ) Next Next image1a = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 PokeInt G_int_bank, 0, 0 ; Clear the bank. PokeByte G_int_bank, 1, 255 ; Store 255 in slot 1. WritePixel x, y, PeekInt( G_int_bank, 0 ) Next Next image2a = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 PokeInt G_int_bank, 0, 0 ; Clear the bank. PokeByte G_int_bank, 2, 255 ; Store 255 in slot 2. WritePixel x, y, PeekInt( G_int_bank, 0 ) Next Next image3a = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 PokeInt G_int_bank, 0, 0 ; Clear the bank. PokeByte G_int_bank, 3, 255 ; Store 255 in slot 3. WritePixel x, y, PeekInt( G_int_bank, 0 ) Next Next image4a = image ;--- image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 WritePixel x, y, 255 ; Set the least significant byte value to 255. Next Next image1b = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 WritePixel x, y, 255 * ( 2 ^ 8 ) ; Set the second byte value to 255. Next Next image2b = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 WritePixel x, y, 255 * ( 2 ^ 16 ) ; Set the third byte value to 255. Next Next image3b = image image = CreateImage( 64, 64 ) SetBuffer ImageBuffer( image ) For x = 0 To 63 For y = 0 To 63 WritePixel x, y, 255 * ( 2 ^ 24 ) ; Set the most significant byte value to 255. Next Next image4b = image SetBuffer BackBuffer() y = o Text 0, y, "This shows the arrangement of pixel bytes in a bank." y = y + 20 Text 0, y, "Slot 0 = Blue. Slot 1 = Green. Slot 2 = Red. Slot 3 = Alpha" y = y + 20 DrawImage image1a, 0, y DrawImage image2a, 64, y DrawImage image3a, 128, y DrawImage image4a, 192, y y = y + 64 + 20 Text 0, y, "This shows the arrangement of pixel data in an integer value." y = y + 20 Text 0, y, "Left = Least significant byte (value: 255). Right = Most significant byte (value: 4278190080)." y = y + 20 DrawImage image1b, 0, y DrawImage image2b, 64, y DrawImage image3b, 128, y DrawImage image4b, 192, y Flip WaitKey End |
Comments
None.
Code Archives Forum