Valhalla Legends Archive

Programming => General Programming => Topic started by: Barabajagal on February 09, 2009, 03:08 PM

Title: Bitmaps, Icons, and Cursors
Post by: Barabajagal on February 09, 2009, 03:08 PM
Since Windows 7 has Vista's overfeatured and shitty Paint version, I've been working on my own. In the process, I've needed to create some cursors, which has lead me to the .cur and .ico format. In the course of reading icon data, I've noticed something quite strange, which is that the icon data stores a width/height which appears to be correct, but the bitmap data stores a (redundant) width/height in which the height is twice what it should be. Has anyone else run into this, or know what it means?
Title: Re: Bitmaps, Icons, and Cursors
Post by: bulletproof tiger on February 09, 2009, 09:53 PM
Your initial thought was to create your own paint program and not to just go download one of the thousands out there?
Title: Re: Bitmaps, Icons, and Cursors
Post by: MyndFyre on February 09, 2009, 10:34 PM
Quote from: chyea on February 09, 2009, 09:53 PM
Your initial thought was to create your own paint program and not to just go download one of the thousands out there?
Because the one that came with Windows has too many features, no less.

http://www.irfanview.com/
Title: Re: Bitmaps, Icons, and Cursors
Post by: Barabajagal on February 09, 2009, 11:05 PM
Neither of you are of any help whatsoever. Mynd, you should know better than to stray from the topic question...
Title: Re: Bitmaps, Icons, and Cursors
Post by: MyndFyre on February 11, 2009, 01:14 AM
Quote from: Andy on February 09, 2009, 11:05 PM
Neither of you are of any help whatsoever. Mynd, you should know better than to stray from the topic question...
Do you have a link to the format spec that you're using to develop this with?  Maybe a hex-formatted part of the file you're working on....
Title: Re: Bitmaps, Icons, and Cursors
Post by: Barabajagal on February 11, 2009, 02:31 AM
The format is listed on Wikipedia (ICO (http://en.wikipedia.org/wiki/ICO_(icon_image_file_format)) wraps around BMP (http://en.wikipedia.org/wiki/BMP_file_format) with DIB header). I've used multiple ICO files (from online, from personal creations in Visual C++ 6 and GIMP, and from Windows itself), but as an example, I'll use a PHP script icon (http://www.php.net/images/logos/php_script.ico) from PHP.net:


ICO Header:
00 00 01 00 0C 00

ICO Directories (12 of them):
30 30 10 00 01 00 04 00 68 06 00 00 C6 00 00 00
20 20 10 00 01 00 04 00 E8 02 00 00 2E 07 00 00
18 18 10 00 01 00 04 00 E8 01 00 00 16 0A 00 00
10 10 10 00 01 00 04 00 28 01 00 00 FE 0B 00 00

30 30 00 00 01 00 08 00 A8 0E 00 00 26 0D 00 00
20 20 00 00 01 00 08 00 A8 08 00 00 CE 1B 00 00
18 18 00 00 01 00 08 00 C8 06 00 00 76 24 00 00
10 10 00 00 01 00 08 00 68 05 00 00 3E 2B 00 00

30 30 00 00 01 00 20 00 A8 25 00 00 A6 30 00 00
20 20 00 00 01 00 20 00 A8 10 00 00 4E 56 00 00
18 18 00 00 01 00 20 00 88 09 00 00 F6 66 00 00
10 10 00 00 01 00 20 00 68 04 00 00 7E 70 00 00

DIB Header for ICO #1:
28 00 00 00
30 00 00 00 <<Correct Width
60 00 00 00 << Doubled Height
etc...
Title: Re: Bitmaps, Icons, and Cursors
Post by: MyndFyre on February 11, 2009, 11:01 AM
Aren't .ico bitmaps stored as two bitmaps - the AND and the XOR versions?  Is it possible that you're seeing the double height because the single DIB section represents both?
Title: Re: Bitmaps, Icons, and Cursors
Post by: Ringo on February 11, 2009, 01:15 PM
Yep, i'm pretty sure what MyndFyre said is the case.
If you have a 2 bitmaps, but the ico format is only giving you the offset and size of 1, as well as the bitmap header saying the image is double the size, then it would be safe to assume both images are next to one another.
Andy, why didn't you spend a min or two, to parse an ico file, save the bitmap(s) and check them out?
Title: Re: Bitmaps, Icons, and Cursors
Post by: Barabajagal on February 11, 2009, 05:06 PM
I was in the process of doing so when I ran into the double height thing...

The problem is that the parsed BMP data in the ICOs don't have a header, and when I try to add a simple one like so:
    cFile.InsertByte &H42
    cFile.InsertByte &H4D
    cFile.InsertDWORD 14 + Len(ImgData(hsIcons.Value))
    cFile.InsertWORD 0
    cFile.InsertWORD 0
    cFile.InsertDWORD 14 + 40 + PalSize
    cFile.InsertString ImgData(hsIcons.Value)

I get an invalid image which opens exclusively in GIMP and looks terrible.
Title: Re: Bitmaps, Icons, and Cursors
Post by: MyndFyre on February 11, 2009, 08:15 PM
Quote from: Andy on February 11, 2009, 05:06 PM
I was in the process of doing so when I ran into the double height thing...

The problem is that the parsed BMP data in the ICOs don't have a header, and when I try to add a simple one like so:
    cFile.InsertByte &H42
    cFile.InsertByte &H4D
    cFile.InsertDWORD 14 + Len(ImgData(hsIcons.Value))
    cFile.InsertWORD 0
    cFile.InsertWORD 0
    cFile.InsertDWORD 14 + 40 + PalSize
    cFile.InsertString ImgData(hsIcons.Value)

I get an invalid image which opens exclusively in GIMP and looks terrible.

They're not going to look correct - you need to use and combine the bitmap data in both bitmaps in order to make a bitmap that properly represents the original icon.
Title: Re: Bitmaps, Icons, and Cursors
Post by: Barabajagal on February 11, 2009, 10:12 PM
So... each ICO image is DIB + 2 * ([Palette] + Image Data)-'s?