Fixed tabulations to 2spaces (the most common in this file). Tiny bit of error-check on saving. Implemented preview scaling to display c64 widepixel pictures properly. Not done yet: Auto-set wide or wide2 pixels after loading a picture with wide pixels.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1016 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-09-05 19:49:18 +00:00
parent 6c3963bf33
commit 2e46820b83

View File

@ -121,7 +121,7 @@ void Load_PNG(void);
void Save_PNG(void); void Save_PNG(void);
#endif #endif
void Init_preview(short width,short height,long size,int format); void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio);
T_Format File_formats[NB_KNOWN_FORMATS] = { T_Format File_formats[NB_KNOWN_FORMATS] = {
{"pkm", Test_PKM, Load_PKM, Save_PKM, 1, 1}, {"pkm", Test_PKM, Load_PKM, Save_PKM, 1, 1},
@ -178,9 +178,34 @@ void Pixel_load_in_preview(word x_pos,word y_pos,byte color)
{ {
if (((x_pos % Preview_factor_X)==0) && ((y_pos % Preview_factor_Y)==0)) if (((x_pos % Preview_factor_X)==0) && ((y_pos % Preview_factor_Y)==0))
if ((x_pos<Main_image_width) && (y_pos<Main_image_height)) if ((x_pos<Main_image_width) && (y_pos<Main_image_height))
{
if (Ratio_of_loaded_image == PIXEL_WIDE &&
Pixel_ratio != PIXEL_WIDE &&
Pixel_ratio != PIXEL_WIDE2)
{
Pixel(Preview_pos_X+(x_pos/Preview_factor_X*2),
Preview_pos_Y+(y_pos/Preview_factor_Y),
color);
Pixel(Preview_pos_X+(x_pos/Preview_factor_X*2)+1,
Preview_pos_Y+(y_pos/Preview_factor_Y),
color);
}
else if (Ratio_of_loaded_image == PIXEL_TALL &&
Pixel_ratio != PIXEL_TALL &&
Pixel_ratio != PIXEL_TALL2)
{
Pixel(Preview_pos_X+(x_pos/Preview_factor_X),
Preview_pos_Y+(y_pos/Preview_factor_Y*2),
color);
Pixel(Preview_pos_X+(x_pos/Preview_factor_X),
Preview_pos_Y+(y_pos/Preview_factor_Y*2)+1,
color);
}
else
Pixel(Preview_pos_X+(x_pos/Preview_factor_X), Pixel(Preview_pos_X+(x_pos/Preview_factor_X),
Preview_pos_Y+(y_pos/Preview_factor_Y), Preview_pos_Y+(y_pos/Preview_factor_Y),
color); color);
}
} }
@ -294,7 +319,7 @@ void Set_palette_fake_24b(T_Palette palette)
void Init_preview_24b(short width,short height,long size,int format) void Init_preview_24b(short width,short height,long size,int format)
{ {
// Call common processing // Call common processing
Init_preview(width,height,size,format); Init_preview(width,height,size,format, PIXEL_SIMPLE);
if (File_error) if (File_error)
return; return;
@ -337,7 +362,7 @@ void Init_preview_24b(short width,short height,long size,int format)
void Init_preview(short width,short height,long size,int format) void Init_preview(short width,short height,long size,int format, enum PIXEL_RATIO ratio)
// //
// Cette procédure doit être appelée par les routines de chargement // Cette procédure doit être appelée par les routines de chargement
// d'images. // d'images.
@ -398,6 +423,15 @@ void Init_preview(short width,short height,long size,int format)
Print_in_window(45,70,Main_comment,MC_Black,MC_Light); Print_in_window(45,70,Main_comment,MC_Black,MC_Light);
// Calculs des données nécessaires à l'affichage de la preview: // Calculs des données nécessaires à l'affichage de la preview:
if (ratio == PIXEL_WIDE &&
Pixel_ratio != PIXEL_WIDE &&
Pixel_ratio != PIXEL_WIDE2)
width*=2;
else if (ratio == PIXEL_TALL &&
Pixel_ratio != PIXEL_TALL &&
Pixel_ratio != PIXEL_TALL2)
height*=2;
Preview_factor_X=Round_div_max(width,122*Menu_factor_X); Preview_factor_X=Round_div_max(width,122*Menu_factor_X);
Preview_factor_Y=Round_div_max(height, 82*Menu_factor_Y); Preview_factor_Y=Round_div_max(height, 82*Menu_factor_Y);
@ -898,7 +932,7 @@ void Load_IMG(void)
buffer=(byte *)malloc(IMG_header.Width); buffer=(byte *)malloc(IMG_header.Width);
Init_preview(IMG_header.Width,IMG_header.Height,file_size,FORMAT_IMG); Init_preview(IMG_header.Width,IMG_header.Height,file_size,FORMAT_IMG,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
memcpy(Main_palette,IMG_header.Palette,sizeof(T_Palette)); memcpy(Main_palette,IMG_header.Palette,sizeof(T_Palette));
@ -1171,7 +1205,7 @@ void Load_PKM(void)
if (!File_error) if (!File_error)
{ {
Init_preview(header.Width,header.Height,file_size,FORMAT_PKM); Init_preview(header.Width,header.Height,file_size,FORMAT_PKM,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
@ -1869,7 +1903,7 @@ void Load_LBM(void)
Original_screen_X = header.X_screen; Original_screen_X = header.X_screen;
Original_screen_Y = header.Y_screen; Original_screen_Y = header.Y_screen;
Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_LBM); Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_LBM,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
if (!memcmp(format,"ILBM",4)) // "ILBM": InterLeaved BitMap if (!memcmp(format,"ILBM",4)) // "ILBM": InterLeaved BitMap
@ -2407,7 +2441,7 @@ void Load_BMP(void)
if (!File_error) if (!File_error)
{ {
Init_preview(header.Width,header.Height,file_size,FORMAT_BMP); Init_preview(header.Width,header.Height,file_size,FORMAT_BMP,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
if (Read_bytes(file,local_palette,nb_colors<<2)) if (Read_bytes(file,local_palette,nb_colors<<2))
@ -3131,7 +3165,7 @@ void Load_GIF(void)
Main_image_width=IDB.Image_width; Main_image_width=IDB.Image_width;
Main_image_height=IDB.Image_height; Main_image_height=IDB.Image_height;
Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF); Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF,PIXEL_SIMPLE);
// Palette locale dispo = (IDB.Indicator and $80) // Palette locale dispo = (IDB.Indicator and $80)
// Image entrelacée = (IDB.Indicator and $40) // Image entrelacée = (IDB.Indicator and $40)
@ -3803,7 +3837,7 @@ void Load_PCX(void)
if (PCX_header.Plane!=3) if (PCX_header.Plane!=3)
{ {
Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_PCX); Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_PCX,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// On prépare la palette à accueillir les valeurs du fichier PCX // On prépare la palette à accueillir les valeurs du fichier PCX
@ -4300,7 +4334,7 @@ void Load_CEL(void)
Main_image_height=header1.Height; Main_image_height=header1.Height;
Original_screen_X=Main_image_width; Original_screen_X=Main_image_width;
Original_screen_Y=Main_image_height; Original_screen_Y=Main_image_height;
Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL); Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// Chargement de l'image // Chargement de l'image
@ -4330,7 +4364,7 @@ void Load_CEL(void)
Main_image_height=header2.Height+header2.Y_offset; Main_image_height=header2.Height+header2.Y_offset;
Original_screen_X=Main_image_width; Original_screen_X=Main_image_width;
Original_screen_Y=Main_image_height; Original_screen_Y=Main_image_height;
Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL); Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// Chargement de l'image // Chargement de l'image
@ -4823,7 +4857,7 @@ void Load_SCx(void)
if ((Read_bytes(file,&SCx_header,sizeof(T_SCx_Header)))) if ((Read_bytes(file,&SCx_header,sizeof(T_SCx_Header))))
{ {
Init_preview(SCx_header.Width,SCx_header.Height,file_size,FORMAT_SCx); Init_preview(SCx_header.Width,SCx_header.Height,file_size,FORMAT_SCx,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
if (!SCx_header.Planes) if (!SCx_header.Planes)
@ -5121,7 +5155,7 @@ void Load_PI1(void)
if (Read_bytes(file,buffer,32034)) if (Read_bytes(file,buffer,32034))
{ {
// Initialisation de la preview // Initialisation de la preview
Init_preview(320,200,File_length_file(file),FORMAT_PI1); Init_preview(320,200,File_length_file(file),FORMAT_PI1,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// Initialisation de la palette // Initialisation de la palette
@ -5455,7 +5489,7 @@ void Load_PC1(void)
if (Read_bytes(file,buffercomp,size)) if (Read_bytes(file,buffercomp,size))
{ {
// Initialisation de la preview // Initialisation de la preview
Init_preview(320,200,File_length_file(file),FORMAT_PC1); Init_preview(320,200,File_length_file(file),FORMAT_PC1,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// Initialisation de la palette // Initialisation de la palette
@ -5732,7 +5766,7 @@ void Load_NEO(void)
if (Read_bytes(file,buffer,32128)) if (Read_bytes(file,buffer,32128))
{ {
// Initialisation de la preview // Initialisation de la preview
Init_preview(320,200,File_length_file(file),FORMAT_NEO); Init_preview(320,200,File_length_file(file),FORMAT_NEO,PIXEL_SIMPLE);
if (File_error==0) if (File_error==0)
{ {
// Initialisation de la palette // Initialisation de la palette
@ -5866,7 +5900,6 @@ void Test_C64(void)
break; break;
default: // then we don't know for now. default: // then we don't know for now.
File_error = 1; File_error = 1;
} }
fclose (file); fclose (file);
} }
@ -5916,7 +5949,6 @@ void Load_C64_multi(byte *bitmap, byte *colors, byte *nybble, byte background)
pixel=bitmap[cy*320+cx*8+y]; pixel=bitmap[cy*320+cx*8+y];
for(x=0; x<4; x++) for(x=0; x<4; x++)
{ {
color=c[(pixel&3)]; color=c[(pixel&3)];
pixel>>=2; pixel>>=2;
Pixel_load_function(cx*4+(3-x),cy*8+y,color); Pixel_load_function(cx*4+(3-x),cy*8+y,color);
@ -5931,7 +5963,6 @@ void Load_C64(void)
FILE* file; FILE* file;
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
long file_size; long file_size;
int newPixel_ratio;
byte background; byte background;
// Palette from http://www.pepto.de/projects/colorvic/ // Palette from http://www.pepto.de/projects/colorvic/
@ -5968,31 +5999,36 @@ void Load_C64(void)
file_size = File_length_file(file); file_size = File_length_file(file);
if(file_size>9002)width=160; if(file_size>9002)
{
width=160;
Ratio_of_loaded_image = PIXEL_WIDE;
}
else
{
Ratio_of_loaded_image = PIXEL_SIMPLE;
}
Init_preview(width, height, file_size, FORMAT_C64); // Do this as soon as you can Init_preview(width, height, file_size, FORMAT_C64, Ratio_of_loaded_image); // Do this as soon as you can
Main_image_width = width ; Main_image_width = width ;
Main_image_height = height; Main_image_height = height;
Read_bytes(file,bitmap,8000); Read_bytes(file,bitmap,8000);
if(file_size>8002)Read_bytes(file,colors,1000); if(file_size>8002)
Read_bytes(file,colors,1000);
if(width==160) if(width==160)
{ {
Read_bytes(file,nybble,1000); Read_bytes(file,nybble,1000);
Read_byte(file,&background); Read_byte(file,&background);
Load_C64_multi(bitmap,colors,nybble,background); Load_C64_multi(bitmap,colors,nybble,background);
newPixel_ratio = PIXEL_WIDE;
} }
else else
{ {
Load_C64_hires(bitmap,colors); Load_C64_hires(bitmap,colors);
newPixel_ratio = PIXEL_SIMPLE;
} }
//Pixel_ratio = newPixel_ratio;
File_error = 0; File_error = 0;
fclose(file); fclose(file);
} }
@ -6074,8 +6110,9 @@ int Save_C64_hires(char *filename)
return 1; return 1;
} }
Write_bytes(file,bitmap,8000); if (!Write_bytes(file,bitmap,8000) ||
Write_bytes(file,colors,1000); !Write_bytes(file,colors,1000))
File_error = 1;
fclose(file); fclose(file);
return 0; return 0;
@ -6108,7 +6145,6 @@ BITS COLOR INFORMATION COMES FROM
{ {
count=cusage[x]; count=cusage[x];
background=x; background=x;
} }
} }
@ -6178,10 +6214,11 @@ BITS COLOR INFORMATION COMES FROM
File_error = 1; File_error = 1;
return 1; return 1;
} }
Write_bytes(file,bitmap,8000); if (!Write_bytes(file,bitmap,8000) ||
Write_bytes(file,screen,1000); !Write_bytes(file,screen,1000) ||
Write_bytes(file,nybble,1000); !Write_bytes(file,nybble,1000) ||
Write_byte(file,background); !Write_byte(file,background))
File_error = 1;
fclose(file); fclose(file);
//printf("\nbg:%d\n",background); //printf("\nbg:%d\n",background);
@ -6191,7 +6228,7 @@ BITS COLOR INFORMATION COMES FROM
void Save_C64(void) void Save_C64(void)
{ {
char filename[MAX_PATH_CHARACTERS]; char filename[MAX_PATH_CHARACTERS];
dword numcolors,cusage[256]; dword numcolors, cusage[256];
numcolors=Count_used_colors(cusage); numcolors=Count_used_colors(cusage);
Get_full_filename(filename,0); Get_full_filename(filename,0);
@ -6214,8 +6251,6 @@ void Save_C64(void)
else else
File_error = Save_C64_multi(filename); File_error = Save_C64_multi(filename);
//fclose(file);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -6351,7 +6386,7 @@ void Load_PNG(void)
if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA)
Init_preview_24b(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG); Init_preview_24b(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG);
else else
Init_preview(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG); Init_preview(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG,Ratio_of_loaded_image);
if (File_error==0) if (File_error==0)
{ {
@ -6567,9 +6602,11 @@ void Save_PNG(void)
switch(Pixel_ratio) switch(Pixel_ratio)
{ {
case PIXEL_WIDE: case PIXEL_WIDE:
case PIXEL_WIDE2:
png_set_pHYs(png_ptr, info_ptr, 3000, 6000, PNG_RESOLUTION_METER); png_set_pHYs(png_ptr, info_ptr, 3000, 6000, PNG_RESOLUTION_METER);
break; break;
case PIXEL_TALL: case PIXEL_TALL:
case PIXEL_TALL2:
png_set_pHYs(png_ptr, info_ptr, 6000, 3000, PNG_RESOLUTION_METER); png_set_pHYs(png_ptr, info_ptr, 6000, 3000, PNG_RESOLUTION_METER);
break; break;
default: default: