Giter Site home page Giter Site logo

gifanimcplusplus's Introduction

gifanim.cpp and gifanim.h

This c++ class has been derived from Charlie Tangora's public domain "gif.h" project, which you can find here. In that spirit, this is also public domain. More of this, less of requiring people to do, or not do, this or that. :)

Basically, you prepare a series of 32-bit (4 RGBA bytes per pixel) images arranged as rows going from the top of the image to the bottom. The A (alpha) channel is ignored, but must be there anyway. Each of the RGBA channels is one byte, with a range of 0 (dark) to 255 (light.)

This class can do color selection for you, but there are better color selectors out there. If you have such a better color selector, then:

  1. Pre-select a GifPalette for each image you provide and supply it to GIFWriteFrame along with the image

  2. Pre-reduce each image to just those 24-bit colors that are contained in the palette you're supplying.

This will bypass all of the palette selection code in this class.

You can't mix the two approaches: either you supply a pre-selected palette for every frame where each image contains only those colors, or you don't supply a palette and the image can be any set of 24-bit colors.

After the setup as explained below, you pass each image to GifWriteFrame() and when they've all been submitted, you call GifEnd().`

Skeletal usage example:

#include "gifanim.h"
{
GifAnim ganim;
GifWriter g;
	// Set up filename,
	// xw=N, yw=N,
	// framedelay=1...1000 or so,
	// loopcount =0 means infinite, otherwise as specified
	// bitdepth=8,
	// dither=false (most likely, but you pick)
	// each image is an array of bytes 0-255, in order ((R G B A) x xw) x yw)
	// ----------------------------------------------------------------------

	// and then:
	// ---------
	ganim.GifBegin(&g, fileName, xw, yw, framedelay, loopcount, bitdepth, dither);

	// For each frame of the animation, set up RGBA-formatted image, then:
	// -------------------------------------------------------------------
	ganim.GifWriteFrame(&g, image, xw, yw, framedelay, bitdepth, dither);
	
	// After all frames, this:
	// -----------------------
	ganim.GifEnd(&g);
}

My fervent thanks to Charlie Tangora for his original public domain c implementation; he saved me a ton of work on my iToolBox Project. Converting his c to a solid c++ class wasn't bad at all; figuring out GIF... that would have been quite the undertaking!

For the record, I'm using this class exactly as provided here inside a Qt c++ project for OS X/MacOS, and it works great there as-is, although I do use a custom memory manager rather than the bare calloc() and free() used here. Nothing you have to worry about, I'm just into firewalling and tracking memory during development so as to catch as many problems as possible, as early as possible. But because I do use such a memory manager, this code has been through rigorous memory behavior validation inside my iToolBox Project, and so I have good reason to think you can confidently trust it to be memory-safe.

gifanimcplusplus's People

Contributors

cpp977 avatar fyngyrz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.