Skip to content

Rearrange ImagingPoint code - #10026

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:point
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:point

Conversation

@radarhere

@radarhere radarhere commented Sep 19, 2026

Copy link
Copy Markdown
Member

I find

if (imIn->type != IMAGING_TYPE_UINT8) {
if (imIn->type != IMAGING_TYPE_INT32 || mode != IMAGING_MODE_L) {
goto mode_mismatch;
}
} else if (!imIn->image8 && imIn->mode != mode) {
goto mode_mismatch;
}

rather confusing to read. Everything is using a negative condition.

Here's my suggestion instead.

if (imIn->type == IMAGING_TYPE_UINT8) {
	if (imIn->mode != mode && !imIn->image8) {
		goto mode_mismatch;
	}
} else if (imIn->type == IMAGING_TYPE_INT32) {
	if (mode != IMAGING_MODE_L) {
		// I images can only be used with L output mode
		goto mode_mismatch;
	}
} else {
	// Reject F modes and modes based on I;16
	goto mode_mismatch;
}

The I images comment is mirroring

Pillow/src/PIL/Image.py

Lines 2023 to 2025 in 852d834

:param mode: Output mode (default is same as input). This can only be used if
the source image has mode "L" or "P", and the output has mode "1" or the
source image mode is "I" and the output mode is "L".

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant