TGA at lesson 24

Started by
1 comment, last by Muksitul 21 years, 11 months ago
Can anyone please describe me these two lines // Determine The TGA Width (highbyte*256+lowbyte) width = header[1] * 256 + header[0]; // Determine The TGA Height (highbyte*256+lowbyte) height = header[3] * 256 + header[2]; why are we multiplying header[1] and header[3] with 256 and also why adding the header[0] and header[2] at the end ? I tried to read the Truevisions pages on TGA but cant find a clue,seems that it talks about a lot of headers that seems to be missing here,like color map and other footer and other sorta data. btw is the TGA file(image) in this lesson 24 or 32 bit ? I will be happy if someone sheds some lights into this With regards muksitul
Advertisement
header is array of bytes. each byte can store maximum value of 255. So if you want to to store bigger values you have to combine more mytes. in this case two.

width = header[1] * 256 + header[0];

eg : with picture width 512 -> header[1] = 2 and header[0] = 0 --> 2*256 + 0 = 512


about depth of texture. you can tell depth from one byte in header. I don''t know number by heart..

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
If you want it to be more clear, multiplying by 256 is the same as bit-shifting to the left by 8 bits (1 byte). Also, the byte telling the bits per pixel follows right after the unsigned short with the height value in it.

So, in the code you''re using, it''s located at header[4]. It''s about the 17th byte, if I''m not mistaken.

Denton Woods, aka DooMWiz
Developer''s Image Library (DevIL) @ http://www.imagelib.org .
Denton Woods, aka DooMWizDeveloper's Image Library (DevIL) @ http://www.imagelib.org .

This topic is closed to new replies.

Advertisement