SCx: Doxygen + fix of file extension selection

This commit is contained in:
Thomas Bernard 2019-02-20 12:04:48 +01:00
parent bc4c2db2e4
commit 760cd0d960
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C

View File

@ -89,6 +89,7 @@
#include "io.h" #include "io.h"
#include "pages.h" #include "pages.h"
#include "windows.h" // Best_color() #include "windows.h" // Best_color()
#include "unicode.h"
#include "fileformats.h" #include "fileformats.h"
#include "oldies.h" #include "oldies.h"
#include "bitcount.h" #include "bitcount.h"
@ -5973,26 +5974,34 @@ void Save_PCX(T_IO_Context * context)
//////////////////////////////////// SCx //////////////////////////////////// //////////////////////////////////// SCx ////////////////////////////////////
/**
* @defgroup SCx SCx format
* @ingroup loadsaveformats
* ColoRix VGA Paint SCx File Format
*
* file extensions are sci, scq, scf, scn, sco
* @{
*/
/// SCx header data
typedef struct typedef struct
{ {
byte Filler1[4]; byte Filler1[4]; ///< "RIX3"
word Width; word Width; ///< Image Width
word Height; word Height; ///< Image Height
byte PaletteType; // M P RGB PIX 0xAF = VGA byte PaletteType; ///< M P RGB PIX 0xAF = VGA
byte StorageType; // 00 = Linear (1 byte per pixel) 01,02 Planar 03 text 80 Compressed 40 extension block 20 encrypted byte StorageType; ///< 00 = Linear (1 byte per pixel) 01,02 Planar 03 text 80 Compressed 40 extension block 20 encrypted
} T_SCx_Header; } T_SCx_Header;
// -- Tester si un fichier est au format SCx -------------------------------- /// Test if a file is SCx format
void Test_SCx(T_IO_Context * context, FILE * file) void Test_SCx(T_IO_Context * context, FILE * file)
{ {
//byte Signature[3];
T_SCx_Header SCx_header; T_SCx_Header SCx_header;
(void)context; (void)context;
File_error=1; File_error=1;
// Ouverture du fichier // read and check header
// Lecture et vérification de la signature
if (Read_bytes(file,SCx_header.Filler1,4) if (Read_bytes(file,SCx_header.Filler1,4)
&& Read_word_le(file, &(SCx_header.Width)) && Read_word_le(file, &(SCx_header.Width))
&& Read_word_le(file, &(SCx_header.Height)) && Read_word_le(file, &(SCx_header.Height))
@ -6007,7 +6016,7 @@ void Test_SCx(T_IO_Context * context, FILE * file)
} }
// -- Lire un fichier au format SCx ----------------------------------------- /// Read a SCx file
void Load_SCx(T_IO_Context * context) void Load_SCx(T_IO_Context * context)
{ {
FILE *file; FILE *file;
@ -6099,16 +6108,17 @@ void Load_SCx(T_IO_Context * context)
File_error=1; File_error=1;
} }
// -- Sauver un fichier au format SCx --------------------------------------- /// Save a SCx file
void Save_SCx(T_IO_Context * context) void Save_SCx(T_IO_Context * context)
{ {
FILE *file; FILE *file;
short x_pos,y_pos; short x_pos,y_pos;
T_SCx_Header SCx_header; T_SCx_Header SCx_header;
byte last_char; size_t last_char;
last_char=strlen(context->File_name)-1; // replace the '?' in file extension with the right letter
if (context->File_name[last_char]=='?') last_char = strlen(context->File_name) - 1;
if (context->File_name[last_char] == '?')
{ {
if (context->Width<=320) if (context->Width<=320)
context->File_name[last_char]='I'; context->File_name[last_char]='I';
@ -6129,17 +6139,27 @@ void Save_SCx(T_IO_Context * context)
} }
} }
} }
// makes it same case as the previous character
if (last_char > 0)
context->File_name[last_char] |= (context->File_name[last_char - 1] & 32);
// also fix the unicode file name
if (context->File_name_unicode != NULL && context->File_name_unicode[0] != 0)
{
size_t ulen = Unicode_strlen(context->File_name_unicode);
if (ulen > 1)
context->File_name_unicode[ulen - 1] = context->File_name[last_char];
}
} }
File_error=0;
// Ouverture du fichier file = Open_file_write(context);
if ((file=Open_file_write(context)))
if (file != NULL)
{ {
T_Palette palette_64; T_Palette palette_64;
setvbuf(file, NULL, _IOFBF, 64*1024); File_error = 0;
memcpy(palette_64,context->Palette,sizeof(T_Palette)); memcpy(palette_64, context->Palette, sizeof(T_Palette));
Palette_256_to_64(palette_64); Palette_256_to_64(palette_64);
memcpy(SCx_header.Filler1,"RIX3",4); memcpy(SCx_header.Filler1,"RIX3",4);
@ -6148,7 +6168,7 @@ void Save_SCx(T_IO_Context * context)
SCx_header.PaletteType=0xAF; SCx_header.PaletteType=0xAF;
SCx_header.StorageType=0x00; SCx_header.StorageType=0x00;
if (Write_bytes(file,SCx_header.Filler1,4) if (Write_bytes(file,SCx_header.Filler1, 4)
&& Write_word_le(file, SCx_header.Width) && Write_word_le(file, SCx_header.Width)
&& Write_word_le(file, SCx_header.Height) && Write_word_le(file, SCx_header.Height)
&& Write_byte(file, SCx_header.PaletteType) && Write_byte(file, SCx_header.PaletteType)
@ -6158,19 +6178,15 @@ void Save_SCx(T_IO_Context * context)
{ {
for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++) for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++)
for (x_pos=0; x_pos<context->Width; x_pos++) for (x_pos=0; x_pos<context->Width; x_pos++)
Write_one_byte(file,Get_pixel(context, x_pos,y_pos)); Write_one_byte(file, Get_pixel(context, x_pos, y_pos));
fclose(file);
if (File_error)
Remove_file(context);
} }
else // Error d'écriture (disque plein ou protégé) else
{ {
fclose(file); File_error = 1;
Remove_file(context);
File_error=1;
} }
fclose(file);
if (File_error)
Remove_file(context);
} }
else else
{ {
@ -6178,6 +6194,8 @@ void Save_SCx(T_IO_Context * context)
} }
} }
/** @} */
//////////////////////////////////// XPM //////////////////////////////////// //////////////////////////////////// XPM ////////////////////////////////////
void Save_XPM(T_IO_Context* context) void Save_XPM(T_IO_Context* context)
{ {