Fix Test_GPL() and Load_GPL()
This commit is contained in:
parent
3103629c02
commit
531cda58b6
@ -2,6 +2,7 @@
|
|||||||
*/
|
*/
|
||||||
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
||||||
|
|
||||||
|
Copyright 2018 Thomas Bernard
|
||||||
Copyright 2011 Pawel Góralski
|
Copyright 2011 Pawel Góralski
|
||||||
Copyright 2009 Petter Lindquist
|
Copyright 2009 Petter Lindquist
|
||||||
Copyright 2008 Yves Rizoud
|
Copyright 2008 Yves Rizoud
|
||||||
@ -99,7 +100,8 @@ void Test_GPL(T_IO_Context * context, FILE * file)
|
|||||||
if (file_size > 33) {
|
if (file_size > 33) {
|
||||||
// minimum header length == 33
|
// minimum header length == 33
|
||||||
// "GIMP Palette" == 12
|
// "GIMP Palette" == 12
|
||||||
fread(buffer, 1, 12, file);
|
if (!Read_bytes(file, buffer, 12))
|
||||||
|
return;
|
||||||
if (strncmp(buffer,"GIMP Palette",12) == 0)
|
if (strncmp(buffer,"GIMP Palette",12) == 0)
|
||||||
File_error = 0;
|
File_error = 0;
|
||||||
}
|
}
|
||||||
@ -109,23 +111,18 @@ void Test_GPL(T_IO_Context * context, FILE * file)
|
|||||||
|
|
||||||
static int skip_padding(FILE *file, int max_chars)
|
static int skip_padding(FILE *file, int max_chars)
|
||||||
{
|
{
|
||||||
char buffer[1];
|
byte b;
|
||||||
int chars_read = 0;
|
int chars_read = 0;
|
||||||
int latest_chars_read = 0;
|
|
||||||
size_t tmp;
|
do {
|
||||||
buffer[0] = ' ';
|
if (chars_read == max_chars)
|
||||||
while (buffer[0] == ' '){
|
|
||||||
latest_chars_read = fread(buffer, 1, 1, file);
|
|
||||||
if ((latest_chars_read != 1) || (chars_read == max_chars))
|
|
||||||
return chars_read; // eof
|
return chars_read; // eof
|
||||||
chars_read += latest_chars_read;
|
if (!Read_byte(file, &b))
|
||||||
}
|
return chars_read;
|
||||||
|
chars_read++;
|
||||||
|
} while (b == ' ');
|
||||||
|
|
||||||
if (chars_read > 0){
|
fseek(file, -1, SEEK_CUR);
|
||||||
tmp = ftell(file);
|
|
||||||
// printf ("rewinding to %d", tmp - 1);
|
|
||||||
fseek(file, tmp - 1, SEEK_SET);
|
|
||||||
}
|
|
||||||
return chars_read;
|
return chars_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,59 +130,60 @@ static int skip_padding(FILE *file, int max_chars)
|
|||||||
void Load_GPL(T_IO_Context * context)
|
void Load_GPL(T_IO_Context * context)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char filename[MAX_PATH_CHARACTERS]; // full filename
|
char buffer[256];
|
||||||
long pos;
|
|
||||||
|
|
||||||
File_error=0;
|
File_error=0;
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
if ((file=Open_file_read(context)))
|
if ((file=Open_file_read(context)))
|
||||||
{
|
{
|
||||||
fread(filename, 1, 13, file);
|
if (!Read_byte_line(file, buffer, sizeof(buffer)))
|
||||||
if (strncmp(filename,"GIMP Palette\n",13) == 0)
|
|
||||||
{
|
{
|
||||||
int i, j, r, g, b, columns, chars_read;
|
File_error = 1;
|
||||||
fscanf(file, "Name: %s\n", filename);
|
return;
|
||||||
printf("DBG: Escaped nominal destruction ~%s~\n", filename); // y
|
}
|
||||||
fscanf(file, "Columns: %d\n", &columns);
|
|
||||||
|
if (memcmp(buffer,"GIMP Palette",12) == 0)
|
||||||
|
{
|
||||||
|
int i, r, g, b, columns;
|
||||||
|
size_t len;
|
||||||
|
// Name: xxxxx
|
||||||
|
if (!Read_byte_line(file, buffer, sizeof(buffer)))
|
||||||
|
{
|
||||||
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Columns: 16
|
||||||
|
fscanf(file, "Columns: %d", &columns);
|
||||||
|
Read_byte_line(file, buffer, sizeof(buffer));
|
||||||
// TODO: set grafx2 columns setting to match.
|
// TODO: set grafx2 columns setting to match.
|
||||||
printf("DBG: Escaped architectural destruction %d\n", columns); // y
|
|
||||||
// #<newline>
|
// #<newline>
|
||||||
fread(filename,1, 2, file);
|
if (!Read_byte_line(file, buffer, sizeof(buffer)))
|
||||||
filename[2] = 0;
|
{
|
||||||
printf("DBG: Escaped grammatical destruction ~%s~\n", filename);
|
File_error = 1;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
|
|
||||||
pos = ftell(file);
|
|
||||||
skip_padding(file, 32);
|
skip_padding(file, 32);
|
||||||
fscanf(file, "%d", &r);
|
fscanf(file, "%d", &r);
|
||||||
skip_padding(file, 32);
|
skip_padding(file, 32);
|
||||||
fscanf(file, "%d", &g);
|
fscanf(file, "%d", &g);
|
||||||
skip_padding(file, 32);
|
skip_padding(file, 32);
|
||||||
fscanf(file, "%d\t", &b);
|
fscanf(file, "%d\t", &b);
|
||||||
filename[0] = 0;
|
if (!Read_byte_line(file, buffer, sizeof(buffer)))
|
||||||
j = 0;
|
break;
|
||||||
do {
|
len = strlen(buffer);
|
||||||
|
while (len > 1)
|
||||||
chars_read = fscanf(file, "%s", filename+j);
|
{
|
||||||
if (chars_read > 0){
|
len--;
|
||||||
j += chars_read;
|
if (buffer[len] == '\r' || buffer[len] == '\n')
|
||||||
// space or newline follows.
|
buffer[len] = '\0';
|
||||||
fread(filename+j, 1, 1, file);
|
}
|
||||||
}
|
|
||||||
else{
|
|
||||||
filename[j] = '\n';
|
|
||||||
}
|
|
||||||
} while (filename[j] != '\n');
|
|
||||||
filename[j] = 0;
|
|
||||||
if (ftell(file) == pos)
|
|
||||||
break; // no more colors.
|
|
||||||
|
|
||||||
// TODO: analyze color names to build shade table
|
// TODO: analyze color names to build shade table
|
||||||
|
|
||||||
printf("DBG: %d: %s\n", i, filename);
|
//printf("DBG: %3d: RGB(%3d,%3d,%3d) %s\n", i, r,g,b, buffer);
|
||||||
context->Palette[i].R = r;
|
context->Palette[i].R = r;
|
||||||
context->Palette[i].G = g;
|
context->Palette[i].G = g;
|
||||||
context->Palette[i].B = b;
|
context->Palette[i].B = b;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user