Skip to content

Commit 794474f

Browse files
committed
Added: option to decode semi-corrupted jpeg files
1 parent 93e4c73 commit 794474f

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

Codecs/CodecJPG/Source/CodecJpeg.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ namespace IMCodec
8686
/*if (canvasWidth != 0 && canvasHeight != 0)
8787
ComputeDesiredDimensions(canvasWidth, canvasHeight, width, height);*/
8888

89-
90-
size_t imageDataSize = width * height * bytesPerPixel;
89+
uint64_t imageDataSize = static_cast<uint64_t>(width) * height * bytesPerPixel;
9190
auto imageItem = std::make_shared<ImageItem>();
9291
imageItem->itemType = ImageItemType::Image;
93-
imageItem->data.Allocate(imageDataSize);
92+
imageItem->data.Allocate(static_cast<size_t>(imageDataSize));
9493

95-
96-
if (tjDecompress2(ftjHandle, const_cast< uint8_t*>(reinterpret_cast<const uint8_t*>( buffer)), jpegSize, reinterpret_cast<unsigned char*>(imageItem->data.data()), width, width * bytesPerPixel, height, TJPF_RGBA, 0) != -1)
94+
95+
auto resultCode = tjDecompress2(ftjHandle, const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(buffer)), jpegSize, reinterpret_cast<unsigned char*>(imageItem->data.data()), width, width * bytesPerPixel, height, TJPF_RGBA, 0);
96+
97+
if (resultCode == 0 || tjGetErrorCode(ftjHandle) == TJERR_WARNING)
9798
{
9899
imageItem->descriptor.texelFormatDecompressed = TexelFormat::I_R8_G8_B8_A8;
99100
imageItem->descriptor.texelFormatStorage = TexelFormat::I_R8_G8_B8;
@@ -103,7 +104,6 @@ namespace IMCodec
103104
out_image = std::make_shared<Image>(imageItem, ImageItemType::Unknown);
104105
result = ImageResult::Success;
105106
}
106-
107107
}
108108

109109
//tjDestroy(ftjHandle);

0 commit comments

Comments
 (0)