* Save CM5 files. There seem to be a problem with "Supports_layers" field. setting it to 1 still triggers the warning that image will be flatenned...

git-svn-id: svn://pulkomandy.tk/GrafX2/branches/cpcmode5@1724 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2011-02-15 19:34:36 +00:00
parent bf9c34d7fe
commit cd8f3e40da
2 changed files with 69 additions and 6 deletions

View File

@ -128,6 +128,7 @@ void Save_SCR(T_IO_Context *);
// -- CM5 (Amstrad CPC)
void Test_CM5(T_IO_Context *);
void Load_CM5(T_IO_Context *);
void Save_CM5(T_IO_Context *);
// -- XPM (X PixMap)
// Loading is done through SDL_Image
@ -166,7 +167,7 @@ T_Format File_formats[] = {
{FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 1, 0, 0, "pal", "pal"},
{FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, 0, "c64", "c64;koa;koala;fli;bml;cdu;prg"},
{FORMAT_SCR, " cpc", NULL, NULL, Save_SCR, 0, 0, 0, "cpc", "cpc;scr"},
{FORMAT_CM5, " cm5", Test_CM5, Load_CM5, NULL, 0, 0, 1, "cm5", "cm5"},
{FORMAT_CM5, " cm5", Test_CM5, Load_CM5, Save_CM5, 0, 0, 1, "cm5", "cm5"},
{FORMAT_XPM, " xpm", NULL, NULL, Save_XPM, 0, 0, 0, "xpm", "xpm"},
{FORMAT_MISC,"misc.",NULL, NULL, NULL, 0, 0, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"},
};

View File

@ -3086,12 +3086,74 @@ void Load_CM5(T_IO_Context* context)
void Save_CM5(T_IO_Context* context)
{
// Check picture has 5 layers
// Check the constraints on the layers
char filename[MAX_PATH_CHARACTERS];
FILE* file;
int tx, ty;
Get_full_filename(filename, context->File_name, context->File_directory);
// TODO: Check picture has 5 layers
// TODO: Check the constraints on the layers
// Layer 1 : 1 color Only
// Layer 2 and 3 : 1 color/line
// Layer 4 : 1 color / 48x1 block
// Layer 5 : colors 1 to 4 only used
// Layer 1..4 are written to the .CM5 file, then layer 5 is written to .scr file using
// the Save_SCR function.
// TODO: handle filesize
if (!(file = fopen(filename,"wb")))
{
File_error = 1;
return;
}
// Write layer 0
Set_layer(context, 0);
Write_byte(file, Get_pixel(context, 0, 0));
for(ty = 0; ty < 256; ty++)
{
Set_layer(context, 1);
Write_byte(file, Get_pixel(context, 0, ty));
Set_layer(context, 2);
Write_byte(file, Get_pixel(context, 0, ty));
Set_layer(context, 3);
for(tx = 0; tx < 6; tx++)
{
Write_byte(file, Get_pixel(context, tx*48, ty));
}
}
fclose(file);
// Now the pixeldata
filename[strlen(filename) - 3] = 0;
strcat(filename,"gfx");
if (!(file = fopen(filename, "wb")))
{
File_error = 2;
return;
}
Set_layer(context, 4);
for (ty = 0; ty < 256; ty++)
{
for (tx = 0; tx < 48*6; tx+=4)
{
byte code = 0;
byte pixel;
pixel = 3-Get_pixel(context, tx+3, ty);
code |= (pixel&2)>>1 | ((pixel & 1)<<4);
pixel = 3-Get_pixel(context, tx+2, ty);
code |= ((pixel&2)<<0) | ((pixel & 1)<<5);
pixel = 3-Get_pixel(context, tx+1, ty);
code |= ((pixel&2)<<1) | ((pixel & 1)<<6);
pixel = 3-Get_pixel(context, tx, ty);
code |= ((pixel&2)<<2) | ((pixel & 1)<<7);
Write_byte(file, code);
}
}
fclose(file);
File_error = 0;
}