Leptonica 1.68
C Image Processing Library
|
Read/write gif format from/to file and memory. More...
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include "allheaders.h"
#include "gif_lib.h"
Go to the source code of this file.
Functions | |
static PIX * | pixInterlaceGIF (PIX *pixs) |
PIX * | pixReadStreamGif (FILE *fp) |
l_int32 | pixWriteStreamGif (FILE *fp, PIX *pix) |
PIX * | pixReadMemGif (const l_uint8 *cdata, size_t size) |
l_int32 | pixWriteMemGif (l_uint8 **pdata, size_t *psize, PIX *pix) |
Variables | |
static const l_int32 | InterlacedOffset [] = {0, 4, 2, 1} |
static const l_int32 | InterlacedJumps [] = {8, 8, 4, 2} |
Read/write gif format from/to file and memory.
Read gif from file PIX *pixReadStreamGif() static PIX *pixInterlaceGIF() Write gif to file l_int32 pixWriteStreamGif() Read/write from/to memory (see warning) PIX *pixReadMemGif() l_int32 pixWriteMemGif() This uses the gif library, version 4.1.6. Do not use 4.1.4. This module was generously contribued by Antony Dovgal. He can be contacted at: tony *AT* daylessday.org
Definition in file gifio.c.
Definition at line 195 of file gifio.c.
References ERROR_PTR, InterlacedJumps, InterlacedOffset, NULL, pixCreateTemplate(), pixGetData(), pixGetDimensions(), pixGetWpl(), and PROCNAME.
Referenced by pixReadStreamGif().
PIX* pixReadStreamGif | ( | FILE * | fp | ) |
Input: stream Return: pix, or null on error
Definition at line 71 of file gifio.c.
References ERROR_PTR, NULL, pixcmapAddColor(), pixcmapCreate(), pixcmapDestroy(), pixCreate(), pixGetData(), pixGetWpl(), pixInterlaceGIF(), pixSetColormap(), pixTransferAllData(), PROCNAME, SET_DATA_BIT, SET_DATA_BYTE, SET_DATA_DIBIT, and SET_DATA_QBIT.
Referenced by pixReadStream().
Input: stream pix (1, 2, 4, 8, 16 or 32 bpp) Return: 0 if OK, 1 on error
Notes: (1) All output gif have colormaps. If the pix is 32 bpp rgb, this quantizes the colors and writes out 8 bpp. If the pix is 16 bpp grayscale, it converts to 8 bpp first. (2) We can't write to memory using open_memstream() because the gif functions write through a file descriptor, not a file stream.
Definition at line 244 of file gifio.c.
References CALLOC, ERROR_INT, FALSE, FREE, GET_DATA_BIT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, L_WARNING, NULL, pixClone(), pixcmapAddColor(), pixcmapCreate(), pixcmapGetColor(), pixcmapGetCount(), pixConvertRGBToColormap(), pixConvertTo8(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetText(), pixGetWpl(), pixSetColormap(), PROCNAME, and TRUE.
Referenced by pixWriteStream().
Input: data (const; gif-encoded) size (of data) Return: pix, or null on error
Notes: (1) Of course, we are cheating here -- writing the data out to file and then reading it back in as a gif format. (2) This should not be assumed to be safe from a sophisticated attack, even though we have attempted to make the filename difficult to guess by embedding the process number and the current time in microseconds. The best way to handle temporary files is to use file descriptors (capabilities) or file handles. However, I know of no way to do this for gif files because of the way that libgif handles the file descriptors. The canonical approach would be to do this: char templ[] = "hiddenfilenameXXXXXX"; l_int32 fd = mkstemp(templ); FILE *fp = fdopen(fd, "w+b"); fwrite(data, 1, size, fp); rewind(fp); Pix *pix = pixReadStreamGif(fp); but this fails because fp is in a bad state after writing.
Definition at line 441 of file gifio.c.
References ERROR_PTR, FREE, genTempFilename(), l_binaryWrite(), NULL, pixRead(), and PROCNAME.
Referenced by pixReadHeaderMem(), and pixReadMem().
Input: &data (<return> data of gif compressed image) &size (<return> size of returned data) pix Return: 0 if OK, 1 on error
Notes: (1) See comments in pixReadMemGif()
Definition at line 477 of file gifio.c.
References ERROR_INT, FREE, genTempFilename(), IFF_GIF, l_binaryRead(), pixWrite(), and PROCNAME.
Referenced by pixWriteMem().
const l_int32 InterlacedOffset[] = {0, 4, 2, 1} [static] |
Definition at line 57 of file gifio.c.
Referenced by pixInterlaceGIF().
const l_int32 InterlacedJumps[] = {8, 8, 4, 2} [static] |
Definition at line 58 of file gifio.c.
Referenced by pixInterlaceGIF().