From: Michal Maciola <71131832+mmaciola@users.noreply.github.com> Date: Mon, 19 Jul 2021 05:55:23 +0000 (+0200) Subject: jpg_loader: decompress header on opening X-Git-Tag: accepted/tizen/unified/20210727.124506~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ccf9f2c32cdf99c99c6b654d67b9701b8e41141c;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git jpg_loader: decompress header on opening --- diff --git a/src/loaders/jpg/tvgJpgLoader.cpp b/src/loaders/jpg/tvgJpgLoader.cpp index d92ada1..685819b 100644 --- a/src/loaders/jpg/tvgJpgLoader.cpp +++ b/src/loaders/jpg/tvgJpgLoader.cpp @@ -76,7 +76,7 @@ bool JpgLoader::open(const string& path) if (fread(data, size, 1, jpegFile) < 1) goto failure; - //FIXME: Decompress header here + if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &inSubsamp, &inColorspace) < 0) goto failure; ret = true; freeData = true; @@ -96,6 +96,8 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy) { clear(); + if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &inSubsamp, &inColorspace) < 0) return false; + if (copy) { this->data = (unsigned char *) malloc(size); if (!this->data) return false; @@ -107,19 +109,12 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy) this->size = size; - //FIXME: Decompress header here - return true; } bool JpgLoader::read() { - //decompress header - int width, height; - int inSubsamp, inColorspace; - if (tjDecompressHeader3(jpegDecompressor, data, size, &width, &height, &inSubsamp, &inColorspace) < 0) return false; - if (image) tjFree(image); image = (unsigned char *)tjAlloc(width * height * tjPixelSize[TJPF_BGRX]); if (!image) return false; diff --git a/src/loaders/jpg/tvgJpgLoader.h b/src/loaders/jpg/tvgJpgLoader.h index 0063da2..91218ba 100644 --- a/src/loaders/jpg/tvgJpgLoader.h +++ b/src/loaders/jpg/tvgJpgLoader.h @@ -47,6 +47,9 @@ private: unsigned char *image = nullptr; unsigned long size = 0; bool freeData = false; + + int width, height; + int inSubsamp, inColorspace; }; #endif //_TVG_JPG_LOADER_H_