summaryrefslogtreecommitdiff
path: root/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/AdvaImg/src/FreeImage/PluginGIF.cpp')
-rw-r--r--plugins/AdvaImg/src/FreeImage/PluginGIF.cpp308
1 files changed, 154 insertions, 154 deletions
diff --git a/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp b/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp
index 7af1d821d8..e8d84afac4 100644
--- a/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp
+++ b/plugins/AdvaImg/src/FreeImage/PluginGIF.cpp
@@ -167,8 +167,8 @@ FreeImage_SetMetadataEx(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key
static BOOL
FreeImage_GetMetadataEx(FREE_IMAGE_MDMODEL model, FIBITMAP *dib, const char *key, FREE_IMAGE_MDTYPE type, FITAG **tag)
{
- if ( FreeImage_GetMetadata(model, dib, key, tag)) {
- if ( FreeImage_GetTagType(*tag) == type ) {
+ if( FreeImage_GetMetadata(model, dib, key, tag) ) {
+ if( FreeImage_GetTagType(*tag) == type ) {
return TRUE;
}
}
@@ -187,10 +187,10 @@ StringTable::StringTable()
StringTable::~StringTable()
{
- if ( m_buffer != NULL ) {
+ if( m_buffer != NULL ) {
delete [] m_buffer;
}
- if ( m_strmap != NULL ) {
+ if( m_strmap != NULL ) {
delete [] m_strmap;
m_strmap = NULL;
}
@@ -218,10 +218,10 @@ void StringTable::Initialize(int minCodeSize)
BYTE *StringTable::FillInputBuffer(int len)
{
- if ( m_buffer == NULL ) {
+ if( m_buffer == NULL ) {
m_buffer = new(std::nothrow) BYTE[len];
m_bufferRealSize = len;
- } else if ( len > m_bufferRealSize ) {
+ } else if( len > m_bufferRealSize ) {
delete [] m_buffer;
m_buffer = new(std::nothrow) BYTE[len];
m_bufferRealSize = len;
@@ -273,7 +273,7 @@ int StringTable::CompressEnd(BYTE *buf)
bool StringTable::Compress(BYTE *buf, int *len)
{
- if ( m_bufferSize == 0 || m_done ) {
+ if( m_bufferSize == 0 || m_done ) {
return false;
}
@@ -288,7 +288,7 @@ bool StringTable::Compress(BYTE *buf, int *len)
int nextprefix = (((m_prefix)<<8)&0xFFF00) + (ch & 0x000FF);
if(firstPixelPassed) {
- if ( m_strmap[nextprefix] > 0) {
+ if( m_strmap[nextprefix] > 0) {
m_prefix = m_strmap[nextprefix];
} else {
m_partial |= m_prefix << m_partialSize;
@@ -304,13 +304,13 @@ bool StringTable::Compress(BYTE *buf, int *len)
m_strmap[nextprefix] = m_nextCode;
//increment the next highest valid code, increase the code size
- if ( m_nextCode == (1 << m_codeSize)) {
+ if( m_nextCode == (1 << m_codeSize) ) {
m_codeSize++;
}
m_nextCode++;
//if we're out of codes, restart the string table
- if ( m_nextCode == MAX_LZW_CODE ) {
+ if( m_nextCode == MAX_LZW_CODE ) {
m_partial |= m_clearCode << m_partialSize;
m_partialSize += m_codeSize;
ClearCompressorTable();
@@ -321,7 +321,7 @@ bool StringTable::Compress(BYTE *buf, int *len)
}
//increment to the next pixel
- if ( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack)) {
+ if( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack) ) {
m_bufferShift -= m_bpp;
} else {
m_bufferPos++;
@@ -329,7 +329,7 @@ bool StringTable::Compress(BYTE *buf, int *len)
}
//jump out here if the output buffer is full
- if ( bufpos - buf == *len ) {
+ if( bufpos - buf == *len ) {
return true;
}
@@ -341,7 +341,7 @@ bool StringTable::Compress(BYTE *buf, int *len)
m_prefix = ch & 0x000FF;
//increment to the next pixel
- if ( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack)) {
+ if( m_bufferShift > 0 && !(m_bufferPos + 1 == m_bufferSize && m_bufferShift <= m_slack) ) {
m_bufferShift -= m_bpp;
} else {
m_bufferPos++;
@@ -349,7 +349,7 @@ bool StringTable::Compress(BYTE *buf, int *len)
}
//jump out here if the output buffer is full
- if ( bufpos - buf == *len ) {
+ if( bufpos - buf == *len ) {
return true;
}
}
@@ -363,12 +363,12 @@ bool StringTable::Compress(BYTE *buf, int *len)
bool StringTable::Decompress(BYTE *buf, int *len)
{
- if ( m_bufferSize == 0 || m_done ) {
+ if( m_bufferSize == 0 || m_done ) {
return false;
}
BYTE *bufpos = buf;
- for ( ; m_bufferPos < m_bufferSize; m_bufferPos++ ) {
+ for( ; m_bufferPos < m_bufferSize; m_bufferPos++ ) {
m_partial |= (int)m_buffer[m_bufferPos] << m_partialSize;
m_partialSize += 8;
while( m_partialSize >= m_codeSize ) {
@@ -376,22 +376,22 @@ bool StringTable::Decompress(BYTE *buf, int *len)
m_partial >>= m_codeSize;
m_partialSize -= m_codeSize;
- if ( code > m_nextCode || (m_nextCode == MAX_LZW_CODE && code != m_clearCode) || code == m_endCode ) {
+ if( code > m_nextCode || (m_nextCode == MAX_LZW_CODE && code != m_clearCode) || code == m_endCode ) {
m_done = true;
*len = (int)(bufpos - buf);
return true;
}
- if ( code == m_clearCode ) {
+ if( code == m_clearCode ) {
ClearDecompressorTable();
continue;
}
//add new string to string table, if not the first pass since a clear code
- if ( m_oldCode != MAX_LZW_CODE ) {
+ if( m_oldCode != MAX_LZW_CODE ) {
m_strings[m_nextCode] = m_strings[m_oldCode] + m_strings[code == m_nextCode ? m_oldCode : code][0];
}
- if ( (int)m_strings[code].size() > *len - (bufpos - buf)) {
+ if( (int)m_strings[code].size() > *len - (bufpos - buf) ) {
//out of space, stuff the code back in for next time
m_partial <<= m_codeSize;
m_partialSize += m_codeSize;
@@ -406,9 +406,9 @@ bool StringTable::Decompress(BYTE *buf, int *len)
bufpos += m_strings[code].size();
//increment the next highest valid code, add a bit to the mask if we need to increase the code size
- if ( m_oldCode != MAX_LZW_CODE && m_nextCode < MAX_LZW_CODE ) {
- if ( ++m_nextCode < MAX_LZW_CODE ) {
- if ( (m_nextCode & m_codeMask) == 0 ) {
+ if( m_oldCode != MAX_LZW_CODE && m_nextCode < MAX_LZW_CODE ) {
+ if( ++m_nextCode < MAX_LZW_CODE ) {
+ if( (m_nextCode & m_codeMask) == 0 ) {
m_codeSize++;
m_codeMask |= m_nextCode;
}
@@ -443,7 +443,7 @@ void StringTable::ClearCompressorTable(void)
void StringTable::ClearDecompressorTable(void)
{
- for ( int i = 0; i < m_clearCode; i++ ) {
+ for( int i = 0; i < m_clearCode; i++ ) {
m_strings[i].resize(1);
m_strings[i][0] = (char)i;
}
@@ -492,13 +492,13 @@ MimeType() {
static BOOL DLL_CALLCONV
Validate(FreeImageIO *io, fi_handle handle) {
char buf[6];
- if ( io->read_proc(buf, 6, 1, handle) < 1 ) {
+ if( io->read_proc(buf, 6, 1, handle) < 1 ) {
return FALSE;
}
BOOL bResult = FALSE;
- if ( !strncmp(buf, "GIF", 3)) {
- if ( buf[3] >= '0' && buf[3] <= '9' && buf[4] >= '0' && buf[4] <= '9' && buf[5] >= 'a' && buf[5] <= 'z' ) {
+ if( !strncmp(buf, "GIF", 3) ) {
+ if( buf[3] >= '0' && buf[3] <= '9' && buf[4] >= '0' && buf[4] <= '9' && buf[5] >= 'a' && buf[5] <= 'z' ) {
bResult = TRUE;
}
}
@@ -525,7 +525,7 @@ SupportsExportType(FREE_IMAGE_TYPE type) {
static void *DLL_CALLCONV
Open(FreeImageIO *io, fi_handle handle, BOOL read) {
GIFinfo *info = new(std::nothrow) GIFinfo;
- if ( info == NULL ) {
+ if( info == NULL ) {
return NULL;
}
@@ -534,10 +534,10 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
// memset(info, 0, sizeof(GIFinfo));
info->read = read;
- if ( read ) {
+ if( read ) {
try {
//Header
- if ( !Validate(io, handle)) {
+ if( !Validate(io, handle) ) {
throw FI_MSG_ERROR_MAGIC_NUMBER;
}
io->seek_proc(handle, 6, SEEK_CUR);
@@ -545,16 +545,16 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
//Logical Screen Descriptor
io->seek_proc(handle, 4, SEEK_CUR);
BYTE packed;
- if ( io->read_proc(&packed, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&packed, 1, 1, handle) < 1 ) {
throw "EOF reading Logical Screen Descriptor";
}
- if ( io->read_proc(&info->background_color, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&info->background_color, 1, 1, handle) < 1 ) {
throw "EOF reading Logical Screen Descriptor";
}
io->seek_proc(handle, 1, SEEK_CUR);
//Global Color Table
- if ( packed & GIF_PACKED_LSD_HAVEGCT ) {
+ if( packed & GIF_PACKED_LSD_HAVEGCT ) {
info->global_color_table_offset = io->tell_proc(handle);
info->global_color_table_size = 2 << (packed & GIF_PACKED_LSD_GCTSIZE);
io->seek_proc(handle, 3 * info->global_color_table_size, SEEK_CUR);
@@ -564,42 +564,42 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
size_t gce_offset = 0;
BYTE block = 0;
while( block != GIF_BLOCK_TRAILER ) {
- if ( io->read_proc(&block, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&block, 1, 1, handle) < 1 ) {
throw "EOF reading blocks";
}
- if ( block == GIF_BLOCK_IMAGE_DESCRIPTOR ) {
+ if( block == GIF_BLOCK_IMAGE_DESCRIPTOR ) {
info->image_descriptor_offsets.push_back(io->tell_proc(handle));
//GCE may be 0, meaning no GCE preceded this ID
info->graphic_control_extension_offsets.push_back(gce_offset);
gce_offset = 0;
io->seek_proc(handle, 8, SEEK_CUR);
- if ( io->read_proc(&packed, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&packed, 1, 1, handle) < 1 ) {
throw "EOF reading Image Descriptor";
}
//Local Color Table
- if ( packed & GIF_PACKED_ID_HAVELCT ) {
+ if( packed & GIF_PACKED_ID_HAVELCT ) {
io->seek_proc(handle, 3 * (2 << (packed & GIF_PACKED_ID_LCTSIZE)), SEEK_CUR);
}
//LZW Minimum Code Size
io->seek_proc(handle, 1, SEEK_CUR);
- } else if ( block == GIF_BLOCK_EXTENSION ) {
+ } else if( block == GIF_BLOCK_EXTENSION ) {
BYTE ext;
- if ( io->read_proc(&ext, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&ext, 1, 1, handle) < 1 ) {
throw "EOF reading extension";
}
- if ( ext == GIF_EXT_GRAPHIC_CONTROL ) {
+ if( ext == GIF_EXT_GRAPHIC_CONTROL ) {
//overwrite previous offset if more than one GCE found before an ID
gce_offset = io->tell_proc(handle);
- } else if ( ext == GIF_EXT_COMMENT ) {
+ } else if( ext == GIF_EXT_COMMENT ) {
info->comment_extension_offsets.push_back(io->tell_proc(handle));
- } else if ( ext == GIF_EXT_APPLICATION ) {
+ } else if( ext == GIF_EXT_APPLICATION ) {
info->application_extension_offsets.push_back(io->tell_proc(handle));
}
- } else if ( block == GIF_BLOCK_TRAILER ) {
+ } else if( block == GIF_BLOCK_TRAILER ) {
continue;
} else {
throw "Invalid GIF block found";
@@ -607,12 +607,12 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
//Data Sub-blocks
BYTE len;
- if ( io->read_proc(&len, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&len, 1, 1, handle) < 1 ) {
throw "EOF reading sub-block";
}
while( len != 0 ) {
io->seek_proc(handle, len, SEEK_CUR);
- if ( io->read_proc(&len, 1, 1, handle) < 1 ) {
+ if( io->read_proc(&len, 1, 1, handle) < 1 ) {
throw "EOF reading sub-block";
}
}
@@ -632,12 +632,12 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
static void DLL_CALLCONV
Close(FreeImageIO *io, fi_handle handle, void *data) {
- if ( data == NULL ) {
+ if( data == NULL ) {
return;
}
GIFinfo *info = (GIFinfo *)data;
- if ( !info->read ) {
+ if( !info->read ) {
//Trailer
BYTE b = GIF_BLOCK_TRAILER;
io->write_proc(&b, 1, 1, handle);
@@ -648,7 +648,7 @@ Close(FreeImageIO *io, fi_handle handle, void *data) {
static int DLL_CALLCONV
PageCount(FreeImageIO *io, fi_handle handle, void *data) {
- if ( data == NULL ) {
+ if( data == NULL ) {
return 0;
}
GIFinfo *info = (GIFinfo *)data;
@@ -658,15 +658,15 @@ PageCount(FreeImageIO *io, fi_handle handle, void *data) {
static FIBITMAP * DLL_CALLCONV
Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
- if ( data == NULL ) {
+ if( data == NULL ) {
return NULL;
}
GIFinfo *info = (GIFinfo *)data;
- if ( page == -1 ) {
+ if( page == -1 ) {
page = 0;
}
- if ( page < 0 || page >= (int)info->image_descriptor_offsets.size()) {
+ if( page < 0 || page >= (int)info->image_descriptor_offsets.size() ) {
return NULL;
}
@@ -679,7 +679,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
WORD w;
//playback pages to generate what the user would see for this frame
- if ( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) {
+ if( (flags & GIF_PLAYBACK) == GIF_PLAYBACK ) {
//Logical Screen Descriptor
io->seek_proc(handle, 6, SEEK_SET);
WORD logicalwidth, logicalheight;
@@ -691,7 +691,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
#endif
//set the background color with 0 alpha
RGBQUAD background;
- if ( info->global_color_table_offset != 0 && info->background_color < info->global_color_table_size ) {
+ if( info->global_color_table_offset != 0 && info->background_color < info->global_color_table_size ) {
io->seek_proc(handle, (long)(info->global_color_table_offset + (info->background_color * 3)), SEEK_SET);
io->read_proc(&background.rgbRed, 1, 1, handle);
io->read_proc(&background.rgbGreen, 1, 1, handle);
@@ -705,16 +705,16 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
//allocate entire logical area
dib = FreeImage_Allocate(logicalwidth, logicalheight, 32);
- if ( dib == NULL ) {
+ if( dib == NULL ) {
throw FI_MSG_ERROR_DIB_MEMORY;
}
//fill with background color to start
int x, y;
RGBQUAD *scanline;
- for ( y = 0; y < logicalheight; y++ ) {
+ for( y = 0; y < logicalheight; y++ ) {
scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, y);
- for ( x = 0; x < logicalwidth; x++ ) {
+ for( x = 0; x < logicalwidth; x++ ) {
*scanline++ = background;
}
}
@@ -743,14 +743,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
pageinfo.push_back(PageInfo(disposal_method, left, top, width, height));
- if ( start != end ) {
- if ( left == 0 && top == 0 && width == logicalwidth && height == logicalheight ) {
- if ( disposal_method == GIF_DISPOSAL_BACKGROUND ) {
+ if( start != end ) {
+ if( left == 0 && top == 0 && width == logicalwidth && height == logicalheight ) {
+ if( disposal_method == GIF_DISPOSAL_BACKGROUND ) {
pageinfo.pop_back();
start++;
break;
- } else if ( disposal_method != GIF_DISPOSAL_PREVIOUS ) {
- if ( !have_transparent ) {
+ } else if( disposal_method != GIF_DISPOSAL_PREVIOUS ) {
+ if( !have_transparent ) {
break;
}
}
@@ -758,23 +758,23 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
}
start--;
}
- if ( start < 0 ) {
+ if( start < 0 ) {
start = 0;
}
//draw each page into the logical area
delay_time = 0;
- for ( page = start; page <= end; page++ ) {
+ for( page = start; page <= end; page++ ) {
PageInfo &info = pageinfo[end - page];
//things we can skip having to decode
- if ( page != end ) {
- if ( info.disposal_method == GIF_DISPOSAL_PREVIOUS ) {
+ if( page != end ) {
+ if( info.disposal_method == GIF_DISPOSAL_PREVIOUS ) {
continue;
}
- if ( info.disposal_method == GIF_DISPOSAL_BACKGROUND ) {
- for ( y = 0; y < info.height; y++ ) {
+ if( info.disposal_method == GIF_DISPOSAL_BACKGROUND ) {
+ for( y = 0; y < info.height; y++ ) {
scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, logicalheight - (y + info.top) - 1) + info.left;
- for ( x = 0; x < info.width; x++ ) {
+ for( x = 0; x < info.width; x++ ) {
*scanline++ = background;
}
}
@@ -784,14 +784,14 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
//decode page
FIBITMAP *pagedib = Load(io, handle, page, GIF_LOAD256, data);
- if ( pagedib != NULL ) {
+ if( pagedib != NULL ) {
RGBQUAD *pal = FreeImage_GetPalette(pagedib);
have_transparent = false;
- if ( FreeImage_IsTransparent(pagedib)) {
+ if( FreeImage_IsTransparent(pagedib) ) {
int count = FreeImage_GetTransparencyCount(pagedib);
BYTE *table = FreeImage_GetTransparencyTable(pagedib);
- for ( int i = 0; i < count; i++ ) {
- if ( table[i] == 0 ) {
+ for( int i = 0; i < count; i++ ) {
+ if( table[i] == 0 ) {
have_transparent = true;
transparent_color = i;
break;
@@ -799,11 +799,11 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
}
}
//copy page data into logical buffer, with full alpha opaqueness
- for ( y = 0; y < info.height; y++ ) {
+ for( y = 0; y < info.height; y++ ) {
scanline = (RGBQUAD *)FreeImage_GetScanLine(dib, logicalheight - (y + info.top) - 1) + info.left;
BYTE *pageline = FreeImage_GetScanLine(pagedib, info.height - y - 1);
- for ( x = 0; x < info.width; x++ ) {
- if ( !have_transparent || *pageline != transparent_color ) {
+ for( x = 0; x < info.width; x++ ) {
+ if( !have_transparent || *pageline != transparent_color ) {
*scanline = pal[*pageline];
scanline->rgbReserved = 255;
}
@@ -812,9 +812,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
}
}
//copy frame time
- if ( page == end ) {
+ if( page == end ) {
FITAG *tag;
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, pagedib, "FrameTime", FIDT_LONG, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, pagedib, "FrameTime", FIDT_LONG, &tag) ) {
delay_time = *(LONG *)FreeImage_GetTagValue(tag);
}
}
@@ -846,18 +846,18 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
no_local_palette = (packed & GIF_PACKED_ID_HAVELCT) ? false : true;
int bpp = 8;
- if ( (flags & GIF_LOAD256) == 0 ) {
- if ( !no_local_palette ) {
+ if( (flags & GIF_LOAD256) == 0 ) {
+ if( !no_local_palette ) {
int size = 2 << (packed & GIF_PACKED_ID_LCTSIZE);
- if ( size <= 2 ) bpp = 1;
- else if ( size <= 16 ) bpp = 4;
- } else if ( info->global_color_table_offset != 0 ) {
- if ( info->global_color_table_size <= 2 ) bpp = 1;
- else if ( info->global_color_table_size <= 16 ) bpp = 4;
+ if( size <= 2 ) bpp = 1;
+ else if( size <= 16 ) bpp = 4;
+ } else if( info->global_color_table_offset != 0 ) {
+ if( info->global_color_table_size <= 2 ) bpp = 1;
+ else if( info->global_color_table_size <= 16 ) bpp = 4;
}
}
dib = FreeImage_Allocate(width, height, bpp);
- if ( dib == NULL ) {
+ if( dib == NULL ) {
throw FI_MSG_ERROR_DIB_MEMORY;
}
@@ -870,7 +870,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
//Palette
RGBQUAD *pal = FreeImage_GetPalette(dib);
- if ( !no_local_palette ) {
+ if( !no_local_palette ) {
int size = 2 << (packed & GIF_PACKED_ID_LCTSIZE);
int i = 0;
@@ -880,7 +880,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
io->read_proc(&pal[i].rgbBlue, 1, 1, handle);
i++;
}
- } else if ( info->global_color_table_offset != 0 ) {
+ } else if( info->global_color_table_offset != 0 ) {
long pos = io->tell_proc(handle);
io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET);
@@ -895,7 +895,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
io->seek_proc(handle, pos, SEEK_SET);
} else {
//its legal to have no palette, but we're going to generate *something*
- for ( int i = 0; i < 256; i++ ) {
+ for( int i = 0; i < 256; i++ ) {
pal[i].rgbRed = (BYTE)i;
pal[i].rgbGreen = (BYTE)i;
pal[i].rgbBlue = (BYTE)i;
@@ -915,25 +915,25 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
while( b ) {
io->read_proc(stringtable->FillInputBuffer(b), b, 1, handle);
int size = sizeof(buf);
- while( stringtable->Decompress(buf, &size)) {
- for ( int i = 0; i < size; i++ ) {
+ while( stringtable->Decompress(buf, &size) ) {
+ for( int i = 0; i < size; i++ ) {
scanline[xpos] |= (buf[i] & mask) << shift;
- if ( shift > 0 ) {
+ if( shift > 0 ) {
shift -= bpp;
} else {
xpos++;
shift = 8 - bpp;
}
- if ( ++x >= width ) {
- if ( interlaced ) {
+ if( ++x >= width ) {
+ if( interlaced ) {
y += g_GifInterlaceIncrement[interlacepass];
- if ( y >= height && ++interlacepass < GIF_INTERLACE_PASSES ) {
+ if( y >= height && ++interlacepass < GIF_INTERLACE_PASSES ) {
y = g_GifInterlaceOffset[interlacepass];
}
} else {
y++;
}
- if ( y >= height ) {
+ if( y >= height ) {
stringtable->Done();
break;
}
@@ -947,7 +947,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
io->read_proc(&b, 1, 1, handle);
}
- if ( page == 0 ) {
+ if( page == 0 ) {
size_t idx;
//Logical Screen Descriptor
@@ -963,7 +963,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", ANIMTAG_LOGICALHEIGHT, FIDT_SHORT, 1, 2, &logicalheight);
//Global Color Table
- if ( info->global_color_table_offset != 0 ) {
+ if( info->global_color_table_offset != 0 ) {
RGBQUAD globalpalette[256];
io->seek_proc(handle, (long)info->global_color_table_offset, SEEK_SET);
int i = 0;
@@ -976,29 +976,29 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
}
FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", ANIMTAG_GLOBALPALETTE, FIDT_PALETTE, info->global_color_table_size, info->global_color_table_size * 4, globalpalette);
//background color
- if ( info->background_color < info->global_color_table_size ) {
+ if( info->background_color < info->global_color_table_size ) {
FreeImage_SetBackgroundColor(dib, &globalpalette[info->background_color]);
}
}
//Application Extension
LONG loop = 1; //If no AE with a loop count is found, the default must be 1
- for ( idx = 0; idx < info->application_extension_offsets.size(); idx++ ) {
+ for( idx = 0; idx < info->application_extension_offsets.size(); idx++ ) {
io->seek_proc(handle, (long)info->application_extension_offsets[idx], SEEK_SET);
io->read_proc(&b, 1, 1, handle);
- if ( b == 11 ) { //All AEs start with an 11 byte sub-block to determine what type of AE it is
+ if( b == 11 ) { //All AEs start with an 11 byte sub-block to determine what type of AE it is
char buf[11];
io->read_proc(buf, 11, 1, handle);
- if ( !memcmp(buf, "NETSCAPE2.0", 11) || !memcmp(buf, "ANIMEXTS1.0", 11)) { //Not everybody recognizes ANIMEXTS1.0 but it is valid
+ if( !memcmp(buf, "NETSCAPE2.0", 11) || !memcmp(buf, "ANIMEXTS1.0", 11) ) { //Not everybody recognizes ANIMEXTS1.0 but it is valid
io->read_proc(&b, 1, 1, handle);
- if ( b == 3 ) { //we're supposed to have a 3 byte sub-block now
+ if( b == 3 ) { //we're supposed to have a 3 byte sub-block now
io->read_proc(&b, 1, 1, handle); //this should be 0x01 but isn't really important
io->read_proc(&w, 2, 1, handle);
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&w);
#endif
loop = w;
- if ( loop > 0 ) loop++;
+ if( loop > 0 ) loop++;
break;
}
}
@@ -1007,7 +1007,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
FreeImage_SetMetadataEx(FIMD_ANIMATION, dib, "Loop", ANIMTAG_LOOP, FIDT_LONG, 1, 4, &loop);
//Comment Extension
- for ( idx = 0; idx < info->comment_extension_offsets.size(); idx++ ) {
+ for( idx = 0; idx < info->comment_extension_offsets.size(); idx++ ) {
io->seek_proc(handle, (long)info->comment_extension_offsets[idx], SEEK_SET);
std::string comment;
char buf[255];
@@ -1025,7 +1025,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
}
//Graphic Control Extension
- if ( info->graphic_control_extension_offsets[page] != 0 ) {
+ if( info->graphic_control_extension_offsets[page] != 0 ) {
io->seek_proc(handle, (long)(info->graphic_control_extension_offsets[page] + 1), SEEK_SET);
io->read_proc(&packed, 1, 1, handle);
io->read_proc(&w, 2, 1, handle);
@@ -1037,9 +1037,9 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
disposal_method = (packed & GIF_PACKED_GCE_DISPOSAL) >> 2;
delay_time = w * 10; //convert cs to ms
transparent_color = b;
- if ( have_transparent ) {
+ if( have_transparent ) {
int size = 1 << bpp;
- if ( transparent_color <= size ) {
+ if( transparent_color <= size ) {
BYTE table[256];
memset(table, 0xFF, size);
table[transparent_color] = 0;
@@ -1054,7 +1054,7 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
delete stringtable;
} catch (const char *msg) {
- if ( dib != NULL ) {
+ if( dib != NULL ) {
FreeImage_Unload(dib);
}
FreeImage_OutputMessageProc(s_format_id, msg);
@@ -1066,12 +1066,12 @@ Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
static BOOL DLL_CALLCONV
Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void *data) {
- if ( data == NULL ) {
+ if( data == NULL ) {
return FALSE;
}
//GIFinfo *info = (GIFinfo *)data;
- if ( page == -1 ) {
+ if( page == -1 ) {
page = 0;
}
@@ -1081,7 +1081,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
FITAG *tag;
int bpp = FreeImage_GetBPP(dib);
- if ( bpp != 1 && bpp != 4 && bpp != 8 ) {
+ if( bpp != 1 && bpp != 4 && bpp != 8 ) {
throw "Only 1, 4, or 8 bpp images supported";
}
@@ -1089,22 +1089,22 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
int disposal_method = GIF_DISPOSAL_BACKGROUND, delay_time = 100, transparent_color = 0;
WORD left = 0, top = 0, width = (WORD)FreeImage_GetWidth(dib), height = (WORD)FreeImage_GetHeight(dib);
WORD output_height = height;
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", FIDT_SHORT, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameLeft", FIDT_SHORT, &tag) ) {
left = *(WORD *)FreeImage_GetTagValue(tag);
}
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTop", FIDT_SHORT, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTop", FIDT_SHORT, &tag) ) {
top = *(WORD *)FreeImage_GetTagValue(tag);
}
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "NoLocalPalette", FIDT_BYTE, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "NoLocalPalette", FIDT_BYTE, &tag) ) {
no_local_palette = *(BYTE *)FreeImage_GetTagValue(tag) ? true : false;
}
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Interlaced", FIDT_BYTE, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Interlaced", FIDT_BYTE, &tag) ) {
interlaced = *(BYTE *)FreeImage_GetTagValue(tag) ? true : false;
}
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", FIDT_LONG, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "FrameTime", FIDT_LONG, &tag) ) {
delay_time = *(LONG *)FreeImage_GetTagValue(tag);
}
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "DisposalMethod", FIDT_BYTE, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "DisposalMethod", FIDT_BYTE, &tag) ) {
disposal_method = *(BYTE *)FreeImage_GetTagValue(tag);
}
@@ -1116,17 +1116,17 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
SwapShort(&height);
#endif
- if ( page == 0 ) {
+ if( page == 0 ) {
//gather some info
WORD logicalwidth = width; // width has already been swapped...
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalWidth", FIDT_SHORT, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalWidth", FIDT_SHORT, &tag) ) {
logicalwidth = *(WORD *)FreeImage_GetTagValue(tag);
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&logicalwidth);
#endif
}
WORD logicalheight = height; // height has already been swapped...
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", FIDT_SHORT, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "LogicalHeight", FIDT_SHORT, &tag) ) {
logicalheight = *(WORD *)FreeImage_GetTagValue(tag);
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&logicalheight);
@@ -1134,9 +1134,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
}
RGBQUAD *globalpalette = NULL;
int globalpalette_size = 0;
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", FIDT_PALETTE, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "GlobalPalette", FIDT_PALETTE, &tag) ) {
globalpalette_size = FreeImage_GetTagCount(tag);
- if ( globalpalette_size >= 2 ) {
+ if( globalpalette_size >= 2 ) {
globalpalette = (RGBQUAD *)FreeImage_GetTagValue(tag);
}
}
@@ -1147,36 +1147,36 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
packed = GIF_PACKED_LSD_COLORRES;
b = 0;
RGBQUAD background_color;
- if ( globalpalette != NULL ) {
+ if( globalpalette != NULL ) {
packed |= GIF_PACKED_LSD_HAVEGCT;
- if ( globalpalette_size < 4 ) {
+ if( globalpalette_size < 4 ) {
globalpalette_size = 2;
packed |= 0 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 8 ) {
+ } else if( globalpalette_size < 8 ) {
globalpalette_size = 4;
packed |= 1 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 16 ) {
+ } else if( globalpalette_size < 16 ) {
globalpalette_size = 8;
packed |= 2 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 32 ) {
+ } else if( globalpalette_size < 32 ) {
globalpalette_size = 16;
packed |= 3 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 64 ) {
+ } else if( globalpalette_size < 64 ) {
globalpalette_size = 32;
packed |= 4 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 128 ) {
+ } else if( globalpalette_size < 128 ) {
globalpalette_size = 64;
packed |= 5 & GIF_PACKED_LSD_GCTSIZE;
- } else if ( globalpalette_size < 256 ) {
+ } 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 &&
+ 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 ) {
@@ -1194,7 +1194,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
io->write_proc(&b, 1, 1, handle);
//Global Color Table
- if ( globalpalette != NULL ) {
+ if( globalpalette != NULL ) {
int i = 0;
while( i < globalpalette_size ) {
io->write_proc(&globalpalette[i].rgbRed, 1, 1, handle);
@@ -1206,13 +1206,13 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
//Application Extension
LONG loop = 0;
- if ( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Loop", FIDT_LONG, &tag)) {
+ if( FreeImage_GetMetadataEx(FIMD_ANIMATION, dib, "Loop", FIDT_LONG, &tag) ) {
loop = *(LONG *)FreeImage_GetTagValue(tag);
}
- if ( loop != 1 ) {
+ if( loop != 1 ) {
//the Netscape extension is really "repeats" not "loops"
- if ( loop > 1 ) loop--;
- if ( loop > 0xFFFF ) loop = 0xFFFF;
+ if( loop > 1 ) loop--;
+ if( loop > 0xFFFF ) loop = 0xFFFF;
w = (WORD)loop;
#ifdef FREEIMAGE_BIGENDIAN
SwapShort(&w);
@@ -1227,9 +1227,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
FIMETADATA *mdhandle = NULL;
FITAG *tag = NULL;
mdhandle = FreeImage_FindFirstMetadata(FIMD_COMMENTS, dib, &tag);
- if ( mdhandle ) {
+ if( mdhandle ) {
do {
- if ( FreeImage_GetTagType(tag) == FIDT_ASCII ) {
+ 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);
@@ -1250,11 +1250,11 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
}
//Graphic Control Extension
- if ( FreeImage_IsTransparent(dib)) {
+ 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 ) {
+ for( int i = 0; i < count; i++ ) {
+ if( table[i] == 0 ) {
have_transparent = true;
transparent_color = i;
break;
@@ -1263,7 +1263,7 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
}
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;
+ 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
@@ -1287,14 +1287,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
io->write_proc(&width, 2, 1, handle);
io->write_proc(&height, 2, 1, handle);
packed = 0;
- if ( !no_local_palette ) packed |= GIF_PACKED_ID_HAVELCT | ((bpp - 1) & GIF_PACKED_ID_LCTSIZE);
- if ( interlaced ) packed |= GIF_PACKED_ID_INTERLACED;
+ if( !no_local_palette ) packed |= GIF_PACKED_ID_HAVELCT | ((bpp - 1) & GIF_PACKED_ID_LCTSIZE);
+ if( interlaced ) packed |= GIF_PACKED_ID_INTERLACED;
io->write_proc(&packed, 1, 1, handle);
//Local Color Table
- if ( !no_local_palette ) {
+ if( !no_local_palette ) {
int palsize = 1 << bpp;
- for ( int i = 0; i < palsize; i++ ) {
+ for( int i = 0; i < palsize; i++ ) {
io->write_proc(&pal[i].rgbRed, 1, 1, handle);
io->write_proc(&pal[i].rgbGreen, 1, 1, handle);
io->write_proc(&pal[i].rgbBlue, 1, 1, handle);
@@ -1316,9 +1316,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
b = sizeof(buf);
while( y < output_height ) {
memcpy(stringtable->FillInputBuffer(line), FreeImage_GetScanLine(dib, output_height - y - 1), line);
- while( stringtable->Compress(bufptr, &size)) {
+ while( stringtable->Compress(bufptr, &size) ) {
bufptr += size;
- if ( bufptr - buf == sizeof(buf)) {
+ if( bufptr - buf == sizeof(buf) ) {
io->write_proc(&b, 1, 1, handle);
io->write_proc(buf, sizeof(buf), 1, handle);
size = sizeof(buf);
@@ -1327,9 +1327,9 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
size = (int)(sizeof(buf) - (bufptr - buf));
}
}
- if ( interlaced ) {
+ if( interlaced ) {
y += g_GifInterlaceIncrement[interlacepass];
- if ( y >= output_height && ++interlacepass < GIF_INTERLACE_PASSES ) {
+ if( y >= output_height && ++interlacepass < GIF_INTERLACE_PASSES ) {
y = g_GifInterlaceOffset[interlacepass];
}
} else {
@@ -1339,14 +1339,14 @@ Save(FreeImageIO *io, FIBITMAP *dib, fi_handle handle, int page, int flags, void
size = (int)(bufptr - buf);
BYTE last[4];
w = (WORD)stringtable->CompressEnd(last);
- if ( size + w >= sizeof(buf)) {
+ if( size + w >= sizeof(buf) ) {
//one last full size sub-block
io->write_proc(&b, 1, 1, handle);
io->write_proc(buf, size, 1, handle);
io->write_proc(last, sizeof(buf) - size, 1, handle);
//and possibly a tiny additional sub-block
b = (BYTE)(w - (sizeof(buf) - size));
- if ( b > 0 ) {
+ if( b > 0 ) {
io->write_proc(&b, 1, 1, handle);
io->write_proc(last + w - b, b, 1, handle);
}