-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for user defined transparency frame diff and merge
- Loading branch information
Showing
4 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |