tests for Load_GOS/Load_SCR/Save_GOS/Save_SCR

This commit is contained in:
Thomas Bernard 2019-12-21 21:01:47 +01:00
parent 3c5c518c83
commit 1fba07db99
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 33 additions and 11 deletions

View File

@ -584,7 +584,7 @@ void Save_SCR(T_IO_Context * context)
FILE* file; FILE* file;
switch(Pixel_ratio) switch(context->Ratio)
{ {
case PIXEL_WIDE: case PIXEL_WIDE:
case PIXEL_WIDE2: case PIXEL_WIDE2:

View File

@ -44,14 +44,19 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size,
context->Surface = New_GFX2_Surface(width, height); context->Surface = New_GFX2_Surface(width, height);
if (context->Surface == NULL) if (context->Surface == NULL)
File_error = 1; File_error = 1;
else
{
context->Target_address = context->Surface->pixels;
context->Pitch = context->Surface->w;
}
} }
} }
byte Get_pixel(T_IO_Context *context, short x, short y) byte Get_pixel(T_IO_Context *context, short x, short y)
{ {
if (context->Type == CONTEXT_SURFACE) if (x < 0 || x >= context->Width || y < 0 || y >= context->Height)
return Get_GFX2_Surface_pixel(context->Surface, x, y);
return 0; return 0;
return context->Target_address[y*context->Pitch + x];
} }
void Pixel_in_layer(int layer, word x, word y, byte color) void Pixel_in_layer(int layer, word x, word y, byte color)

View File

@ -44,6 +44,8 @@
// 16 colors 320x200 format. For testing Atari ST formats. // 16 colors 320x200 format. For testing Atari ST formats.
#define FLAG_16C 1 #define FLAG_16C 1
// 16 color 192x272 format. CPC overscan
#define FLAG_CPCO 2
// Load/Save // Load/Save
#define TESTFMTF(fmt, sample, flags) { FORMAT_ ## fmt, # fmt, Test_ ## fmt, Load_ ## fmt, Save_ ## fmt, flags, sample }, #define TESTFMTF(fmt, sample, flags) { FORMAT_ ## fmt, # fmt, Test_ ## fmt, Load_ ## fmt, Save_ ## fmt, flags, sample },
@ -72,10 +74,10 @@ static const struct {
TESTFMTL(C64, "c64/multicolor/ARKANOID.KOA") // Format with limitations TESTFMTL(C64, "c64/multicolor/ARKANOID.KOA") // Format with limitations
TESTFMTL(PRG, "c64/multicolor/speedball2_loading_jonegg.prg") TESTFMTL(PRG, "c64/multicolor/speedball2_loading_jonegg.prg")
TESTFMTL(GPX, "c64/pixcen/Cyberbird.gpx") TESTFMTL(GPX, "c64/pixcen/Cyberbird.gpx")
TESTFMTL(SCR, "cpc/scr/DANCEOFF.SCR") // Format with limitations TESTFMTF(SCR, "cpc/scr/DANCEOFF.SCR", FLAG_CPCO)
TESTFMTL(CM5, "cpc/mode5/spidey.cm5") // Format with limitations TESTFMTL(CM5, "cpc/mode5/spidey.cm5") // Format with limitations
TESTFMTL(PPH, "cpc/pph/BF.PPH") // Format with limitations TESTFMTL(PPH, "cpc/pph/BF.PPH") // Format with limitations
TESTFMTL(GOS, "cpc/iMPdraw_GFX/SONIC.GO1") TESTFMTF(GOS, "cpc/iMPdraw_GFX/SONIC.GO1", FLAG_CPCO)
TESTFMTL(MOTO,"thomson/exocet-alientis.map") // Format with limitations TESTFMTL(MOTO,"thomson/exocet-alientis.map") // Format with limitations
TESTFMTL(HGR, "apple2/hgr/pop-swordfight.hgr") // Format with limitations TESTFMTL(HGR, "apple2/hgr/pop-swordfight.hgr") // Format with limitations
TESTFMTL(ACBM, "iff/ACBM/Jupiter_alt.pic") TESTFMTL(ACBM, "iff/ACBM/Jupiter_alt.pic")
@ -232,6 +234,7 @@ int Test_Save(void)
int ok = 0; int ok = 0;
T_GFX2_Surface * testpic256 = NULL; T_GFX2_Surface * testpic256 = NULL;
T_GFX2_Surface * testpic16 = NULL; T_GFX2_Surface * testpic16 = NULL;
T_GFX2_Surface * testpiccpco = NULL;
memset(&context, 0, sizeof(context)); memset(&context, 0, sizeof(context));
context.Type = CONTEXT_SURFACE; context.Type = CONTEXT_SURFACE;
@ -259,6 +262,17 @@ int Test_Save(void)
testpic16 = context.Surface; testpic16 = context.Surface;
context.Surface = NULL; context.Surface = NULL;
memcpy(testpic16->palette, context.Palette, sizeof(T_Palette)); memcpy(testpic16->palette, context.Palette, sizeof(T_Palette));
// Load POULPE.GO1/GO2 etc.
context_set_file_path(&context, "../tests/pic-samples/cpc/iMPdraw_GFX/POULPE.GO1");
Load_GOS(&context);
if (File_error != 0)
{
fprintf(stderr, "Failed to load reference CPC overscan mode 0 picture\n");
goto ret;
}
testpiccpco = context.Surface;
context.Surface = NULL;
memcpy(testpiccpco->palette, context.Palette, sizeof(T_Palette));
snprintf(tmpdir, sizeof(tmpdir), "/tmp/grafx2-test.XXXXXX"); snprintf(tmpdir, sizeof(tmpdir), "/tmp/grafx2-test.XXXXXX");
if (mkdtemp(tmpdir) == NULL) if (mkdtemp(tmpdir) == NULL)
@ -277,11 +291,12 @@ int Test_Save(void)
context_set_file_path(&context, path); context_set_file_path(&context, path);
// save the reference picture // save the reference picture
context.Surface = (formats[i].flags & FLAG_16C) ? testpic16 : testpic256; context.Surface = (formats[i].flags & FLAG_16C) ? testpic16 : (formats[i].flags & FLAG_CPCO) ? testpiccpco : testpic256;
context.Target_address = context.Surface->pixels; context.Target_address = context.Surface->pixels;
context.Pitch = context.Surface->w; context.Pitch = context.Surface->w;
context.Width = context.Surface->w; context.Width = context.Surface->w;
context.Height = context.Surface->h; context.Height = context.Surface->h;
context.Ratio = (formats[i].flags & FLAG_CPCO) ? PIXEL_WIDE : PIXEL_SIMPLE;
memcpy(context.Palette, context.Surface->palette, sizeof(T_Palette)); memcpy(context.Palette, context.Surface->palette, sizeof(T_Palette));
context.Format = formats[i].format; context.Format = formats[i].format;
File_error = 0; File_error = 0;
@ -323,7 +338,7 @@ int Test_Save(void)
} }
else else
{ {
T_GFX2_Surface * ref = (formats[i].flags & FLAG_16C) ? testpic16 : testpic256; T_GFX2_Surface * ref = (formats[i].flags & FLAG_16C) ? testpic16 : (formats[i].flags & FLAG_CPCO) ? testpiccpco : testpic256;
// compare with the reference picture // compare with the reference picture
if (context.Surface->w != ref->w || context.Surface->h != ref->h) if (context.Surface->w != ref->w || context.Surface->h != ref->h)
{ {
@ -333,12 +348,12 @@ int Test_Save(void)
} }
else if (0 != memcmp(context.Surface->pixels, ref->pixels, ref->w * ref->h)) else if (0 != memcmp(context.Surface->pixels, ref->pixels, ref->w * ref->h))
{ {
GFX2_Log(GFX2_ERROR, "Save%s/Load_%s: Pixels mismatch\n", formats[i].name, formats[i].name); GFX2_Log(GFX2_ERROR, "Save_%s/Load_%s: Pixels mismatch\n", formats[i].name, formats[i].name);
ok = 0; ok = 0;
} }
else if (0 != memcmp(context.Palette, ref->palette, (formats[i].flags & FLAG_16C) ? 16 * sizeof(T_Components) : sizeof(T_Palette))) else if (!(formats[i].flags & FLAG_CPCO) && 0 != memcmp(context.Palette, ref->palette, (formats[i].flags & FLAG_16C) ? 16 * sizeof(T_Components) : sizeof(T_Palette)))
{ {
GFX2_Log(GFX2_ERROR, "Save%s/Load_%s: Palette mismatch\n", formats[i].name, formats[i].name); GFX2_Log(GFX2_ERROR, "Save_%s/Load_%s: Palette mismatch\n", formats[i].name, formats[i].name);
ok = 0; ok = 0;
} }
else else
@ -358,6 +373,8 @@ ret:
Free_GFX2_Surface(testpic16); Free_GFX2_Surface(testpic16);
if (testpic256) if (testpic256)
Free_GFX2_Surface(testpic256); Free_GFX2_Surface(testpic256);
if (testpiccpco)
Free_GFX2_Surface(testpiccpco);
free(context.File_name); free(context.File_name);
free(context.File_directory); free(context.File_directory);
return ok; return ok;