-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
What did you do?
I tried to decode a JPEG2000 image using Pillow.
What did you expect to happen?
I expected Pillow to decode and display the image.
What actually happened?
An OSError exception was raised:
OSError: broken data stream when reading image file
What are your OS, Python and Pillow versions?
- OS: Mac OSX 10.15.6
- Python: 3.9
- Pillow: 8.0.1
- Openjpeg: 2.1.1
ZIP archive containing the example.j2k image: example.zip
from PIL import Image
image = Image.open('example.j2k')
image.show()Note that openjpeg can decompress the image:
$ opj_decompress -i example.j2k -o example.png
[INFO] Start to read j2k main header (0).
[INFO] Main header has been correctly decoded.
[INFO] No decoded area parameters, set the decoded area to the whole image
[INFO] Header of tile 1 / 1 has been read.
[INFO] Generated Outfile example.png
decode time: 2 ms
In addition, I can open the image on my Mac using Preview and Safari without problems.
Analysis
This is what the image header looks like:
$ opj_dump -i example.j2k
[INFO] Start to read j2k main header (0).
[INFO] Main header has been correctly decoded.
Image info {
x0=0, y0=0
x1=256, y1=256
numcomps=3
component 0 {
dx=1, dy=1
prec=8
sgnd=0
}
component 1 {
dx=2, dy=1
prec=8
sgnd=0
}
component 2 {
dx=2, dy=1
prec=8
sgnd=0
}
}
Codestream info from main header: {
tx0=0, ty0=0
tdx=256, tdy=256
tw=1, th=1
default tile {
csty=0
prg=0
numlayers=1
mct=0
comp 0 {
csty=0
numresolutions=6
cblkw=2^6
cblkh=2^6
cblksty=0
qmfbid=0
preccintsize (w,h)=(15,15) (15,15) (15,15) (15,15) (15,15) (15,15)
qntsty=2
numgbits=1
stepsizes (m,e)=(460,11) (464,10) (464,10) (434,9) (478,9) (478,9) (459,8) (528,8) (528,8) (544,7) (651,7) (651,7) (738,6) (616,6) (616,6) (542,5)
roishift=0
}
comp 1 {
csty=0
numresolutions=6
cblkw=2^6
cblkh=2^6
cblksty=0
qmfbid=0
preccintsize (w,h)=(15,15) (15,15) (15,15) (15,15) (15,15) (15,15)
qntsty=2
numgbits=1
stepsizes (m,e)=(460,11) (464,10) (464,10) (434,9) (478,9) (478,9) (459,8) (528,8) (528,8) (544,7) (651,7) (651,7) (738,6) (616,6) (616,6) (542,5)
roishift=0
}
comp 2 {
csty=0
numresolutions=6
cblkw=2^6
cblkh=2^6
cblksty=0
qmfbid=0
preccintsize (w,h)=(15,15) (15,15) (15,15) (15,15) (15,15) (15,15)
qntsty=2
numgbits=1
stepsizes (m,e)=(460,11) (464,10) (464,10) (434,9) (478,9) (478,9) (459,8) (528,8) (528,8) (544,7) (651,7) (651,7) (738,6) (616,6) (616,6) (542,5)
roishift=0
}
}
}
Codestream index from main header: {
Main header start position=0
Main header end position=112
Marker list: {
type=0xff4f, pos=0, len=2
type=0xff51, pos=2, len=49
type=0xff52, pos=51, len=14
type=0xff5c, pos=65, len=37
type=0xff64, pos=102, len=10
}
}