* Load Microsoft RIFF palette files
* Make byte, word, dword, qword typedefs instead of defines. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1954 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
235f7d4d1c
commit
2aa9ea7f8e
@ -26,6 +26,7 @@
|
|||||||
///@file miscfileformats.c
|
///@file miscfileformats.c
|
||||||
/// Formats that aren't fully saving, either because of palette restrictions or other things
|
/// Formats that aren't fully saving, either because of palette restrictions or other things
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -34,7 +35,6 @@
|
|||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
#include "libraw2crtc.h"
|
#include "libraw2crtc.h"
|
||||||
#include <limits.h>
|
|
||||||
#include "loadsave.h"
|
#include "loadsave.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "sdlscreen.h"
|
#include "sdlscreen.h"
|
||||||
@ -45,31 +45,45 @@
|
|||||||
//////////////////////////////////// PAL ////////////////////////////////////
|
//////////////////////////////////// PAL ////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
|
||||||
// -- Tester si un fichier est au format PAL --------------------------------
|
// -- Test wether a file is in PAL format --------------------------------
|
||||||
void Test_PAL(T_IO_Context * context)
|
void Test_PAL(T_IO_Context * context)
|
||||||
{
|
{
|
||||||
FILE *file; // Fichier du fichier
|
FILE *file;
|
||||||
char filename[MAX_PATH_CHARACTERS]; // Nom complet du fichier
|
char filename[MAX_PATH_CHARACTERS];
|
||||||
long file_size; // Taille du fichier
|
long file_size;
|
||||||
|
|
||||||
Get_full_filename(filename, context->File_name, context->File_directory);
|
Get_full_filename(filename, context->File_name, context->File_directory);
|
||||||
|
|
||||||
File_error = 1;
|
File_error = 1;
|
||||||
|
|
||||||
// Ouverture du fichier
|
|
||||||
if ((file = fopen(filename, "rb")))
|
if ((file = fopen(filename, "rb")))
|
||||||
{
|
{
|
||||||
// Lecture de la taille du fichier
|
|
||||||
file_size = File_length_file(file);
|
file_size = File_length_file(file);
|
||||||
// Le fichier ne peut être au format PAL que si sa taille vaut 768 octets
|
// First check for GrafX2 legacy palette format. The simplest one, 768 bytes
|
||||||
|
// of RGB data. It is a raw dump of the T_Palette structure. There is no
|
||||||
|
// header at all, so we check for the file size.
|
||||||
if (file_size == sizeof(T_Palette))
|
if (file_size == sizeof(T_Palette))
|
||||||
File_error = 0;
|
File_error = 0;
|
||||||
else {
|
else {
|
||||||
// Sinon c'est peut être un fichier palette ASCII "Jasc"
|
// Bigger (or smaller ?) files may be in other formats. These have an
|
||||||
|
// header, so look for it.
|
||||||
fread(filename, 1, 8, file);
|
fread(filename, 1, 8, file);
|
||||||
if (strncmp(filename,"JASC-PAL",8) == 0)
|
if (strncmp(filename,"JASC-PAL",8) == 0)
|
||||||
{
|
{
|
||||||
|
// JASC file format, used by Paint Shop Pro and GIMP. This is also the
|
||||||
|
// one used for saving, as it brings greater interoperability.
|
||||||
File_error = 0;
|
File_error = 0;
|
||||||
|
} else if(strncmp(filename,"RIFF", 4) == 0)
|
||||||
|
{
|
||||||
|
// Microsoft RIFF file
|
||||||
|
// This is a data container (similar to IFF). We only check the first
|
||||||
|
// chunk header, and give up if that's not a palette.
|
||||||
|
fseek(file, 8, SEEK_SET);
|
||||||
|
fread(filename, 1, 8, file);
|
||||||
|
if (strncmp(filename, "PAL data", 8) == 0)
|
||||||
|
{
|
||||||
|
File_error = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@ -129,7 +143,29 @@ void Load_PAL(T_IO_Context * context)
|
|||||||
context->Palette[i].B = b;
|
context->Palette[i].B = b;
|
||||||
}
|
}
|
||||||
Palette_loaded(context);
|
Palette_loaded(context);
|
||||||
|
} else if(strncmp(filename, "RIFF", 4) == 0) {
|
||||||
|
// Microsoft RIFF format.
|
||||||
|
fseek(file, 8, SEEK_SET);
|
||||||
|
fread(filename, 1, 8, file);
|
||||||
|
if (strncmp(filename, "PAL data", 8) == 0)
|
||||||
|
{
|
||||||
|
char buffer[4];
|
||||||
|
word color_count;
|
||||||
|
word i = 0;
|
||||||
|
|
||||||
|
fseek(file, 22, SEEK_SET);
|
||||||
|
Read_word_le(file, &color_count);
|
||||||
|
for(i = 0; i < color_count; i++)
|
||||||
|
{
|
||||||
|
Read_bytes(file, buffer, 4);
|
||||||
|
context->Palette[i].R = buffer[0];
|
||||||
|
context->Palette[i].G = buffer[1];
|
||||||
|
context->Palette[i].B = buffer[2];
|
||||||
|
}
|
||||||
|
|
||||||
} else File_error = 2;
|
} else File_error = 2;
|
||||||
|
} else
|
||||||
|
File_error = 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -44,13 +44,13 @@
|
|||||||
|
|
||||||
// Definition of the base data types
|
// Definition of the base data types
|
||||||
/// 8bit unsigned integer
|
/// 8bit unsigned integer
|
||||||
#define byte uint8_t
|
typedef uint8_t byte;
|
||||||
/// 16bit unsigned integer
|
/// 16bit unsigned integer
|
||||||
#define word uint16_t
|
typedef uint16_t word;
|
||||||
/// 32bit unsigned integer
|
/// 32bit unsigned integer
|
||||||
#define dword uint32_t
|
typedef uint32_t dword;
|
||||||
/// 64bit unsigned integer
|
/// 64bit unsigned integer
|
||||||
#define qword uint64_t
|
typedef uint64_t qword;
|
||||||
|
|
||||||
// Named function prototypes
|
// Named function prototypes
|
||||||
// GrafX2 use a lot of function pointer to do the drawing depending in the "fake hardware zoom" and the magnifier status.
|
// GrafX2 use a lot of function pointer to do the drawing depending in the "fake hardware zoom" and the magnifier status.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user