mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-27 00:26:51 +00:00
jpg_loader: decompress header on opening
This commit is contained in:
parent
94eeb92dbe
commit
8826394b56
2 changed files with 6 additions and 8 deletions
|
@ -76,7 +76,7 @@ bool JpgLoader::open(const string& path)
|
||||||
|
|
||||||
if (fread(data, size, 1, jpegFile) < 1) goto failure;
|
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;
|
ret = true;
|
||||||
freeData = true;
|
freeData = true;
|
||||||
|
@ -96,6 +96,8 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
if (tjDecompressHeader3(jpegDecompressor, (unsigned char *) data, size, &width, &height, &inSubsamp, &inColorspace) < 0) return false;
|
||||||
|
|
||||||
if (copy) {
|
if (copy) {
|
||||||
this->data = (unsigned char *) malloc(size);
|
this->data = (unsigned char *) malloc(size);
|
||||||
if (!this->data) return false;
|
if (!this->data) return false;
|
||||||
|
@ -107,19 +109,12 @@ bool JpgLoader::open(const char* data, uint32_t size, bool copy)
|
||||||
|
|
||||||
this->size = size;
|
this->size = size;
|
||||||
|
|
||||||
//FIXME: Decompress header here
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool JpgLoader::read()
|
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);
|
if (image) tjFree(image);
|
||||||
image = (unsigned char *)tjAlloc(width * height * tjPixelSize[TJPF_BGRX]);
|
image = (unsigned char *)tjAlloc(width * height * tjPixelSize[TJPF_BGRX]);
|
||||||
if (!image) return false;
|
if (!image) return false;
|
||||||
|
|
|
@ -47,6 +47,9 @@ private:
|
||||||
unsigned char *image = nullptr;
|
unsigned char *image = nullptr;
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
bool freeData = false;
|
bool freeData = false;
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
int inSubsamp, inColorspace;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //_TVG_JPG_LOADER_H_
|
#endif //_TVG_JPG_LOADER_H_
|
||||||
|
|
Loading…
Add table
Reference in a new issue