Reading GIF with SDL

Is there any way to display GIFs with SDL without using SDL_Image library (for example using
only Giflib codec) ?

dekyco

I’m sure there is. It is likely to be complex however. You might want
to look at the SDL_Image source to see how it builds surfaces.

Why is SDL_Image unsuitable?

– BrianOn 11 October 2010 12:06, dekyco wrote:

Is there any way to display GIFs with SDL without using SDL_Image library
(for example using
only Giflib codec) ?

Hi,

I’m going to suggest that if Giflib can read a GIF and create an in-memory
image with all its necessary parts: height, width, bit depth, and an array
of values for the pixels, then you can easily populate an SDL_Surface using
those.

All images exist in the same way once they’re unpacked from their
compression format. Unpacked, ready to render, an image is just an array of
pixels. SDL_Image provides functions to read and decode (unpack) many image
formats. If Giflib can do that as well, then you should be good.

ChristianOn Mon, Oct 11, 2010 at 7:06 AM, dekyco wrote:

Is there any way to display GIFs with SDL without using SDL_Image library
(for example using
only Giflib codec) ?

dekyco


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL_Image is suitable enough but requirement for application is to have
only basic SDL dependencies (for linux).These are structures from Giflib
and SDL_video (namely SDL_Surface).Can I do with these anything to make
this GifFileType handler compatible with SDL_Surface?My goal is to use

GifFileType *DGifOpenFileName(const char *GifFileName)

instead of

SDL_Surface * IMG_Load(const char *file);

Code:

typedef struct GifColorType {
GifByteType Red, Green, Blue;
} GifColorType;

typedef struct GifFileType {

int GifWord SWidth, SHeight,        /* Screen dimensions. */
  SColorResolution,         /* How many colors can we generate? */
  SBackGroundColor;         

typedef struct ColorMapObject {
		int ColorCount;
		int BitsPerPixel;
		GifColorType *Colors;    /* on malloc(3) heap */
} ColorMapObject *SColorMap;

int ImageCount;             /* Number of current image */

typedef struct GifImageDesc {
	int GifWord Left, Top, Width, Height,   /* Current image dimensions. */
  Interlace;                    /* Sequential/Interlaced lines. */
		typedef struct ColorMapObject {
			int ColorCount;
			int BitsPerPixel;
			GifColorType *Colors;    /* on malloc(3) heap */
		} ColorMapObject
} GifImageDesc Image;

struct SavedImage *SavedImages; /* Use this to accumulate file state */
VoidPtr UserData;           /* hook to attach user data (TVT) */
VoidPtr Private;            /* Don't mess with this! */

} GifFileType;

and SDL_Surface:

Code:

typedef struct SDL_Surface {
Uint32 flags;/* Read-only */
typedef struct SDL_PixelFormat {
typedef struct SDL_Palette {
int ncolors;
typedef struct SDL_Color {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color *colors;
} SDL_Palette palette;
Uint8 BitsPerPixel;
Uint8 BytesPerPixel;
Uint8 Rloss;
Uint8 Gloss;
Uint8 Bloss;
Uint8 Aloss;
Uint8 Rshift;
Uint8 Gshift;
Uint8 Bshift;
Uint8 Ashift;
Uint32 Rmask;
Uint32 Gmask;
Uint32 Bmask;
Uint32 Amask;
/
RGB color key information /
Uint32 colorkey;
/
Alpha value information (per-surface alpha) */
Uint8 alpha;
} SDL_PixelFormat *format;

int w, h;				/* Read-only */
Uint16 pitch;				/* Read-only */
void *pixels;				/* Read-write */
int offset;				/* Private */

/* Hardware-specific surface info */
struct private_hwdata *hwdata;

/* clipping information */
typedef struct SDL_Rect {
		Sint16 x, y;
		Uint16 w, h;
	} SDL_Rect clip_rect;

Uint32 unused1;				/* for binary compatibility */

/* Allow recursive locks */
Uint32 locked;				/* Private */

/* info for fast blit mapping to other surfaces */
struct SDL_BlitMap *map;		/* Private */

/* format version, bumped at every change to invalidate blit maps */
unsigned int format_version;		/* Private */

/* Reference count -- used when freeing surface */
int refcount;				/* Read-mostly */

} SDL_Surface;

dekyco

Hi,

Sure you can make it “compatible”. You just have to create a matching
SDL_Surface and copy every pixel. But if you have no clue how to do this,
then the subrequirement “capable programmer who can replace the easy
sdl_image with the non-standard giflib” is not fulfilled. There is not only
a “i want this this way”, there is also a “i can do it this way”.
Read the documentation, look at the structures and then the way how to do
this should be clear. The only advantage i see is that you can access all
images in an animated gif.

Regards

Christoph

SDL_Image is suitable enough but requirement for application is to
have
only basic SDL dependencies (for linux).These are structures from
GiflibOn Tue, 12 Oct 2010 02:20:39 -0700, “dekyco” wrote:
and SDL_video (namely SDL_Surface).Can I do with these anything to make
this GifFileType handler compatible with SDL_Surface?My goal is to use

GifFileType *DGifOpenFileName(const char *GifFileName)

instead of

SDL_Surface * IMG_Load(const char *file);

  Code:

typedef struct GifColorType {
GifByteType Red, Green, Blue;
} GifColorType;

typedef struct GifFileType {

int GifWord SWidth, SHeight, /* Screen dimensions. /
SColorResolution, /
How many colors can we generate? */
SBackGroundColor;

typedef struct ColorMapObject {
int ColorCount;
int BitsPerPixel;
GifColorType Colors; / on malloc(3) heap */
} ColorMapObject *SColorMap;

int ImageCount; /* Number of current image */

typedef struct GifImageDesc {
int GifWord Left, Top, Width, Height, /* Current image dimensions. /
Interlace; /
Sequential/Interlaced lines. */
typedef struct ColorMapObject {
int ColorCount;
int BitsPerPixel;
GifColorType Colors; / on malloc(3) heap */
} ColorMapObject
} GifImageDesc Image;

struct SavedImage SavedImages; / Use this to accumulate file state /
VoidPtr UserData; /
hook to attach user data (TVT) /
VoidPtr Private; /
Don’t mess with this! */

} GifFileType;

and SDL_Surface:

  Code:

typedef struct SDL_Surface {
Uint32 flags;/* Read-only */
typedef struct SDL_PixelFormat {
typedef struct SDL_Palette {
int ncolors;
typedef struct SDL_Color {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 unused;
} SDL_Color *colors;
} SDL_Palette palette;
Uint8 BitsPerPixel;
Uint8 BytesPerPixel;
Uint8 Rloss;
Uint8 Gloss;
Uint8 Bloss;
Uint8 Aloss;
Uint8 Rshift;
Uint8 Gshift;
Uint8 Bshift;
Uint8 Ashift;
Uint32 Rmask;
Uint32 Gmask;
Uint32 Bmask;
Uint32 Amask;
/
RGB color key information /
Uint32 colorkey;
/
Alpha value information (per-surface alpha) */
Uint8 alpha;
} SDL_PixelFormat *format;

int w, h; /* Read-only /
Uint16 pitch; /
Read-only */
void pixels; / Read-write /
int offset; /
Private */

/* Hardware-specific surface info */
struct private_hwdata *hwdata;

/* clipping information */
typedef struct SDL_Rect {
Sint16 x, y;
Uint16 w, h;
} SDL_Rect clip_rect;

Uint32 unused1; /* for binary compatibility */

/* Allow recursive locks /
Uint32 locked; /
Private */

/* info for fast blit mapping to other surfaces */
struct SDL_BlitMap map; / Private */

/* format version, bumped at every change to invalidate blit maps /
unsigned int format_version; /
Private */

/* Reference count – used when freeing surface /
int refcount; /
Read-mostly */

} SDL_Surface;

dekyco


Christoph Nelles

E-Mail : @Christoph_Nelles
Jabber : eazrael at evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt

You are right Christoph, thank you for reply

dekyco