jpg_loader: decompress header on opening

This commit is contained in:
Michal Maciola 2021-07-19 07:55:23 +02:00 committed by GitHub
parent 94eeb92dbe
commit 8826394b56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View file

@ -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;

View file

@ -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_