Removed struct packing everywhere, except RGB 24bit struct (and thus 768-byte palettes). This might fix some issue on Caanoo, where either the packing didn't work (and the struct had wrong size) or it worked and caused unaligned reads/writes.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1639 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud
2010-10-26 22:51:07 +00:00
parent e5272e74f7
commit fba72c9ebd
5 changed files with 41 additions and 46 deletions

View File

@@ -367,7 +367,8 @@ void Load_PKM(T_IO_Context * context)
Compteur_de_donnees_packees=0;
Compteur_de_pixels=0;
Taille_pack=(file_size)-sizeof(T_PKM_Header)-header.Jump;
// Header size is 780
Taille_pack=(file_size)-780-header.Jump;
// Boucle de décompression:
while ( (Compteur_de_pixels<image_size) && (Compteur_de_donnees_packees<Taille_pack) && (!File_error) )
@@ -636,7 +637,6 @@ void Save_PKM(T_IO_Context * context)
//////////////////////////////////// CEL ////////////////////////////////////
#pragma pack(1)
typedef struct
{
word Width; // width de l'image
@@ -655,7 +655,6 @@ typedef struct
word Y_offset; // Offset en Y de l'image
byte Filler2[16]; // ???
} T_CEL_Header2;
#pragma pack()
// -- Tester si un fichier est au format CEL --------------------------------
@@ -688,7 +687,7 @@ void Test_CEL(T_IO_Context * context)
// Vu que ce header n'a pas de signature, il va falloir tester la
// cohérence de la dimension de l'image avec celle du fichier.
size=file_size-sizeof(T_CEL_Header1);
size=file_size-4;
if ( (!size) || ( (((header1.Width+1)>>1)*header1.Height)!=size ) )
{
// Tentative de reconnaissance de la signature des nouveaux fichiers
@@ -973,7 +972,6 @@ void Save_CEL(T_IO_Context * context)
//////////////////////////////////// KCF ////////////////////////////////////
#pragma pack(1)
typedef struct
{
struct
@@ -985,7 +983,6 @@ typedef struct
} color[16];
} Palette[10];
} T_KCF_Header;
#pragma pack()
// -- Tester si un fichier est au format KCF --------------------------------
@@ -993,7 +990,7 @@ void Test_KCF(T_IO_Context * context)
{
char filename[MAX_PATH_CHARACTERS];
FILE *file;
T_KCF_Header buffer;
T_KCF_Header header1;
T_CEL_Header2 header2;
int pal_index;
int color_index;
@@ -1002,13 +999,17 @@ void Test_KCF(T_IO_Context * context)
Get_full_filename(filename, context->File_name, context->File_directory);
if ((file=fopen(filename, "rb")))
{
if (File_length_file(file)==sizeof(T_KCF_Header))
if (File_length_file(file)==320)
{
Read_bytes(file,&buffer,sizeof(T_KCF_Header));
for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte1) ||
!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
// On vérifie une propriété de la structure de palette:
for (pal_index=0;pal_index<10;pal_index++)
for (color_index=0;color_index<16;color_index++)
if ((buffer.Palette[pal_index].color[color_index].Byte2>>4)!=0)
if ((header1.Palette[pal_index].color[color_index].Byte2>>4)!=0)
File_error=1;
}
else
@@ -1048,7 +1049,7 @@ void Load_KCF(T_IO_Context * context)
{
char filename[MAX_PATH_CHARACTERS];
FILE *file;
T_KCF_Header buffer;
T_KCF_Header header1;
T_CEL_Header2 header2;
byte bytes[3];
int pal_index;
@@ -1062,11 +1063,16 @@ void Load_KCF(T_IO_Context * context)
if ((file=fopen(filename, "rb")))
{
file_size=File_length_file(file);
if (file_size==sizeof(T_KCF_Header))
if (file_size==320)
{
// Fichier KCF à l'ancien format
for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte1) ||
!Read_byte(file,&header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
if (Read_bytes(file,&buffer,sizeof(T_KCF_Header)))
if (!File_error)
{
// Pre_load(context, ?); // Pas possible... pas d'image...
@@ -1078,9 +1084,9 @@ void Load_KCF(T_IO_Context * context)
for (color_index=0;color_index<16;color_index++)
{
index=16+(pal_index*16)+color_index;
context->Palette[index].R=((buffer.Palette[pal_index].color[color_index].Byte1 >> 4) << 4);
context->Palette[index].B=((buffer.Palette[pal_index].color[color_index].Byte1 & 15) << 4);
context->Palette[index].G=((buffer.Palette[pal_index].color[color_index].Byte2 & 15) << 4);
context->Palette[index].R=((header1.Palette[pal_index].color[color_index].Byte1 >> 4) << 4);
context->Palette[index].B=((header1.Palette[pal_index].color[color_index].Byte1 & 15) << 4);
context->Palette[index].G=((header1.Palette[pal_index].color[color_index].Byte2 & 15) << 4);
}
for (index=0;index<16;index++)
@@ -1167,7 +1173,7 @@ void Save_KCF(T_IO_Context * context)
{
char filename[MAX_PATH_CHARACTERS];
FILE *file;
T_KCF_Header buffer;
T_KCF_Header header1;
T_CEL_Header2 header2;
byte bytes[3];
int pal_index;
@@ -1195,12 +1201,16 @@ void Save_KCF(T_IO_Context * context)
for (color_index=0;color_index<16;color_index++)
{
index=16+(pal_index*16)+color_index;
buffer.Palette[pal_index].color[color_index].Byte1=((context->Palette[index].R>>4)<<4) | (context->Palette[index].B>>4);
buffer.Palette[pal_index].color[color_index].Byte2=context->Palette[index].G>>4;
header1.Palette[pal_index].color[color_index].Byte1=((context->Palette[index].R>>4)<<4) | (context->Palette[index].B>>4);
header1.Palette[pal_index].color[color_index].Byte2=context->Palette[index].G>>4;
}
if (! Write_bytes(file,&buffer,sizeof(T_KCF_Header)))
File_error=1;
// Write all
for (pal_index=0;pal_index<10 && !File_error;pal_index++)
for (color_index=0;color_index<16 && !File_error;color_index++)
if (!Write_byte(file,header1.Palette[pal_index].color[color_index].Byte1) ||
!Write_byte(file,header1.Palette[pal_index].color[color_index].Byte2))
File_error=1;
}
else
{
@@ -2296,13 +2306,13 @@ int Save_C64_window(byte *saveWhat, byte *loadAddr)
Print_in_window(13,18,"Data:",MC_Dark,MC_Light);
what=Window_set_dropdown_button(10,28,90,15,70,what_label[*saveWhat],1, 0, 1, LEFT_SIDE,0);
Window_dropdown_clear_items(what);
for (i=0; i<sizeof(what_label)/sizeof(char *); i++)
for (i=0; i<sizeof(what_label)/sizeof(what_label[0]); i++)
Window_dropdown_add_item(what,i,what_label[i]);
Print_in_window(113,18,"Address:",MC_Dark,MC_Light);
addr=Window_set_dropdown_button(110,28,70,15,70,address_label[*loadAddr/32],1, 0, 1, LEFT_SIDE,0);
Window_dropdown_clear_items(addr);
for (i=0; i<sizeof(address_label)/sizeof(char *); i++)
for (i=0; i<sizeof(address_label)/sizeof(address_label[0]); i++)
Window_dropdown_add_item(addr,i,address_label[i]);
Update_window_area(0,0,Window_width,Window_height);