-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'JPX: Out of packet' when reading J2k file with more than one precinct per resolution level #5475
Comments
|
I'm using this code for debugging and to show the picture in the browser: This is an ugly code that was ported from the example code of a library called j2k.js. I put these files in the following directory structure: Double clicking pdfjs.html within that directory structure enables reproducing and debugging JPX.js as a standalone. I'll try to investigate the content in the PDF you have uploaded. I'm not really familiar with embedding j2k within pdf (as I said, I'm using JPX.js as a standalone for reading jpeg2000). Maybe the codestream is changed by Adobe when embedded within a PDF? |
EDIT: Ignore this comment, it's wrong. I checked the differences between the two files using hex editor. My suggestion was right - the content was changed when embedded within the document. More specific, Adobe added a decomposition level and changed all levels to contain only one precinct - a case in which this bug cannot be reproduced. |
Sorry, I uploaded the wrong image. I'm really sorry about wasting your time... Here is a link for the correct j2k file in which the bug is reproduced: |
Ok, now I see the issue. I updated the link to the pdf file in my #5475 (comment) above. |
Hi,
Perhaps it should be:
since PJ is the precinct counter in the vertical axis, while PI is in the horizontal axis. This simple substituion has solved the problem for a toy image with |
I think I found the problem and have a ready fix. There are two issues here, first is the PI/PJ inverted counters that I have stated in the comment above. The second, is the mapping of codeblocks to their precincts for non-degenerate precinct partition. Jasper library defines these sizes as codeblock group width and height. From the JPEG2000.pdf at Jasper documentation, section K: tier-2 coding:
I suggest the following changes in jpx.js:
function: buildPackets
function: buildCodeblocks
That has worked for me for a real image, RGB, 2 resolution levels, 2 quality layers, and Paul |
do you feel comfortable with submitting a pull request? you did some really good investigation here and deserve the credit for the change. otherwise somebody else could pick it up. |
@MaMazav Are you the author of the jp2 file, and if so can we include it in our test suite? |
I generated it according to @plroit's instructions. I'll try to check the copyright issue and maybe will generate another file with dummy content to avoid the copyright issue. Anyway the bug still occurs on the following file: I think that @plroit's solution is good for a situations in which the codeblock is larger than the precinct. If the codeblocks are smaller I still get the exception. I tried to change @plroit's calculation of cblkGroupWidth and cblkGroupHeight to 1 << dimensions.xcb_ and 1 << dimensions.ycb_ but it doesn't work. I'm still trying to work on it. |
Hi, Thank you for your input, I have tested the new image from @MaMazav and found several more problems with the precinct number calculation. I will commit a fix shortly. The tested images are taken from unsplash, which states at the license that:
|
When I'm trying to read a jpeg2000 file with more than one precinct per level, I have an 'Out of packet' exception and the picture get messed.
Link to j2k file for reproducing (EDIT: This is the wrong file):
https://www.dropbox.com/s/fi1bwc73a3ynawv/cabs_1tile_bw_puniform_2levels_lrcp.jp2?dl=0
EDIT: Here is the correct file:
https://www.dropbox.com/s/vekbn3m4nkhmv3o/cabs_1tile_bw_puniform_lrcp.jp2?dl=0
(I'm using JPX.js as a standalone J2k reader, so the reproduce example is not a pdf but a jp2 file. Sorry for that):
I'll be happy to contribute if I succeed to solve the bug, but I'm not sure I'll succeed in solving it. However I have some technical information I collected from debugging, which may be useful:
I saw that the offsets of the beginning of the packets is wrong. The offset get wrong after parsing the first precinct of the second level.
I did it by creating a file which is identical to the one that demonstrating the bug, but with PLT information. Using the PLT information I know that the packet offsets should be as follows (offsets are from the beginning of the bitstream, right after the SOD marker):
level 0: 0, 14953, 29404, 43500
level 1: 58852, 85548, 109067, 132132
end of bitstream: 160939
However when debugging JPX I saw the following offsets (by watching the value of position parameter at the first line of the while loop in parseTilePackets function. Can be reproduced by a breakpoint at line 830 in 5.11.2014 version):
level 0: 0, 14953, 29404, 43500
level 1: 58852, 78779, ... (the continuation is not important as the parsing is wrong from now because of the wrong offset).
The text was updated successfully, but these errors were encountered: