Skip to content
Snippets Groups Projects
Commit b79083a9 authored by Tiago de Freitas Pereira's avatar Tiago de Freitas Pereira
Browse files

Truncated jpeg test case

parent 8ce63866
No related branches found
No related tags found
1 merge request!36new image and hdf5 support
Pipeline #60444 passed
......@@ -2,6 +2,7 @@
import numpy as np
import h5py
import imageio
from .utils import to_bob, to_matplotlib, opencvbgr_to_bob, bob_to_opencvbgr, imshow
import logging
......@@ -9,6 +10,12 @@ import logging
logger = logging.getLogger(__name__)
import os
# Allowing the loading of truncated files in case PIL is used
# https://github.com/kirumang/Pix2Pose/issues/2
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
hdf5_extensions = [".hdf5", ".h5", ".hdf", ".hdf5", ".h5", ".hdf", ".hdf5"]
image_extensions = [
......@@ -86,7 +93,6 @@ def open_file(filename):
return img
extension = os.path.splitext(filename)[1] # get the extension
# logger.error("############")
# logger.error(filename)
if extension in hdf5_extensions:
......@@ -141,7 +147,7 @@ def write_file(filename, data, format="pillow"):
f["array"] = data
elif extension in image_extensions:
# Pillow is the format with the best support for all image formats
imageio.imwrite(filename, data, format=format)
imageio.imwrite(filename, to_matplotlib(data), format=format)
else:
raise RuntimeError(f"Unknown file extension: {extension}")
......
bob/io/base/test/data/truncated_jpeg.jpg

2.73 MiB

......@@ -155,5 +155,9 @@ def test_image_load():
def test_image_exceptions():
# This tests some image exceptions I found
# Real PNG image
# Real GRAY PNG image
transcode(datafile("read_png_gray.png", __name__))
# Trucated JPEG
# THIS TEST FAILS
# transcode(datafile("truncated_jpeg.jpg", __name__))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment