Load and save palettes using JASC "standard" format. Still load old palettes from DOS Grafx2, but now we handle full color :)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1137 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
a725f0035e
commit
1406e74f56
14
loadsave.c
14
loadsave.c
@ -497,20 +497,6 @@ void Init_preview(short width,short height,long size,int format, enum PIXEL_RATI
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Draw_palette_preview(void)
|
||||
{
|
||||
short index;
|
||||
|
||||
if (Pixel_load_function==Pixel_load_in_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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Calcul du nom complet du fichier
|
||||
void Get_full_filename(char * filename, byte is_colorix_format)
|
||||
{
|
||||
|
||||
@ -23,13 +23,30 @@
|
||||
///@file miscfileformats.c
|
||||
/// Formats that aren't fully saving, either because of palette restrictions or other things
|
||||
|
||||
#include "errors.h"
|
||||
#include "global.h"
|
||||
#include "io.h"
|
||||
#include "limits.h"
|
||||
#include "loadsave.h"
|
||||
#include "misc.h"
|
||||
#include "sdlscreen.h"
|
||||
#include "struct.h"
|
||||
#include "windows.h"
|
||||
|
||||
//////////////////////////////////// PAL ////////////////////////////////////
|
||||
//
|
||||
void Draw_palette_preview(void)
|
||||
{
|
||||
short index;
|
||||
|
||||
if (Pixel_load_function==Pixel_load_in_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(void)
|
||||
@ -47,10 +64,18 @@ void Test_PAL(void)
|
||||
{
|
||||
// Lecture de la taille du fichier
|
||||
file_size = File_length_file(file);
|
||||
fclose(file);
|
||||
// Le fichier ne peut être au format PAL que si sa taille vaut 768 octets
|
||||
if (file_size == sizeof(T_Palette))
|
||||
File_error = 0;
|
||||
else {
|
||||
// Sinon c'est peut être un fichier palette ASCII "Jasc"
|
||||
fread(filename, 1, 8, file);
|
||||
if (strncmp(filename,"JASC-PAL",8) == 0)
|
||||
{
|
||||
File_error = 0;
|
||||
}
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,6 +93,10 @@ void Load_PAL(void)
|
||||
|
||||
// Ouverture du fichier
|
||||
if ((file=fopen(filename, "rb")))
|
||||
{
|
||||
long file_size = File_length_file(file);
|
||||
// Le fichier ne peut être au format PAL que si sa taille vaut 768 octets
|
||||
if (file_size == sizeof(T_Palette))
|
||||
{
|
||||
T_Palette palette_64;
|
||||
// Init_preview(?); // Pas possible... pas d'image...
|
||||
@ -85,6 +114,36 @@ void Load_PAL(void)
|
||||
}
|
||||
else
|
||||
File_error = 2;
|
||||
} else {
|
||||
fread(filename, 1, 8, file);
|
||||
if (strncmp(filename,"JASC-PAL",8) == 0)
|
||||
{
|
||||
int i, n, r, g, b;
|
||||
fscanf(file, "%d",&n);
|
||||
if(n != 100)
|
||||
{
|
||||
File_error = 2;
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
// Read color count
|
||||
fscanf(file, "%d",&n);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fscanf(file, "%d %d %d",&r, &g, &b);
|
||||
Main_palette[i].R = r;
|
||||
Main_palette[i].G = g;
|
||||
Main_palette[i].B = b;
|
||||
|
||||
Set_palette(Main_palette);
|
||||
Remap_fileselector();
|
||||
|
||||
// On dessine une preview de la palette (si chargement = preview)
|
||||
Draw_palette_preview();
|
||||
}
|
||||
} else File_error = 2;
|
||||
|
||||
}
|
||||
|
||||
// Fermeture du fichier
|
||||
fclose(file);
|
||||
@ -107,20 +166,12 @@ void Save_PAL(void)
|
||||
File_error=0;
|
||||
|
||||
// Ouverture du fichier
|
||||
if ((file=fopen(filename,"wb")))
|
||||
if ((file=fopen(filename,"w")))
|
||||
{
|
||||
T_Palette palette_64;
|
||||
memcpy(palette_64,Main_palette,sizeof(T_Palette));
|
||||
Palette_256_to_64(palette_64);
|
||||
// Enregistrement de Main_palette dans le fichier
|
||||
if (! Write_bytes(file,palette_64,sizeof(T_Palette)))
|
||||
{
|
||||
File_error=1;
|
||||
fclose(file);
|
||||
remove(filename);
|
||||
}
|
||||
else // Ecriture correcte => Fermeture normale du fichier
|
||||
fclose(file);
|
||||
int i;
|
||||
fputs("JASC-PAL\n0100\n256\n", file);
|
||||
for (i = 0; i < 256; i++)
|
||||
fprintf(file,"%d %d %d\n",Main_palette[i].R, Main_palette[i].G, Main_palette[i].B);
|
||||
}
|
||||
else // Si on n'a pas réussi à ouvrir le fichier, alors il y a eu une erreur
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user