Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/FreeImage/PluginGIF.cpp view on Meta::CPAN
} else if( globalpalette_size < 128 ) {
globalpalette_size = 64;
packed |= 5 & GIF_PACKED_LSD_GCTSIZE;
} else if( globalpalette_size < 256 ) {
globalpalette_size = 128;
packed |= 6 & GIF_PACKED_LSD_GCTSIZE;
} else {
globalpalette_size = 256;
packed |= 7 & GIF_PACKED_LSD_GCTSIZE;
}
if( FreeImage_GetBackgroundColor(dib, &background_color) ) {
for( int i = 0; i < globalpalette_size; i++ ) {
if( background_color.rgbRed == globalpalette[i].rgbRed &&
background_color.rgbGreen == globalpalette[i].rgbGreen &&
background_color.rgbBlue == globalpalette[i].rgbBlue ) {
b = (BYTE)i;
break;
}
}
}
} else {
packed |= (bpp - 1) & GIF_PACKED_LSD_GCTSIZE;
}
io->write_proc(&packed, 1, 1, handle);
io->write_proc(&b, 1, 1, handle);
b = 0;
io->write_proc(&b, 1, 1, handle);
//Global Color Table
if( globalpalette != NULL ) {
int i = 0;
while( i < globalpalette_size ) {
io->write_proc(&globalpalette[i].rgbRed, 1, 1, handle);
io->write_proc(&globalpalette[i].rgbGreen, 1, 1, handle);
io->write_proc(&globalpalette[i].rgbBlue, 1, 1, handle);
i++;
}
}
//Application Extension
LONG loop = 0;
if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Loop", FIDT_LONG, &tag) ) {
loop = *(LONG *)FreeImage_GetTagValue(tag);
}
if( loop != 1 ) {
//the Netscape extension is really "repeats" not "loops"
if( loop > 1 ) loop--;
if( loop > 0xFFFF ) loop = 0xFFFF;
w = (WORD)loop;
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&w);
#endif
io->write_proc((void *)"\x21\xFF\x0BNETSCAPE2.0\x03\x01", 16, 1, handle);
io->write_proc(&w, 2, 1, handle);
b = 0;
io->write_proc(&b, 1, 1, handle);
}
//Comment Extension
FIMETADATA *mdhandle = NULL;
FITAG *tag = NULL;
mdhandle = FreeImage_FindFirstMetadata(FIMD_COMMENTS, dib, &tag);
if( mdhandle ) {
do {
if( FreeImage_GetTagType(tag) == FIDT_ASCII ) {
int length = FreeImage_GetTagLength(tag) - 1;
char *value = (char *)FreeImage_GetTagValue(tag);
io->write_proc((void *)"\x21\xFE", 2, 1, handle);
while( length > 0 ) {
b = (BYTE)(length >= 255 ? 255 : length);
io->write_proc(&b, 1, 1, handle);
io->write_proc(value, b, 1, handle);
value += b;
length -= b;
}
b = 0;
io->write_proc(&b, 1, 1, handle);
}
} while(FreeImage_FindNextMetadata(mdhandle, &tag));
FreeImage_FindCloseMetadata(mdhandle);
}
}
//Graphic Control Extension
if( FreeImage_IsTransparent(dib) ) {
int count = FreeImage_GetTransparencyCount(dib);
BYTE *table = FreeImage_GetTransparencyTable(dib);
for( int i = 0; i < count; i++ ) {
if( table[i] == 0 ) {
have_transparent = true;
transparent_color = i;
break;
}
}
}
io->write_proc((void *)"\x21\xF9\x04", 3, 1, handle);
b = (BYTE)((disposal_method << 2) & GIF_PACKED_GCE_DISPOSAL);
if( have_transparent ) b |= GIF_PACKED_GCE_HAVETRANS;
io->write_proc(&b, 1, 1, handle);
//Notes about delay time for GIFs:
//IE5/IE6 have a minimum and default of 100ms
//Mozilla/Firefox/Netscape 6+/Opera have a minimum of 20ms and a default of 100ms if <20ms is specified or the GCE is absent
//Netscape 4 has a minimum of 10ms if 0ms is specified, but will use 0ms if the GCE is absent
w = (WORD)(delay_time / 10); //convert ms to cs
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&w);
#endif
io->write_proc(&w, 2, 1, handle);
b = (BYTE)transparent_color;
io->write_proc(&b, 1, 1, handle);
b = 0;
io->write_proc(&b, 1, 1, handle);
//Image Descriptor
b = GIF_BLOCK_IMAGE_DESCRIPTOR;
io->write_proc(&b, 1, 1, handle);
io->write_proc(&left, 2, 1, handle);
io->write_proc(&top, 2, 1, handle);
io->write_proc(&width, 2, 1, handle);
( run in 0.736 second using v1.01-cache-2.11-cpan-13bb782fe5a )