Skip to content

Commit

Permalink
add tests for user defined transparency frame diff and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dloebl committed Aug 13, 2024
1 parent 0d08c2e commit f931c91
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ tests = [
{ 'name' : 'stripe_pattern_interlaced', 'seed_should_fail' : false},
{ 'name' : 'switchpattern', 'seed_should_fail' : false},
{ 'name' : 'trans_inc_initdict', 'seed_should_fail' : false},
{ 'name' : 'user_trans_diff_area', 'seed_should_fail' : false},
{ 'name' : 'user_trans_merge', 'seed_should_fail' : false},
{ 'name' : 'user_trans', 'seed_should_fail' : false},
{ 'name' : 'write_fn', 'seed_should_fail' : false},
]
Expand Down
2 changes: 2 additions & 0 deletions tests/tests.sha256
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ ff1da19b0448af07d8561f0ee62b184f99ac7dcb75f1a2215474190ec6648901 noise6.gif
161a132972bfbc060ea0359d8c40513d2e22e65b27a7c11553f883fe3856fe30 stripe_pattern_interlaced.gif
b8a7e72024a1263229e85f27168800400489cf993f7b90f45f00d39323763261 switchpattern.gif
1eb29910b6633bc1c6be49fc85ba7f5c24f415083d81f35c366ea50d55bcdf8d trans_inc_initdict.gif
0e02f2440b2db58268f6ef7906e41b088177e9fcdb2cb37e9540f4bfc9a7fa17 user_trans_diff_area.gif
55b64d9c9a359f9daeecdf55c83e485aca3f90d2a6dd29f86d5b14a0e1396770 user_trans.gif
86a08337540a8332dea3cb092394c3aac04fbbe98d9d884eb169a6c85d20f9a6 user_trans_merge.gif
5d301094a0b54287cabcc71c6972f7be417a5bea87cde01d85089a8893fd17fd write_fn.gif
62 changes: 62 additions & 0 deletions tests/user_trans_diff_area.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "cgif.h"

#define WIDTH 2
#define HEIGHT 2

int main(void) {
CGIF* pGIF;
CGIF_Config gConfig;
CGIF_FrameConfig fConfig;
uint8_t* pImageData;
uint8_t aPalette[] = {
0x00, 0xFF, 0x00, // green
0xFF, 0xFF, 0xFF, // white
};
cgif_result r;

memset(&gConfig, 0, sizeof(CGIF_Config));
memset(&fConfig, 0, sizeof(CGIF_FrameConfig));
gConfig.attrFlags = CGIF_ATTR_IS_ANIMATED;
gConfig.genFlags = CGIF_GEN_KEEP_IDENT_FRAMES;
gConfig.width = WIDTH;
gConfig.height = HEIGHT;
gConfig.pGlobalPalette = aPalette;
gConfig.numGlobalPaletteEntries = 2;
gConfig.path = "user_trans_diff_area.gif";
//
// create new GIF
pGIF = cgif_newgif(&gConfig);
if(pGIF == NULL) {
fputs("failed to create new GIF via cgif_newgif()\n", stderr);
return 1;
}
//
// add frames to GIF
pImageData = malloc(WIDTH * HEIGHT);
memset(pImageData, 0, WIDTH * HEIGHT);
fConfig.pImageData = pImageData;
fConfig.delay = 500;
cgif_addframe(pGIF, &fConfig);
fConfig.attrFlags = CGIF_FRAME_ATTR_HAS_SET_TRANS;
fConfig.genFlags = CGIF_FRAME_GEN_USE_DIFF_WINDOW;
fConfig.transIndex = 1;
// set everything to transparent (frame from before shines through)
memset(pImageData, 1, WIDTH * HEIGHT);
r = cgif_addframe(pGIF, &fConfig);
free(pImageData);
//
// write GIF to file
r = cgif_close(pGIF);

// check for errors
if(r != CGIF_OK) {
fprintf(stderr, "failed to create GIF. error code: %d\n", r);
return 2;
}
return 0;
}
61 changes: 61 additions & 0 deletions tests/user_trans_merge.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "cgif.h"

#define WIDTH 2
#define HEIGHT 2

int main(void) {
CGIF* pGIF;
CGIF_Config gConfig;
CGIF_FrameConfig fConfig;
uint8_t* pImageData;
uint8_t aPalette[] = {
0x00, 0xFF, 0x00, // green
0xFF, 0xFF, 0xFF, // white
};
cgif_result r;

memset(&gConfig, 0, sizeof(CGIF_Config));
memset(&fConfig, 0, sizeof(CGIF_FrameConfig));
gConfig.attrFlags = CGIF_ATTR_IS_ANIMATED;
gConfig.width = WIDTH;
gConfig.height = HEIGHT;
gConfig.pGlobalPalette = aPalette;
gConfig.numGlobalPaletteEntries = 2;
gConfig.path = "user_trans_merge.gif";
//
// create new GIF
pGIF = cgif_newgif(&gConfig);
if(pGIF == NULL) {
fputs("failed to create new GIF via cgif_newgif()\n", stderr);
return 1;
}
//
// add frames to GIF
pImageData = malloc(WIDTH * HEIGHT);
memset(pImageData, 0, WIDTH * HEIGHT);
fConfig.pImageData = pImageData;
fConfig.delay = 500;
cgif_addframe(pGIF, &fConfig);
fConfig.attrFlags = CGIF_FRAME_ATTR_HAS_SET_TRANS;
fConfig.genFlags = CGIF_FRAME_GEN_USE_DIFF_WINDOW;
fConfig.transIndex = 1;
// set everything to transparent (frame from before shines through)
memset(pImageData, 1, WIDTH * HEIGHT);
r = cgif_addframe(pGIF, &fConfig);
free(pImageData);
//
// write GIF to file
r = cgif_close(pGIF);

// check for errors
if(r != CGIF_OK) {
fprintf(stderr, "failed to create GIF. error code: %d\n", r);
return 2;
}
return 0;
}

0 comments on commit f931c91

Please sign in to comment.