本文整理汇总了C++中DGifGetCodeNext函数的典型用法代码示例。如果您正苦于以下问题:C++ DGifGetCodeNext函数的具体用法?C++ DGifGetCodeNext怎么用?C++ DGifGetCodeNext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DGifGetCodeNext函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DGifGetLine
static int DGifGetLine(GifFileType * GifFile, GifPixelType * Line, int LineLen)
{
GifByteType *Dummy;
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private))
{
_GifError = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (!LineLen)
LineLen = GifFile->Image.Width;
if ((Private->PixelCount -= LineLen) > 0xffff0000UL)
{
_GifError = D_GIF_ERR_DATA_TOO_BIG;
return GIF_ERROR;
}
if (DGifDecompressLine(GifFile, Line, LineLen) == GIF_OK)
{
if (Private->PixelCount == 0)
{
do
if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
return GIF_ERROR; while (Dummy != NULL);
}
return GIF_OK;
}
else
return GIF_ERROR;
}
示例2: pixel
/******************************************************************************
Put one pixel (Pixel) into GIF file.
******************************************************************************/
int
DGifGetPixel(GifFileType *GifFile, GifPixelType Pixel)
{
GifByteType *Dummy;
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (--Private->PixelCount > 0xffff0000UL)
{
GifFile->Error = D_GIF_ERR_DATA_TOO_BIG;
return GIF_ERROR;
}
if (DGifDecompressLine(GifFile, &Pixel, 1) == GIF_OK) {
if (Private->PixelCount == 0) {
/* We probably won't be called any more, so let's clean up
* everything before we return: need to flush out all the
* rest of image until an empty block (size 0)
* detected. We use GetCodeNext.
*/
do
if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
return GIF_ERROR;
while (Dummy != NULL) ;
}
return GIF_OK;
} else
return GIF_ERROR;
}
示例3: DGifGetLZCodes
/******************************************************************************
Interface for accessing the LZ codes directly. Set Code to the real code
(12bits), or to -1 if EOF code is returned.
******************************************************************************/
int
DGifGetLZCodes(GifFileType *GifFile, int *Code)
{
GifByteType *CodeBlock;
GifFilePrivateType *Private = (GifFilePrivateType *)GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
GifFile->Error = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (DGifDecompressInput(GifFile, Code) == GIF_ERROR)
return GIF_ERROR;
if (*Code == Private->EOFCode) {
/* Skip rest of codes (hopefully only NULL terminating block): */
do {
if (DGifGetCodeNext(GifFile, &CodeBlock) == GIF_ERROR)
return GIF_ERROR;
} while (CodeBlock != NULL) ;
*Code = -1;
} else if (*Code == Private->ClearCode) {
/* We need to start over again: */
Private->RunningCode = Private->EOFCode + 1;
Private->RunningBits = Private->BitsPerPixel + 1;
Private->MaxCode1 = 1 << Private->RunningBits;
}
return GIF_OK;
}
示例4: DGifGetLine
/******************************************************************************
* Get one full scanned line (Line) of length LineLen from GIF file.
*****************************************************************************/
static int
DGifGetLine(GifFileType * GifFile,
GifPixelType * Line,
int LineLen) {
GifByteType *Dummy;
GifFilePrivateType *Private = GifFile->Private;
if (!LineLen)
LineLen = GifFile->Image.Width;
if ((Private->PixelCount -= LineLen) > 0xffff0000UL) {
return GIF_ERROR;
}
if (DGifDecompressLine(GifFile, Line, LineLen) == GIF_OK) {
if (Private->PixelCount == 0) {
/* We probably would not be called any more, so lets clean
* everything before we return: need to flush out all rest of
* image until empty block (size 0) detected. We use GetCodeNext. */
do
if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
return GIF_ERROR;
while (Dummy != NULL) ;
}
return GIF_OK;
} else
return GIF_ERROR;
}
示例5: DGifGetPixel
/******************************************************************************
* Put one pixel (Pixel) into GIF file. *
******************************************************************************/
int DGifGetPixel(GifFileType *GifFile, GifPixelType *Pixel)
{
GifByteType *Dummy;
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
_GifError = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
#if defined(__MSDOS__) || defined(__GNUC__)
if (--Private->PixelCount > 0xffff0000UL)
#else
if (--Private->PixelCount > 0xffff0000)
#endif /* __MSDOS__ */
{
_GifError = D_GIF_ERR_DATA_TOO_BIG;
return GIF_ERROR;
}
if (DGifDecompressLine(GifFile, Pixel, 1) == GIF_OK) {
if (Private->PixelCount == 0) {
/* We probably would not be called any more, so lets clean */
/* everything before we return: need to flush out all rest of */
/* image until empty block (size 0) detected. We use GetCodeNext.*/
do if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
return GIF_ERROR;
while (Dummy != NULL);
}
return GIF_OK;
}
else
return GIF_ERROR;
}
示例6: main
//.........这里部分代码省略.........
QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if ((++ImageNum == ImageN) && ImageNFlag) {
/* We are suppose to modify this image color map, do it: */
GifFileIn->SColorMap =ModifyColorMap(GifFileIn->SColorMap);
if (!HasGIFOutput) {
/* We can quit here, as we have the color map: */
if (GifFileIn != NULL) DGifCloseFile(GifFileIn);
fclose(ColorFile);
exit(EXIT_SUCCESS);
}
}
if (HasGIFOutput)
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (!TranslateFlag || (ImageNFlag && (ImageN != ImageNum)))
{
/* Now read image itself in decoded form as we don't */
/* really care what we have there, and this is much */
/* faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (HasGIFOutput)
if (EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL) {
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (HasGIFOutput)
if (EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
}
else /* we need to mung pixels intices */
{
int i;
register GifPixelType *cp;
GifPixelType *Line
= (GifPixelType *) malloc(GifFileIn->Image.Width *
sizeof(GifPixelType));
for (i = 0; i < GifFileIn->Image.Height; i++) {
if (DGifGetLine(GifFileIn, Line,GifFileIn->Image.Width)
== GIF_ERROR) {
QuitGifError(GifFileIn, GifFileOut);
}
/* translation step goes here */
for (cp = Line; cp < Line+GifFileIn->Image.Width; cp++)
*cp = Translation[*cp];
if (EGifPutLine(GifFileOut,
Line, GifFileIn->Image.Width)
== GIF_ERROR) {
QuitGifError(GifFileIn, GifFileOut);
}
}
free((char *) Line);
}
break;
case EXTENSION_RECORD_TYPE:
/* Skip any extension blocks in file: */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (HasGIFOutput)
if (EGifPutExtension(GifFileOut, ExtCode, Extension[0],
Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* No support to more than one extension blocks, so discard: */
while (Extension != NULL) {
if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be traps by DGifGetRecordType. */
break;
}
}
while (RecordType != TERMINATE_RECORD_TYPE);
if (DGifCloseFile(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (HasGIFOutput)
if (EGifCloseFile(GifFileOut) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
return 0;
}
示例7: main
/******************************************************************************
Main sequence
******************************************************************************/
int main(int argc, char **argv)
{
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
GifRecordType RecordType;
int CodeSize, ExtCode, ErrorCode;
GifByteType *CodeBlock, *Extension;
/*
* Command-line processing goes here.
*/
/* Use stdin as input (note this also read screen descriptor in: */
if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);
}
/* Use the stdout as output: */
if ((GifFileOut = EGifOpenFileHandle(1, &ErrorCode)) == NULL) {
PrintGifError(ErrorCode);
exit(EXIT_FAILURE);
}
/* And dump out its screen information: */
if (EGifPutScreenDesc(GifFileOut,
GifFileIn->SWidth, GifFileIn->SHeight,
GifFileIn->SColorResolution, GifFileIn->SBackGroundColor,
GifFileIn->SColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Scan the content of the input GIF file and load the image(s) in: */
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Put image descriptor to out file: */
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont really */
/* care what we have there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR ||
EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL) {
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case EXTENSION_RECORD_TYPE:
/* pass through extension records */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtensionLeader(GifFileOut, ExtCode) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtensionBlock(GifFileOut,
Extension[0],
Extension + 1) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (Extension != NULL) {
if (DGifGetExtensionNext(GifFileIn, &Extension)==GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (Extension != NULL)
if (EGifPutExtensionBlock(GifFileOut,
Extension[0],
Extension + 1) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
if (EGifPutExtensionTrailer(GifFileOut) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be trapped by DGifGetRecordType */
break;
}
}
while (RecordType != TERMINATE_RECORD_TYPE);
if (DGifCloseFile(GifFileIn, &ErrorCode) == GIF_ERROR)
{
PrintGifError(ErrorCode);
if (GifFileIn != NULL) {
EGifCloseFile(GifFileIn, NULL);
}
exit(EXIT_FAILURE);
}
if (EGifCloseFile(GifFileOut, &ErrorCode) == GIF_ERROR)
//.........这里部分代码省略.........
示例8: DDGifSlurp
void DDGifSlurp(GifInfo *info, bool shouldDecode) {
GifRecordType RecordType;
GifByteType *ExtData;
int codeSize;
int ExtFunction;
do {
if (DGifGetRecordType(info->gifFilePtr, &RecordType) == GIF_ERROR)
return;
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(info->gifFilePtr, !shouldDecode) == GIF_ERROR)
return;
const uint_fast16_t requiredScreenWidth = info->gifFilePtr->Image.Left + info->gifFilePtr->Image.Width;
const uint_fast16_t requiredScreenHeight = info->gifFilePtr->Image.Top + info->gifFilePtr->Image.Height;
if (requiredScreenWidth > info->gifFilePtr->SWidth || requiredScreenHeight > info->gifFilePtr->SHeight) {
if (shouldDecode) {
void *tmpRasterBits = realloc(info->rasterBits,
requiredScreenWidth * requiredScreenHeight * sizeof(GifPixelType));
if (tmpRasterBits == NULL) {
info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return;
}
info->rasterBits = tmpRasterBits;
}
else {
info->gifFilePtr->SWidth = requiredScreenWidth;
info->gifFilePtr->SHeight = requiredScreenHeight;
}
}
if (shouldDecode) {
if (info->gifFilePtr->Image.Interlace) {
uint_fast16_t i, j;
/*
* The way an interlaced image should be read -
* offsets and jumps...
*/
uint_fast8_t InterlacedOffset[] = {0, 4, 2, 1};
uint_fast8_t InterlacedJumps[] = {8, 8, 4, 2};
/* Need to perform 4 passes on the image */
for (i = 0; i < 4; i++)
for (j = InterlacedOffset[i]; j < info->gifFilePtr->Image.Height; j += InterlacedJumps[i]) {
if (DGifGetLine(info->gifFilePtr, info->rasterBits + j * info->gifFilePtr->Image.Width,
info->gifFilePtr->Image.Width) == GIF_ERROR)
return;
}
}
else {
if (DGifGetLine(
info->gifFilePtr, info->rasterBits,
info->gifFilePtr->Image.Width * info->gifFilePtr->Image.Height) == GIF_ERROR)
return;
}
return;
}
else {
if (DGifGetCode(info->gifFilePtr, &codeSize, &ExtData) == GIF_ERROR)
return;
while (ExtData != NULL) {
if (DGifGetCodeNext(info->gifFilePtr, &ExtData) == GIF_ERROR)
return;
}
}
break;
case EXTENSION_RECORD_TYPE:
if (DGifGetExtension(info->gifFilePtr, &ExtFunction, &ExtData) == GIF_ERROR)
return;
if (!shouldDecode) {
GraphicsControlBlock *tmpInfos = realloc(info->controlBlock,
(info->gifFilePtr->ImageCount + 1) *
sizeof(GraphicsControlBlock));
if (tmpInfos == NULL) {
info->gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return;
}
info->controlBlock = tmpInfos;
info->controlBlock[info->gifFilePtr->ImageCount].DelayTime = DEFAULT_FRAME_DURATION_MS;
if (readExtensions(ExtFunction, ExtData, info) == GIF_ERROR)
return;
}
while (ExtData != NULL) {
if (DGifGetExtensionNext(info->gifFilePtr, &ExtData,
&ExtFunction) == GIF_ERROR)
return;
if (!shouldDecode) {
if (readExtensions(ExtFunction, ExtData, info) == GIF_ERROR)
return;
}
}
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be trapped by DGifGetRecordType */
break;
//.........这里部分代码省略.........
示例9: DoDisassemblyNum
/******************************************************************************
* Perform the disassembly operation - take one input files into few output. *
******************************************************************************/
static int DoDisassemblyNum(const char *InFileName, char *OutFileName, int FileNum)
{
int ExtCode, CodeSize, FileEmpty;
GifRecordType RecordType;
char CrntFileName[80], *p;
GifByteType *Extension, *CodeBlock;
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
int ErrorCode;
/* If name has type postfix, strip it out, and make sure name is less */
/* or equal to 6 chars, so we will have 2 chars in name for numbers. */
//strupr(OutFileName); /* Make sure all is upper case */
#if 0
printf("OutFileName : %s\n", OutFileName);
if ((p = strrchr(OutFileName, '.')) != NULL && strlen(p) <= 4) p[0] = 0;
if ((p = strrchr(OutFileName, '/')) != NULL ||
(p = strrchr(OutFileName, '\\')) != NULL ||
(p = strrchr(OutFileName, ':')) != NULL) {
if (strlen(p) > 7) p[7] = 0; /* p includes the '/', '\\', ':' char */
}
else {
/* Only name is given for current directory: */
//if (strlen(OutFileName) > 6) OutFileName[6] = 0;
}
printf("OutFileName : %s\n", OutFileName);
#endif
/* Open input file: */
if (InFileName != NULL) {
if ((GifFileIn = DGifOpenFileName(InFileName, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
}
else {
/* Use the stdin instead: */
if ((GifFileIn = DGifOpenFileHandle(0, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
}
/* Scan the content of GIF file and dump image(s) to seperate file(s): */
//sprintf(CrntFileName, "%s_%02d.gif", OutFileName, FileNum);
sprintf(CrntFileName, "%s", OutFileName);
if ((GifFileOut = EGifOpenFileName(CrntFileName, TRUE, &ErrorCode)) == NULL)
return QuitGifError(GifFileIn, GifFileOut);
FileEmpty = TRUE;
/* And dump out its exactly same screen information: */
if (EGifPutScreenDesc(GifFileOut,
GifFileIn->SWidth, GifFileIn->SHeight,
GifFileIn->SColorResolution, GifFileIn->SBackGroundColor,
GifFileIn->SColorMap) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
FileEmpty = FALSE;
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* Put same image descriptor to out file: */
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont */
/* really care what is there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR
|| EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL)
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
break;
case EXTENSION_RECORD_TYPE:
FileEmpty = FALSE;
/* Skip any extension blocks in file: */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension)
== GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtension(GifFileOut, ExtCode, Extension[0],
Extension) == GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
/* No support to more than one extension blocks, discard */
while (Extension != NULL)
if (DGifGetExtensionNext(GifFileIn, &Extension)
== GIF_ERROR)
return QuitGifError(GifFileIn, GifFileOut);
break;
case TERMINATE_RECORD_TYPE:
break;
//.........这里部分代码省略.........
示例10: DoAssembly
/******************************************************************************
* Perform the assembly operation - take few input files into one output. *
******************************************************************************/
static void DoAssembly(int NumFiles, char **FileNames)
{
int i, ExtCode, CodeSize;
GifRecordType RecordType;
GifByteType *Extension, *CodeBlock;
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
/* Open stdout for the output file: */
if ((GifFileOut = EGifOpenFileHandle(1)) == NULL)
QuitGifError(GifFileIn, GifFileOut);
/* Scan the content of the GIF file and load the image(s) in: */
for (i = 0; i < NumFiles; i++) {
if ((GifFileIn = DGifOpenFileName(FileNames[i])) == NULL)
QuitGifError(GifFileIn, GifFileOut);
/* And dump out screen descriptor iff its first image. */
if (i == 0)
if (EGifPutScreenDesc(GifFileOut,
GifFileIn -> SWidth, GifFileIn -> SHeight,
GifFileIn -> SColorResolution, GifFileIn -> SBackGroundColor,
GifFileIn -> SBitsPerPixel, GifFileIn -> SColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Put image descriptor to out file: */
if (EGifPutImageDesc(GifFileOut,
GifFileIn -> ILeft, GifFileIn -> ITop,
GifFileIn -> IWidth, GifFileIn -> IHeight,
GifFileIn -> IInterlace, GifFileIn -> IBitsPerPixel,
GifFileIn -> IColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont */
/* dont care what is there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR
|| EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL)
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
break;
case EXTENSION_RECORD_TYPE:
/* Skip any extension blocks in file: */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension)
== GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtension(GifFileOut, ExtCode, Extension[0],
Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* No support to more than one extension blocks, discard.*/
while (Extension != NULL)
if (DGifGetExtensionNext(GifFileIn, &Extension)
== GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be traps by DGifGetRecordType. */
break;
}
}
while (RecordType != TERMINATE_RECORD_TYPE);
if (DGifCloseFile(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
if (EGifCloseFile(GifFileOut) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
示例11: main
//.........这里部分代码省略.........
}
GifQprintf("\b\b\b\b%-4d", i);
}
/* Clip the lines from ImageY1 to ImageY2 (to X1 - X2): */
for (i = ImageY1; i <= ImageY2; i++) {
if (DGifGetLine(GifFileIn, Line, GifFileIn->Image.Width)
== GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (!Complement)
if (EGifPutLine(GifFileOut, &Line[ImageX1],
ImageWidth) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
GifQprintf("\b\b\b\b%-4d", i);
}
/* Skip lines above ImageY2: */
for (i = ImageY2 + 1; i < GifFileIn->Image.Height; i++) {
if (DGifGetLine(GifFileIn, Line, GifFileIn->Image.Width)
== GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (Complement) {
if (ImageX1 == ImageX2) {
/* don't remove any vertical band */
if (EGifPutLine(GifFileOut, Line,
ImageWidth) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
else
{
if (EGifPutLine(GifFileOut, Line,
ImageX1) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutLine(GifFileOut,
&Line[ImageX2 + 1],
GifFileIn->SWidth - (ImageX2 + 1)
) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
}
GifQprintf("\b\b\b\b%-4d", i);
}
free((char *) Line);
}
else {
/* Copy the image as is (we dont modify this one): */
if (EGifPutImageDesc(GifFileOut,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height,
GifFileIn->Image.Interlace,
GifFileIn->Image.ColorMap) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* Now read image itself in decoded form as we dont */
/* really care what is there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR
|| EGifPutCode(GifFileOut, CodeSize, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL)
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR ||
EGifPutCodeNext(GifFileOut, CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case EXTENSION_RECORD_TYPE:
/* Skip any extension blocks in file: */
if (DGifGetExtension(GifFileIn, &ExtCode, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifPutExtension(GifFileOut, ExtCode, Extension[0],
Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
/* No support to more than one extension blocks, so discard: */
while (Extension != NULL) {
if (DGifGetExtensionNext(GifFileIn, &Extension) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case TERMINATE_RECORD_TYPE:
break;
default: /* Should be traps by DGifGetRecordType. */
break;
}
}
while (RecordType != TERMINATE_RECORD_TYPE);
if (DGifCloseFile(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (EGifCloseFile(GifFileOut) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
return 0;
}
示例12: DDGifSlurp
void DDGifSlurp(GifInfo *info, bool decode, bool exitAfterFrame) {
GifRecordType RecordType;
GifByteType *ExtData;
int ExtFunction;
GifFileType *gifFilePtr;
gifFilePtr = info->gifFilePtr;
uint_fast32_t lastAllocatedGCBIndex = 0;
do {
if (DGifGetRecordType(gifFilePtr, &RecordType) == GIF_ERROR)
return;
bool isInitialPass = !decode && !exitAfterFrame;
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(gifFilePtr, isInitialPass) == GIF_ERROR)
return;
if (isInitialPass) {
int_fast32_t widthOverflow = gifFilePtr->Image.Width - gifFilePtr->SWidth;
int_fast32_t heightOverflow = gifFilePtr->Image.Height - gifFilePtr->SHeight;
if (widthOverflow > 0 || heightOverflow > 0) {
gifFilePtr->SWidth += widthOverflow;
gifFilePtr->SHeight += heightOverflow;
}
SavedImage *sp = &gifFilePtr->SavedImages[gifFilePtr->ImageCount - 1];
int_fast32_t topOverflow = gifFilePtr->Image.Top + gifFilePtr->Image.Height - gifFilePtr->SHeight;
if (topOverflow > 0) {
sp->ImageDesc.Top -= topOverflow;
}
int_fast32_t leftOverflow = gifFilePtr->Image.Left + gifFilePtr->Image.Width - gifFilePtr->SWidth;
if (leftOverflow > 0) {
sp->ImageDesc.Left -= leftOverflow;
}
if (!updateGCB(info, &lastAllocatedGCBIndex)) {
return;
}
}
if (decode) {
int_fast32_t widthOverflow = gifFilePtr->Image.Width - info->originalWidth;
int_fast32_t heightOverflow = gifFilePtr->Image.Height - info->originalHeight;
if (widthOverflow > 0 || heightOverflow > 0) {
void *tmpRasterBits = reallocarray(info->rasterBits, info->originalWidth * info->originalHeight, sizeof(GifPixelType));
if (tmpRasterBits == NULL) {
gifFilePtr->Error = D_GIF_ERR_NOT_ENOUGH_MEM;
return;
}
info->rasterBits = tmpRasterBits;
}
if (gifFilePtr->Image.Interlace) {
uint_fast16_t i, j;
/*
* The way an interlaced image should be read -
* offsets and jumps...
*/
uint_fast8_t InterlacedOffset[] = {0, 4, 2, 1};
uint_fast8_t InterlacedJumps[] = {8, 8, 4, 2};
/* Need to perform 4 passes on the image */
for (i = 0; i < 4; i++)
for (j = InterlacedOffset[i]; j < gifFilePtr->Image.Height; j += InterlacedJumps[i]) {
if (DGifGetLine(gifFilePtr, info->rasterBits + j * gifFilePtr->Image.Width, gifFilePtr->Image.Width) == GIF_ERROR)
return;
}
} else {
if (DGifGetLine(gifFilePtr, info->rasterBits, gifFilePtr->Image.Width * gifFilePtr->Image.Height) == GIF_ERROR) {
return;
}
}
if (info->sampleSize > 1) {
unsigned char *dst = info->rasterBits;
unsigned char *src = info->rasterBits;
unsigned char *const srcEndImage = info->rasterBits + gifFilePtr->Image.Width * gifFilePtr->Image.Height;
do {
unsigned char *srcNextLineStart = src + gifFilePtr->Image.Width * info->sampleSize;
unsigned char *const srcEndLine = src + gifFilePtr->Image.Width;
unsigned char *dstEndLine = dst + gifFilePtr->Image.Width / info->sampleSize;
do {
*dst = *src;
dst++;
src += info->sampleSize;
} while (src < srcEndLine);
dst = dstEndLine;
src = srcNextLineStart;
} while (src < srcEndImage);
}
return;
} else {
do {
if (DGifGetCodeNext(gifFilePtr, &ExtData) == GIF_ERROR) {
return;
}
} while (ExtData != NULL);
if (exitAfterFrame) {
return;
}
}
break;
//.........这里部分代码省略.........
示例13: main
/******************************************************************************
* Interpret the command line and scan the given GIF file. *
******************************************************************************/
int main(int argc, char **argv)
{
int i, j, Size, Error, NumFiles, ExtCode, CodeSize, NumColors = 2, Color,
Count, ImageNum = 0, TextFlag = FALSE, SizeFlag = FALSE,
ImageNFlag = FALSE, BackGroundFlag = FALSE, HelpFlag = FALSE;
long Scaler, Histogram[256];
GifRecordType RecordType;
GifByteType *Extension, *CodeBlock;
char **FileName = NULL;
GifRowType Line;
GifFileType *GifFileIn = NULL, *GifFileOut = NULL;
/* Same image dimension vars for both Image & ImageN as only one allowed */
if ((Error = GAGetArgs(argc, argv, CtrlStr, &GifQuietPrint,
&TextFlag, &SizeFlag, &ImageWidth, &ImageHeight,
&ImageNFlag, &ImageN, &BackGroundFlag,
&HelpFlag, &NumFiles, &FileName)) != FALSE ||
(NumFiles > 1 && !HelpFlag)) {
if (Error)
GAPrintErrMsg(Error);
else if (NumFiles > 1)
GIF_MESSAGE("Error in command line parsing - one GIF file please.");
GAPrintHowTo(CtrlStr);
exit(EXIT_FAILURE);
}
if (HelpFlag) {
fprintf(stderr, VersionStr);
GAPrintHowTo(CtrlStr);
exit(EXIT_SUCCESS);
}
if (NumFiles == 1) {
if ((GifFileIn = DGifOpenFileName(*FileName)) == NULL)
QuitGifError(GifFileIn, GifFileOut);
}
else {
/* Use the stdin instead: */
if ((GifFileIn = DGifOpenFileHandle(0)) == NULL)
QuitGifError(GifFileIn, GifFileOut);
}
for (i = 0; i < 256; i++) Histogram[i] = 0; /* Reset counters. */
/* Scan the content of the GIF file and load the image(s) in: */
do {
if (DGifGetRecordType(GifFileIn, &RecordType) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
switch (RecordType) {
case IMAGE_DESC_RECORD_TYPE:
if (DGifGetImageDesc(GifFileIn) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
if (GifFileIn->Image.ColorMap)
NumColors = GifFileIn->Image.ColorMap->ColorCount;
else if (GifFileIn->SColorMap)
NumColors = GifFileIn->SColorMap->ColorCount;
else
GIF_EXIT("Neither Screen nor Image color map exists.");
if ((ImageHeight / NumColors) * NumColors != ImageHeight)
GIF_EXIT("Image height specified not dividable by #colors.");
if (++ImageNum == ImageN) {
/* This is the image we should make histogram for: */
Line = (GifRowType) malloc(GifFileIn->Image.Width *
sizeof(GifPixelType));
GifQprintf("\n%s: Image %d at (%d, %d) [%dx%d]: ",
PROGRAM_NAME, ImageNum,
GifFileIn->Image.Left, GifFileIn->Image.Top,
GifFileIn->Image.Width, GifFileIn->Image.Height);
for (i = 0; i < GifFileIn->Image.Height; i++) {
if (DGifGetLine(GifFileIn, Line, GifFileIn->Image.Width)
== GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
for (j = 0; j < GifFileIn->Image.Width; j++)
Histogram[Line[j]]++;
GifQprintf("\b\b\b\b%-4d", i);
}
free((char *) Line);
}
else {
/* Skip the image: */
/* Now read image itself in decoded form as we dont */
/* really care what is there, and this is much faster. */
if (DGifGetCode(GifFileIn, &CodeSize, &CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
while (CodeBlock != NULL)
if (DGifGetCodeNext(GifFileIn, &CodeBlock) == GIF_ERROR)
QuitGifError(GifFileIn, GifFileOut);
}
break;
case EXTENSION_RECORD_TYPE:
/* Skip any extension blocks in file: */
//.........这里部分代码省略.........
示例14: main
//.........这里部分代码省略.........
printf(", BitsPerPixel = %d.\n",
GifFile->Image.ColorMap->BitsPerPixel);
else
printf(".\n");
if (GifFile->Image.ColorMap)
printf("\tImage Has Color Map.\n");
else
printf("\tNo Image Color Map.\n");
if (ColorMapFlag && GifFile->Image.ColorMap) {
printf("\tSort Flag: %s\n",
GifFile->Image.ColorMap->SortFlag ? "on":"off");
Len = 1 << GifFile->Image.ColorMap->BitsPerPixel;
for (i = 0; i < Len; i+=4) {
for (j = 0; j < 4 && j < Len; j++) {
printf("%3d: %02xh %02xh %02xh ", i + j,
GifFile->Image.ColorMap->Colors[i + j].Red,
GifFile->Image.ColorMap->Colors[i + j].Green,
GifFile->Image.ColorMap->Colors[i + j].Blue);
}
printf("\n");
}
}
}
if (EncodedFlag) {
if (DGifGetCode(GifFile, &CodeSize, &CodeBlock) == GIF_ERROR) {
PrintGifError(GifFile->Error);
exit(EXIT_FAILURE);
}
printf("\nImage LZ compressed Codes (Code Size = %d):\n",
CodeSize);
PrintCodeBlock(GifFile, CodeBlock, true);
while (CodeBlock != NULL) {
if (DGifGetCodeNext(GifFile, &CodeBlock) == GIF_ERROR) {
PrintGifError(GifFile->Error);
exit(EXIT_FAILURE);
}
PrintCodeBlock(GifFile, CodeBlock, false);
}
}
else if (LZCodesFlag) {
PrintLZCodes(GifFile);
}
else if (PixelFlag) {
Line = (GifPixelType *) malloc(GifFile->Image.Width *
sizeof(GifPixelType));
for (i = 0; i < GifFile->Image.Height; i++) {
if (DGifGetLine(GifFile, Line, GifFile->Image.Width)
== GIF_ERROR) {
PrintGifError(GifFile->Error);
exit(EXIT_FAILURE);
}
PrintPixelBlock(Line, GifFile->Image.Width, i == 0);
}
PrintPixelBlock(NULL, GifFile->Image.Width, false);
free((char *) Line);
}
else if (RawFlag) {
Line = (GifPixelType *) malloc(GifFile->Image.Width *
sizeof(GifPixelType));
for (i = 0; i < GifFile->Image.Height; i++) {
if (DGifGetLine(GifFile, Line, GifFile->Image.Width)
== GIF_ERROR) {
PrintGifError(GifFile->Error);
exit(EXIT_FAILURE);
}
示例15: DGifGetLine
/******************************************************************************
* Get one full scanned line (Line) of length LineLen from GIF file. *
******************************************************************************/
int DGifGetLine(GifFileType *GifFile, GifPixelType *Line, int LineLen)
{
GifByteType *Dummy;
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
_GifError = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (!LineLen) LineLen = GifFile->Image.Width;
#if defined(__MSDOS__) || defined(__GNUC__)
if ((Private->PixelCount -= LineLen) > 0xffff0000UL) {
#else
if ((Private->PixelCount -= LineLen) > 0xffff0000) {
#endif /* __MSDOS__ */
_GifError = D_GIF_ERR_DATA_TOO_BIG;
return GIF_ERROR;
}
if (DGifDecompressLine(GifFile, Line, LineLen) == GIF_OK) {
if (Private->PixelCount == 0) {
/* We probably would not be called any more, so lets clean */
/* everything before we return: need to flush out all rest of */
/* image until empty block (size 0) detected. We use GetCodeNext.*/
do if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
return GIF_ERROR;
while (Dummy != NULL);
}
return GIF_OK;
}
else
return GIF_ERROR;
}
/******************************************************************************
* Get an extension block (see GIF manual) from gif file. This routine only *
* returns the first data block, and DGifGetExtensionNext shouldbe called *
* after this one until NULL extension is returned. *
* The Extension should NOT be freed by the user (not dynamically allocated).*
* Note it is assumed the Extension desc. header ('!') has been read. *
******************************************************************************/
int DGifGetExtension(GifFileType *GifFile, int *ExtCode,
GifByteType **Extension)
{
GifByteType Buf;
GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
if (!IS_READABLE(Private)) {
/* This file was NOT open for reading: */
_GifError = D_GIF_ERR_NOT_READABLE;
return GIF_ERROR;
}
if (READ(GifFile,&Buf, 1) != 1) {
_GifError = D_GIF_ERR_READ_FAILED;
return GIF_ERROR;
}
*ExtCode = Buf;
return DGifGetExtensionNext(GifFile, Extension);
}