X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77b83d0a0f152e0eea6e6d357fced42319ecb118..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/common/imaggif.cpp?ds=sidebyside diff --git a/src/common/imaggif.cpp b/src/common/imaggif.cpp index b0c4399d9c..52f9cf14c4 100644 --- a/src/common/imaggif.cpp +++ b/src/common/imaggif.cpp @@ -69,8 +69,6 @@ struct GifHashTableType wxUint32 HTable[HT_SIZE]; }; -/*static*/ wxString wxGIFHandler::ms_comment; - IMPLEMENT_DYNAMIC_CLASS(wxGIFHandler,wxImageHandler) //---------------------------------------------------------------------------- @@ -94,8 +92,7 @@ static bool wxGIFHandler_Write(wxOutputStream *, const void *buf, size_t len); static bool wxGIFHandler_WriteByte(wxOutputStream *, wxUint8); static bool wxGIFHandler_WriteWord(wxOutputStream *, wxUint16); static bool wxGIFHandler_WriteHeader(wxOutputStream *, int width, int height, - bool loop, const wxRGB *pal, int palCount, - const wxString& comment = wxEmptyString); + bool loop, const wxRGB *pal, int palCount); static bool wxGIFHandler_WriteRect(wxOutputStream *, int width, int height); #if wxUSE_PALETTE static bool wxGIFHandler_WriteTerm(wxOutputStream *); @@ -179,7 +176,7 @@ bool wxGIFHandler::SaveFile(wxImage *image, return wxGIFHandler_GetPalette(*image, pal, &palCount, &maskIndex) && DoSaveFile(*image, &stream, verbose, true /*first?*/, 0, - false /*loop?*/, pal, palCount, maskIndex, ms_comment) + false /*loop?*/, pal, palCount, maskIndex) && wxGIFHandler_WriteTerm(&stream); #else wxUnusedVar(image); @@ -211,7 +208,7 @@ int wxGIFHandler::DoGetImageCount( wxInputStream& stream ) bool wxGIFHandler::DoSaveFile(const wxImage& image, wxOutputStream *stream, bool WXUNUSED(verbose), bool first, int delayMilliSecs, bool loop, - const wxRGB *pal, int palCount, int maskIndex, const wxString& comment) + const wxRGB *pal, int palCount, int maskIndex) { const unsigned long colorcount = image.CountColours(256+1); bool ok = colorcount && (colorcount <= 256); @@ -227,10 +224,13 @@ bool wxGIFHandler::DoSaveFile(const wxImage& image, wxOutputStream *stream, if (first) { ok = wxGIFHandler_WriteHeader(stream, width, height, loop, - pal, palCount, comment); + pal, palCount); } - ok = ok && wxGIFHandler_WriteControl(stream, maskIndex, delayMilliSecs) + ok = ok + && wxGIFHandler_WriteComment(stream, + image.GetOption(wxIMAGE_OPTION_GIF_COMMENT)) + && wxGIFHandler_WriteControl(stream, maskIndex, delayMilliSecs) && wxGIFHandler_WriteByte(stream, GIF_MARKER_SEP) && wxGIFHandler_WriteRect(stream, width, height); @@ -301,8 +301,7 @@ bool wxGIFHandler::DoSaveFile(const wxImage& image, wxOutputStream *stream, } bool wxGIFHandler::SaveAnimation(const wxImageArray& images, - wxOutputStream *stream, bool verbose, int delayMilliSecs, - const wxString& comment) + wxOutputStream *stream, bool verbose, int delayMilliSecs) { #if wxUSE_PALETTE bool ok = true; @@ -334,8 +333,7 @@ bool wxGIFHandler::SaveAnimation(const wxImageArray& images, ok = wxGIFHandler_GetPalette(image, pal, &palCount, &maskIndex) && DoSaveFile(image, stream, verbose, i == 0 /*first?*/, delayMilliSecs, - true /*loop?*/, pal, palCount, maskIndex, - comment.length() ? comment : ms_comment); + true /*loop?*/, pal, palCount, maskIndex); } return ok && wxGIFHandler_WriteTerm(stream); @@ -344,7 +342,6 @@ bool wxGIFHandler::SaveAnimation(const wxImageArray& images, wxUnusedVar(stream); wxUnusedVar(verbose); wxUnusedVar(delayMilliSecs); - wxUnusedVar(comment); return false; #endif @@ -646,11 +643,11 @@ bool wxGIFHandler_WriteWord(wxOutputStream *stream, wxUint16 word) buf[0] = word & 0xff; buf[1] = (word >> 8) & 0xff; - return wxGIFHandler_Write(stream, &word, sizeof(word)); + return wxGIFHandler_Write(stream, &buf, sizeof(buf)); } bool wxGIFHandler_WriteHeader(wxOutputStream *stream, int width, int height, - bool loop, const wxRGB *pal, int palCount, const wxString& comment) + bool loop, const wxRGB *pal, int palCount) { const int bpp = wxGIFHandler_BitSize(palCount); wxUint8 buf[3]; @@ -672,11 +669,6 @@ bool wxGIFHandler_WriteHeader(wxOutputStream *stream, int width, int height, ok = ok && wxGIFHandler_WriteLoop(stream); } - if (comment.length()) - { - ok = ok && wxGIFHandler_WriteComment(stream, comment); - } - return ok; } @@ -744,18 +736,44 @@ bool wxGIFHandler_WriteControl(wxOutputStream *stream, bool wxGIFHandler_WriteComment(wxOutputStream *stream, const wxString& comment) { - wxUint8 buf[3]; - wxCharBuffer text(comment.mb_str()); - size_t len = strlen(text.data()); - len = wxMin(len, 255); + if ( comment.empty() ) + { + return true; + } + // Write comment header. + wxUint8 buf[2]; buf[0] = GIF_MARKER_EXT; buf[1] = GIF_MARKER_EXT_COMMENT; - buf[2] = (wxUint8)len; + if ( !wxGIFHandler_Write(stream, buf, sizeof(buf)) ) + { + return false; + } - return wxGIFHandler_Write(stream, buf, sizeof(buf)) - && wxGIFHandler_Write(stream, text.data(), len) - && wxGIFHandler_WriteZero(stream); + /* + If comment is longer than 255 bytes write it in blocks of maximum 255 + bytes each. + */ + wxCharBuffer text( comment.mb_str() ); + + size_t pos = 0, fullLength = text.length(); + + do + { + size_t blockLength = wxMin(fullLength - pos, 255); + + if ( !wxGIFHandler_WriteByte(stream, (wxUint8) blockLength) + || !wxGIFHandler_Write(stream, &text.data()[pos], blockLength) ) + { + return false; + } + + pos += blockLength; + }while (pos < fullLength); + + + // Write comment footer. + return wxGIFHandler_WriteZero(stream); } bool wxGIFHandler_WriteLoop(wxOutputStream *stream)