ReactOS 0.4.16-dev-981-g80eb313
ungif.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GifColorType
 
struct  ColorMapObject
 
struct  GifImageDesc
 
struct  ExtensionBlock
 
struct  Extensions
 
struct  GifFileType
 
struct  SavedImage
 

Macros

#define GIF_ERROR   0
 
#define GIF_OK   1
 
#define TRUE   1
 
#define FALSE   0
 
#define NULL   0
 
#define GIF_STAMP   "GIFVER" /* First chars in file - GIF stamp. */
 
#define GIF_STAMP_LEN   sizeof(GIF_STAMP) - 1
 
#define GIF_VERSION_POS   3 /* Version first character in stamp. */
 
#define GIF87_STAMP   "GIF87a" /* First chars in file - GIF stamp. */
 
#define GIF89_STAMP   "GIF89a" /* First chars in file - GIF stamp. */
 
#define GIF_FILE_BUFFER_SIZE   16384 /* Files uses bigger buffers than usual. */
 
#define COMMENT_EXT_FUNC_CODE   0xfe /* comment */
 
#define GRAPHICS_EXT_FUNC_CODE   0xf9 /* graphics control */
 
#define PLAINTEXT_EXT_FUNC_CODE   0x01 /* plaintext */
 
#define APPLICATION_EXT_FUNC_CODE   0xff /* application block */
 
#define D_GIF_ERR_OPEN_FAILED   101 /* And DGif possible errors. */
 
#define D_GIF_ERR_READ_FAILED   102
 
#define D_GIF_ERR_NOT_GIF_FILE   103
 
#define D_GIF_ERR_NO_SCRN_DSCR   104
 
#define D_GIF_ERR_NO_IMAG_DSCR   105
 
#define D_GIF_ERR_NO_COLOR_MAP   106
 
#define D_GIF_ERR_WRONG_RECORD   107
 
#define D_GIF_ERR_DATA_TOO_BIG   108
 
#define D_GIF_ERR_NOT_ENOUGH_MEM   109
 
#define D_GIF_ERR_CLOSE_FAILED   110
 
#define D_GIF_ERR_NOT_READABLE   111
 
#define D_GIF_ERR_IMAGE_DEFECT   112
 
#define D_GIF_ERR_EOF_TOO_SOON   113
 

Typedefs

typedef int GifBooleanType
 
typedef unsigned char GifPixelType
 
typedef unsigned charGifRowType
 
typedef unsigned char GifByteType
 
typedef unsigned int GifPrefixType
 
typedef int GifWord
 
typedef struct GifColorType GifColorType
 
typedef struct ColorMapObject ColorMapObject
 
typedef struct GifImageDesc GifImageDesc
 
typedef struct GifFileType GifFileType
 
typedef int(* InputFunc) (GifFileType *, GifByteType *, int)
 
typedef struct SavedImage SavedImage
 

Enumerations

enum  GifRecordType {
  UNDEFINED_RECORD_TYPE , SCREEN_DESC_RECORD_TYPE , IMAGE_DESC_RECORD_TYPE , EXTENSION_RECORD_TYPE ,
  TERMINATE_RECORD_TYPE
}
 

Functions

int DGifSlurp (GifFileType *GifFile)
 
GifFileTypeDGifOpen (void *userPtr, InputFunc readFunc)
 
int DGifCloseFile (GifFileType *GifFile)
 

Macro Definition Documentation

◆ APPLICATION_EXT_FUNC_CODE

#define APPLICATION_EXT_FUNC_CODE   0xff /* application block */

Definition at line 145 of file ungif.h.

◆ COMMENT_EXT_FUNC_CODE

#define COMMENT_EXT_FUNC_CODE   0xfe /* comment */

Definition at line 142 of file ungif.h.

◆ D_GIF_ERR_CLOSE_FAILED

#define D_GIF_ERR_CLOSE_FAILED   110

Definition at line 161 of file ungif.h.

◆ D_GIF_ERR_DATA_TOO_BIG

#define D_GIF_ERR_DATA_TOO_BIG   108

Definition at line 159 of file ungif.h.

◆ D_GIF_ERR_EOF_TOO_SOON

#define D_GIF_ERR_EOF_TOO_SOON   113

Definition at line 164 of file ungif.h.

◆ D_GIF_ERR_IMAGE_DEFECT

#define D_GIF_ERR_IMAGE_DEFECT   112

Definition at line 163 of file ungif.h.

◆ D_GIF_ERR_NO_COLOR_MAP

#define D_GIF_ERR_NO_COLOR_MAP   106

Definition at line 157 of file ungif.h.

◆ D_GIF_ERR_NO_IMAG_DSCR

#define D_GIF_ERR_NO_IMAG_DSCR   105

Definition at line 156 of file ungif.h.

◆ D_GIF_ERR_NO_SCRN_DSCR

#define D_GIF_ERR_NO_SCRN_DSCR   104

Definition at line 155 of file ungif.h.

◆ D_GIF_ERR_NOT_ENOUGH_MEM

#define D_GIF_ERR_NOT_ENOUGH_MEM   109

Definition at line 160 of file ungif.h.

◆ D_GIF_ERR_NOT_GIF_FILE

#define D_GIF_ERR_NOT_GIF_FILE   103

Definition at line 154 of file ungif.h.

◆ D_GIF_ERR_NOT_READABLE

#define D_GIF_ERR_NOT_READABLE   111

Definition at line 162 of file ungif.h.

◆ D_GIF_ERR_OPEN_FAILED

#define D_GIF_ERR_OPEN_FAILED   101 /* And DGif possible errors. */

Definition at line 152 of file ungif.h.

◆ D_GIF_ERR_READ_FAILED

#define D_GIF_ERR_READ_FAILED   102

Definition at line 153 of file ungif.h.

◆ D_GIF_ERR_WRONG_RECORD

#define D_GIF_ERR_WRONG_RECORD   107

Definition at line 158 of file ungif.h.

◆ FALSE

#define FALSE   0

Definition at line 62 of file ungif.h.

◆ GIF87_STAMP

#define GIF87_STAMP   "GIF87a" /* First chars in file - GIF stamp. */

Definition at line 72 of file ungif.h.

◆ GIF89_STAMP

#define GIF89_STAMP   "GIF89a" /* First chars in file - GIF stamp. */

Definition at line 73 of file ungif.h.

◆ GIF_ERROR

#define GIF_ERROR   0

Definition at line 55 of file ungif.h.

◆ GIF_FILE_BUFFER_SIZE

#define GIF_FILE_BUFFER_SIZE   16384 /* Files uses bigger buffers than usual. */

Definition at line 75 of file ungif.h.

◆ GIF_OK

#define GIF_OK   1

Definition at line 56 of file ungif.h.

◆ GIF_STAMP

#define GIF_STAMP   "GIFVER" /* First chars in file - GIF stamp. */

Definition at line 69 of file ungif.h.

◆ GIF_STAMP_LEN

#define GIF_STAMP_LEN   sizeof(GIF_STAMP) - 1

Definition at line 70 of file ungif.h.

◆ GIF_VERSION_POS

#define GIF_VERSION_POS   3 /* Version first character in stamp. */

Definition at line 71 of file ungif.h.

◆ GRAPHICS_EXT_FUNC_CODE

#define GRAPHICS_EXT_FUNC_CODE   0xf9 /* graphics control */

Definition at line 143 of file ungif.h.

◆ NULL

#define NULL   0

Definition at line 66 of file ungif.h.

◆ PLAINTEXT_EXT_FUNC_CODE

#define PLAINTEXT_EXT_FUNC_CODE   0x01 /* plaintext */

Definition at line 144 of file ungif.h.

◆ TRUE

#define TRUE   1

Definition at line 59 of file ungif.h.

Typedef Documentation

◆ ColorMapObject

◆ GifBooleanType

Definition at line 77 of file ungif.h.

◆ GifByteType

Definition at line 80 of file ungif.h.

◆ GifColorType

◆ GifFileType

◆ GifImageDesc

◆ GifPixelType

Definition at line 78 of file ungif.h.

◆ GifPrefixType

Definition at line 81 of file ungif.h.

◆ GifRowType

Definition at line 79 of file ungif.h.

◆ GifWord

typedef int GifWord

Definition at line 82 of file ungif.h.

◆ InputFunc

typedef int(* InputFunc) (GifFileType *, GifByteType *, int)

Definition at line 138 of file ungif.h.

◆ SavedImage

Enumeration Type Documentation

◆ GifRecordType

Enumerator
UNDEFINED_RECORD_TYPE 
SCREEN_DESC_RECORD_TYPE 
IMAGE_DESC_RECORD_TYPE 
EXTENSION_RECORD_TYPE 
TERMINATE_RECORD_TYPE 

Definition at line 129 of file ungif.h.

129 {
132 IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
133 EXTENSION_RECORD_TYPE, /* Begin with '!' */
134 TERMINATE_RECORD_TYPE /* Begin with ';' */
GifRecordType
Definition: ungif.h:129
@ EXTENSION_RECORD_TYPE
Definition: ungif.h:133
@ UNDEFINED_RECORD_TYPE
Definition: ungif.h:130
@ IMAGE_DESC_RECORD_TYPE
Definition: ungif.h:132
@ TERMINATE_RECORD_TYPE
Definition: ungif.h:134
@ SCREEN_DESC_RECORD_TYPE
Definition: ungif.h:131

Function Documentation

◆ DGifCloseFile()

int DGifCloseFile ( GifFileType GifFile)

Definition at line 1018 of file ungif.c.

1018 {
1019
1020 GifFilePrivateType *Private;
1021
1022 if (GifFile == NULL)
1023 return GIF_ERROR;
1024
1025 Private = GifFile->Private;
1026
1027 if (GifFile->Image.ColorMap) {
1028 FreeMapObject(GifFile->Image.ColorMap);
1029 GifFile->Image.ColorMap = NULL;
1030 }
1031
1032 if (GifFile->SColorMap) {
1033 FreeMapObject(GifFile->SColorMap);
1034 GifFile->SColorMap = NULL;
1035 }
1036
1037 free(Private);
1038 Private = NULL;
1039
1040 if (GifFile->SavedImages) {
1041 FreeSavedImages(GifFile);
1042 GifFile->SavedImages = NULL;
1043 }
1044
1045 FreeExtension(&GifFile->Extensions);
1046
1047 free(GifFile);
1048
1049 return GIF_OK;
1050}
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
Extensions Extensions
Definition: ungif.h:121
GifImageDesc Image
Definition: ungif.h:123
struct SavedImage * SavedImages
Definition: ungif.h:124
ColorMapObject * SColorMap
Definition: ungif.h:120
void * Private
Definition: ungif.h:126
ColorMapObject * ColorMap
Definition: ungif.h:98
static void FreeMapObject(ColorMapObject *Object)
Definition: ungif.c:162
static void FreeExtension(Extensions *Extensions)
Definition: ungif.c:237
static void FreeSavedImages(GifFileType *GifFile)
Definition: ungif.c:256
#define GIF_OK
Definition: ungif.h:56
#define GIF_ERROR
Definition: ungif.h:55

Referenced by GifDecoder_Release().

◆ DGifOpen()

GifFileType * DGifOpen ( void userPtr,
InputFunc  readFunc 
)

Definition at line 964 of file ungif.c.

965 {
966
967 unsigned char Buf[GIF_STAMP_LEN + 1];
968 GifFileType *GifFile;
969 GifFilePrivateType *Private;
970
971 GifFile = malloc(sizeof(GifFileType));
972 if (GifFile == NULL) {
973 return NULL;
974 }
975
976 memset(GifFile, '\0', sizeof(GifFileType));
977
978 Private = malloc(sizeof(GifFilePrivateType));
979 if (!Private) {
980 free(GifFile);
981 return NULL;
982 }
983
984 GifFile->Private = (void*)Private;
985
986 Private->Read = readFunc; /* TVT */
987 GifFile->UserData = userData; /* TVT */
988
989 /* Lets see if this is a GIF file: */
990 if (READ(GifFile, Buf, GIF_STAMP_LEN) != GIF_STAMP_LEN) {
991 free(Private);
992 free(GifFile);
993 return NULL;
994 }
995
996 /* The GIF Version number is ignored at this time. Maybe we should do
997 * something more useful with it. */
998 Buf[GIF_STAMP_LEN] = 0;
999 if (memcmp(GIF_STAMP, Buf, GIF_VERSION_POS) != 0) {
1000 free(Private);
1001 free(GifFile);
1002 return NULL;
1003 }
1004
1005 if (DGifGetScreenDesc(GifFile) == GIF_ERROR) {
1006 free(Private);
1007 free(GifFile);
1008 return NULL;
1009 }
1010
1011 return GifFile;
1012}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define malloc
Definition: debug_ros.c:4
#define memset(x, y, z)
Definition: compat.h:39
InputFunc Read
Definition: ungif.c:79
void * UserData
Definition: ungif.h:125
static int DGifGetScreenDesc(GifFileType *GifFile)
Definition: ungif.c:284
#define READ(_gif, _buf, _len)
Definition: ungif.c:87
#define GIF_VERSION_POS
Definition: ungif.h:71
#define GIF_STAMP_LEN
Definition: ungif.h:70
#define GIF_STAMP
Definition: ungif.h:69

Referenced by GifDecoder_Initialize().

◆ DGifSlurp()

int DGifSlurp ( GifFileType GifFile)

Definition at line 847 of file ungif.c.

847 {
848
849 int ImageSize;
850 GifRecordType RecordType;
851 SavedImage *sp;
852 GifByteType *ExtData;
853 Extensions temp_save;
854
855 temp_save.ExtensionBlocks = NULL;
856 temp_save.ExtensionBlockCount = 0;
857
858 do {
859 if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR)
860 return (GIF_ERROR);
861
862 switch (RecordType) {
864 if (DGifGetImageDesc(GifFile) == GIF_ERROR)
865 return (GIF_ERROR);
866
867 sp = &GifFile->SavedImages[GifFile->ImageCount - 1];
868 ImageSize = sp->ImageDesc.Width * sp->ImageDesc.Height;
869
870 sp->RasterBits = malloc(ImageSize * sizeof(GifPixelType));
871 if (sp->RasterBits == NULL) {
872 return GIF_ERROR;
873 }
874 if (DGifGetLine(GifFile, sp->RasterBits, ImageSize) ==
875 GIF_ERROR)
876 return (GIF_ERROR);
877 if (temp_save.ExtensionBlocks) {
878 sp->Extensions.ExtensionBlocks = temp_save.ExtensionBlocks;
879 sp->Extensions.ExtensionBlockCount = temp_save.ExtensionBlockCount;
880
881 temp_save.ExtensionBlocks = NULL;
882 temp_save.ExtensionBlockCount = 0;
883
884 /* FIXME: The following is wrong. It is left in only for
885 * backwards compatibility. Someday it should go away. Use
886 * the sp->ExtensionBlocks->Function variable instead. */
887 sp->Extensions.Function = sp->Extensions.ExtensionBlocks[0].Function;
888 }
889 break;
890
892 {
893 int Function;
895
896 if (DGifGetExtension(GifFile, &Function, &ExtData) == GIF_ERROR)
897 return (GIF_ERROR);
898
899 if (GifFile->ImageCount || Function == GRAPHICS_EXT_FUNC_CODE)
900 Extensions = &temp_save;
901 else
902 Extensions = &GifFile->Extensions;
903
905
906 if (ExtData)
907 {
908 /* Create an extension block with our data */
909 if (AddExtensionBlock(Extensions, ExtData[0], &ExtData[1]) == GIF_ERROR)
910 return (GIF_ERROR);
911 }
912 else /* Empty extension block */
913 {
915 return (GIF_ERROR);
916 }
917
918 while (ExtData != NULL) {
919 int Len;
921
922 if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR)
923 return (GIF_ERROR);
924
925 if (ExtData)
926 {
927 Len = ExtData[0];
928 Data = &ExtData[1];
929 }
930 else
931 {
932 Len = 0;
933 Data = NULL;
934 }
935
937 return (GIF_ERROR);
938 }
939 break;
940 }
941
943 break;
944
945 default: /* Should be trapped by DGifGetRecordType */
946 break;
947 }
948 } while (RecordType != TERMINATE_RECORD_TYPE);
949
950 /* Just in case the Gif has an extension block without an associated
951 * image... (Should we save this into a savefile structure with no image
952 * instead? Have to check if the present writing code can handle that as
953 * well.... */
954 if (temp_save.ExtensionBlocks)
955 FreeExtension(&temp_save);
956
957 return (GIF_OK);
958}
_In_ CDROM_SCAN_FOR_SPECIAL_INFO _In_ PCDROM_SCAN_FOR_SPECIAL_HANDLER Function
Definition: cdrom.h:1156
#define Len
Definition: deflate.h:82
static const WCHAR sp[]
Definition: suminfo.c:287
int Function
Definition: ungif.h:109
ExtensionBlock * ExtensionBlocks
Definition: ungif.h:111
int ExtensionBlockCount
Definition: ungif.h:110
int ImageCount
Definition: ungif.h:122
static int DGifGetExtension(GifFileType *GifFile, int *ExtCode, GifByteType **Extension)
Definition: ungif.c:486
static int AppendExtensionBlock(Extensions *New, int Len, const unsigned char ExtData[])
Definition: ungif.c:211
static int DGifGetRecordType(GifFileType *GifFile, GifRecordType *Type)
Definition: ungif.c:333
static int DGifGetImageDesc(GifFileType *GifFile)
Definition: ungif.c:368
static int AddExtensionBlock(Extensions *New, int Len, const unsigned char ExtData[])
Definition: ungif.c:177
static int DGifGetLine(GifFileType *GifFile, GifPixelType *Line, int LineLen)
Definition: ungif.c:446
static int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension)
Definition: ungif.c:506
unsigned char GifPixelType
Definition: ungif.h:78
unsigned char GifByteType
Definition: ungif.h:80
#define GRAPHICS_EXT_FUNC_CODE
Definition: ungif.h:143

Referenced by GifDecoder_Initialize().