From 2053bbbc3714b488c7ebf1b559d29240d67d00c8 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 16 Nov 2023 15:04:46 +0900 Subject: [PATCH] gif: fixed a regresion bug by clear() change by 66305f3e6d0001ffca70e4337275900cdda8e5bb --- src/savers/gif/meson.build | 1 + src/savers/gif/{gif.h => tvgGifEncoder.h} | 55 ++++++++++++++++------- src/savers/gif/tvgGifSaver.cpp | 3 +- 3 files changed, 42 insertions(+), 17 deletions(-) rename src/savers/gif/{gif.h => tvgGifEncoder.h} (92%) diff --git a/src/savers/gif/meson.build b/src/savers/gif/meson.build index b07e9003..3bd72a98 100644 --- a/src/savers/gif/meson.build +++ b/src/savers/gif/meson.build @@ -1,4 +1,5 @@ source_file = [ + 'tvgGifEncoder.h', 'tvgGifSaver.h', 'tvgGifSaver.cpp', ] diff --git a/src/savers/gif/gif.h b/src/savers/gif/tvgGifEncoder.h similarity index 92% rename from src/savers/gif/gif.h rename to src/savers/gif/tvgGifEncoder.h index 32e1f409..e5ace31e 100644 --- a/src/savers/gif/gif.h +++ b/src/savers/gif/tvgGifEncoder.h @@ -1,3 +1,26 @@ +/* + * Copyright (c) 2023 the ThorVG project. All rights reserved. + + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + // // gif.h // by Charlie Tangora @@ -26,8 +49,8 @@ // Finally, call GifEnd() to close the file handle and free memory. // -#ifndef gif_h -#define gif_h +#ifndef TVG_GIF_ENCODER_H +#define TVG_GIF_ENCODER_H #include // for FILE* #include // for memcpy and bzero @@ -282,19 +305,20 @@ void GifSplitPalette(uint8_t* image, int numPixels, int firstElt, int lastElt, i // moves them to the from of the buffer. // This allows us to build a palette optimized for the colors of the // changed pixels only. -int GifPickChangedPixels( const uint8_t* lastFrame, uint8_t* frame, int numPixels ) +int GifPickChangedPixels( const uint8_t* lastFrame, uint8_t* frame, int numPixels, bool transparent) { int numChanged = 0; uint8_t* writeIter = frame; - for (int ii=0; iibitDepth = bitDepth; @@ -316,8 +340,7 @@ void GifMakePalette( const uint8_t* lastFrame, const uint8_t* nextFrame, uint32_ memcpy(destroyableImage, nextFrame, imageSize); int numPixels = (int)(width * height); - if(lastFrame) - numPixels = GifPickChangedPixels(lastFrame, destroyableImage, numPixels); + if(lastFrame) numPixels = GifPickChangedPixels(lastFrame, destroyableImage, numPixels, transparent); const int lastElt = 1 << bitDepth; const int splitElt = lastElt/2; @@ -663,7 +686,7 @@ bool GifWriteFrame(GifWriter* writer, const uint8_t* image, uint32_t width, uint writer->firstFrame = false; GifPalette pal; - GifMakePalette(oldImage, image, width, height, 8, &pal); + GifMakePalette(oldImage, image, width, height, 8, &pal, transparent); GifThresholdImage(oldImage, image, writer->oldImage, width, height, &pal, transparent); @@ -689,4 +712,4 @@ bool GifEnd( GifWriter* writer ) return true; } -#endif +#endif //TVG_GIF_ENCODER_H diff --git a/src/savers/gif/tvgGifSaver.cpp b/src/savers/gif/tvgGifSaver.cpp index 7d59489e..175aeb02 100644 --- a/src/savers/gif/tvgGifSaver.cpp +++ b/src/savers/gif/tvgGifSaver.cpp @@ -21,7 +21,7 @@ */ #include -#include "gif.h" +#include "tvgGifEncoder.h" #include "tvgGifSaver.h" @@ -63,6 +63,7 @@ void GifSaver::run(unsigned tid) auto duration = animation->duration(); for (auto p = 0.0f; p < duration; p += delay) { + canvas->clear(false); auto frameNo = animation->totalFrame() * (p / duration); animation->frame(frameNo); canvas->update();