Load_IFF() parse BMHD as a normal chunk. Use stored_bit_planes var
This commit is contained in:
parent
4c92e87d52
commit
d4753919ee
@ -596,7 +596,7 @@ void Load_IFF(T_IO_Context * context)
|
|||||||
char section[4];
|
char section[4];
|
||||||
byte temp_byte;
|
byte temp_byte;
|
||||||
short b256;
|
short b256;
|
||||||
dword nb_colors;
|
dword nb_colors = 0; // number of colors in the CMAP (color map)
|
||||||
dword section_size;
|
dword section_size;
|
||||||
short x_pos;
|
short x_pos;
|
||||||
short y_pos;
|
short y_pos;
|
||||||
@ -660,13 +660,17 @@ void Load_IFF(T_IO_Context * context)
|
|||||||
File_error=1;
|
File_error=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IFF_Wait_for(IFF_file, "BMHD"))
|
|
||||||
File_error=1;
|
|
||||||
Read_dword_be(IFF_file,&dummy); // SIZE
|
|
||||||
|
|
||||||
// Maintenant on lit le header pour pouvoir commencer le chargement de l'image
|
{
|
||||||
if (File_error == 0
|
byte real_bit_planes = 0;
|
||||||
&& (Read_word_be(IFF_file,&header.Width))
|
byte stored_bit_planes = 0;
|
||||||
|
while (File_error == 0
|
||||||
|
&& Read_bytes(IFF_file,section,4)
|
||||||
|
&& Read_dword_be(IFF_file,§ion_size))
|
||||||
|
{
|
||||||
|
if (memcmp(section, "BMHD", 4) == 0)
|
||||||
|
{
|
||||||
|
if (!((Read_word_be(IFF_file,&header.Width))
|
||||||
&& (Read_word_be(IFF_file,&header.Height))
|
&& (Read_word_be(IFF_file,&header.Height))
|
||||||
&& (Read_word_be(IFF_file,&header.X_org))
|
&& (Read_word_be(IFF_file,&header.X_org))
|
||||||
&& (Read_word_be(IFF_file,&header.Y_org))
|
&& (Read_word_be(IFF_file,&header.Y_org))
|
||||||
@ -679,13 +683,15 @@ void Load_IFF(T_IO_Context * context)
|
|||||||
&& (Read_byte(IFF_file,&header.Y_aspect))
|
&& (Read_byte(IFF_file,&header.Y_aspect))
|
||||||
&& (Read_word_be(IFF_file,&header.X_screen))
|
&& (Read_word_be(IFF_file,&header.X_screen))
|
||||||
&& (Read_word_be(IFF_file,&header.Y_screen))
|
&& (Read_word_be(IFF_file,&header.Y_screen))
|
||||||
&& header.Width && header.Height)
|
&& header.Width && header.Height))
|
||||||
{
|
{
|
||||||
byte real_bit_planes = header.BitPlanes;
|
File_error = 1;
|
||||||
nb_colors = 1 << real_bit_planes;
|
break;
|
||||||
|
}
|
||||||
|
real_bit_planes = header.BitPlanes;
|
||||||
|
stored_bit_planes = header.BitPlanes;
|
||||||
if (header.Mask==1)
|
if (header.Mask==1)
|
||||||
header.BitPlanes++;
|
stored_bit_planes++;
|
||||||
Back_color=header.Transp_col;
|
|
||||||
Image_HAM=0;
|
Image_HAM=0;
|
||||||
if (header.X_aspect != 0 && header.Y_aspect != 0)
|
if (header.X_aspect != 0 && header.Y_aspect != 0)
|
||||||
{
|
{
|
||||||
@ -699,12 +705,8 @@ void Load_IFF(T_IO_Context * context)
|
|||||||
ratio = PIXEL_WIDE; // 1.5 <= ratio
|
ratio = PIXEL_WIDE; // 1.5 <= ratio
|
||||||
}
|
}
|
||||||
bpp = header.BitPlanes;
|
bpp = header.BitPlanes;
|
||||||
|
}
|
||||||
while (File_error == 0
|
else if (memcmp(section, "CMAP", 4) == 0)
|
||||||
&& Read_bytes(IFF_file,section,4)
|
|
||||||
&& Read_dword_be(IFF_file,§ion_size))
|
|
||||||
{
|
|
||||||
if (memcmp(section, "CMAP", 4) == 0)
|
|
||||||
{
|
{
|
||||||
nb_colors = section_size/3;
|
nb_colors = section_size/3;
|
||||||
|
|
||||||
@ -1024,11 +1026,11 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
// compute row size
|
// compute row size
|
||||||
real_line_size = (context->Width+15) & ~15;
|
real_line_size = (context->Width+15) & ~15;
|
||||||
plane_line_size = real_line_size >> 3; // 8bits per byte
|
plane_line_size = real_line_size >> 3; // 8bits per byte
|
||||||
line_size = plane_line_size * header.BitPlanes;
|
line_size = plane_line_size * stored_bit_planes;
|
||||||
buffer = malloc(line_size * context->Height);
|
buffer = malloc(line_size * context->Height);
|
||||||
if ((dword)(line_size * context->Height) == section_size)
|
if ((dword)(line_size * context->Height) == section_size)
|
||||||
header.Compression = 0; // size is of uncompressed data. Forcing.
|
header.Compression = 0; // size is of uncompressed data. Forcing.
|
||||||
for (plane = 0; plane < header.BitPlanes; plane++)
|
for (plane = 0; plane < stored_bit_planes; plane++)
|
||||||
{
|
{
|
||||||
for (y_pos = 0; y_pos < context->Height; y_pos++)
|
for (y_pos = 0; y_pos < context->Height; y_pos++)
|
||||||
{
|
{
|
||||||
@ -1053,9 +1055,9 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
for (y_pos = 0; y_pos < context->Height; y_pos++)
|
for (y_pos = 0; y_pos < context->Height; y_pos++)
|
||||||
{
|
{
|
||||||
if (Image_HAM <= 1)
|
if (Image_HAM <= 1)
|
||||||
Draw_IFF_line(context, buffer+y_pos*line_size, y_pos,real_line_size, header.BitPlanes);
|
Draw_IFF_line(context, buffer+y_pos*line_size, y_pos,real_line_size, stored_bit_planes);
|
||||||
else
|
else
|
||||||
Draw_IFF_line_HAM(context, buffer+y_pos*line_size, y_pos,real_line_size, header.BitPlanes, SHAM_palettes, SHAM_palette_count);
|
Draw_IFF_line_HAM(context, buffer+y_pos*line_size, y_pos,real_line_size, stored_bit_planes, SHAM_palettes, SHAM_palette_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@ -1080,7 +1082,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
// compute row size
|
// compute row size
|
||||||
real_line_size = (context->Width+15) & ~15;
|
real_line_size = (context->Width+15) & ~15;
|
||||||
plane_line_size = real_line_size >> 3; // 8bits per byte
|
plane_line_size = real_line_size >> 3; // 8bits per byte
|
||||||
line_size = plane_line_size * header.BitPlanes;
|
line_size = plane_line_size * stored_bit_planes;
|
||||||
|
|
||||||
switch(header.Compression)
|
switch(header.Compression)
|
||||||
{
|
{
|
||||||
@ -1091,11 +1093,11 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
if (Read_bytes(IFF_file,buffer,line_size))
|
if (Read_bytes(IFF_file,buffer,line_size))
|
||||||
{
|
{
|
||||||
if (PCHG_palettes)
|
if (PCHG_palettes)
|
||||||
Draw_IFF_line_PCHG(context, buffer, y_pos,real_line_size, header.BitPlanes, PCHG_palettes);
|
Draw_IFF_line_PCHG(context, buffer, y_pos,real_line_size, stored_bit_planes, PCHG_palettes);
|
||||||
else if (Image_HAM <= 1)
|
else if (Image_HAM <= 1)
|
||||||
Draw_IFF_line(context, buffer, y_pos,real_line_size, header.BitPlanes);
|
Draw_IFF_line(context, buffer, y_pos,real_line_size, stored_bit_planes);
|
||||||
else
|
else
|
||||||
Draw_IFF_line_HAM(context, buffer, y_pos,real_line_size, header.BitPlanes, SHAM_palettes, SHAM_palette_count);
|
Draw_IFF_line_HAM(context, buffer, y_pos,real_line_size, stored_bit_planes, SHAM_palettes, SHAM_palette_count);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
File_error=21;
|
File_error=21;
|
||||||
@ -1114,7 +1116,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// temp_byte > 127 => repeat (256-temp_byte) the next byte
|
// temp_byte > 127 => repeat (256-temp_byte) the next byte
|
||||||
// temp_byte <= 127 => copy (temp_byte' + 1) bytes
|
// temp_byte <= 127 => copy (temp_byte + 1) bytes
|
||||||
if(temp_byte == 128) // 128 = NOP !
|
if(temp_byte == 128) // 128 = NOP !
|
||||||
{
|
{
|
||||||
Warning("NOP in packbits stream");
|
Warning("NOP in packbits stream");
|
||||||
@ -1151,11 +1153,11 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
if (!File_error)
|
if (!File_error)
|
||||||
{
|
{
|
||||||
if (PCHG_palettes)
|
if (PCHG_palettes)
|
||||||
Draw_IFF_line_PCHG(context, buffer, y_pos,real_line_size, header.BitPlanes, PCHG_palettes);
|
Draw_IFF_line_PCHG(context, buffer, y_pos,real_line_size, stored_bit_planes, PCHG_palettes);
|
||||||
else if (Image_HAM <= 1)
|
else if (Image_HAM <= 1)
|
||||||
Draw_IFF_line(context, buffer, y_pos,real_line_size,header.BitPlanes);
|
Draw_IFF_line(context, buffer, y_pos,real_line_size,stored_bit_planes);
|
||||||
else
|
else
|
||||||
Draw_IFF_line_HAM(context, buffer, y_pos,real_line_size, header.BitPlanes, SHAM_palettes, SHAM_palette_count);
|
Draw_IFF_line_HAM(context, buffer, y_pos,real_line_size, stored_bit_planes, SHAM_palettes, SHAM_palette_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buffer);
|
free(buffer);
|
||||||
@ -1168,7 +1170,7 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
Warning("Failed to allocate memory for IFF decoding");
|
Warning("Failed to allocate memory for IFF decoding");
|
||||||
}
|
}
|
||||||
plane_line_size = real_line_size >> 3;
|
plane_line_size = real_line_size >> 3;
|
||||||
for (plane = 0; plane < header.BitPlanes && !File_error; plane++)
|
for (plane = 0; plane < stored_bit_planes && !File_error; plane++)
|
||||||
{
|
{
|
||||||
word cmd_count;
|
word cmd_count;
|
||||||
word cmd;
|
word cmd;
|
||||||
@ -1302,8 +1304,6 @@ printf("%d x %d = %d %d\n", tiny_width, tiny_height, tiny_width*tiny_height, s
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
else
|
|
||||||
File_error=1;
|
|
||||||
|
|
||||||
fclose(IFF_file);
|
fclose(IFF_file);
|
||||||
IFF_file = NULL;
|
IFF_file = NULL;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user