Merge trunk to the cpcmode5 branch. This gets us a more recent grafx2 with the cpcmode5 drawing. Now to make this mode optional so users can still work in regular mode :)

git-svn-id: svn://pulkomandy.tk/GrafX2/branches/cpcmode5@1719 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues
2011-02-13 21:49:31 +00:00
parent 4e60f5ad74
commit eba26aaa96
65 changed files with 8669 additions and 3286 deletions

View File

@@ -2,6 +2,7 @@
*/
/* Grafx2 - The Ultimate 256-color bitmap paint program
Copyright 2011 Pawel Góralski
Copyright 2009 Petter Lindquist
Copyright 2008 Yves Rizoud
Copyright 2008 Franck Charlet
@@ -368,7 +369,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) )
@@ -637,7 +639,6 @@ void Save_PKM(T_IO_Context * context)
//////////////////////////////////// CEL ////////////////////////////////////
#pragma pack(1)
typedef struct
{
word Width; // width de l'image
@@ -656,7 +657,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 --------------------------------
@@ -689,7 +689,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
@@ -735,7 +735,7 @@ void Load_CEL(T_IO_Context * context)
short y_pos;
byte last_byte=0;
long file_size;
const long int header_size = (long int)(sizeof(header1.Width)+sizeof(header1.Height));
const long int header_size = 4;
File_error=0;
Get_full_filename(filename, context->File_name, context->File_directory);
@@ -775,7 +775,7 @@ void Load_CEL(T_IO_Context * context)
// On réessaye avec le nouveau format
fseek(file,0,SEEK_SET);
if (Read_bytes(file,header2.Signature,sizeof(header2.Signature))
if (Read_bytes(file,header2.Signature,4)
&& Read_byte(file,&(header2.Kind))
&& Read_byte(file,&(header2.Nb_bits))
&& Read_word_le(file,&(header2.Filler1))
@@ -783,7 +783,7 @@ void Load_CEL(T_IO_Context * context)
&& Read_word_le(file,&(header2.Height))
&& Read_word_le(file,&(header2.X_offset))
&& Read_word_le(file,&(header2.Y_offset))
&& Read_bytes(file,header2.Filler2,sizeof(header2.Filler2))
&& Read_bytes(file,header2.Filler2,16)
)
{
// Chargement d'un fichier CEL avec signature (nouveaux fichiers)
@@ -942,7 +942,7 @@ void Save_CEL(T_IO_Context * context)
for (x_pos=0;x_pos<16;x_pos++) // Initialisation du filler 2 (?)
header2.Filler2[x_pos]=0;
if (Write_bytes(file,header2.Signature,sizeof(header2.Signature))
if (Write_bytes(file,header2.Signature,4)
&& Write_byte(file,header2.Kind)
&& Write_byte(file,header2.Nb_bits)
&& Write_word_le(file,header2.Filler1)
@@ -950,7 +950,7 @@ void Save_CEL(T_IO_Context * context)
&& Write_word_le(file,header2.Height)
&& Write_word_le(file,header2.X_offset)
&& Write_word_le(file,header2.Y_offset)
&& Write_bytes(file,header2.Filler2,sizeof(header2.Filler2))
&& Write_bytes(file,header2.Filler2,14)
)
{
// Sauvegarde de l'image
@@ -974,7 +974,6 @@ void Save_CEL(T_IO_Context * context)
//////////////////////////////////// KCF ////////////////////////////////////
#pragma pack(1)
typedef struct
{
struct
@@ -986,7 +985,6 @@ typedef struct
} color[16];
} Palette[10];
} T_KCF_Header;
#pragma pack()
// -- Tester si un fichier est au format KCF --------------------------------
@@ -994,7 +992,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;
@@ -1003,18 +1001,22 @@ 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
{
if (Read_bytes(file,header2.Signature,sizeof(header2.Signature))
if (Read_bytes(file,header2.Signature,4)
&& Read_byte(file,&(header2.Kind))
&& Read_byte(file,&(header2.Nb_bits))
&& Read_word_le(file,&(header2.Filler1))
@@ -1022,7 +1024,7 @@ void Test_KCF(T_IO_Context * context)
&& Read_word_le(file,&(header2.Height))
&& Read_word_le(file,&(header2.X_offset))
&& Read_word_le(file,&(header2.Y_offset))
&& Read_bytes(file,header2.Filler2,sizeof(header2.Filler2))
&& Read_bytes(file,header2.Filler2,14)
)
{
if (memcmp(header2.Signature,"KiSS",4)==0)
@@ -1049,7 +1051,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;
@@ -1063,11 +1065,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...
@@ -1079,9 +1086,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++)
@@ -1100,7 +1107,7 @@ void Load_KCF(T_IO_Context * context)
{
// Fichier KCF au nouveau format
if (Read_bytes(file,header2.Signature,sizeof(header2.Signature))
if (Read_bytes(file,header2.Signature,4)
&& Read_byte(file,&(header2.Kind))
&& Read_byte(file,&(header2.Nb_bits))
&& Read_word_le(file,&(header2.Filler1))
@@ -1108,7 +1115,7 @@ void Load_KCF(T_IO_Context * context)
&& Read_word_le(file,&(header2.Height))
&& Read_word_le(file,&(header2.X_offset))
&& Read_word_le(file,&(header2.Y_offset))
&& Read_bytes(file,header2.Filler2,sizeof(header2.Filler2))
&& Read_bytes(file,header2.Filler2,14)
)
{
// Pre_load(context, ?); // Pas possible... pas d'image...
@@ -1168,7 +1175,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;
@@ -1196,12 +1203,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
{
@@ -1218,7 +1229,7 @@ void Save_KCF(T_IO_Context * context)
for (index=0;index<16;index++) // Initialisation du filler 2 (?)
header2.Filler2[index]=0;
if (!Write_bytes(file,header2.Signature,sizeof(header2.Signature))
if (!Write_bytes(file,header2.Signature,4)
|| !Write_byte(file,header2.Kind)
|| !Write_byte(file,header2.Nb_bits)
|| !Write_word_le(file,header2.Filler1)
@@ -1226,7 +1237,7 @@ void Save_KCF(T_IO_Context * context)
|| !Write_word_le(file,header2.Height)
|| !Write_word_le(file,header2.X_offset)
|| !Write_word_le(file,header2.Y_offset)
|| !Write_bytes(file,header2.Filler2,sizeof(header2.Filler2))
|| !Write_bytes(file,header2.Filler2,14)
)
File_error=1;
@@ -1322,17 +1333,29 @@ void PI1_decode_palette(byte * src,byte * palette)
// Low High
// VVVV RRRR | 0000 BBBB
// 0321 0321 | 0321
ip=0;
for (i=0;i<16;i++)
{
w=((word)src[(i*2)+1]<<8) | src[(i*2)+0];
// Traitement des couleurs rouge, verte et bleue:
palette[ip++]=(((w & 0x0007) << 1) | ((w & 0x0008) >> 3)) << 4;
palette[ip++]=(((w & 0x7000) >> 11) | ((w & 0x8000) >> 15)) << 4;
palette[ip++]=(((w & 0x0700) >> 7) | ((w & 0x0800) >> 11)) << 4;
}
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
w=(((word)src[(i*2)+1]<<8) | (src[(i*2)+0]));
// Traitement des couleurs rouge, verte et bleue:
palette[ip++]=(((w & 0x0007) << 1) | ((w & 0x0008) >> 3)) << 4;
palette[ip++]=(((w & 0x7000) >> 11) | ((w & 0x8000) >> 15)) << 4;
palette[ip++]=(((w & 0x0700) >> 7) | ((w & 0x0800) >> 11)) << 4;
#else
w=(((word)src[(i*2+1)])|(((word)src[(i*2)])<<8));
palette[ip++] = (((w & 0x0700)>>7) | ((w & 0x0800) >> 7))<<4 ;
palette[ip++]=(((w & 0x0070)>>3) | ((w & 0x0080) >> 3))<<4 ;
palette[ip++] = (((w & 0x0007)<<1) | ((w & 0x0008)))<<4 ;
#endif
}
}
//// CODAGE de la PALETTE ////
@@ -1345,20 +1368,31 @@ void PI1_code_palette(byte * palette,byte * dest)
// Schéma d'un word =
//
// Low High
// Low High
// VVVV RRRR | 0000 BBBB
// 0321 0321 | 0321
ip=0;
for (i=0;i<16;i++)
{
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
// Traitement des couleurs rouge, verte et bleue:
w =(((word)(palette[ip]>>2) & 0x38) >> 3) | (((word)(palette[ip]>>2) & 0x04) << 1); ip++;
w|=(((word)(palette[ip]>>2) & 0x38) << 9) | (((word)(palette[ip]>>2) & 0x04) << 13); ip++;
w|=(((word)(palette[ip]>>2) & 0x38) << 5) | (((word)(palette[ip]>>2) & 0x04) << 9); ip++;
dest[(i*2)+0]=w & 0x00FF;
dest[(i*2)+1]=(w>>8);
#else
w=(((word)(palette[ip]<<3))&0x0700);ip++;
w|=(((word)(palette[ip]>>1))&0x0070);ip++;
w|=(((word)(palette[ip]>>5))&0x0007);ip++;
dest[(i*2)+1]=w & 0x00FF;
dest[(i*2)+0]=(w>>8);
#endif
}
}
@@ -2472,13 +2506,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); // 3
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); // 4
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);