Save_IFF(): support Comment saving (in ANNO chunk)
This commit is contained in:
parent
268887f456
commit
a94f07ddde
@ -1599,14 +1599,15 @@ void Save_IFF(T_IO_Context * context)
|
|||||||
word x_pos;
|
word x_pos;
|
||||||
word y_pos;
|
word y_pos;
|
||||||
byte temp_byte;
|
byte temp_byte;
|
||||||
int file_size;
|
|
||||||
int i;
|
int i;
|
||||||
int palette_entries;
|
int palette_entries;
|
||||||
byte bit_depth;
|
byte bit_depth;
|
||||||
|
long body_offset = -1;
|
||||||
|
|
||||||
if (context->Format == FORMAT_LBM)
|
if (context->Format == FORMAT_LBM)
|
||||||
{
|
{
|
||||||
// Check how many bits are used by pixel colors
|
// Check how many bits are used by pixel colors
|
||||||
|
temp_byte = 0;
|
||||||
for (y_pos=0; y_pos<context->Height; y_pos++)
|
for (y_pos=0; y_pos<context->Height; y_pos++)
|
||||||
for (x_pos=0; x_pos<context->Width; x_pos++)
|
for (x_pos=0; x_pos<context->Width; x_pos++)
|
||||||
temp_byte |= Get_pixel(context, x_pos,y_pos);
|
temp_byte |= Get_pixel(context, x_pos,y_pos);
|
||||||
@ -1675,6 +1676,18 @@ void Save_IFF(T_IO_Context * context)
|
|||||||
Write_dword_be(IFF_file,palette_entries*3);
|
Write_dword_be(IFF_file,palette_entries*3);
|
||||||
|
|
||||||
Write_bytes(IFF_file,context->Palette,palette_entries*3);
|
Write_bytes(IFF_file,context->Palette,palette_entries*3);
|
||||||
|
|
||||||
|
if (context->Comment[0]) // write ANNO
|
||||||
|
{
|
||||||
|
dword comment_size;
|
||||||
|
|
||||||
|
Write_bytes(IFF_file,"ANNO",4); // Chunk name
|
||||||
|
comment_size = strlen(context->Comment); // NULL termination is not needed
|
||||||
|
Write_dword_be(IFF_file, comment_size); // Section size
|
||||||
|
Write_bytes(IFF_file, context->Comment, comment_size);
|
||||||
|
if (comment_size&1)
|
||||||
|
Write_byte(IFF_file, 0); // align to WORD boundaries
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i<context->Color_cycles; i++)
|
for (i=0; i<context->Color_cycles; i++)
|
||||||
{
|
{
|
||||||
@ -1691,7 +1704,8 @@ void Save_IFF(T_IO_Context * context)
|
|||||||
Write_byte(IFF_file,context->Cycle_range[i].End); // Max color
|
Write_byte(IFF_file,context->Cycle_range[i].End); // Max color
|
||||||
// No padding, size is multiple of 2
|
// No padding, size is multiple of 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body_offset = ftell(IFF_file);
|
||||||
Write_bytes(IFF_file,"BODY",4);
|
Write_bytes(IFF_file,"BODY",4);
|
||||||
Write_dword_be(IFF_file,0); // On mettra la taille à jour à la fin
|
Write_dword_be(IFF_file,0); // On mettra la taille à jour à la fin
|
||||||
|
|
||||||
@ -1758,49 +1772,27 @@ void Save_IFF(T_IO_Context * context)
|
|||||||
Transfer_colors(IFF_file);
|
Transfer_colors(IFF_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(IFF_file);
|
// Now update FORM and BODY size
|
||||||
IFF_file = NULL;
|
|
||||||
|
|
||||||
if (!File_error)
|
if (!File_error)
|
||||||
{
|
{
|
||||||
file_size=File_length(filename);
|
long file_size = ftell(IFF_file);
|
||||||
|
if (file_size&1)
|
||||||
IFF_file=fopen(filename,"rb+");
|
|
||||||
fseek(IFF_file,52+palette_entries*3+context->Color_cycles*16,SEEK_SET);
|
|
||||||
Write_dword_be(IFF_file,file_size-56-palette_entries*3-context->Color_cycles*16);
|
|
||||||
|
|
||||||
if (!File_error)
|
|
||||||
{
|
{
|
||||||
fseek(IFF_file,4,SEEK_SET);
|
// PAD to even file size
|
||||||
|
if (! Write_byte(IFF_file,0))
|
||||||
// Si la taille de la section de l'image (taille fichier-8) est
|
File_error=1;
|
||||||
// impaire, on rajoute un 0 (Padding) à la fin.
|
|
||||||
if ((file_size) & 1)
|
|
||||||
{
|
|
||||||
Write_dword_be(IFF_file,file_size-7);
|
|
||||||
fseek(IFF_file,0,SEEK_END);
|
|
||||||
temp_byte=0;
|
|
||||||
if (! Write_bytes(IFF_file,&temp_byte,1))
|
|
||||||
File_error=1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
Write_dword_be(IFF_file,file_size-8);
|
|
||||||
|
|
||||||
fclose(IFF_file);
|
|
||||||
IFF_file = NULL;
|
|
||||||
|
|
||||||
if (File_error)
|
|
||||||
remove(filename);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
File_error=1;
|
|
||||||
fclose(IFF_file);
|
|
||||||
IFF_file = NULL;
|
|
||||||
remove(filename);
|
|
||||||
}
|
}
|
||||||
|
// Write BODY size
|
||||||
|
fseek(IFF_file, body_offset + 4, SEEK_SET);
|
||||||
|
Write_dword_be(IFF_file, file_size-body_offset-8);
|
||||||
|
// Write FORM size
|
||||||
|
file_size = (file_size+1)&~1;
|
||||||
|
fseek(IFF_file,4,SEEK_SET);
|
||||||
|
Write_dword_be(IFF_file,file_size-8);
|
||||||
}
|
}
|
||||||
else // Il y a eu une erreur lors du compactage => on efface le fichier
|
fclose(IFF_file);
|
||||||
|
IFF_file = NULL;
|
||||||
|
if (File_error != 0) // delete file if any error during saving
|
||||||
remove(filename);
|
remove(filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -164,7 +164,7 @@ void Load_SDL_Image(T_IO_Context *);
|
|||||||
|
|
||||||
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
|
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
|
||||||
const T_Format File_formats[] = {
|
const T_Format File_formats[] = {
|
||||||
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;2bp;pcx;pkm;iff;lbm;ilbm;sham;acbm;pic;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;c64;koa;koala;fli;bml;cdu;prg;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico;ic2;cur;cm5;pph"},
|
{FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;2bp;pcx;pkm;iff;lbm;ilbm;sham;ham;ham6;ham8;acbm;pic;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;c64;koa;koala;fli;bml;cdu;prg;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico;ic2;cur;cm5;pph"},
|
||||||
{FORMAT_ALL_PALETTES, "(pal)", NULL, NULL, NULL, 1, 0, 0, "", "kcf;pal;gpl"},
|
{FORMAT_ALL_PALETTES, "(pal)", NULL, NULL, NULL, 1, 0, 0, "", "kcf;pal;gpl"},
|
||||||
{FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, 0, "", "*"},
|
{FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, 0, "", "*"},
|
||||||
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 0, 1, 1, "gif", "gif"},
|
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 0, 1, 1, "gif", "gif"},
|
||||||
@ -174,9 +174,9 @@ const T_Format File_formats[] = {
|
|||||||
{FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 0, 0, 0, "bmp", "bmp;2bp"},
|
{FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 0, 0, 0, "bmp", "bmp;2bp"},
|
||||||
{FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 0, 0, 0, "pcx", "pcx"},
|
{FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 0, 0, 0, "pcx", "pcx"},
|
||||||
{FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, 0, "pkm", "pkm"},
|
{FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, 0, "pkm", "pkm"},
|
||||||
{FORMAT_LBM, " lbm", Test_LBM, Load_IFF, Save_IFF, 0, 0, 0, "iff", "iff;lbm;ilbm;sham"},
|
{FORMAT_LBM, " lbm", Test_LBM, Load_IFF, Save_IFF, 0, 1, 0, "iff", "iff;lbm;ilbm;sham;ham;ham6;ham8"},
|
||||||
{FORMAT_PBM, " pbm", Test_PBM, Load_IFF, Save_IFF, 0, 0, 0, "iff", "iff;pbm;lbm"},
|
{FORMAT_PBM, " pbm", Test_PBM, Load_IFF, Save_IFF, 0, 1, 0, "iff", "iff;pbm;lbm"},
|
||||||
{FORMAT_ACBM," acbm",Test_ACBM,Load_IFF, NULL, 0, 0, 0, "iff", "iff;pic;acbm"},
|
{FORMAT_ACBM," acbm",Test_ACBM,Load_IFF, NULL, 0, 1, 0, "iff", "iff;pic;acbm"},
|
||||||
{FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 0, 0, 0, "img", "img"},
|
{FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 0, 0, 0, "img", "img"},
|
||||||
{FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 0, 0, 0, "sc?", "sci;scq;scf;scn;sco"},
|
{FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 0, 0, 0, "sc?", "sci;scq;scf;scn;sco"},
|
||||||
{FORMAT_PI1, " pi1", Test_PI1, Load_PI1, Save_PI1, 0, 0, 0, "pi1", "pi1"},
|
{FORMAT_PI1, " pi1", Test_PI1, Load_PI1, Save_PI1, 0, 0, 0, "pi1", "pi1"},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user