Skip to content

Add support for reading TIFFs with PlanarConfiguration=2#5178

Closed
wiredfool wants to merge 12 commits intopython-pillow:masterfrom
wiredfool:4641_rebase
Closed

Add support for reading TIFFs with PlanarConfiguration=2#5178
wiredfool wants to merge 12 commits intopython-pillow:masterfrom
wiredfool:4641_rebase

Conversation

@wiredfool
Copy link
Copy Markdown
Member

@wiredfool wiredfool commented Jan 2, 2021

@hugovk hugovk changed the title Rebase of #4641 Add support for reading TIFFs with PlanarConfiguration=2 Jan 2, 2021
@wiredfool
Copy link
Copy Markdown
Member Author

I'm afraid I don't have the setup to debug the windows side of this at the moment.

@radarhere radarhere added the TIFF label Jan 2, 2021
@kkopachev
Copy link
Copy Markdown
Contributor

I am not familiar with Windows specifics here, but here is some observations:
Current code failed only on x86. On few runs it died with 'Access violation' error and on Python 3.9 it throws Col out of range, max 99 error. I thought it's something wrong in calculation of accessing tile width and enabled TRACE to see what's up - and x86 runs all successful, but now it failed on all x64 in different test.
Thought that might be helpful.

@wiredfool
Copy link
Copy Markdown
Member Author

@nulano Do you have any insight into this?

Comment on lines +634 to +637
shuffler((UINT8*) im->image[tile_y + y] + x * im->pixelsize,
state->buffer + current_line * row_byte_size,
current_tile_width
);
Copy link
Copy Markdown
Contributor

@nulano nulano Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not yet sure what is going on, but compiling with debug information shows that state->buffer is NULL on this line even though it was valid on line 587 for the realloc call.

The error doesn't show up when compiling with in a debug build (setup.py build_ext --dubug), I had to change setup.py line 852 to Extension("PIL._imaging", files, extra_compile_args=["/Z7"], extra_link_args=["/DEBUG"]), and copy the PDB to the PIL directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved it, see wiredfool#6

uint16 photometric = 0; // init to not PHOTOMETRIC_YCBCR
int isYCbCr = 0;
UINT8 planarconfig = 0;
UINT8 planes = 1;
Copy link
Copy Markdown
Contributor

@nulano nulano Jan 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkopachev Is there any reason to use UINT8 for planes? It looks to me like it would make more sense to use int.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, should be just int 🤦

// if number of bands is 1, there is no difference with contig case
if (planarconfig == PLANARCONFIG_SEPARATE &&
im->bands > 1 &&
photometric != PHOTOMETRIC_YCBCR) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
photometric != PHOTOMETRIC_YCBCR) {
!isYCbCr) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nulano and @kkopachev

Copy link
Copy Markdown
Contributor

@nulano nulano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as UINT8 planes -> int planes.

state->errcode = IMAGING_CODEC_BROKEN;
return -1;
}
UINT8 plane;

This comment was marked as resolved.

* backwards
*/

UINT8 plane;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UINT8 plane;
int plane;

@kkopachev
Copy link
Copy Markdown
Contributor

@wiredfool I have some changes I did on top of this PR to fix BigEndian skipped tests and a bit of refactoring. Do you want me to create PR into this branch or wait until this merged and open into Pillow:master afterwards for separate review?
changes are here: wiredfool/Pillow@4641_rebase...kkopachev:4641_rebase

@wiredfool
Copy link
Copy Markdown
Member Author

Might as well pr to this branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants