add Test_Packbits()
This commit is contained in:
parent
cd1349fdab
commit
3ba4472626
@ -818,7 +818,7 @@ OBJS += loadrecoil.o recoil.o
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
TESTSOBJS = $(patsubst %.c,%.o,$(wildcard tests/*.c)) \
|
TESTSOBJS = $(patsubst %.c,%.o,$(wildcard tests/*.c)) \
|
||||||
miscfileformats.o oldies.o libraw2crtc.o \
|
miscfileformats.o fileformats.o oldies.o libraw2crtc.o \
|
||||||
loadsavefuncs.o \
|
loadsavefuncs.o \
|
||||||
unicode.o \
|
unicode.o \
|
||||||
io.o realpath.o version.o pversion.o \
|
io.o realpath.o version.o pversion.o \
|
||||||
|
|||||||
@ -692,7 +692,7 @@ static void LBM_Decode(T_IO_Context * context, FILE * file, byte compression, by
|
|||||||
File_error=22;
|
File_error=22;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// temp_byte > 127 => repeat (256-temp_byte) the next byte
|
// temp_byte > 127 => repeat (257-temp_byte) the next byte
|
||||||
// temp_byte <= 127 => copy (temp_byte + 1) bytes
|
// temp_byte <= 127 => copy (temp_byte + 1) bytes
|
||||||
if(temp_byte == 128) // 128 = NOP !
|
if(temp_byte == 128) // 128 = NOP !
|
||||||
{
|
{
|
||||||
@ -2202,7 +2202,7 @@ void Load_IFF(T_IO_Context * context)
|
|||||||
byte IFF_repetition_mode;
|
byte IFF_repetition_mode;
|
||||||
|
|
||||||
// ------------- Ecrire les couleurs que l'on vient de traiter ------------
|
// ------------- Ecrire les couleurs que l'on vient de traiter ------------
|
||||||
static void Transfer_colors(FILE * file)
|
void Transfer_colors(FILE * file)
|
||||||
{
|
{
|
||||||
byte index;
|
byte index;
|
||||||
|
|
||||||
@ -4467,7 +4467,7 @@ void Load_GIF(T_IO_Context * context)
|
|||||||
// on jette les autres.
|
// on jette les autres.
|
||||||
if (context->Comment[0]=='\0')
|
if (context->Comment[0]=='\0')
|
||||||
{
|
{
|
||||||
int nb_char_to_keep=Min(size_to_read,COMMENT_SIZE);
|
int nb_char_to_keep = MIN(size_to_read, COMMENT_SIZE);
|
||||||
|
|
||||||
Read_bytes(GIF_file,context->Comment,nb_char_to_keep);
|
Read_bytes(GIF_file,context->Comment,nb_char_to_keep);
|
||||||
context->Comment[nb_char_to_keep+1]='\0';
|
context->Comment[nb_char_to_keep+1]='\0';
|
||||||
|
|||||||
@ -54,6 +54,21 @@ void Set_pixel(T_IO_Context *context, short x, short y, byte c)
|
|||||||
(void)c;
|
(void)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Set_pixel_24b(T_IO_Context *context, short x, short y, byte r, byte g, byte b)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
(void)x;
|
||||||
|
(void)y;
|
||||||
|
(void)r;
|
||||||
|
(void)g;
|
||||||
|
(void)b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Fill_canvas(T_IO_Context *context, byte color)
|
||||||
|
{
|
||||||
|
printf("Fill_canvas(%p, %hhu)\n", context, color);
|
||||||
|
}
|
||||||
|
|
||||||
void Set_saving_layer(T_IO_Context *context, int layer)
|
void Set_saving_layer(T_IO_Context *context, int layer)
|
||||||
{
|
{
|
||||||
printf("Set_saving_layer(%p, %d)\n", context, layer);
|
printf("Set_saving_layer(%p, %d)\n", context, layer);
|
||||||
@ -73,3 +88,9 @@ void Set_frame_duration(T_IO_Context *context, int duration)
|
|||||||
{
|
{
|
||||||
printf("Set_frame_duration(%p, %d)\n", context, duration);
|
printf("Set_frame_duration(%p, %d)\n", context, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Get_frame_duration(T_IO_Context *context)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
TEST(MOTO_MAP_pack)
|
TEST(MOTO_MAP_pack)
|
||||||
TEST(CPC_compare_colors)
|
TEST(CPC_compare_colors)
|
||||||
|
TEST(Packbits)
|
||||||
|
|||||||
@ -27,7 +27,9 @@
|
|||||||
/// Unit tests.
|
/// Unit tests.
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
#include "../struct.h"
|
#include "../struct.h"
|
||||||
#include "../global.h"
|
#include "../global.h"
|
||||||
#include "../gfx2log.h"
|
#include "../gfx2log.h"
|
||||||
@ -100,6 +102,7 @@ int main(int argc, char * * argv)
|
|||||||
int i, r;
|
int i, r;
|
||||||
int fail = 0;
|
int fail = 0;
|
||||||
|
|
||||||
|
srandom(time(NULL));
|
||||||
GFX2_verbosity_level = GFX2_DEBUG;
|
GFX2_verbosity_level = GFX2_DEBUG;
|
||||||
|
|
||||||
for (i = 0; tests[i].test_func != 0; i++)
|
for (i = 0; tests[i].test_func != 0; i++)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
*/
|
*/
|
||||||
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
/* Grafx2 - The Ultimate 256-color bitmap paint program
|
||||||
|
|
||||||
Copyright 2018 Thomas Bernard
|
Copyright 2018-2019 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
|
||||||
@ -28,11 +28,15 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "../struct.h"
|
#include "../struct.h"
|
||||||
#include "../oldies.h"
|
#include "../oldies.h"
|
||||||
#include "../gfx2log.h"
|
#include "../gfx2log.h"
|
||||||
|
|
||||||
|
unsigned int MOTO_MAP_pack(byte * packed, const byte * unpacked, unsigned int unpacked_len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for MOTO_MAP_pack()
|
* Tests for MOTO_MAP_pack()
|
||||||
*/
|
*/
|
||||||
@ -84,6 +88,9 @@ int Test_MOTO_MAP_pack(void)
|
|||||||
return 1; // test OK
|
return 1; // test OK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for Test_CPC_compare_colors()
|
||||||
|
*/
|
||||||
int Test_CPC_compare_colors(void)
|
int Test_CPC_compare_colors(void)
|
||||||
{
|
{
|
||||||
unsigned int r, g, b;
|
unsigned int r, g, b;
|
||||||
@ -129,3 +136,68 @@ int Test_CPC_compare_colors(void)
|
|||||||
}
|
}
|
||||||
return 1; // test OK
|
return 1; // test OK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern word IFF_list_size;
|
||||||
|
void New_color(FILE * f, byte color);
|
||||||
|
void Transfer_colors(FILE * f);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for the packbits compression used in IFF ILBM, etc.
|
||||||
|
* see http://fileformats.archiveteam.org/wiki/PackBits
|
||||||
|
*/
|
||||||
|
int Test_Packbits(void)
|
||||||
|
{
|
||||||
|
char tempfilename[64];
|
||||||
|
FILE * f;
|
||||||
|
int i, j;
|
||||||
|
long unpacked;
|
||||||
|
long packed;
|
||||||
|
static const char * tests[] = {
|
||||||
|
"1234AAAAAAAAAAAAAAAAAAAAA", // best : 03 "1234" -20(ec) 'A' => 7 bytes
|
||||||
|
"AABBCCDDDDDDD12345@@@54321", // best : -1(ff) 'A' -1(ff) 'B' -1(ff) 'C' -6(fa) 'D' 12(0c) "12345@@@54321" => 22 bytes
|
||||||
|
// or 04 "12345" -2(fe) '@' 04 "54321"
|
||||||
|
"123AA123BBB123CCCC123DDDDD", // best : 07 "123AA123" -2 'B' 02 "123" -3(fd) 'C' 02 "123" -4(fc) 'D' => 23 bytes
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
const long best_packed = 7 + 22 + 23;
|
||||||
|
|
||||||
|
snprintf(tempfilename, sizeof(tempfilename), "/tmp/gfx2test-packbits-%lx", random());
|
||||||
|
GFX2_Log(GFX2_DEBUG, "tempfile %s\n", tempfilename);
|
||||||
|
f = fopen(tempfilename, "wb");
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
GFX2_Log(GFX2_ERROR, "Failed to open %s for writing\n", tempfilename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start encoding
|
||||||
|
IFF_list_size = 0;
|
||||||
|
for (i = 0, unpacked = 0; tests[i]; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; tests[i][j]; j++)
|
||||||
|
{
|
||||||
|
New_color(f, (byte)tests[i][j]);
|
||||||
|
unpacked++;
|
||||||
|
}
|
||||||
|
Transfer_colors(f);
|
||||||
|
}
|
||||||
|
packed = ftell(f);
|
||||||
|
fclose(f);
|
||||||
|
GFX2_Log(GFX2_DEBUG, "Compressed %ld bytes to %ld\n", unpacked, packed);
|
||||||
|
if (packed > best_packed) {
|
||||||
|
GFX2_Log(GFX2_ERROR, "*** Packbits less efficient as expected (%ld > %ld bytes) ***\n",
|
||||||
|
packed, best_packed);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO : test unpacking
|
||||||
|
f = fopen(tempfilename, "rb");
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
GFX2_Log(GFX2_ERROR, "Failed to open %s for reading\n", tempfilename);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
unlink(tempfilename);
|
||||||
|
return 1; // test OK
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user