Load .ico files containing PNG images
This commit is contained in:
parent
37a5a0a85c
commit
d9ca2e1092
@ -2033,11 +2033,39 @@ void Load_ICO(T_IO_Context * context)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
T_BMP_Header bmpheader;
|
byte png_header[8];
|
||||||
|
|
||||||
entry = images + i;
|
entry = images + i;
|
||||||
fseek(file, entry->offset, SEEK_SET);
|
fseek(file, entry->offset, SEEK_SET);
|
||||||
// TODO : detect PNG icons
|
|
||||||
|
// detect PNG icons
|
||||||
|
// Load header (8 first bytes)
|
||||||
|
if (!Read_bytes(file,png_header,8))
|
||||||
|
{
|
||||||
|
File_error = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Do we recognize a png file signature ?
|
||||||
|
#ifndef __no_pnglib__
|
||||||
|
if (png_sig_cmp(png_header, 0, 8) == 0)
|
||||||
|
{
|
||||||
|
Load_PNG_Sub(context, file);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (0 = memcmp(png_header, "\x89PNG", 4))
|
||||||
|
{
|
||||||
|
// NO PNG Support
|
||||||
|
Warning("PNG Signature : Compiled without libpng support");
|
||||||
|
File_error = 2;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else
|
||||||
|
{
|
||||||
|
T_BMP_Header bmpheader;
|
||||||
|
|
||||||
|
fseek(file, -8, SEEK_CUR); // back
|
||||||
|
// BMP
|
||||||
if (Read_dword_le(file,&(bmpheader.Size_2)) // 40
|
if (Read_dword_le(file,&(bmpheader.Size_2)) // 40
|
||||||
&& Read_dword_le(file,&(bmpheader.Width))
|
&& Read_dword_le(file,&(bmpheader.Width))
|
||||||
&& Read_dword_le(file,(dword *)&(bmpheader.Height))
|
&& Read_dword_le(file,(dword *)&(bmpheader.Height))
|
||||||
@ -2055,7 +2083,6 @@ void Load_ICO(T_IO_Context * context)
|
|||||||
nb_colors=bmpheader.Nb_Clr;
|
nb_colors=bmpheader.Nb_Clr;
|
||||||
else
|
else
|
||||||
nb_colors=1<<bmpheader.Nb_bits;
|
nb_colors=1<<bmpheader.Nb_bits;
|
||||||
printf("size=%d width=%d height=%d planes=%d nbbits=%d nb_colors=%d\n", bmpheader.Size_2, bmpheader.Width, bmpheader.Height, bmpheader.Planes, bmpheader.Nb_bits, nb_colors);
|
|
||||||
// bmpheader.Width != entry.width...
|
// bmpheader.Width != entry.width...
|
||||||
// Image 16/24/32 bits
|
// Image 16/24/32 bits
|
||||||
if (bmpheader.Nb_bits == 16)
|
if (bmpheader.Nb_bits == 16)
|
||||||
@ -2073,12 +2100,24 @@ void Load_ICO(T_IO_Context * context)
|
|||||||
Pre_load(context, bmpheader.Width,bmpheader.Height/2,0/*file_size*/,FORMAT_ICO,PIXEL_SIMPLE,(entry->bpp > 8));
|
Pre_load(context, bmpheader.Width,bmpheader.Height/2,0/*file_size*/,FORMAT_ICO,PIXEL_SIMPLE,(entry->bpp > 8));
|
||||||
if (entry->bpp <= 8)
|
if (entry->bpp <= 8)
|
||||||
Load_BMP_Palette(context, file, nb_colors, 0);
|
Load_BMP_Palette(context, file, nb_colors, 0);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bmpheader.Compression == 3) // BI_BITFIELDS
|
||||||
|
{
|
||||||
|
if (!Read_dword_le(file,&mask[0]) ||
|
||||||
|
!Read_dword_le(file,&mask[1]) ||
|
||||||
|
!Read_dword_le(file,&mask[2]))
|
||||||
|
File_error=2;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (File_error == 0)
|
if (File_error == 0)
|
||||||
{
|
{
|
||||||
Load_BMP_Pixels(context, file, bmpheader.Compression, bmpheader.Nb_bits, (bmpheader.Height < 0) ? 1 : 0, mask);
|
Load_BMP_Pixels(context, file, bmpheader.Compression, bmpheader.Nb_bits, (bmpheader.Height < 0) ? 1 : 0, mask);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
free(images);
|
free(images);
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user