Animated screenshot and gif encoder...



Hi !

I'm currently looking for an "easy" method to take animated screenshots.
I had searched into gdk library but "GIF encoder" seems not belonging to it.

Do you know an easy way to create animated gif using GdkSimpleAnim or
several pixbuf ?

Actually I have made a small testing function (just create a simple 4x4 gif)
but I don't know how to compress the data part (with LZW algorythm). So
value are simply choosen randomly.

Here the small testing function :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <tilem.h>
#include <gtk/gtk.h>
#include <gui.h>

void create_gif(char* filename) {
    FILE * fp;
    int i;
    /* Magic number for Gif file format */
    char magic_number[] = {'G', 'I', 'F', '8', '9', 'a'};
    /* Size of canvas width on 2 bytes, heigth on 2 bytes, GCT , bg color i,
aspect pixel ratio */
    char canvas[] = { 4, 0, 4, 0, 0x80, 0x00, 0x00};
    /* define palette value */
    char palette[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};


    /* Extension block introduced by 0x21 ('!'), and an img introduced by
0x2c (',') followed by coordinate corner(0,0), canvas 4 bytes, no local
color table */
    static char gif_img[18] = {0x21, 0xf9, 4, 5, 11, 0, 0x0f, 0, 0x2c, 0, 0,
0, 0, 4, 0, 4, 0, 0};
    /* Sample img */
    /* LWZ min file encoding, then length data follows, then data */
    static char example[13] = {0x08, 0x11, 0xff, 0x0c, 0xc0, 0xff, 0x0a,
0x1f, 0xb0, 0xbf, 0xff, 0xcf, 0x00}; // Hardcoded for testing

    char end[1] = { 0xC3};

    printf("testGIF\n");
    fp = fopen(filename, "wb");
    fwrite(magic_number, 6, 1, fp);
    fwrite(canvas, 7, 1, fp);
    fwrite(palette, 9, 1, fp);
    fwrite(gif_img, 18, 1, fp);
    fwrite(example, 13, 1, fp);  // --> Here I want a function to encode a
pixbuf in LZW
    fwrite(end, 1, 1, fp);
    fclose(fp);
}

I know animated gif and static gif are not exactly the same, here it's
"static gif" (only one img).

I hesitate to use byzanz encoder from Benjamin Otte <otte gnome org> (it
seems very good :D).

Do you know another encoder or an easy way to do that?

Thanks a lot by advance.


Thibault Duponchelle



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]