Threshold
Squire
USA
44 Posts |
Posted - May 13 2005 : 3:32:55 PM
|
I need to find the width and height of various image file formats, including BMP, PNG, JPG, and GIF. I have found some useful information on http://www.wotsit.org/. However, PNG has evaded me.
I do have "working" but slow methods for finding out JPG and GIF, and BMP is quite simple [byte offset of 18 (location 19) for width [LONG] and height [also LONG] immediately follows].
For PNG, though, I can't find anything that tells me simply where in the file to find dimensions.
If you know a method of finding PNG dimensions please let me know, and/or if you have any efficient methods of getting the dimensions of GIF and JPG I would greatly appreciate to share the knowledge.
I'm using it for DirectX8 texture coordinates. You'd think D3DTexture8 would have some way of giving the image dimensions to you since it has to find them itself anyway! As far as I've seen, it doesn't.
EDIT: Eric, the "automatic URL to link" feature accidentally included the period at the end of my sentence in the URL. |
Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun." |
Edited by - Threshold on May 13 2005 3:40:34 PM
|
|
Threshold
Squire
USA
44 Posts |
Posted - May 13 2005 : 4:03:41 PM
|
I just found some information in the SDK hinting that one of the arguments in the CreateTextureFromFileEx method returns a D3DXIMAGE_INFO structure with a bunch of useful file information in it. I'll test it and get back to you guys.
|
Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun." |
|
|
Threshold
Squire
USA
44 Posts |
Posted - May 13 2005 : 11:35:45 PM
|
Indeed it works. Simply pass a D3DXIMAGE_INFO variable to the srcInfo argument of the D3DDevice8.CreateTextureFromFileEx method and read the width and height (and depth) from that.
I'm still open to any information regarding a direct method for this in the case that someone does not want to load the graphic to find its dimensions. |
Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun." |
|
|
Eric Coleman
Gladiator
USA
811 Posts |
Posted - May 14 2005 : 10:39:49 AM
|
PNG width and height should be offset by 12 bytes. 8 bytes for the PNG file format header, and then 4 more bytes for the IHDR chunk. Then Width is 4 bytes and then Height is 4 bytes. The values are unsigned 32 bit integers (LONG in VB). Source |
|
|
sdw
Warrior
USA
160 Posts |
Posted - May 21 2005 : 1:44:58 PM
|
quote: The values are unsigned 32 bit integers (LONG in VB).
Are VB longs not 16 bit unsigned integers? |
|
|
Threshold
Squire
USA
44 Posts |
Posted - May 21 2005 : 1:59:24 PM
|
As far as I know, VB Longs are 32 bit (4 bytes, a.k.a. double word (dword)) signed integers. So basically, with other languages that have 32 bit unsigned primitive data types, you could get a much larger positive integer in the saved data type than could a VB Long. But it would be limited to positive integers only whereas the VB Long is capable of positive and negative integers alike.
Please correct me if I'm wrong. |
Life is short. They say "don't waste it, have fun." They're right, don't waste it...but DO redefine "fun." |
|
|
sdw
Warrior
USA
160 Posts |
Posted - May 21 2005 : 2:21:03 PM
|
According to http://www.developerfusion.com/show/32/ VB longs are 32 bits signed, ranging from -2,147,483,648 to 2,147,483,647. I could have sworn I read Longs ranged from 0 to 65536. Looks like you win :\
quote: The values are unsigned 32 bit integers (LONG in VB).
But I still object to the unsigned bit of it >:) So does that mean you need to do some bit shifting to acquire the correct dimensions?
|
|
|
Eric Coleman
Gladiator
USA
811 Posts |
|