diff options
author | Brendan Shillingford <brendan2609@gmail.com> | 2015-09-16 17:47:48 +0300 |
---|---|---|
committer | Brendan Shillingford <brendan2609@gmail.com> | 2015-09-16 17:47:48 +0300 |
commit | 5c7ee2a3c11719377697096522f9fc9422338560 (patch) | |
tree | 106787f5b7f95cf0a276ae1f748a5972d5b42695 | |
parent | 0112463987778e9fcf476505ec904b16c73281a8 (diff) |
Fix JPEG magic number to handle more JPEGs
for example, these are all valid:
FF D8 FF E0
FF D8 FF E1
FF D8 FF E3
FF D8 FF E8
FF D8 FF DB
sources:
https://en.wikipedia.org/wiki/List_of_file_signatures
http://filesignatures.net/?page=all&order=SIGNATURE&alpha=J
-rw-r--r-- | init.lua | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -93,12 +93,15 @@ local function todepth(img, depth) end local function isPNG(magicTensor) - pngMagic = torch.ByteTensor({0x89,0x50,0x4e,0x47}) + local pngMagic = torch.ByteTensor({0x89,0x50,0x4e,0x47}) return torch.all(torch.eq(magicTensor, pngMagic)) end local function isJPG(magicTensor) - jpgMagic = torch.ByteTensor({0xff, 0xd8, 0xff, 0xe0}) + -- There are many valid 4th bytes, so only check the first 3 bytes. + -- libjpeg should support most if not all of these: + -- source: http://filesignatures.net/?page=all&order=SIGNATURE&alpha=J + local jpgMagic = torch.ByteTensor({0xff, 0xd8, 0xff}) return torch.all(torch.eq(magicTensor, jpgMagic)) end @@ -107,7 +110,7 @@ local function decompress(tensor, depth, tensortype) dok.error('Input tensor must be a byte tensor', 'image.decompress') end - if isJPG(tensor[{{1,4}}]) then + if isJPG(tensor[{{1,3}}]) then return image.decompressJPG(tensor, depth, tensortype) elseif isPNG(tensor[{{1,4}}]) then return image.decompressPNG(tensor, depth, tensortype) |