-
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.
Merge pull request #48 from dloebl/no-loop
Allow creating GIF animations with no repetitions
- Loading branch information
Showing
9 changed files
with
82 additions
and
4 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
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
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,71 @@ | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <time.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "cgif.h" | ||
|
||
#define WIDTH 50 | ||
#define HEIGHT 50 | ||
|
||
static void initGIFConfig(CGIF_Config* pConfig, uint8_t* pGlobalPalette, uint16_t numColors, uint32_t attrFlags, uint16_t width, uint16_t height) { | ||
memset(pConfig, 0, sizeof(CGIF_Config)); | ||
pConfig->attrFlags = attrFlags; | ||
pConfig->width = width; | ||
pConfig->height = height; | ||
pConfig->pGlobalPalette = pGlobalPalette; | ||
pConfig->numGlobalPaletteEntries = numColors; | ||
pConfig->path = "noloop.gif"; | ||
} | ||
|
||
static void initFrameConfig(CGIF_FrameConfig* pConfig, uint8_t* pImageData, uint16_t delay, uint32_t genFlags) { | ||
memset(pConfig, 0, sizeof(CGIF_FrameConfig)); | ||
pConfig->pImageData = pImageData; | ||
pConfig->delay = delay; | ||
pConfig->genFlags = genFlags; | ||
} | ||
|
||
int main(void) { | ||
CGIF* pGIF; | ||
CGIF_Config gConfig; | ||
CGIF_FrameConfig fConfig; | ||
uint8_t* pImageData; | ||
uint8_t aPalette[] = { | ||
0xFF, 0xFF, 0xFF, // white | ||
0xFF, 0x00, 0x00, // red | ||
0x00, 0xFF, 0x00, // green | ||
}; | ||
cgif_result r; | ||
const uint16_t numColors = 3; // number of colors in aPalette | ||
// | ||
// create new GIF | ||
initGIFConfig(&gConfig, aPalette, numColors, CGIF_ATTR_IS_ANIMATED | CGIF_ATTR_NO_LOOP, WIDTH, HEIGHT); | ||
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); // Actual image data | ||
memset(pImageData, 0, WIDTH * HEIGHT); | ||
initFrameConfig(&fConfig, pImageData, 50, CGIF_FRAME_GEN_USE_TRANSPARENCY | CGIF_FRAME_GEN_USE_DIFF_WINDOW); | ||
r = cgif_addframe(pGIF, &fConfig); // append the new frame | ||
memset(pImageData, 1, WIDTH * HEIGHT); | ||
r = cgif_addframe(pGIF, &fConfig); // append the next frame | ||
memset(pImageData, 2, WIDTH * HEIGHT); | ||
r = cgif_addframe(pGIF, &fConfig); // append the next frame | ||
// | ||
free(pImageData); | ||
// | ||
// Free allocated space at the end of the session | ||
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