Fix missing preview of palette formats. Fixed JASC PAL saving that didn't close file (!), so saving more than once would make empty file. Fixed loading palette formats that didn't have any effect.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1280 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
bece65fcbb
commit
b07ab82b20
40
loadsave.c
40
loadsave.c
@ -285,6 +285,18 @@ void Palette_loaded(T_IO_Context *context)
|
||||
}
|
||||
*/
|
||||
Remap_screen_after_menu_colors_change();
|
||||
|
||||
// Preview palette
|
||||
if (Get_fileformat(context->Format)->Palette_only)
|
||||
{
|
||||
short index;
|
||||
|
||||
if (context->Type == CONTEXT_PREVIEW)
|
||||
for (index=0; index<256; index++)
|
||||
Window_rectangle(183+(index/16)*7,95+(index&15)*5,5,5,index);
|
||||
|
||||
Update_window_area(183,95,120,80);
|
||||
}
|
||||
break;
|
||||
|
||||
case CONTEXT_MAIN_IMAGE:
|
||||
@ -621,6 +633,7 @@ void Load_image(T_IO_Context *context)
|
||||
|
||||
if (File_error)
|
||||
{
|
||||
context->Format = DEFAULT_FILEFORMAT;
|
||||
// Last try: with SDL_image
|
||||
Load_SDL_Image(context);
|
||||
|
||||
@ -637,6 +650,7 @@ void Load_image(T_IO_Context *context)
|
||||
else
|
||||
// Si on a su déterminer avec succès le format du fichier:
|
||||
{
|
||||
context->Format = format->Identifier;
|
||||
// On peut charger le fichier:
|
||||
// Dans certains cas il est possible que le chargement plante
|
||||
// après avoir modifié la palette. TODO
|
||||
@ -698,19 +712,21 @@ void Load_image(T_IO_Context *context)
|
||||
|
||||
if (context->Type == CONTEXT_MAIN_IMAGE)
|
||||
{
|
||||
if ( (File_error!=1) && (!format->Palette_only) )
|
||||
if ( File_error!=1)
|
||||
{
|
||||
/* Shouldn't happen ???
|
||||
if (Pixel_load_function==Pixel_load_in_preview)
|
||||
if (format->Palette_only)
|
||||
{
|
||||
dword color_usage[256];
|
||||
Count_used_colors_screen_area(color_usage,context->Preview_pos_X,context->Preview_pos_Y,context->Width/context->Preview_factor_X,context->Height/context->Preview_factor_Y);
|
||||
//Count_used_colors(color_usage);
|
||||
Display_cursor();
|
||||
Set_nice_menu_colors(color_usage,1);
|
||||
Hide_cursor();
|
||||
// Make a backup step
|
||||
Backup_layers(0);
|
||||
}
|
||||
*/
|
||||
// Copy the loaded palette
|
||||
memcpy(Main_palette, context->Palette, sizeof(T_Palette));
|
||||
memcpy(Main_backups->Pages->Palette, context->Palette, sizeof(T_Palette));
|
||||
|
||||
// For formats that handle more than just the palette:
|
||||
// Transfer the data to main image.
|
||||
if (!format->Palette_only)
|
||||
{
|
||||
strcpy(Main_backups->Pages->Filename,context->File_name);
|
||||
strcpy(Main_backups->Pages->File_directory,context->File_directory);
|
||||
|
||||
@ -722,8 +738,6 @@ void Load_image(T_IO_Context *context)
|
||||
// already done initially on Backup_with_new_dimensions
|
||||
//Main_image_width= context->Width;
|
||||
//Main_image_height= context->Height;
|
||||
memcpy(Main_palette, context->Palette, sizeof(T_Palette));
|
||||
memcpy(Main_backups->Pages->Palette, context->Palette, sizeof(T_Palette));
|
||||
|
||||
Main_current_layer = context->Nb_layers - 1;
|
||||
Main_layers_visible = (2<<Main_current_layer)-1;
|
||||
@ -733,7 +747,7 @@ void Load_image(T_IO_Context *context)
|
||||
Main_image_width=1;
|
||||
if (Main_image_height<1)
|
||||
Main_image_height=1;
|
||||
|
||||
}
|
||||
}
|
||||
else if (File_error!=1)
|
||||
{
|
||||
|
||||
@ -39,18 +39,6 @@
|
||||
|
||||
//////////////////////////////////// PAL ////////////////////////////////////
|
||||
//
|
||||
void Draw_palette_preview(T_IO_Context * context)
|
||||
{
|
||||
short index;
|
||||
|
||||
if (context->Type == CONTEXT_PREVIEW)
|
||||
for (index=0; index<256; index++)
|
||||
Window_rectangle(183+(index/16)*7,95+(index&15)*5,5,5,index);
|
||||
|
||||
Update_window_area(183,95,120,80);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -- Tester si un fichier est au format PAL --------------------------------
|
||||
void Test_PAL(T_IO_Context * context)
|
||||
@ -111,9 +99,6 @@ void Load_PAL(T_IO_Context * context)
|
||||
Palette_64_to_256(palette_64);
|
||||
memcpy(context->Palette, palette_64, sizeof(T_Palette));
|
||||
Palette_loaded(context);
|
||||
|
||||
// On dessine une preview de la palette (si chargement = preview)
|
||||
Draw_palette_preview(context);
|
||||
}
|
||||
else
|
||||
File_error = 2;
|
||||
@ -137,12 +122,8 @@ void Load_PAL(T_IO_Context * context)
|
||||
context->Palette[i].R = r;
|
||||
context->Palette[i].G = g;
|
||||
context->Palette[i].B = b;
|
||||
|
||||
Palette_loaded(context);
|
||||
|
||||
// On dessine une preview de la palette (si chargement = preview)
|
||||
Draw_palette_preview(context);
|
||||
}
|
||||
Palette_loaded(context);
|
||||
} else File_error = 2;
|
||||
|
||||
}
|
||||
@ -159,31 +140,34 @@ void Load_PAL(T_IO_Context * context)
|
||||
// -- Sauver un fichier au format PAL ---------------------------------------
|
||||
void Save_PAL(T_IO_Context * context)
|
||||
{
|
||||
FILE *file; // Fichier du fichier
|
||||
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
|
||||
//long file_size; // Taille du fichier
|
||||
FILE *file;
|
||||
char filename[MAX_PATH_CHARACTERS]; ///< full filename
|
||||
|
||||
Get_full_filename(filename, context->File_name, context->File_directory);
|
||||
|
||||
File_error=0;
|
||||
|
||||
// Ouverture du fichier
|
||||
// Open output file
|
||||
if ((file=fopen(filename,"w")))
|
||||
{
|
||||
int i;
|
||||
fputs("JASC-PAL\n0100\n256\n", file);
|
||||
for (i = 0; i < 256; i++)
|
||||
fprintf(file,"%d %d %d\n",context->Palette[i].R, context->Palette[i].G, context->Palette[i].B);
|
||||
}
|
||||
else // Si on n'a pas réussi à ouvrir le fichier, alors il y a eu une erreur
|
||||
{
|
||||
if (fputs("JASC-PAL\n0100\n256\n", file)==EOF)
|
||||
File_error=1;
|
||||
for (i = 0; i < 256 && File_error==0; i++)
|
||||
{
|
||||
if (fprintf(file,"%d %d %d\n",context->Palette[i].R, context->Palette[i].G, context->Palette[i].B) <= 0)
|
||||
File_error=1;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
if (File_error)
|
||||
remove(filename);
|
||||
// On se fout du résultat de l'opération car si ça
|
||||
// renvoie 0 c'est que le fichier avait été partiel-
|
||||
// -lement écrit, sinon pas du tout. Or dans tous les
|
||||
// cas ça revient au même pour nous: Sauvegarde ratée!
|
||||
}
|
||||
else
|
||||
{
|
||||
// unable to open output file, nothing saved.
|
||||
File_error=1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1171,8 +1155,6 @@ void Load_KCF(T_IO_Context * context)
|
||||
}
|
||||
else
|
||||
File_error=1;
|
||||
|
||||
if (!File_error) Draw_palette_preview(context);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user