Advertisement

bitmap colors

Started by May 14, 2003 12:06 PM
4 comments, last by Heineken 21 years, 9 months ago
hey, i''m reading a 24 bits bitmap to use for a texture. i don''t use the glaux lib but i made my own code. but when i see the texture rendered on screen the colors are different. at first i thought the colors were like bgr instead of rgb, but that doesn''t seem the problem... i use glTexImage2D to create the texture when i use gluBuild2DMipmaps it''s ok, but i just want to know exactly how the colors in a bitmap are stored... does anyone know a solution? ok, danny heineken
could be padding issues. bitmaps may have bogus bytes of data to compensate for padding purposes. the image data shud be taking up a 'rectangular' region of storage. meaning, the data shud be represntable in a (x by y) dimension. of course, sometimes that may not be the case so padding bytes are inserted to make this true. without em, u'll get distorted images or colors. just a possibility.

[edited by - crazee on May 14, 2003 1:31:28 PM]
- To learn, we share... Give some to take some -
Advertisement
a sample snippet from my BMP loader goes as follows

    // Compute data padding sizepadding = 4 - ((bmpInfoHeader.biWidth * 3) % 4);     // Extract and store bitmap image dataif(4 != padding){   // Load padded image data...   for(long i = 0; i < m_lHeight; ++i)   {     fread(&m_ptrData[i * m_lWidth * (m_usBitCount >> 3)], 1, m_lWidth * (m_usBitCount >> 3), filePtr);     if(i != (m_lHeight - 1))        fseek(filePtr, padding, SEEK_CUR);   }}else   fread(m_ptrData, 1, m_ulImageSize, filePtr);// Swap image data R-B channelsfor(unsigned long j = 0; j < m_ulImageSize; j += 3){   // Perform XOR swapping   m_ptrData[j]   = m_ptrData[j] ^ m_ptrData[j+2];   m_ptrData[j+2] = m_ptrData[j] ^ m_ptrData[j+2];   m_ptrData[j]   = m_ptrData[j] ^ m_ptrData[j+2];}    


notice that when padding occurs, image must be read on a line by line basis. if u're writing BMP files urself, u must be careful with padding yet again. if u can understand the loading, writing shudn't be difficult.

The I/O setup is not shown. also, the code above does not show error checking for any pointer validity. Omitted for clarity

[edited by - crazee on May 14, 2003 1:42:21 PM]
- To learn, we share... Give some to take some -
yeah!
thanks!
i needed the swapping part...

[edited by - Heineken on May 14, 2003 1:47:52 PM]
erm, can u be a bit more descriptive about the problem then? also, u mentioned it worked fine with gluBuild2DMipmaps... care to share ur texture loading/initialization code for inspection?
- To learn, we share... Give some to take some -
i was just stoopid...
i made a function that swaps red and blue but it wasn''t correct...
after swapping it increased the address 1 bit instead of 3...
like if you use this in your function...
for( unsigned long j = 0; j < m_iWidth * m_iHeight * m_iChannels; j ++)

i now have this:
void RBSwap( void *address, short lngth )
{
__asm
{
mov ebx, address
mov cx, lngth
sub cx, 2
label:
mov al, [ebx]
xchg [ebx+2], al
xchg [ebx], al
add ebx, 2
inc ebx
loop label
}
}

in my first function i forgot add ebx, 2

thanks

This topic is closed to new replies.

Advertisement