Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,6 @@ if(WITH_PNG)
target_link_libraries(infinisim PRIVATE png_static)
endif()

target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/gif-h")

install(TARGETS infinisim DESTINATION bin)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ Using the keyboard the following events can be triggered:
- `h` ... set heartrate running, and on further presses increase by 10 bpm
- `H` ... stop heartrate
- `i` ... take screenshot
- `I` ... start/stop Gif scren capture

## Licenses

Expand Down
24 changes: 24 additions & 0 deletions gif-h/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org>
45 changes: 45 additions & 0 deletions gif-h/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
gif-h
=====

This one-header library offers a simple, very limited way to create animated GIFs directly in code.
Those looking for particular cleverness are likely to be disappointed; it's pretty much a straight-ahead
implementation of the GIF format with optional Floyd-Steinberg dithering. (It does at least use delta
encoding - only the changed portions of each frame are saved.)

So resulting files are often quite large. The hope is that it will be handy nonetheless as a quick and easily-integrated way for programs to spit out animations.

Only RGBA8 is currently supported as an input format. (The alpha is ignored.)

Email me : ctangora -at- gmail -dot- com

Usage:
-------------------
Create a GifWriter struct.

Pass the struct to GifBegin() to initialize values and write the file header.

Pass frames of the animation to GifWriteFrame().

Finally, call GifEnd() to close the file handle and free memory.

#include <vector>
#include <cstdint>
#include <gif.h>
int main()
{
int width = 100;
int height = 200;
std::vector<uint8_t> black(width * height * 4, 0);
std::vector<uint8_t> white(width * height * 4, 255);

auto fileName = "bwgif.gif";
int delay = 100;
GifWriter g;
GifBegin(&g, fileName, width, height, delay);
GifWriteFrame(&g, black.data(), width, height, delay);
GifWriteFrame(&g, white.data(), width, height, delay);
GifEnd(&g);

return 0;
}

80 changes: 80 additions & 0 deletions gif-h/gif-h-demo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// gif-h-demo.cpp
// by Charlie Tangora
// Public domain.
// Email me : ctangora -at- gmail -dot- com
//
// Shows an example usage of gif.h
//

#include "gif.h"

#include <math.h>

const int width = 256;
const int height = 256;
uint8_t image[ width * height * 4 ];

void SetPixel( int xx, int yy, uint8_t red, uint8_t grn, uint8_t blu )
{
uint8_t* pixel = &image[(yy*width+xx)*4];
pixel[0] = red;
pixel[1] = blu;
pixel[2] = grn;
pixel[3] = 255; // no alpha for this demo
}

void SetPixelFloat( int xx, int yy, float fred, float fgrn, float fblu )
{
// convert float to unorm
uint8_t red = (uint8_t)roundf( 255.0f * fred );
uint8_t grn = (uint8_t)roundf( 255.0f * fgrn );
uint8_t blu = (uint8_t)roundf( 255.0f * fblu );

SetPixel( xx, yy, red, grn, blu );
}

int main(int argc, const char * argv[])
{
const char* filename = "./MyGif.gif";
if( argc > 1 )
{
filename = argv[1];
}

// Create a gif
GifWriter writer = {};
GifBegin( &writer, filename, width, height, 2, 8, true );

for( int frame=0; frame<256; ++frame )
{

// Make an image, somehow
// this is the default shadertoy - credit to shadertoy.com
float tt = frame * 3.14159f * 2 / 255.0f;
for( int yy=0; yy<height; ++yy )
{
for( int xx=0; xx<width; ++xx )
{
float fx = xx / (float)width;
float fy = yy / (float)height;

float red = 0.5f + 0.5f * cosf(tt+fx);
float grn = 0.5f + 0.5f * cosf(tt+fy+2.f);
float blu = 0.5f + 0.5f * cosf(tt+fx+4.f);

SetPixelFloat( xx, yy, red, grn, blu );
}
}


// Write the frame to the gif
printf( "Writing frame %d...\n", frame );
GifWriteFrame( &writer, image, width, height, 2, 8, true );
}

// Write EOF
GifEnd( &writer );

return 0;
}
Loading