summaryrefslogtreecommitdiff
path: root/libs/freeimage/src/FreeImage/PluginGIF.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-07 23:58:40 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-07 23:58:40 +0300
commitbd864aa049acee3bd236858b29ab5e219bf79b62 (patch)
tree412d8cafc87f897244b2033cd4c9eb8f693f3315 /libs/freeimage/src/FreeImage/PluginGIF.cpp
parent62385245de7390d630cdd1459d13c69fd315a302 (diff)
FreeImage: update to 3.18.0
Diffstat (limited to 'libs/freeimage/src/FreeImage/PluginGIF.cpp')
-rw-r--r--libs/freeimage/src/FreeImage/PluginGIF.cpp47
1 files changed, 23 insertions, 24 deletions
diff --git a/libs/freeimage/src/FreeImage/PluginGIF.cpp b/libs/freeimage/src/FreeImage/PluginGIF.cpp
index 1a7a84041b..8fe0422b31 100644
--- a/libs/freeimage/src/FreeImage/PluginGIF.cpp
+++ b/libs/freeimage/src/FreeImage/PluginGIF.cpp
@@ -3,9 +3,13 @@
//
// Design and implementation by
// - Ryan Rubley <ryan@lostreality.org>
-// - RaphaŠ»l Gaquer <raphael.gaquer@alcer.com>
+// - Raphaėl Gaquer <raphael.gaquer@alcer.com>
// - Aaron Shumate <aaron@shumate.us>
//
+// References
+// http://www.w3.org/Graphics/GIF/spec-gif87.txt
+// http://www.w3.org/Graphics/GIF/spec-gif89a.txt
+//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
@@ -41,6 +45,7 @@
// Constant/Typedef declarations
// ==========================================================
+
struct GIFinfo {
BOOL read;
//only really used when reading
@@ -488,23 +493,20 @@ MimeType() {
return "image/gif";
}
-static BOOL DLL_CALLCONV
+static BOOL DLL_CALLCONV
Validate(FreeImageIO *io, fi_handle handle) {
- char buf[6];
- if( io->read_proc(buf, 6, 1, handle) < 1 ) {
- return FALSE;
- }
+ BYTE GIF89a[] = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 }; // ASCII code for "GIF89a"
+ BYTE GIF87a[] = { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 }; // ASCII code for "GIF87a"
+ BYTE signature[6] = { 0, 0, 0, 0, 0, 0 };
- 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' ) {
- bResult = TRUE;
- }
- }
+ io->read_proc(signature, 1, 6, handle);
- io->seek_proc(handle, -6, SEEK_CUR);
+ if (memcmp(GIF89a, signature, 6) == 0)
+ return TRUE;
+ if (memcmp(GIF87a, signature, 6) == 0)
+ return TRUE;
- return bResult;
+ return FALSE;
}
static BOOL DLL_CALLCONV
@@ -528,18 +530,15 @@ Open(FreeImageIO *io, fi_handle handle, BOOL read) {
return NULL;
}
- // 25/02/2008 MDA: Not safe to memset GIFinfo structure with VS 2008 (safe iterators),
- // perform initialization in constructor instead.
- // memset(info, 0, sizeof(GIFinfo));
-
+ // set Read/Write mode
info->read = read;
+
if( read ) {
try {
- //Header
+ // read Header (6 bytes)
if( !Validate(io, handle) ) {
throw FI_MSG_ERROR_MAGIC_NUMBER;
}
- io->seek_proc(handle, 6, SEEK_CUR);
//Logical Screen Descriptor
io->seek_proc(handle, 4, SEEK_CUR);
@@ -1013,19 +1012,19 @@ 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++) {
+ //Comment Extension
+ 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];
io->read_proc(&b, 1, 1, handle);
- while (b) {
+ while( b ) {
io->read_proc(buf, b, 1, handle);
comment.append(buf, b);
io->read_proc(&b, 1, 1, handle);
}
comment.append(1, '\0');
- sprintf(buf, "Comment%d", (int)idx);
+ sprintf(buf, "Comment%zd", idx);
DWORD comment_size = (DWORD)comment.size();
FreeImage_SetMetadataEx(FIMD_COMMENTS, dib, buf, 1, FIDT_ASCII, comment_size, comment_size, comment.c_str());
}