use mode structs in map.c

This commit is contained in:
Yay295 2024-04-22 12:59:17 -05:00
parent ebbe5d844b
commit 1b1f250b74

View File

@ -55,7 +55,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
PyObject *target; PyObject *target;
Py_buffer view; Py_buffer view;
char *mode; char *mode_name;
char *codec; char *codec;
Py_ssize_t offset; Py_ssize_t offset;
int xsize, ysize; int xsize, ysize;
@ -70,7 +70,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
&ysize, &ysize,
&codec, &codec,
&offset, &offset,
&mode, &mode_name,
&stride, &stride,
&ystep &ystep
)) { )) {
@ -82,8 +82,10 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
return NULL; return NULL;
} }
const Mode * const mode = findMode(mode_name);
if (stride <= 0) { if (stride <= 0) {
if (!strcmp(mode, "L") || !strcmp(mode, "P")) { if (mode == IMAGING_MODE_L || mode == IMAGING_MODE_P) {
stride = xsize; stride = xsize;
} else if (isModeI16(mode)) { } else if (isModeI16(mode)) {
stride = xsize * 2; stride = xsize * 2;