Skip to content
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

Simplified access code #7296

Merged
merged 2 commits into from
Jul 22, 2023
Merged

Simplified access code #7296

merged 2 commits into from
Jul 22, 2023

Conversation

radarhere
Copy link
Member

  1. The put_pixel function is only currently used for LA, La and PA.
    ADD("1", get_pixel_8, put_pixel_8);
    ADD("L", get_pixel_8, put_pixel_8);
    ADD("LA", get_pixel, put_pixel);
    ADD("La", get_pixel, put_pixel);
    ADD("I", get_pixel_32, put_pixel_32);
    ADD("I;16", get_pixel_16L, put_pixel_16L);
    ADD("I;16L", get_pixel_16L, put_pixel_16L);
    ADD("I;16B", get_pixel_16B, put_pixel_16B);
    ADD("I;16N", get_pixel_16, put_pixel_16L);
    ADD("I;32L", get_pixel_32L, put_pixel_32L);
    ADD("I;32B", get_pixel_32B, put_pixel_32B);
    ADD("F", get_pixel_32, put_pixel_32);
    ADD("P", get_pixel_8, put_pixel_8);
    ADD("PA", get_pixel, put_pixel);
    ADD("RGB", get_pixel_32, put_pixel_32);
    ADD("RGBA", get_pixel_32, put_pixel_32);
    ADD("RGBa", get_pixel_32, put_pixel_32);
    ADD("RGBX", get_pixel_32, put_pixel_32);
    ADD("CMYK", get_pixel_32, put_pixel_32);
    ADD("YCbCr", get_pixel_32, put_pixel_32);
    ADD("LAB", get_pixel_32, put_pixel_32);
    ADD("HSV", get_pixel_32, put_pixel_32);

static void
put_pixel(Imaging im, int x, int y, const void *color) {
if (im->image8) {
im->image8[y][x] = *((UINT8 *)color);
} else {
memcpy(&im->image32[y][x], color, sizeof(INT32));
}
}

Since these are not image8 modes, it would be simpler to just call put_pixel_32 instead

static void
put_pixel_32(Imaging im, int x, int y, const void *color) {
memcpy(&im->image32[y][x], color, sizeof(INT32));
}

and remove put_pixel.

  1. get_pixel is similarly only currently used for LA, La and PA.

It does have unique behaviour, so we can't remove it completely.

static void
get_pixel(Imaging im, int x, int y, void *color) {
char *out = color;
/* generic pixel access*/
if (im->image8) {
out[0] = im->image8[y][x];
} else {
UINT8 *p = (UINT8 *)&im->image32[y][x];
if (im->type == IMAGING_TYPE_UINT8 && im->bands == 2) {
out[0] = p[0];
out[1] = p[3];
return;
}
memcpy(out, p, im->pixelsize);
}
}

However, this PR removes the check for image8, since it is false for these modes, and the check if this is UINT8 2 bands, since it is true for these modes, and renames the function to get_pixel_32_2bands to indicate that it is specific.

@hugovk hugovk merged commit 06e66f7 into python-pillow:main Jul 22, 2023
52 checks passed
@radarhere radarhere deleted the access branch July 22, 2023 21:57
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.

3 participants