Skip to content

Commit a594446

Browse files
committed
Add gif-h helper to create screen capture
Press key `I` (shift+`i`) to start a screen capture creating a gif with the captured screen. Hit `I` again to stop the screen recording. --- Add gif-h helper header only library Copied from https://github.com/charlietangora/gif-h charlietangora/gif-h@3d2657b
1 parent ae9a020 commit a594446

File tree

7 files changed

+1075
-1
lines changed

7 files changed

+1075
-1
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,6 @@ if(WITH_PNG)
286286
target_link_libraries(infinisim PRIVATE png_static)
287287
endif()
288288

289+
target_include_directories(infinisim PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/gif-h")
290+
289291
install(TARGETS infinisim DESTINATION bin)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Using the keyboard the following events can be triggered:
112112
- `h` ... set heartrate running, and on further presses increase by 10 bpm
113113
- `H` ... stop heartrate
114114
- `i` ... take screenshot
115+
- `I` ... start/stop Gif scren capture
115116

116117
## Licenses
117118

gif-h/LICENSE

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org>

gif-h/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
gif-h
2+
=====
3+
4+
This one-header library offers a simple, very limited way to create animated GIFs directly in code.
5+
Those looking for particular cleverness are likely to be disappointed; it's pretty much a straight-ahead
6+
implementation of the GIF format with optional Floyd-Steinberg dithering. (It does at least use delta
7+
encoding - only the changed portions of each frame are saved.)
8+
9+
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.
10+
11+
Only RGBA8 is currently supported as an input format. (The alpha is ignored.)
12+
13+
Email me : ctangora -at- gmail -dot- com
14+
15+
Usage:
16+
-------------------
17+
Create a GifWriter struct.
18+
19+
Pass the struct to GifBegin() to initialize values and write the file header.
20+
21+
Pass frames of the animation to GifWriteFrame().
22+
23+
Finally, call GifEnd() to close the file handle and free memory.
24+
25+
#include <vector>
26+
#include <cstdint>
27+
#include <gif.h>
28+
int main()
29+
{
30+
int width = 100;
31+
int height = 200;
32+
std::vector<uint8_t> black(width * height * 4, 0);
33+
std::vector<uint8_t> white(width * height * 4, 255);
34+
35+
auto fileName = "bwgif.gif";
36+
int delay = 100;
37+
GifWriter g;
38+
GifBegin(&g, fileName, width, height, delay);
39+
GifWriteFrame(&g, black.data(), width, height, delay);
40+
GifWriteFrame(&g, white.data(), width, height, delay);
41+
GifEnd(&g);
42+
43+
return 0;
44+
}
45+

gif-h/gif-h-demo.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// gif-h-demo.cpp
3+
// by Charlie Tangora
4+
// Public domain.
5+
// Email me : ctangora -at- gmail -dot- com
6+
//
7+
// Shows an example usage of gif.h
8+
//
9+
10+
#include "gif.h"
11+
12+
#include <math.h>
13+
14+
const int width = 256;
15+
const int height = 256;
16+
uint8_t image[ width * height * 4 ];
17+
18+
void SetPixel( int xx, int yy, uint8_t red, uint8_t grn, uint8_t blu )
19+
{
20+
uint8_t* pixel = &image[(yy*width+xx)*4];
21+
pixel[0] = red;
22+
pixel[1] = blu;
23+
pixel[2] = grn;
24+
pixel[3] = 255; // no alpha for this demo
25+
}
26+
27+
void SetPixelFloat( int xx, int yy, float fred, float fgrn, float fblu )
28+
{
29+
// convert float to unorm
30+
uint8_t red = (uint8_t)roundf( 255.0f * fred );
31+
uint8_t grn = (uint8_t)roundf( 255.0f * fgrn );
32+
uint8_t blu = (uint8_t)roundf( 255.0f * fblu );
33+
34+
SetPixel( xx, yy, red, grn, blu );
35+
}
36+
37+
int main(int argc, const char * argv[])
38+
{
39+
const char* filename = "./MyGif.gif";
40+
if( argc > 1 )
41+
{
42+
filename = argv[1];
43+
}
44+
45+
// Create a gif
46+
GifWriter writer = {};
47+
GifBegin( &writer, filename, width, height, 2, 8, true );
48+
49+
for( int frame=0; frame<256; ++frame )
50+
{
51+
52+
// Make an image, somehow
53+
// this is the default shadertoy - credit to shadertoy.com
54+
float tt = frame * 3.14159f * 2 / 255.0f;
55+
for( int yy=0; yy<height; ++yy )
56+
{
57+
for( int xx=0; xx<width; ++xx )
58+
{
59+
float fx = xx / (float)width;
60+
float fy = yy / (float)height;
61+
62+
float red = 0.5f + 0.5f * cosf(tt+fx);
63+
float grn = 0.5f + 0.5f * cosf(tt+fy+2.f);
64+
float blu = 0.5f + 0.5f * cosf(tt+fx+4.f);
65+
66+
SetPixelFloat( xx, yy, red, grn, blu );
67+
}
68+
}
69+
70+
71+
// Write the frame to the gif
72+
printf( "Writing frame %d...\n", frame );
73+
GifWriteFrame( &writer, image, width, height, 2, 8, true );
74+
}
75+
76+
// Write EOF
77+
GifEnd( &writer );
78+
79+
return 0;
80+
}

0 commit comments

Comments
 (0)