Merge r1787 (Fix loading of BMPs with negative heights) from release (2.3) to trunk (2.4wip)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1795 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
8cc20115d5
commit
1af5ee33f1
@ -1102,7 +1102,7 @@ typedef struct
|
||||
|
||||
dword Size_2; // 40
|
||||
dword Width;
|
||||
dword Height;
|
||||
int32_t Height; // signed: negative means a top-down bitmap (rare)
|
||||
word Planes; // 1
|
||||
word Nb_bits; // 1,4,8 ou 24
|
||||
dword Compression;
|
||||
@ -1132,7 +1132,7 @@ void Test_BMP(T_IO_Context * context)
|
||||
&& Read_dword_le(file,&(header.Offset))
|
||||
&& Read_dword_le(file,&(header.Size_2))
|
||||
&& Read_dword_le(file,&(header.Width))
|
||||
&& Read_dword_le(file,&(header.Height))
|
||||
&& Read_dword_le(file,(dword *)&(header.Height))
|
||||
&& Read_word_le(file,&(header.Planes))
|
||||
&& Read_word_le(file,&(header.Nb_bits))
|
||||
&& Read_dword_le(file,&(header.Compression))
|
||||
@ -1209,6 +1209,7 @@ void Load_BMP(T_IO_Context * context)
|
||||
word line_size;
|
||||
byte a,b,c=0;
|
||||
long file_size;
|
||||
byte negative_height;
|
||||
|
||||
Get_full_filename(filename, context->File_name, context->File_directory);
|
||||
|
||||
@ -1225,7 +1226,7 @@ void Load_BMP(T_IO_Context * context)
|
||||
&& Read_dword_le(file,&(header.Offset))
|
||||
&& Read_dword_le(file,&(header.Size_2))
|
||||
&& Read_dword_le(file,&(header.Width))
|
||||
&& Read_dword_le(file,&(header.Height))
|
||||
&& Read_dword_le(file,(dword *)&(header.Height))
|
||||
&& Read_word_le(file,&(header.Planes))
|
||||
&& Read_word_le(file,&(header.Nb_bits))
|
||||
&& Read_dword_le(file,&(header.Compression))
|
||||
@ -1249,6 +1250,16 @@ void Load_BMP(T_IO_Context * context)
|
||||
default:
|
||||
File_error=1;
|
||||
}
|
||||
|
||||
if (header.Height < 0)
|
||||
{
|
||||
negative_height=1;
|
||||
header.Height = -header.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
negative_height=0;
|
||||
}
|
||||
|
||||
if (!File_error)
|
||||
{
|
||||
@ -1271,6 +1282,9 @@ void Load_BMP(T_IO_Context * context)
|
||||
context->Width=header.Width;
|
||||
context->Height=header.Height;
|
||||
|
||||
if (fseek(file, header.Offset, SEEK_SET))
|
||||
File_error=2;
|
||||
|
||||
switch (header.Compression)
|
||||
{
|
||||
case 0 : // Pas de compression
|
||||
@ -1283,26 +1297,29 @@ void Load_BMP(T_IO_Context * context)
|
||||
line_size=(line_size*header.Nb_bits)>>3;
|
||||
|
||||
buffer=(byte *)malloc(line_size);
|
||||
for (y_pos=context->Height-1; ((y_pos>=0) && (!File_error)); y_pos--)
|
||||
for (y_pos=0; (y_pos < context->Height && !File_error); y_pos++)
|
||||
{
|
||||
short target_y;
|
||||
target_y = negative_height ? y_pos : context->Height-1-y_pos;
|
||||
|
||||
if (Read_bytes(file,buffer,line_size))
|
||||
for (x_pos=0; x_pos<context->Width; x_pos++)
|
||||
switch (header.Nb_bits)
|
||||
{
|
||||
case 8 :
|
||||
Set_pixel(context, x_pos,y_pos,buffer[x_pos]);
|
||||
Set_pixel(context, x_pos,target_y,buffer[x_pos]);
|
||||
break;
|
||||
case 4 :
|
||||
if (x_pos & 1)
|
||||
Set_pixel(context, x_pos,y_pos,buffer[x_pos>>1] & 0xF);
|
||||
Set_pixel(context, x_pos,target_y,buffer[x_pos>>1] & 0xF);
|
||||
else
|
||||
Set_pixel(context, x_pos,y_pos,buffer[x_pos>>1] >> 4 );
|
||||
Set_pixel(context, x_pos,target_y,buffer[x_pos>>1] >> 4 );
|
||||
break;
|
||||
case 1 :
|
||||
if ( buffer[x_pos>>3] & (0x80>>(x_pos&7)) )
|
||||
Set_pixel(context, x_pos,y_pos,1);
|
||||
Set_pixel(context, x_pos,target_y,1);
|
||||
else
|
||||
Set_pixel(context, x_pos,y_pos,0);
|
||||
Set_pixel(context, x_pos,target_y,0);
|
||||
}
|
||||
else
|
||||
File_error=2;
|
||||
@ -1481,11 +1498,14 @@ void Load_BMP(T_IO_Context * context)
|
||||
line_size+=(4-x_pos);
|
||||
|
||||
buffer=(byte *)malloc(line_size);
|
||||
for (y_pos=context->Height-1; ((y_pos>=0) && (!File_error)); y_pos--)
|
||||
for (y_pos=0; (y_pos < context->Height && !File_error); y_pos++)
|
||||
{
|
||||
short target_y;
|
||||
target_y = negative_height ? y_pos : context->Height-1-y_pos;
|
||||
|
||||
if (Read_bytes(file,buffer,line_size))
|
||||
for (x_pos=0,index=0; x_pos<context->Width; x_pos++,index+=3)
|
||||
Set_pixel_24b(context, x_pos,y_pos,buffer[index+2],buffer[index+1],buffer[index+0]);
|
||||
Set_pixel_24b(context, x_pos,target_y,buffer[index+2],buffer[index+1],buffer[index+0]);
|
||||
else
|
||||
File_error=2;
|
||||
}
|
||||
@ -1495,13 +1515,15 @@ void Load_BMP(T_IO_Context * context)
|
||||
case 32:
|
||||
line_size=context->Width*4;
|
||||
buffer=(byte *)malloc(line_size);
|
||||
for (y_pos=context->Height-1; ((y_pos>=0) && (!File_error)); y_pos--)
|
||||
for (y_pos=0; (y_pos < context->Height && !File_error); y_pos++)
|
||||
{
|
||||
short target_y;
|
||||
target_y = negative_height ? y_pos : context->Height-1-y_pos;
|
||||
if (Read_bytes(file,buffer,line_size))
|
||||
for (x_pos=0; x_pos<context->Width; x_pos++)
|
||||
{
|
||||
dword pixel=*(((dword *)buffer)+x_pos);
|
||||
Set_pixel_24b(context, x_pos,y_pos,Bitmap_mask(pixel,red_mask),Bitmap_mask(pixel,green_mask),Bitmap_mask(pixel,blue_mask));
|
||||
Set_pixel_24b(context, x_pos,target_y,Bitmap_mask(pixel,red_mask),Bitmap_mask(pixel,green_mask),Bitmap_mask(pixel,blue_mask));
|
||||
}
|
||||
else
|
||||
File_error=2;
|
||||
@ -1512,13 +1534,15 @@ void Load_BMP(T_IO_Context * context)
|
||||
case 16:
|
||||
line_size=(context->Width*2) + (context->Width&1)*2;
|
||||
buffer=(byte *)malloc(line_size);
|
||||
for (y_pos=context->Height-1; ((y_pos>=0) && (!File_error)); y_pos--)
|
||||
for (y_pos=0; (y_pos < context->Height && !File_error); y_pos++)
|
||||
{
|
||||
short target_y;
|
||||
target_y = negative_height ? y_pos : context->Height-1-y_pos;
|
||||
if (Read_bytes(file,buffer,line_size))
|
||||
for (x_pos=0; x_pos<context->Width; x_pos++)
|
||||
{
|
||||
word pixel=*(((word *)buffer)+x_pos);
|
||||
Set_pixel_24b(context, x_pos,y_pos,Bitmap_mask(pixel,red_mask),Bitmap_mask(pixel,green_mask),Bitmap_mask(pixel,blue_mask));
|
||||
Set_pixel_24b(context, x_pos,target_y,Bitmap_mask(pixel,red_mask),Bitmap_mask(pixel,green_mask),Bitmap_mask(pixel,blue_mask));
|
||||
}
|
||||
else
|
||||
File_error=2;
|
||||
|
||||
@ -453,21 +453,22 @@ static const T_Help_table helptable_credits[] =
|
||||
HELP_TITLE(" BUGFINDERS")
|
||||
HELP_TEXT ("")
|
||||
//HELP_TEXT ("0----5----0----5----0----5----0----5----0--X")
|
||||
HELP_TEXT (" anibiqme blumunkee BDCIron ")
|
||||
HELP_TEXT (" Ced DarkDefende DawnBringer ")
|
||||
HELP_TEXT (" El Topo falenblood fanickbux ")
|
||||
HELP_TEXT (" fano fogbot121 Frost ")
|
||||
HELP_TEXT (" Grimmy Gürkan Sengün Hatch ")
|
||||
HELP_TEXT (" HoraK-FDF iLKke Iw2evk ")
|
||||
HELP_TEXT (" jackfrost128 Jamon keito ")
|
||||
HELP_TEXT (" kusma Lord Graga Lorenzo Gatti ")
|
||||
HELP_TEXT (" MagerValp maymunbeyin mind ")
|
||||
HELP_TEXT (" MooZ Pasi Kallinen the Peach ")
|
||||
HELP_TEXT (" petter PheeL Ravey1138 ")
|
||||
HELP_TEXT (" richienyhus sm4tik spratek ")
|
||||
HELP_TEXT (" Surt tape.yrm TeeEmCee ")
|
||||
HELP_TEXT (" tempest Timo Kurrpa titus^Rab ")
|
||||
HELP_TEXT (" Tobé yakumo2975 00ai99")
|
||||
HELP_TEXT (" anibiqme antdzeryn blumunkee ")
|
||||
HELP_TEXT (" BDCIron Ced DarkDefende ")
|
||||
HELP_TEXT (" DawnBringer El Topo falenblood ")
|
||||
HELP_TEXT (" fanickbux fano fogbot121 ")
|
||||
HELP_TEXT (" Frost Grimmy Gürkan Sengün ")
|
||||
HELP_TEXT (" Hatch HoraK-FDF iLKke ")
|
||||
HELP_TEXT (" Iw2evk jackfrost128 Jamon ")
|
||||
HELP_TEXT (" keito kusma Lord Graga ")
|
||||
HELP_TEXT (" Lorenzo Gatti MagerValp maymunbeyin ")
|
||||
HELP_TEXT (" mind MooZ Pasi Kallinen ")
|
||||
HELP_TEXT (" the Peach petter PheeL ")
|
||||
HELP_TEXT (" Ravey1138 richienyhus sm4tik ")
|
||||
HELP_TEXT (" spratek Surt tape.yrm ")
|
||||
HELP_TEXT (" TeeEmCee tempest Timo Kurrpa ")
|
||||
HELP_TEXT (" titus^Rab Tobé yakumo2975 ")
|
||||
HELP_TEXT (" 00ai99")
|
||||
HELP_TEXT ("")
|
||||
HELP_TEXT (" ... posted the annoying bug reports.")
|
||||
HELP_TEXT ("")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user