mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #8067 from Yay295/patch-2
Change AlignAfterOpenBracket in .clang-format to BlockIndent
This commit is contained in:
		
						commit
						011da4b646
					
				| 
						 | 
				
			
			@ -3,7 +3,7 @@
 | 
			
		|||
BasedOnStyle: Google
 | 
			
		||||
AlwaysBreakAfterReturnType: All
 | 
			
		||||
AllowShortIfStatementsOnASingleLine: false
 | 
			
		||||
AlignAfterOpenBracket: AlwaysBreak
 | 
			
		||||
AlignAfterOpenBracket: BlockIndent
 | 
			
		||||
BinPackArguments: false
 | 
			
		||||
BinPackParameters: false
 | 
			
		||||
BreakBeforeBraces: Attach
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,7 +80,8 @@ typedef struct Tcl_Command_ *Tcl_Command;
 | 
			
		|||
typedef void *ClientData;
 | 
			
		||||
 | 
			
		||||
typedef int(Tcl_CmdProc)(
 | 
			
		||||
    ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]);
 | 
			
		||||
    ClientData clientData, Tcl_Interp *interp, int argc, const char *argv[]
 | 
			
		||||
);
 | 
			
		||||
typedef void(Tcl_CmdDeleteProc)(ClientData clientData);
 | 
			
		||||
 | 
			
		||||
/* Typedefs derived from function signatures in Tcl header */
 | 
			
		||||
| 
						 | 
				
			
			@ -90,7 +91,8 @@ typedef Tcl_Command (*Tcl_CreateCommand_t)(
 | 
			
		|||
    const char *cmdName,
 | 
			
		||||
    Tcl_CmdProc *proc,
 | 
			
		||||
    ClientData clientData,
 | 
			
		||||
    Tcl_CmdDeleteProc *deleteProc);
 | 
			
		||||
    Tcl_CmdDeleteProc *deleteProc
 | 
			
		||||
);
 | 
			
		||||
/* Tcl_AppendResult */
 | 
			
		||||
typedef void (*Tcl_AppendResult_t)(Tcl_Interp *interp, ...);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -127,7 +129,8 @@ typedef int (*Tk_PhotoPutBlock_t)(
 | 
			
		|||
    int y,
 | 
			
		||||
    int width,
 | 
			
		||||
    int height,
 | 
			
		||||
    int compRule);
 | 
			
		||||
    int compRule
 | 
			
		||||
);
 | 
			
		||||
/* Tk_FindPhoto */
 | 
			
		||||
typedef Tk_PhotoHandle (*Tk_FindPhoto_t)(Tcl_Interp *interp, const char *imageName);
 | 
			
		||||
/* Tk_PhotoGetImage */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -73,14 +73,16 @@ ImagingFind(const char *name) {
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
PyImagingPhotoPut(
 | 
			
		||||
    ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv) {
 | 
			
		||||
    ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv
 | 
			
		||||
) {
 | 
			
		||||
    Imaging im;
 | 
			
		||||
    Tk_PhotoHandle photo;
 | 
			
		||||
    Tk_PhotoImageBlock block;
 | 
			
		||||
 | 
			
		||||
    if (argc != 3) {
 | 
			
		||||
        TCL_APPEND_RESULT(
 | 
			
		||||
            interp, "usage: ", argv[0], " destPhoto srcImage", (char *)NULL);
 | 
			
		||||
            interp, "usage: ", argv[0], " destPhoto srcImage", (char *)NULL
 | 
			
		||||
        );
 | 
			
		||||
        return TCL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -128,14 +130,16 @@ PyImagingPhotoPut(
 | 
			
		|||
    block.pixelPtr = (unsigned char *)im->block;
 | 
			
		||||
 | 
			
		||||
    TK_PHOTO_PUT_BLOCK(
 | 
			
		||||
        interp, photo, &block, 0, 0, block.width, block.height, TK_PHOTO_COMPOSITE_SET);
 | 
			
		||||
        interp, photo, &block, 0, 0, block.width, block.height, TK_PHOTO_COMPOSITE_SET
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return TCL_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
PyImagingPhotoGet(
 | 
			
		||||
    ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv) {
 | 
			
		||||
    ClientData clientdata, Tcl_Interp *interp, int argc, const char **argv
 | 
			
		||||
) {
 | 
			
		||||
    Imaging im;
 | 
			
		||||
    Tk_PhotoHandle photo;
 | 
			
		||||
    Tk_PhotoImageBlock block;
 | 
			
		||||
| 
						 | 
				
			
			@ -143,7 +147,8 @@ PyImagingPhotoGet(
 | 
			
		|||
 | 
			
		||||
    if (argc != 3) {
 | 
			
		||||
        TCL_APPEND_RESULT(
 | 
			
		||||
            interp, "usage: ", argv[0], " srcPhoto destImage", (char *)NULL);
 | 
			
		||||
            interp, "usage: ", argv[0], " srcPhoto destImage", (char *)NULL
 | 
			
		||||
        );
 | 
			
		||||
        return TCL_ERROR;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -183,13 +188,15 @@ TkImaging_Init(Tcl_Interp *interp) {
 | 
			
		|||
        "PyImagingPhoto",
 | 
			
		||||
        PyImagingPhotoPut,
 | 
			
		||||
        (ClientData)0,
 | 
			
		||||
        (Tcl_CmdDeleteProc *)NULL);
 | 
			
		||||
        (Tcl_CmdDeleteProc *)NULL
 | 
			
		||||
    );
 | 
			
		||||
    TCL_CREATE_COMMAND(
 | 
			
		||||
        interp,
 | 
			
		||||
        "PyImagingPhotoGet",
 | 
			
		||||
        PyImagingPhotoGet,
 | 
			
		||||
        (ClientData)0,
 | 
			
		||||
        (Tcl_CmdDeleteProc *)NULL);
 | 
			
		||||
        (Tcl_CmdDeleteProc *)NULL
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -394,7 +401,8 @@ _func_loader(void *lib) {
 | 
			
		|||
    }
 | 
			
		||||
    return (
 | 
			
		||||
        (TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)_dfunc(lib, "Tk_PhotoPutBlock")) ==
 | 
			
		||||
        NULL);
 | 
			
		||||
        NULL
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										175
									
								
								src/_imaging.c
									
									
									
									
									
								
							
							
						
						
									
										175
									
								
								src/_imaging.c
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -290,7 +290,8 @@ ImagingError_ModeError(void) {
 | 
			
		|||
void *
 | 
			
		||||
ImagingError_ValueError(const char *message) {
 | 
			
		||||
    PyErr_SetString(
 | 
			
		||||
        PyExc_ValueError, (message) ? (char *)message : "unrecognized argument value");
 | 
			
		||||
        PyExc_ValueError, (message) ? (char *)message : "unrecognized argument value"
 | 
			
		||||
    );
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +468,8 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) {
 | 
			
		|||
                    return Py_BuildValue("BBB", pixel.b[0], pixel.b[1], pixel.b[2]);
 | 
			
		||||
                case 4:
 | 
			
		||||
                    return Py_BuildValue(
 | 
			
		||||
                        "BBBB", pixel.b[0], pixel.b[1], pixel.b[2], pixel.b[3]);
 | 
			
		||||
                        "BBBB", pixel.b[0], pixel.b[1], pixel.b[2], pixel.b[3]
 | 
			
		||||
                    );
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case IMAGING_TYPE_INT32:
 | 
			
		||||
| 
						 | 
				
			
			@ -518,7 +520,8 @@ getink(PyObject *color, Imaging im, char *ink) {
 | 
			
		|||
            rIsInt = 1;
 | 
			
		||||
        } else if (im->bands == 1) {
 | 
			
		||||
            PyErr_SetString(
 | 
			
		||||
                PyExc_TypeError, "color must be int or single-element tuple");
 | 
			
		||||
                PyExc_TypeError, "color must be int or single-element tuple"
 | 
			
		||||
            );
 | 
			
		||||
            return NULL;
 | 
			
		||||
        } else if (tupleSize == -1) {
 | 
			
		||||
            PyErr_SetString(PyExc_TypeError, "color must be int or tuple");
 | 
			
		||||
| 
						 | 
				
			
			@ -534,8 +537,8 @@ getink(PyObject *color, Imaging im, char *ink) {
 | 
			
		|||
                if (rIsInt != 1) {
 | 
			
		||||
                    if (tupleSize != 1) {
 | 
			
		||||
                        PyErr_SetString(
 | 
			
		||||
                            PyExc_TypeError,
 | 
			
		||||
                            "color must be int or single-element tuple");
 | 
			
		||||
                            PyExc_TypeError, "color must be int or single-element tuple"
 | 
			
		||||
                        );
 | 
			
		||||
                        return NULL;
 | 
			
		||||
                    } else if (!PyArg_ParseTuple(color, "L", &r)) {
 | 
			
		||||
                        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -556,7 +559,8 @@ getink(PyObject *color, Imaging im, char *ink) {
 | 
			
		|||
                        if (tupleSize != 1 && tupleSize != 2) {
 | 
			
		||||
                            PyErr_SetString(
 | 
			
		||||
                                PyExc_TypeError,
 | 
			
		||||
                                "color must be int, or tuple of one or two elements");
 | 
			
		||||
                                "color must be int, or tuple of one or two elements"
 | 
			
		||||
                            );
 | 
			
		||||
                            return NULL;
 | 
			
		||||
                        } else if (!PyArg_ParseTuple(color, "L|i", &r, &a)) {
 | 
			
		||||
                            return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -567,7 +571,8 @@ getink(PyObject *color, Imaging im, char *ink) {
 | 
			
		|||
                            PyErr_SetString(
 | 
			
		||||
                                PyExc_TypeError,
 | 
			
		||||
                                "color must be int, or tuple of one, three or four "
 | 
			
		||||
                                "elements");
 | 
			
		||||
                                "elements"
 | 
			
		||||
                            );
 | 
			
		||||
                            return NULL;
 | 
			
		||||
                        } else if (!PyArg_ParseTuple(color, "Lii|i", &r, &g, &b, &a)) {
 | 
			
		||||
                            return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -608,7 +613,8 @@ getink(PyObject *color, Imaging im, char *ink) {
 | 
			
		|||
                } else if (tupleSize != 3) {
 | 
			
		||||
                    PyErr_SetString(
 | 
			
		||||
                        PyExc_TypeError,
 | 
			
		||||
                        "color must be int, or tuple of one or three elements");
 | 
			
		||||
                        "color must be int, or tuple of one or three elements"
 | 
			
		||||
                    );
 | 
			
		||||
                    return NULL;
 | 
			
		||||
                } else if (!PyArg_ParseTuple(color, "iiL", &b, &g, &r)) {
 | 
			
		||||
                    return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -733,7 +739,8 @@ _alpha_composite(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    ImagingObject *imagep2;
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2)) {
 | 
			
		||||
            args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -748,7 +755,8 @@ _blend(ImagingObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
    alpha = 0.5;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O!O!|d", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2, &alpha)) {
 | 
			
		||||
            args, "O!O!|d", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2, &alpha
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -827,7 +835,8 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) {
 | 
			
		|||
                break;
 | 
			
		||||
            case TYPE_FLOAT32:
 | 
			
		||||
                memcpy(
 | 
			
		||||
                    &item, ((char *)table_data) + i * sizeof(FLOAT32), sizeof(FLOAT32));
 | 
			
		||||
                    &item, ((char *)table_data) + i * sizeof(FLOAT32), sizeof(FLOAT32)
 | 
			
		||||
                );
 | 
			
		||||
                break;
 | 
			
		||||
            case TYPE_DOUBLE:
 | 
			
		||||
                memcpy(&dtmp, ((char *)table_data) + i * sizeof(dtmp), sizeof(dtmp));
 | 
			
		||||
| 
						 | 
				
			
			@ -878,7 +887,8 @@ _color_lut_3d(ImagingObject *self, PyObject *args) {
 | 
			
		|||
            &size1D,
 | 
			
		||||
            &size2D,
 | 
			
		||||
            &size3D,
 | 
			
		||||
            &table)) {
 | 
			
		||||
            &table
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -896,7 +906,8 @@ _color_lut_3d(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    if (2 > size1D || size1D > 65 || 2 > size2D || size2D > 65 || 2 > size3D ||
 | 
			
		||||
        size3D > 65) {
 | 
			
		||||
        PyErr_SetString(
 | 
			
		||||
            PyExc_ValueError, "Table size in any dimension should be from 2 to 65");
 | 
			
		||||
            PyExc_ValueError, "Table size in any dimension should be from 2 to 65"
 | 
			
		||||
        );
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -913,13 +924,8 @@ _color_lut_3d(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (!ImagingColorLUT3D_linear(
 | 
			
		||||
            imOut,
 | 
			
		||||
            self->image,
 | 
			
		||||
            table_channels,
 | 
			
		||||
            size1D,
 | 
			
		||||
            size2D,
 | 
			
		||||
            size3D,
 | 
			
		||||
            prepared_table)) {
 | 
			
		||||
            imOut, self->image, table_channels, size1D, size2D, size3D, prepared_table
 | 
			
		||||
        )) {
 | 
			
		||||
        free(prepared_table);
 | 
			
		||||
        ImagingDelete(imOut);
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -943,7 +949,8 @@ _convert(ImagingObject *self, PyObject *args) {
 | 
			
		|||
        if (!PyImaging_Check(paletteimage)) {
 | 
			
		||||
            PyObject_Print((PyObject *)paletteimage, stderr, 0);
 | 
			
		||||
            PyErr_SetString(
 | 
			
		||||
                PyExc_ValueError, "palette argument must be image with mode 'P'");
 | 
			
		||||
                PyExc_ValueError, "palette argument must be image with mode 'P'"
 | 
			
		||||
            );
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
        if (paletteimage->image->palette == NULL) {
 | 
			
		||||
| 
						 | 
				
			
			@ -953,7 +960,8 @@ _convert(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    return PyImagingNew(ImagingConvert(
 | 
			
		||||
        self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither));
 | 
			
		||||
        self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither
 | 
			
		||||
    ));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -961,7 +969,8 @@ _convert2(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    ImagingObject *imagep1;
 | 
			
		||||
    ImagingObject *imagep2;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2)) {
 | 
			
		||||
            args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -994,7 +1003,8 @@ _convert_matrix(ImagingObject *self, PyObject *args) {
 | 
			
		|||
                m + 8,
 | 
			
		||||
                m + 9,
 | 
			
		||||
                m + 10,
 | 
			
		||||
                m + 11)) {
 | 
			
		||||
                m + 11
 | 
			
		||||
            )) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1055,7 +1065,8 @@ _filter(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    float divisor, offset;
 | 
			
		||||
    PyObject *kernel = NULL;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "(ii)ffO", &xsize, &ysize, &divisor, &offset, &kernel)) {
 | 
			
		||||
            args, "(ii)ffO", &xsize, &ysize, &divisor, &offset, &kernel
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1138,7 +1149,8 @@ _getpalette(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    pack(
 | 
			
		||||
        (UINT8 *)PyBytes_AsString(palette), self->image->palette->palette, palettesize);
 | 
			
		||||
        (UINT8 *)PyBytes_AsString(palette), self->image->palette->palette, palettesize
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return palette;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1232,7 +1244,8 @@ union hist_extrema {
 | 
			
		|||
 | 
			
		||||
static union hist_extrema *
 | 
			
		||||
parse_histogram_extremap(
 | 
			
		||||
    ImagingObject *self, PyObject *extremap, union hist_extrema *ep) {
 | 
			
		||||
    ImagingObject *self, PyObject *extremap, union hist_extrema *ep
 | 
			
		||||
) {
 | 
			
		||||
    int i0, i1;
 | 
			
		||||
    double f0, f1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1392,7 +1405,8 @@ _paste(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    int x0, y0, x1, y1;
 | 
			
		||||
    ImagingObject *maskp = NULL;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O(iiii)|O!", &source, &x0, &y0, &x1, &y1, &Imaging_Type, &maskp)) {
 | 
			
		||||
            args, "O(iiii)|O!", &source, &x0, &y0, &x1, &y1, &Imaging_Type, &maskp
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1404,14 +1418,16 @@ _paste(ImagingObject *self, PyObject *args) {
 | 
			
		|||
            x0,
 | 
			
		||||
            y0,
 | 
			
		||||
            x1,
 | 
			
		||||
            y1);
 | 
			
		||||
            y1
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
        if (!getink(source, self->image, ink)) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
        status = ImagingFill2(
 | 
			
		||||
            self->image, ink, (maskp) ? maskp->image : NULL, x0, y0, x1, y1);
 | 
			
		||||
            self->image, ink, (maskp) ? maskp->image : NULL, x0, y0, x1, y1
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (status < 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1729,7 +1745,8 @@ _putpalette(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    UINT8 *palette;
 | 
			
		||||
    Py_ssize_t palettesize;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "ssy#", &palette_mode, &rawmode, &palette, &palettesize)) {
 | 
			
		||||
            args, "ssy#", &palette_mode, &rawmode, &palette, &palettesize
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1887,7 +1904,8 @@ _resize(ImagingObject *self, PyObject *args) {
 | 
			
		|||
            &box[0],
 | 
			
		||||
            &box[1],
 | 
			
		||||
            &box[2],
 | 
			
		||||
            &box[3])) {
 | 
			
		||||
            &box[3]
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1923,7 +1941,8 @@ _resize(ImagingObject *self, PyObject *args) {
 | 
			
		|||
        imOut = ImagingNewDirty(imIn->mode, xsize, ysize);
 | 
			
		||||
 | 
			
		||||
        imOut = ImagingTransform(
 | 
			
		||||
            imOut, imIn, IMAGING_TRANSFORM_AFFINE, 0, 0, xsize, ysize, a, filter, 1);
 | 
			
		||||
            imOut, imIn, IMAGING_TRANSFORM_AFFINE, 0, 0, xsize, ysize, a, filter, 1
 | 
			
		||||
        );
 | 
			
		||||
    } else {
 | 
			
		||||
        imOut = ImagingResample(imIn, xsize, ysize, filter, box);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1944,14 +1963,8 @@ _reduce(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    box[3] = imIn->ysize;
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args,
 | 
			
		||||
            "(ii)|(iiii)",
 | 
			
		||||
            &xscale,
 | 
			
		||||
            &yscale,
 | 
			
		||||
            &box[0],
 | 
			
		||||
            &box[1],
 | 
			
		||||
            &box[2],
 | 
			
		||||
            &box[3])) {
 | 
			
		||||
            args, "(ii)|(iiii)", &xscale, &yscale, &box[0], &box[1], &box[2], &box[3]
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2053,7 +2066,8 @@ _transform(ImagingObject *self, PyObject *args) {
 | 
			
		|||
            &method,
 | 
			
		||||
            &data,
 | 
			
		||||
            &filter,
 | 
			
		||||
            &fill)) {
 | 
			
		||||
            &fill
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2077,7 +2091,8 @@ _transform(ImagingObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    imOut = ImagingTransform(
 | 
			
		||||
        self->image, imagep->image, method, x0, y0, x1, y1, a, filter, fill);
 | 
			
		||||
        self->image, imagep->image, method, x0, y0, x1, y1, a, filter, fill
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(a);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2250,7 +2265,8 @@ _getcolors(ImagingObject *self, PyObject *args) {
 | 
			
		|||
        for (i = 0; i < colors; i++) {
 | 
			
		||||
            ImagingColorItem *v = &items[i];
 | 
			
		||||
            PyObject *item = Py_BuildValue(
 | 
			
		||||
                "iN", v->count, getpixel(self->image, self->access, v->x, v->y));
 | 
			
		||||
                "iN", v->count, getpixel(self->image, self->access, v->x, v->y)
 | 
			
		||||
            );
 | 
			
		||||
            if (item == NULL) {
 | 
			
		||||
                Py_DECREF(out);
 | 
			
		||||
                free(items);
 | 
			
		||||
| 
						 | 
				
			
			@ -2316,14 +2332,16 @@ _getprojection(ImagingObject *self) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    ImagingGetProjection(
 | 
			
		||||
        self->image, (unsigned char *)xprofile, (unsigned char *)yprofile);
 | 
			
		||||
        self->image, (unsigned char *)xprofile, (unsigned char *)yprofile
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    result = Py_BuildValue(
 | 
			
		||||
        "y#y#",
 | 
			
		||||
        xprofile,
 | 
			
		||||
        (Py_ssize_t)self->image->xsize,
 | 
			
		||||
        yprofile,
 | 
			
		||||
        (Py_ssize_t)self->image->ysize);
 | 
			
		||||
        (Py_ssize_t)self->image->ysize
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xprofile);
 | 
			
		||||
    free(yprofile);
 | 
			
		||||
| 
						 | 
				
			
			@ -2397,7 +2415,8 @@ _merge(PyObject *self, PyObject *args) {
 | 
			
		|||
            &Imaging_Type,
 | 
			
		||||
            &band2,
 | 
			
		||||
            &Imaging_Type,
 | 
			
		||||
            &band3)) {
 | 
			
		||||
            &band3
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2643,7 +2662,8 @@ _font_new(PyObject *self_, PyObject *args) {
 | 
			
		|||
    unsigned char *glyphdata;
 | 
			
		||||
    Py_ssize_t glyphdata_length;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O!y#", &Imaging_Type, &imagep, &glyphdata, &glyphdata_length)) {
 | 
			
		||||
            args, "O!y#", &Imaging_Type, &imagep, &glyphdata, &glyphdata_length
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2801,7 +2821,8 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
 | 
			
		|||
        if (i == 0 || text[i] != text[i - 1]) {
 | 
			
		||||
            ImagingDelete(bitmap);
 | 
			
		||||
            bitmap = ImagingCrop(
 | 
			
		||||
                self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1);
 | 
			
		||||
                self->bitmap, glyph->sx0, glyph->sy0, glyph->sx1, glyph->sy1
 | 
			
		||||
            );
 | 
			
		||||
            if (!bitmap) {
 | 
			
		||||
                goto failed;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -2813,7 +2834,8 @@ _font_getmask(ImagingFontObject *self, PyObject *args) {
 | 
			
		|||
            glyph->dx0 + x,
 | 
			
		||||
            glyph->dy0 + b,
 | 
			
		||||
            glyph->dx1 + x,
 | 
			
		||||
            glyph->dy1 + b);
 | 
			
		||||
            glyph->dy1 + b
 | 
			
		||||
        );
 | 
			
		||||
        if (status < 0) {
 | 
			
		||||
            goto failed;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -2952,7 +2974,8 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
        end,
 | 
			
		||||
        &ink,
 | 
			
		||||
        width,
 | 
			
		||||
        self->blend);
 | 
			
		||||
        self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2982,13 +3005,15 @@ _draw_bitmap(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
    if (n != 1) {
 | 
			
		||||
        PyErr_SetString(
 | 
			
		||||
            PyExc_TypeError, "coordinate list must contain exactly 1 coordinate");
 | 
			
		||||
            PyExc_TypeError, "coordinate list must contain exactly 1 coordinate"
 | 
			
		||||
        );
 | 
			
		||||
        free(xy);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    n = ImagingDrawBitmap(
 | 
			
		||||
        self->image->image, (int)xy[0], (int)xy[1], bitmap->image, &ink, self->blend);
 | 
			
		||||
        self->image->image, (int)xy[0], (int)xy[1], bitmap->image, &ink, self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3044,7 +3069,8 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
        &ink,
 | 
			
		||||
        fill,
 | 
			
		||||
        width,
 | 
			
		||||
        self->blend);
 | 
			
		||||
        self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3098,7 +3124,8 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
        &ink,
 | 
			
		||||
        fill,
 | 
			
		||||
        width,
 | 
			
		||||
        self->blend);
 | 
			
		||||
        self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3138,14 +3165,16 @@ _draw_lines(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
                    (int)p[2],
 | 
			
		||||
                    (int)p[3],
 | 
			
		||||
                    &ink,
 | 
			
		||||
                    self->blend) < 0) {
 | 
			
		||||
                    self->blend
 | 
			
		||||
                ) < 0) {
 | 
			
		||||
                free(xy);
 | 
			
		||||
                return NULL;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (p) { /* draw last point */
 | 
			
		||||
            ImagingDrawPoint(
 | 
			
		||||
                self->image->image, (int)p[2], (int)p[3], &ink, self->blend);
 | 
			
		||||
                self->image->image, (int)p[2], (int)p[3], &ink, self->blend
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        for (i = 0; i < n - 1; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -3158,7 +3187,8 @@ _draw_lines(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
                    (int)p[3],
 | 
			
		||||
                    &ink,
 | 
			
		||||
                    width,
 | 
			
		||||
                    self->blend) < 0) {
 | 
			
		||||
                    self->blend
 | 
			
		||||
                ) < 0) {
 | 
			
		||||
                free(xy);
 | 
			
		||||
                return NULL;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -3190,7 +3220,8 @@ _draw_points(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
    for (i = 0; i < n; i++) {
 | 
			
		||||
        double *p = &xy[i + i];
 | 
			
		||||
        if (ImagingDrawPoint(
 | 
			
		||||
                self->image->image, (int)p[0], (int)p[1], &ink, self->blend) < 0) {
 | 
			
		||||
                self->image->image, (int)p[0], (int)p[1], &ink, self->blend
 | 
			
		||||
            ) < 0) {
 | 
			
		||||
            free(xy);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -3279,7 +3310,8 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
        &ink,
 | 
			
		||||
        fill,
 | 
			
		||||
        width,
 | 
			
		||||
        self->blend);
 | 
			
		||||
        self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3311,7 +3343,8 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
    if (n < 2) {
 | 
			
		||||
        PyErr_SetString(
 | 
			
		||||
            PyExc_TypeError, "coordinate list must contain at least 2 coordinates");
 | 
			
		||||
            PyExc_TypeError, "coordinate list must contain at least 2 coordinates"
 | 
			
		||||
        );
 | 
			
		||||
        free(xy);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -3384,7 +3417,8 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
 | 
			
		|||
        &ink,
 | 
			
		||||
        fill,
 | 
			
		||||
        width,
 | 
			
		||||
        self->blend);
 | 
			
		||||
        self->blend
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(xy);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3524,7 +3558,8 @@ _effect_mandelbrot(ImagingObject *self, PyObject *args) {
 | 
			
		|||
            &extent[1],
 | 
			
		||||
            &extent[2],
 | 
			
		||||
            &extent[3],
 | 
			
		||||
            &quality)) {
 | 
			
		||||
            &quality
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3752,7 +3787,8 @@ _getattr_unsafe_ptrs(ImagingObject *self, void *closure) {
 | 
			
		|||
        "image32",
 | 
			
		||||
        self->image->image32,
 | 
			
		||||
        "image",
 | 
			
		||||
        self->image->image);
 | 
			
		||||
        self->image->image
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct PyGetSetDef getsetters[] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -3762,7 +3798,8 @@ static struct PyGetSetDef getsetters[] = {
 | 
			
		|||
    {"id", (getter)_getattr_id},
 | 
			
		||||
    {"ptr", (getter)_getattr_ptr},
 | 
			
		||||
    {"unsafe_ptrs", (getter)_getattr_unsafe_ptrs},
 | 
			
		||||
    {NULL}};
 | 
			
		||||
    {NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* basic sequence semantics */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -4071,9 +4108,8 @@ _set_blocks_max(PyObject *self, PyObject *args) {
 | 
			
		|||
    if (blocks_max < 0) {
 | 
			
		||||
        PyErr_SetString(PyExc_ValueError, "blocks_max should be greater than 0");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    } else if (
 | 
			
		||||
        (unsigned long)blocks_max >
 | 
			
		||||
        SIZE_MAX / sizeof(ImagingDefaultArena.blocks_pool[0])) {
 | 
			
		||||
    } else if ((unsigned long)blocks_max >
 | 
			
		||||
               SIZE_MAX / sizeof(ImagingDefaultArena.blocks_pool[0])) {
 | 
			
		||||
        PyErr_SetString(PyExc_ValueError, "blocks_max is too large");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -4428,7 +4464,8 @@ setup_module(PyObject *m) {
 | 
			
		|||
 | 
			
		||||
    PyObject *pillow_version = PyUnicode_FromString(version);
 | 
			
		||||
    PyDict_SetItemString(
 | 
			
		||||
        d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None);
 | 
			
		||||
        d, "PILLOW_VERSION", pillow_version ? pillow_version : Py_None
 | 
			
		||||
    );
 | 
			
		||||
    Py_XDECREF(pillow_version);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -331,7 +331,8 @@ pyCMScopyAux(cmsHTRANSFORM hTransform, Imaging imDst, const Imaging imSrc) {
 | 
			
		|||
                memcpy(
 | 
			
		||||
                    pDstExtras + x * dstChunkSize,
 | 
			
		||||
                    pSrcExtras + x * srcChunkSize,
 | 
			
		||||
                    channelSize);
 | 
			
		||||
                    channelSize
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -373,7 +374,8 @@ _buildTransform(
 | 
			
		|||
    char *sInMode,
 | 
			
		||||
    char *sOutMode,
 | 
			
		||||
    int iRenderingIntent,
 | 
			
		||||
    cmsUInt32Number cmsFLAGS) {
 | 
			
		||||
    cmsUInt32Number cmsFLAGS
 | 
			
		||||
) {
 | 
			
		||||
    cmsHTRANSFORM hTransform;
 | 
			
		||||
 | 
			
		||||
    Py_BEGIN_ALLOW_THREADS
 | 
			
		||||
| 
						 | 
				
			
			@ -385,7 +387,8 @@ _buildTransform(
 | 
			
		|||
            hOutputProfile,
 | 
			
		||||
            findLCMStype(sOutMode),
 | 
			
		||||
            iRenderingIntent,
 | 
			
		||||
            cmsFLAGS);
 | 
			
		||||
            cmsFLAGS
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    Py_END_ALLOW_THREADS;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -405,7 +408,8 @@ _buildProofTransform(
 | 
			
		|||
    char *sOutMode,
 | 
			
		||||
    int iRenderingIntent,
 | 
			
		||||
    int iProofIntent,
 | 
			
		||||
    cmsUInt32Number cmsFLAGS) {
 | 
			
		||||
    cmsUInt32Number cmsFLAGS
 | 
			
		||||
) {
 | 
			
		||||
    cmsHTRANSFORM hTransform;
 | 
			
		||||
 | 
			
		||||
    Py_BEGIN_ALLOW_THREADS
 | 
			
		||||
| 
						 | 
				
			
			@ -419,7 +423,8 @@ _buildProofTransform(
 | 
			
		|||
            hProofProfile,
 | 
			
		||||
            iRenderingIntent,
 | 
			
		||||
            iProofIntent,
 | 
			
		||||
            cmsFLAGS);
 | 
			
		||||
            cmsFLAGS
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    Py_END_ALLOW_THREADS;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -454,7 +459,8 @@ buildTransform(PyObject *self, PyObject *args) {
 | 
			
		|||
            &sInMode,
 | 
			
		||||
            &sOutMode,
 | 
			
		||||
            &iRenderingIntent,
 | 
			
		||||
            &cmsFLAGS)) {
 | 
			
		||||
            &cmsFLAGS
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -464,7 +470,8 @@ buildTransform(PyObject *self, PyObject *args) {
 | 
			
		|||
        sInMode,
 | 
			
		||||
        sOutMode,
 | 
			
		||||
        iRenderingIntent,
 | 
			
		||||
        cmsFLAGS);
 | 
			
		||||
        cmsFLAGS
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!transform) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -499,7 +506,8 @@ buildProofTransform(PyObject *self, PyObject *args) {
 | 
			
		|||
            &sOutMode,
 | 
			
		||||
            &iRenderingIntent,
 | 
			
		||||
            &iProofIntent,
 | 
			
		||||
            &cmsFLAGS)) {
 | 
			
		||||
            &cmsFLAGS
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -511,7 +519,8 @@ buildProofTransform(PyObject *self, PyObject *args) {
 | 
			
		|||
        sOutMode,
 | 
			
		||||
        iRenderingIntent,
 | 
			
		||||
        iProofIntent,
 | 
			
		||||
        cmsFLAGS);
 | 
			
		||||
        cmsFLAGS
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!transform) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -563,7 +572,8 @@ createProfile(PyObject *self, PyObject *args) {
 | 
			
		|||
                PyErr_SetString(
 | 
			
		||||
                    PyExc_ValueError,
 | 
			
		||||
                    "ERROR: Could not calculate white point from color temperature "
 | 
			
		||||
                    "provided, must be float in degrees Kelvin");
 | 
			
		||||
                    "provided, must be float in degrees Kelvin"
 | 
			
		||||
                );
 | 
			
		||||
                return NULL;
 | 
			
		||||
            }
 | 
			
		||||
            hProfile = cmsCreateLab2Profile(&whitePoint);
 | 
			
		||||
| 
						 | 
				
			
			@ -624,7 +634,8 @@ cms_get_display_profile_win32(PyObject *self, PyObject *args) {
 | 
			
		|||
    HANDLE handle = 0;
 | 
			
		||||
    int is_dc = 0;
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "|" F_HANDLE "i:get_display_profile", &handle, &is_dc)) {
 | 
			
		||||
            args, "|" F_HANDLE "i:get_display_profile", &handle, &is_dc
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -729,7 +740,8 @@ _xyz_py(cmsCIEXYZ *XYZ) {
 | 
			
		|||
    cmsCIExyY xyY;
 | 
			
		||||
    cmsXYZ2xyY(&xyY, XYZ);
 | 
			
		||||
    return Py_BuildValue(
 | 
			
		||||
        "((d,d,d),(d,d,d))", XYZ->X, XYZ->Y, XYZ->Z, xyY.x, xyY.y, xyY.Y);
 | 
			
		||||
        "((d,d,d),(d,d,d))", XYZ->X, XYZ->Y, XYZ->Z, xyY.x, xyY.y, xyY.Y
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -758,7 +770,8 @@ _xyz3_py(cmsCIEXYZ *XYZ) {
 | 
			
		|||
        xyY[1].Y,
 | 
			
		||||
        xyY[2].x,
 | 
			
		||||
        xyY[2].y,
 | 
			
		||||
        xyY[2].Y);
 | 
			
		||||
        xyY[2].Y
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -809,7 +822,8 @@ _profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info) {
 | 
			
		|||
        triple->Green.Y,
 | 
			
		||||
        triple->Blue.x,
 | 
			
		||||
        triple->Blue.y,
 | 
			
		||||
        triple->Blue.Y);
 | 
			
		||||
        triple->Blue.Y
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -873,7 +887,8 @@ _calculate_rgb_primaries(CmsProfileObject *self, cmsCIEXYZTRIPLE *result) {
 | 
			
		|||
        hXYZ,
 | 
			
		||||
        TYPE_XYZ_DBL,
 | 
			
		||||
        INTENT_RELATIVE_COLORIMETRIC,
 | 
			
		||||
        cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE);
 | 
			
		||||
        cmsFLAGS_NOCACHE | cmsFLAGS_NOOPTIMIZE
 | 
			
		||||
    );
 | 
			
		||||
    cmsCloseProfile(hXYZ);
 | 
			
		||||
    if (hTransform == NULL) {
 | 
			
		||||
        return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -889,7 +904,8 @@ _check_intent(
 | 
			
		|||
    int clut,
 | 
			
		||||
    cmsHPROFILE hProfile,
 | 
			
		||||
    cmsUInt32Number Intent,
 | 
			
		||||
    cmsUInt32Number UsedDirection) {
 | 
			
		||||
    cmsUInt32Number UsedDirection
 | 
			
		||||
) {
 | 
			
		||||
    if (clut) {
 | 
			
		||||
        return cmsIsCLUT(hProfile, Intent, UsedDirection);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -934,7 +950,8 @@ _is_intent_supported(CmsProfileObject *self, int clut) {
 | 
			
		|||
            _check_intent(clut, self->profile, intent, LCMS_USED_AS_OUTPUT) ? Py_True
 | 
			
		||||
                                                                            : Py_False,
 | 
			
		||||
            _check_intent(clut, self->profile, intent, LCMS_USED_AS_PROOF) ? Py_True
 | 
			
		||||
                                                                           : Py_False);
 | 
			
		||||
                                                                           : Py_False
 | 
			
		||||
        );
 | 
			
		||||
        if (id == NULL || entry == NULL) {
 | 
			
		||||
            Py_XDECREF(id);
 | 
			
		||||
            Py_XDECREF(entry);
 | 
			
		||||
| 
						 | 
				
			
			@ -968,7 +985,8 @@ static PyMethodDef pyCMSdll_methods[] = {
 | 
			
		|||
    {"get_display_profile_win32", cms_get_display_profile_win32, METH_VARARGS},
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    {NULL, NULL}};
 | 
			
		||||
    {NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct PyMethodDef cms_profile_methods[] = {
 | 
			
		||||
    {"is_intent_supported", (PyCFunction)cms_profile_is_intent_supported, METH_VARARGS},
 | 
			
		||||
| 
						 | 
				
			
			@ -1028,7 +1046,8 @@ cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    return PyDateTime_FromDateAndTime(
 | 
			
		||||
        1900 + ct.tm_year, ct.tm_mon, ct.tm_mday, ct.tm_hour, ct.tm_min, ct.tm_sec, 0);
 | 
			
		||||
        1900 + ct.tm_year, ct.tm_mon, ct.tm_mday, ct.tm_hour, ct.tm_min, ct.tm_sec, 0
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -1106,13 +1125,15 @@ cms_profile_getattr_colorimetric_intent(CmsProfileObject *self, void *closure) {
 | 
			
		|||
 | 
			
		||||
static PyObject *
 | 
			
		||||
cms_profile_getattr_perceptual_rendering_intent_gamut(
 | 
			
		||||
    CmsProfileObject *self, void *closure) {
 | 
			
		||||
    CmsProfileObject *self, void *closure
 | 
			
		||||
) {
 | 
			
		||||
    return _profile_read_signature(self, cmsSigPerceptualRenderingIntentGamutTag);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
cms_profile_getattr_saturation_rendering_intent_gamut(
 | 
			
		||||
    CmsProfileObject *self, void *closure) {
 | 
			
		||||
    CmsProfileObject *self, void *closure
 | 
			
		||||
) {
 | 
			
		||||
    return _profile_read_signature(self, cmsSigSaturationRenderingIntentGamutTag);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1145,7 +1166,8 @@ cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) {
 | 
			
		|||
 | 
			
		||||
static PyObject *
 | 
			
		||||
cms_profile_getattr_media_white_point_temperature(
 | 
			
		||||
    CmsProfileObject *self, void *closure) {
 | 
			
		||||
    CmsProfileObject *self, void *closure
 | 
			
		||||
) {
 | 
			
		||||
    cmsCIEXYZ *XYZ;
 | 
			
		||||
    cmsCIExyY xyY;
 | 
			
		||||
    cmsFloat64Number tempK;
 | 
			
		||||
| 
						 | 
				
			
			@ -1329,7 +1351,8 @@ cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *clos
 | 
			
		|||
        "flare",
 | 
			
		||||
        mc->Flare,
 | 
			
		||||
        "illuminant_type",
 | 
			
		||||
        _illu_map(mc->IlluminantType));
 | 
			
		||||
        _illu_map(mc->IlluminantType)
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -1359,7 +1382,8 @@ cms_profile_getattr_icc_viewing_condition(CmsProfileObject *self, void *closure)
 | 
			
		|||
        vc->SurroundXYZ.Y,
 | 
			
		||||
        vc->SurroundXYZ.Z,
 | 
			
		||||
        "illuminant_type",
 | 
			
		||||
        _illu_map(vc->IlluminantType));
 | 
			
		||||
        _illu_map(vc->IlluminantType)
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct PyGetSetDef cms_profile_getsetters[] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -1407,11 +1431,12 @@ static struct PyGetSetDef cms_profile_getsetters[] = {
 | 
			
		|||
    {"colorant_table_out", (getter)cms_profile_getattr_colorant_table_out},
 | 
			
		||||
    {"intent_supported", (getter)cms_profile_getattr_is_intent_supported},
 | 
			
		||||
    {"clut", (getter)cms_profile_getattr_is_clut},
 | 
			
		||||
    {"icc_measurement_condition",
 | 
			
		||||
     (getter)cms_profile_getattr_icc_measurement_condition},
 | 
			
		||||
    {"icc_measurement_condition", (getter)cms_profile_getattr_icc_measurement_condition
 | 
			
		||||
    },
 | 
			
		||||
    {"icc_viewing_condition", (getter)cms_profile_getattr_icc_viewing_condition},
 | 
			
		||||
 | 
			
		||||
    {NULL}};
 | 
			
		||||
    {NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static PyTypeObject CmsProfile_Type = {
 | 
			
		||||
    PyVarObject_HEAD_INIT(NULL, 0) "PIL.ImageCms.core.CmsProfile", /*tp_name*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -126,7 +126,8 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
 | 
			
		|||
    unsigned char *font_bytes;
 | 
			
		||||
    Py_ssize_t font_bytes_size = 0;
 | 
			
		||||
    static char *kwlist[] = {
 | 
			
		||||
        "filename", "size", "index", "encoding", "font_bytes", "layout_engine", NULL};
 | 
			
		||||
        "filename", "size", "index", "encoding", "font_bytes", "layout_engine", NULL
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    if (!library) {
 | 
			
		||||
        PyErr_SetString(PyExc_OSError, "failed to initialize FreeType library");
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +149,8 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
 | 
			
		|||
            &encoding,
 | 
			
		||||
            &font_bytes,
 | 
			
		||||
            &font_bytes_size,
 | 
			
		||||
            &layout_engine)) {
 | 
			
		||||
            &layout_engine
 | 
			
		||||
        )) {
 | 
			
		||||
        PyConfig_Clear(&config);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -166,7 +168,8 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
 | 
			
		|||
            &encoding,
 | 
			
		||||
            &font_bytes,
 | 
			
		||||
            &font_bytes_size,
 | 
			
		||||
            &layout_engine)) {
 | 
			
		||||
            &layout_engine
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -199,7 +202,8 @@ getfont(PyObject *self_, PyObject *args, PyObject *kw) {
 | 
			
		|||
                (FT_Byte *)self->font_bytes,
 | 
			
		||||
                font_bytes_size,
 | 
			
		||||
                index,
 | 
			
		||||
                &self->face);
 | 
			
		||||
                &self->face
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -243,7 +247,8 @@ text_layout_raqm(
 | 
			
		|||
    const char *dir,
 | 
			
		||||
    PyObject *features,
 | 
			
		||||
    const char *lang,
 | 
			
		||||
    GlyphInfo **glyph_info) {
 | 
			
		||||
    GlyphInfo **glyph_info
 | 
			
		||||
) {
 | 
			
		||||
    size_t i = 0, count = 0, start = 0;
 | 
			
		||||
    raqm_t *rq;
 | 
			
		||||
    raqm_glyph_t *glyphs = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -297,13 +302,14 @@ text_layout_raqm(
 | 
			
		|||
#if !defined(RAQM_VERSION_ATLEAST)
 | 
			
		||||
            /* RAQM_VERSION_ATLEAST was added in Raqm 0.7.0 */
 | 
			
		||||
            PyErr_SetString(
 | 
			
		||||
                PyExc_ValueError,
 | 
			
		||||
                "libraqm 0.7 or greater required for 'ttb' direction");
 | 
			
		||||
                PyExc_ValueError, "libraqm 0.7 or greater required for 'ttb' direction"
 | 
			
		||||
            );
 | 
			
		||||
            goto failed;
 | 
			
		||||
#endif
 | 
			
		||||
        } else {
 | 
			
		||||
            PyErr_SetString(
 | 
			
		||||
                PyExc_ValueError, "direction must be either 'rtl', 'ltr' or 'ttb'");
 | 
			
		||||
                PyExc_ValueError, "direction must be either 'rtl', 'ltr' or 'ttb'"
 | 
			
		||||
            );
 | 
			
		||||
            goto failed;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -399,7 +405,8 @@ text_layout_fallback(
 | 
			
		|||
    const char *lang,
 | 
			
		||||
    GlyphInfo **glyph_info,
 | 
			
		||||
    int mask,
 | 
			
		||||
    int color) {
 | 
			
		||||
    int color
 | 
			
		||||
) {
 | 
			
		||||
    int error, load_flags, i;
 | 
			
		||||
    char *buffer = NULL;
 | 
			
		||||
    FT_ULong ch;
 | 
			
		||||
| 
						 | 
				
			
			@ -412,7 +419,8 @@ text_layout_fallback(
 | 
			
		|||
        PyErr_SetString(
 | 
			
		||||
            PyExc_KeyError,
 | 
			
		||||
            "setting text direction, language or font features is not supported "
 | 
			
		||||
            "without libraqm");
 | 
			
		||||
            "without libraqm"
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (PyUnicode_Check(string)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -459,7 +467,8 @@ text_layout_fallback(
 | 
			
		|||
                    last_index,
 | 
			
		||||
                    (*glyph_info)[i].index,
 | 
			
		||||
                    ft_kerning_default,
 | 
			
		||||
                    &delta) == 0) {
 | 
			
		||||
                    &delta
 | 
			
		||||
                ) == 0) {
 | 
			
		||||
                (*glyph_info)[i - 1].x_advance += PIXEL(delta.x);
 | 
			
		||||
                (*glyph_info)[i - 1].y_advance += PIXEL(delta.y);
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -483,7 +492,8 @@ text_layout(
 | 
			
		|||
    const char *lang,
 | 
			
		||||
    GlyphInfo **glyph_info,
 | 
			
		||||
    int mask,
 | 
			
		||||
    int color) {
 | 
			
		||||
    int color
 | 
			
		||||
) {
 | 
			
		||||
    size_t count;
 | 
			
		||||
#ifdef HAVE_RAQM
 | 
			
		||||
    if (have_raqm && self->layout_engine == LAYOUT_RAQM) {
 | 
			
		||||
| 
						 | 
				
			
			@ -492,7 +502,8 @@ text_layout(
 | 
			
		|||
#endif
 | 
			
		||||
    {
 | 
			
		||||
        count = text_layout_fallback(
 | 
			
		||||
            string, self, dir, features, lang, glyph_info, mask, color);
 | 
			
		||||
            string, self, dir, features, lang, glyph_info, mask, color
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -514,7 +525,8 @@ font_getlength(FontObject *self, PyObject *args) {
 | 
			
		|||
    /* calculate size and bearing for a given string */
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O|zzOz:getlength", &string, &mode, &dir, &features, &lang)) {
 | 
			
		||||
            args, "O|zzOz:getlength", &string, &mode, &dir, &features, &lang
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -556,7 +568,8 @@ bounding_box_and_anchors(
 | 
			
		|||
    int *width,
 | 
			
		||||
    int *height,
 | 
			
		||||
    int *x_offset,
 | 
			
		||||
    int *y_offset) {
 | 
			
		||||
    int *y_offset
 | 
			
		||||
) {
 | 
			
		||||
    int position; /* pen position along primary axis, in 26.6 precision */
 | 
			
		||||
    int advanced; /* pen position along primary axis, in pixels */
 | 
			
		||||
    int px, py;   /* position of current glyph, in pixels */
 | 
			
		||||
| 
						 | 
				
			
			@ -661,7 +674,8 @@ bounding_box_and_anchors(
 | 
			
		|||
                case 'm':  // middle (ascender + descender) / 2
 | 
			
		||||
                    y_anchor = PIXEL(
 | 
			
		||||
                        (face->size->metrics.ascender + face->size->metrics.descender) /
 | 
			
		||||
                        2);
 | 
			
		||||
                        2
 | 
			
		||||
                    );
 | 
			
		||||
                    break;
 | 
			
		||||
                case 's':  // horizontal baseline
 | 
			
		||||
                    y_anchor = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -741,7 +755,8 @@ font_getsize(FontObject *self, PyObject *args) {
 | 
			
		|||
    /* calculate size and bearing for a given string */
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "O|zzOzz:getsize", &string, &mode, &dir, &features, &lang, &anchor)) {
 | 
			
		||||
            args, "O|zzOzz:getsize", &string, &mode, &dir, &features, &lang, &anchor
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -773,7 +788,8 @@ font_getsize(FontObject *self, PyObject *args) {
 | 
			
		|||
        &width,
 | 
			
		||||
        &height,
 | 
			
		||||
        &x_offset,
 | 
			
		||||
        &y_offset);
 | 
			
		||||
        &y_offset
 | 
			
		||||
    );
 | 
			
		||||
    if (glyph_info) {
 | 
			
		||||
        PyMem_Free(glyph_info);
 | 
			
		||||
        glyph_info = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -842,7 +858,8 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
            &anchor,
 | 
			
		||||
            &foreground_ink_long,
 | 
			
		||||
            &x_start,
 | 
			
		||||
            &y_start)) {
 | 
			
		||||
            &y_start
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -889,7 +906,8 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
        &width,
 | 
			
		||||
        &height,
 | 
			
		||||
        &x_offset,
 | 
			
		||||
        &y_offset);
 | 
			
		||||
        &y_offset
 | 
			
		||||
    );
 | 
			
		||||
    if (error) {
 | 
			
		||||
        PyMem_Del(glyph_info);
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -929,7 +947,8 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
            (FT_Fixed)stroke_width * 64,
 | 
			
		||||
            FT_STROKER_LINECAP_ROUND,
 | 
			
		||||
            FT_STROKER_LINEJOIN_ROUND,
 | 
			
		||||
            0);
 | 
			
		||||
            0
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
| 
						 | 
				
			
			@ -1104,8 +1123,8 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
                                    BLEND(src_alpha, target[k * 4 + 2], src_blue, tmp);
 | 
			
		||||
                                target[k * 4 + 3] = CLIP8(
 | 
			
		||||
                                    src_alpha +
 | 
			
		||||
                                    MULDIV255(
 | 
			
		||||
                                        target[k * 4 + 3], (255 - src_alpha), tmp));
 | 
			
		||||
                                    MULDIV255(target[k * 4 + 3], (255 - src_alpha), tmp)
 | 
			
		||||
                                );
 | 
			
		||||
                            } else {
 | 
			
		||||
                                /* paste unpremultiplied RGBA values */
 | 
			
		||||
                                target[k * 4 + 0] = src_red;
 | 
			
		||||
| 
						 | 
				
			
			@ -1123,15 +1142,20 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
                            if (src_alpha > 0) {
 | 
			
		||||
                                if (target[k * 4 + 3] > 0) {
 | 
			
		||||
                                    target[k * 4 + 0] = BLEND(
 | 
			
		||||
                                        src_alpha, target[k * 4 + 0], ink[0], tmp);
 | 
			
		||||
                                        src_alpha, target[k * 4 + 0], ink[0], tmp
 | 
			
		||||
                                    );
 | 
			
		||||
                                    target[k * 4 + 1] = BLEND(
 | 
			
		||||
                                        src_alpha, target[k * 4 + 1], ink[1], tmp);
 | 
			
		||||
                                        src_alpha, target[k * 4 + 1], ink[1], tmp
 | 
			
		||||
                                    );
 | 
			
		||||
                                    target[k * 4 + 2] = BLEND(
 | 
			
		||||
                                        src_alpha, target[k * 4 + 2], ink[2], tmp);
 | 
			
		||||
                                        src_alpha, target[k * 4 + 2], ink[2], tmp
 | 
			
		||||
                                    );
 | 
			
		||||
                                    target[k * 4 + 3] = CLIP8(
 | 
			
		||||
                                        src_alpha +
 | 
			
		||||
                                        MULDIV255(
 | 
			
		||||
                                            target[k * 4 + 3], (255 - src_alpha), tmp));
 | 
			
		||||
                                            target[k * 4 + 3], (255 - src_alpha), tmp
 | 
			
		||||
                                        )
 | 
			
		||||
                                    );
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    target[k * 4 + 0] = ink[0];
 | 
			
		||||
                                    target[k * 4 + 1] = ink[1];
 | 
			
		||||
| 
						 | 
				
			
			@ -1149,7 +1173,9 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
                                        ? CLIP8(
 | 
			
		||||
                                              src_alpha +
 | 
			
		||||
                                              MULDIV255(
 | 
			
		||||
                                                  target[k], (255 - src_alpha), tmp))
 | 
			
		||||
                                                  target[k], (255 - src_alpha), tmp
 | 
			
		||||
                                              )
 | 
			
		||||
                                          )
 | 
			
		||||
                                        : src_alpha;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1425,7 +1451,8 @@ static PyMethodDef font_methods[] = {
 | 
			
		|||
    {"setvarname", (PyCFunction)font_setvarname, METH_VARARGS},
 | 
			
		||||
    {"setvaraxes", (PyCFunction)font_setvaraxes, METH_VARARGS},
 | 
			
		||||
#endif
 | 
			
		||||
    {NULL, NULL}};
 | 
			
		||||
    {NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static PyObject *
 | 
			
		||||
font_getattr_family(FontObject *self, void *closure) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1482,7 +1509,8 @@ static struct PyGetSetDef font_getsetters[] = {
 | 
			
		|||
    {"x_ppem", (getter)font_getattr_x_ppem},
 | 
			
		||||
    {"y_ppem", (getter)font_getattr_y_ppem},
 | 
			
		||||
    {"glyphs", (getter)font_getattr_glyphs},
 | 
			
		||||
    {NULL}};
 | 
			
		||||
    {NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static PyTypeObject Font_Type = {
 | 
			
		||||
    PyVarObject_HEAD_INIT(NULL, 0) "Font", /*tp_name*/
 | 
			
		||||
| 
						 | 
				
			
			@ -1518,7 +1546,8 @@ static PyTypeObject Font_Type = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
static PyMethodDef _functions[] = {
 | 
			
		||||
    {"getfont", (PyCFunction)getfont, METH_VARARGS | METH_KEYWORDS}, {NULL, NULL}};
 | 
			
		||||
    {"getfont", (PyCFunction)getfont, METH_VARARGS | METH_KEYWORDS}, {NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
setup_module(PyObject *m) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -209,7 +209,8 @@ _binop(PyObject *self, PyObject *args) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static PyMethodDef _functions[] = {
 | 
			
		||||
    {"unop", _unop, 1}, {"binop", _binop, 1}, {NULL, NULL}};
 | 
			
		||||
    {"unop", _unop, 1}, {"binop", _binop, 1}, {NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
install(PyObject *d, char *name, void *value) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -253,7 +253,8 @@ static PyMethodDef functions[] = {
 | 
			
		|||
    {"apply", (PyCFunction)apply, METH_VARARGS, NULL},
 | 
			
		||||
    {"get_on_pixels", (PyCFunction)get_on_pixels, METH_VARARGS, NULL},
 | 
			
		||||
    {"match", (PyCFunction)match, METH_VARARGS, NULL},
 | 
			
		||||
    {NULL, NULL, 0, NULL}};
 | 
			
		||||
    {NULL, NULL, 0, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
PyMODINIT_FUNC
 | 
			
		||||
PyInit__imagingmorph(void) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										45
									
								
								src/_webp.c
									
									
									
									
									
								
							
							
						
						
									
										45
									
								
								src/_webp.c
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -42,7 +42,8 @@ static const char *const kErrorMessages[-WEBP_MUX_NOT_ENOUGH_DATA + 1] = {
 | 
			
		|||
    "WEBP_MUX_INVALID_ARGUMENT",
 | 
			
		||||
    "WEBP_MUX_BAD_DATA",
 | 
			
		||||
    "WEBP_MUX_MEMORY_ERROR",
 | 
			
		||||
    "WEBP_MUX_NOT_ENOUGH_DATA"};
 | 
			
		||||
    "WEBP_MUX_NOT_ENOUGH_DATA"
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
PyObject *
 | 
			
		||||
HandleMuxError(WebPMuxError err, char *chunk) {
 | 
			
		||||
| 
						 | 
				
			
			@ -61,7 +62,8 @@ HandleMuxError(WebPMuxError err, char *chunk) {
 | 
			
		|||
            sprintf(message, "could not assemble chunks: %s", kErrorMessages[-err]);
 | 
			
		||||
    } else {
 | 
			
		||||
        message_len = sprintf(
 | 
			
		||||
            message, "could not set %.4s chunk: %s", chunk, kErrorMessages[-err]);
 | 
			
		||||
            message, "could not set %.4s chunk: %s", chunk, kErrorMessages[-err]
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
    if (message_len < 0) {
 | 
			
		||||
        PyErr_SetString(PyExc_RuntimeError, "failed to construct error message");
 | 
			
		||||
| 
						 | 
				
			
			@ -138,7 +140,8 @@ _anim_encoder_new(PyObject *self, PyObject *args) {
 | 
			
		|||
            &kmin,
 | 
			
		||||
            &kmax,
 | 
			
		||||
            &allow_mixed,
 | 
			
		||||
            &verbose)) {
 | 
			
		||||
            &verbose
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -214,7 +217,8 @@ _anim_encoder_add(PyObject *self, PyObject *args) {
 | 
			
		|||
            &lossless,
 | 
			
		||||
            &quality_factor,
 | 
			
		||||
            &alpha_quality_factor,
 | 
			
		||||
            &method)) {
 | 
			
		||||
            &method
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -283,7 +287,8 @@ _anim_encoder_assemble(PyObject *self, PyObject *args) {
 | 
			
		|||
            &exif_bytes,
 | 
			
		||||
            &exif_size,
 | 
			
		||||
            &xmp_bytes,
 | 
			
		||||
            &xmp_size)) {
 | 
			
		||||
            &xmp_size
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -421,7 +426,8 @@ _anim_decoder_get_info(PyObject *self) {
 | 
			
		|||
        info->loop_count,
 | 
			
		||||
        info->bgcolor,
 | 
			
		||||
        info->frame_count,
 | 
			
		||||
        decp->mode);
 | 
			
		||||
        decp->mode
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PyObject *
 | 
			
		||||
| 
						 | 
				
			
			@ -466,7 +472,8 @@ _anim_decoder_get_next(PyObject *self) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    bytes = PyBytes_FromStringAndSize(
 | 
			
		||||
        (char *)buf, decp->info.canvas_width * 4 * decp->info.canvas_height);
 | 
			
		||||
        (char *)buf, decp->info.canvas_width * 4 * decp->info.canvas_height
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    ret = Py_BuildValue("Si", bytes, timestamp);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -621,7 +628,8 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
 | 
			
		|||
            &exif_bytes,
 | 
			
		||||
            &exif_size,
 | 
			
		||||
            &xmp_bytes,
 | 
			
		||||
            &xmp_size)) {
 | 
			
		||||
            &xmp_size
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -828,12 +836,14 @@ WebPDecode_wrapper(PyObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
            if (WEBP_MUX_OK == WebPMuxGetChunk(mux, "ICCP", &icc_profile_data)) {
 | 
			
		||||
                icc_profile = PyBytes_FromStringAndSize(
 | 
			
		||||
                    (const char *)icc_profile_data.bytes, icc_profile_data.size);
 | 
			
		||||
                    (const char *)icc_profile_data.bytes, icc_profile_data.size
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (WEBP_MUX_OK == WebPMuxGetChunk(mux, "EXIF", &exif_data)) {
 | 
			
		||||
                exif = PyBytes_FromStringAndSize(
 | 
			
		||||
                    (const char *)exif_data.bytes, exif_data.size);
 | 
			
		||||
                    (const char *)exif_data.bytes, exif_data.size
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            WebPDataClear(&image.bitstream);
 | 
			
		||||
| 
						 | 
				
			
			@ -848,12 +858,14 @@ WebPDecode_wrapper(PyObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
    if (config.output.colorspace < MODE_YUV) {
 | 
			
		||||
        bytes = PyBytes_FromStringAndSize(
 | 
			
		||||
            (char *)config.output.u.RGBA.rgba, config.output.u.RGBA.size);
 | 
			
		||||
            (char *)config.output.u.RGBA.rgba, config.output.u.RGBA.size
 | 
			
		||||
        );
 | 
			
		||||
    } else {
 | 
			
		||||
        // Skipping YUV for now. Need Test Images.
 | 
			
		||||
        // UNDONE -- unclear if we'll ever get here if we set mode_rgb*
 | 
			
		||||
        bytes = PyBytes_FromStringAndSize(
 | 
			
		||||
            (char *)config.output.u.YUVA.y, config.output.u.YUVA.y_size);
 | 
			
		||||
            (char *)config.output.u.YUVA.y, config.output.u.YUVA.y_size
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pymode = PyUnicode_FromString(mode);
 | 
			
		||||
| 
						 | 
				
			
			@ -864,7 +876,8 @@ WebPDecode_wrapper(PyObject *self, PyObject *args) {
 | 
			
		|||
        config.output.height,
 | 
			
		||||
        pymode,
 | 
			
		||||
        NULL == icc_profile ? Py_None : icc_profile,
 | 
			
		||||
        NULL == exif ? Py_None : exif);
 | 
			
		||||
        NULL == exif ? Py_None : exif
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
end:
 | 
			
		||||
    WebPFreeDecBuffer(&config.output);
 | 
			
		||||
| 
						 | 
				
			
			@ -898,7 +911,8 @@ WebPDecoderVersion_str(void) {
 | 
			
		|||
        "%d.%d.%d",
 | 
			
		||||
        version_number >> 16,
 | 
			
		||||
        (version_number >> 8) % 0x100,
 | 
			
		||||
        version_number % 0x100);
 | 
			
		||||
        version_number % 0x100
 | 
			
		||||
    );
 | 
			
		||||
    return version;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -932,7 +946,8 @@ static PyMethodDef webpMethods[] = {
 | 
			
		|||
     WebPDecoderBuggyAlpha_wrapper,
 | 
			
		||||
     METH_NOARGS,
 | 
			
		||||
     "WebPDecoderBuggyAlpha"},
 | 
			
		||||
    {NULL, NULL}};
 | 
			
		||||
    {NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
addMuxFlagToModule(PyObject *m) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -46,7 +46,8 @@
 | 
			
		|||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    PyObject_HEAD int (*decode)(
 | 
			
		||||
        Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
        Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
    );
 | 
			
		||||
    int (*cleanup)(ImagingCodecState state);
 | 
			
		||||
    struct ImagingCodecStateInstance state;
 | 
			
		||||
    Imaging im;
 | 
			
		||||
| 
						 | 
				
			
			@ -889,7 +890,8 @@ PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
    PY_LONG_LONG length = -1;
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "ss|iiiL", &mode, &format, &reduce, &layers, &fd, &length)) {
 | 
			
		||||
            args, "ss|iiiL", &mode, &format, &reduce, &layers, &fd, &length
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -105,7 +105,8 @@ _draw(ImagingDisplayObject *display, PyObject *args) {
 | 
			
		|||
            src + 0,
 | 
			
		||||
            src + 1,
 | 
			
		||||
            src + 2,
 | 
			
		||||
            src + 3)) {
 | 
			
		||||
            src + 3
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -221,7 +222,8 @@ _tobytes(ImagingDisplayObject *display, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    return PyBytes_FromStringAndSize(
 | 
			
		||||
        display->dib->bits, display->dib->ysize * display->dib->linesize);
 | 
			
		||||
        display->dib->bits, display->dib->ysize * display->dib->linesize
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct PyMethodDef methods[] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -247,7 +249,8 @@ _getattr_size(ImagingDisplayObject *self, void *closure) {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
static struct PyGetSetDef getsetters[] = {
 | 
			
		||||
    {"mode", (getter)_getattr_mode}, {"size", (getter)_getattr_size}, {NULL}};
 | 
			
		||||
    {"mode", (getter)_getattr_mode}, {"size", (getter)_getattr_size}, {NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static PyTypeObject ImagingDisplayType = {
 | 
			
		||||
    PyVarObject_HEAD_INIT(NULL, 0) "ImagingDisplay", /*tp_name*/
 | 
			
		||||
| 
						 | 
				
			
			@ -341,9 +344,8 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
 | 
			
		|||
    // added in Windows 10 (1607)
 | 
			
		||||
    // loaded dynamically to avoid link errors
 | 
			
		||||
    user32 = LoadLibraryA("User32.dll");
 | 
			
		||||
    SetThreadDpiAwarenessContext_function =
 | 
			
		||||
        (Func_SetThreadDpiAwarenessContext)GetProcAddress(
 | 
			
		||||
            user32, "SetThreadDpiAwarenessContext");
 | 
			
		||||
    SetThreadDpiAwarenessContext_function = (Func_SetThreadDpiAwarenessContext
 | 
			
		||||
    )GetProcAddress(user32, "SetThreadDpiAwarenessContext");
 | 
			
		||||
    if (SetThreadDpiAwarenessContext_function != NULL) {
 | 
			
		||||
        // DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = ((DPI_CONTEXT_HANDLE)-3)
 | 
			
		||||
        dpiAwareness = SetThreadDpiAwarenessContext_function((HANDLE)-3);
 | 
			
		||||
| 
						 | 
				
			
			@ -403,7 +405,8 @@ PyImaging_GrabScreenWin32(PyObject *self, PyObject *args) {
 | 
			
		|||
            height,
 | 
			
		||||
            PyBytes_AS_STRING(buffer),
 | 
			
		||||
            (BITMAPINFO *)&core,
 | 
			
		||||
            DIB_RGB_COLORS)) {
 | 
			
		||||
            DIB_RGB_COLORS
 | 
			
		||||
        )) {
 | 
			
		||||
        goto error;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -547,7 +550,8 @@ windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
 | 
			
		|||
                ps.rcPaint.left,
 | 
			
		||||
                ps.rcPaint.top,
 | 
			
		||||
                ps.rcPaint.right,
 | 
			
		||||
                ps.rcPaint.bottom);
 | 
			
		||||
                ps.rcPaint.bottom
 | 
			
		||||
            );
 | 
			
		||||
            if (result) {
 | 
			
		||||
                Py_DECREF(result);
 | 
			
		||||
            } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -562,7 +566,8 @@ windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
 | 
			
		|||
                0,
 | 
			
		||||
                0,
 | 
			
		||||
                rect.right - rect.left,
 | 
			
		||||
                rect.bottom - rect.top);
 | 
			
		||||
                rect.bottom - rect.top
 | 
			
		||||
            );
 | 
			
		||||
            if (result) {
 | 
			
		||||
                Py_DECREF(result);
 | 
			
		||||
            } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -577,7 +582,8 @@ windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
 | 
			
		|||
                0,
 | 
			
		||||
                0,
 | 
			
		||||
                rect.right - rect.left,
 | 
			
		||||
                rect.bottom - rect.top);
 | 
			
		||||
                rect.bottom - rect.top
 | 
			
		||||
            );
 | 
			
		||||
            if (result) {
 | 
			
		||||
                Py_DECREF(result);
 | 
			
		||||
            } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -591,7 +597,8 @@ windowCallback(HWND wnd, UINT message, WPARAM wParam, LPARAM lParam) {
 | 
			
		|||
        case WM_SIZE:
 | 
			
		||||
            /* resize window */
 | 
			
		||||
            result = PyObject_CallFunction(
 | 
			
		||||
                callback, "sii", "resize", LOWORD(lParam), HIWORD(lParam));
 | 
			
		||||
                callback, "sii", "resize", LOWORD(lParam), HIWORD(lParam)
 | 
			
		||||
            );
 | 
			
		||||
            if (result) {
 | 
			
		||||
                InvalidateRect(wnd, NULL, 1);
 | 
			
		||||
                Py_DECREF(result);
 | 
			
		||||
| 
						 | 
				
			
			@ -670,7 +677,8 @@ PyImaging_CreateWindowWin32(PyObject *self, PyObject *args) {
 | 
			
		|||
        HWND_DESKTOP,
 | 
			
		||||
        NULL,
 | 
			
		||||
        NULL,
 | 
			
		||||
        NULL);
 | 
			
		||||
        NULL
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    if (!wnd) {
 | 
			
		||||
        PyErr_SetString(PyExc_OSError, "failed to create window");
 | 
			
		||||
| 
						 | 
				
			
			@ -732,7 +740,8 @@ PyImaging_DrawWmf(PyObject *self, PyObject *args) {
 | 
			
		|||
            &x0,
 | 
			
		||||
            &x1,
 | 
			
		||||
            &y0,
 | 
			
		||||
            &y1)) {
 | 
			
		||||
            &y1
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -844,7 +853,8 @@ PyImaging_GrabScreenX11(PyObject *self, PyObject *args) {
 | 
			
		|||
        PyErr_Format(
 | 
			
		||||
            PyExc_OSError,
 | 
			
		||||
            "X connection failed: error %i",
 | 
			
		||||
            xcb_connection_has_error(connection));
 | 
			
		||||
            xcb_connection_has_error(connection)
 | 
			
		||||
        );
 | 
			
		||||
        xcb_disconnect(connection);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -878,8 +888,10 @@ PyImaging_GrabScreenX11(PyObject *self, PyObject *args) {
 | 
			
		|||
            0,
 | 
			
		||||
            width,
 | 
			
		||||
            height,
 | 
			
		||||
            0x00ffffff),
 | 
			
		||||
        &error);
 | 
			
		||||
            0x00ffffff
 | 
			
		||||
        ),
 | 
			
		||||
        &error
 | 
			
		||||
    );
 | 
			
		||||
    if (reply == NULL) {
 | 
			
		||||
        PyErr_Format(
 | 
			
		||||
            PyExc_OSError,
 | 
			
		||||
| 
						 | 
				
			
			@ -887,7 +899,8 @@ PyImaging_GrabScreenX11(PyObject *self, PyObject *args) {
 | 
			
		|||
            error->error_code,
 | 
			
		||||
            error->major_code,
 | 
			
		||||
            error->minor_code,
 | 
			
		||||
            error->resource_id);
 | 
			
		||||
            error->resource_id
 | 
			
		||||
        );
 | 
			
		||||
        free(error);
 | 
			
		||||
        xcb_disconnect(connection);
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -897,7 +910,8 @@ PyImaging_GrabScreenX11(PyObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
    if (reply->depth == 24) {
 | 
			
		||||
        buffer = PyBytes_FromStringAndSize(
 | 
			
		||||
            (char *)xcb_get_image_data(reply), xcb_get_image_data_length(reply));
 | 
			
		||||
            (char *)xcb_get_image_data(reply), xcb_get_image_data_length(reply)
 | 
			
		||||
        );
 | 
			
		||||
    } else {
 | 
			
		||||
        PyErr_Format(PyExc_OSError, "unsupported bit depth: %i", reply->depth);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										108
									
								
								src/encode.c
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								src/encode.c
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -39,7 +39,8 @@
 | 
			
		|||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    PyObject_HEAD int (*encode)(
 | 
			
		||||
        Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
 | 
			
		||||
        Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes
 | 
			
		||||
    );
 | 
			
		||||
    int (*cleanup)(ImagingCodecState state);
 | 
			
		||||
    struct ImagingCodecStateInstance state;
 | 
			
		||||
    Imaging im;
 | 
			
		||||
| 
						 | 
				
			
			@ -135,7 +136,8 @@ _encode(ImagingEncoderObject *encoder, PyObject *args) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    status = encoder->encode(
 | 
			
		||||
        encoder->im, &encoder->state, (UINT8 *)PyBytes_AsString(buf), bufsize);
 | 
			
		||||
        encoder->im, &encoder->state, (UINT8 *)PyBytes_AsString(buf), bufsize
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    /* adjust string length to avoid slicing in encoder */
 | 
			
		||||
    if (_PyBytes_Resize(&buf, (status > 0) ? status : 0) < 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -572,7 +574,8 @@ PyImaging_ZipEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
            &compress_level,
 | 
			
		||||
            &compress_type,
 | 
			
		||||
            &dictionary,
 | 
			
		||||
            &dictionary_size)) {
 | 
			
		||||
            &dictionary_size
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -653,15 +656,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
    PyObject *item;
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args,
 | 
			
		||||
            "sssnsOO",
 | 
			
		||||
            &mode,
 | 
			
		||||
            &rawmode,
 | 
			
		||||
            &compname,
 | 
			
		||||
            &fp,
 | 
			
		||||
            &filename,
 | 
			
		||||
            &tags,
 | 
			
		||||
            &types)) {
 | 
			
		||||
            args, "sssnsOO", &mode, &rawmode, &compname, &fp, &filename, &tags, &types
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -785,7 +781,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                is_var_length = 1;
 | 
			
		||||
            }
 | 
			
		||||
            if (ImagingLibTiffMergeFieldInfo(
 | 
			
		||||
                    &encoder->state, type, key_int, is_var_length)) {
 | 
			
		||||
                    &encoder->state, type, key_int, is_var_length
 | 
			
		||||
                )) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -795,7 +792,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                &encoder->state,
 | 
			
		||||
                (ttag_t)key_int,
 | 
			
		||||
                PyBytes_Size(value),
 | 
			
		||||
                PyBytes_AsString(value));
 | 
			
		||||
                PyBytes_AsString(value)
 | 
			
		||||
            );
 | 
			
		||||
        } else if (is_var_length) {
 | 
			
		||||
            Py_ssize_t len, i;
 | 
			
		||||
            TRACE(("Setting from Tuple: %d \n", key_int));
 | 
			
		||||
| 
						 | 
				
			
			@ -805,7 +803,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                int stride = 256;
 | 
			
		||||
                if (len != 768) {
 | 
			
		||||
                    PyErr_SetString(
 | 
			
		||||
                        PyExc_ValueError, "Requiring 768 items for Colormap");
 | 
			
		||||
                        PyExc_ValueError, "Requiring 768 items for Colormap"
 | 
			
		||||
                    );
 | 
			
		||||
                    return NULL;
 | 
			
		||||
                }
 | 
			
		||||
                UINT16 *av;
 | 
			
		||||
| 
						 | 
				
			
			@ -820,7 +819,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        (ttag_t)key_int,
 | 
			
		||||
                        av,
 | 
			
		||||
                        av + stride,
 | 
			
		||||
                        av + stride * 2);
 | 
			
		||||
                        av + stride * 2
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (key_int == TIFFTAG_YCBCRSUBSAMPLING) {
 | 
			
		||||
| 
						 | 
				
			
			@ -828,7 +828,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                    &encoder->state,
 | 
			
		||||
                    (ttag_t)key_int,
 | 
			
		||||
                    (UINT16)PyLong_AsLong(PyTuple_GetItem(value, 0)),
 | 
			
		||||
                    (UINT16)PyLong_AsLong(PyTuple_GetItem(value, 1)));
 | 
			
		||||
                    (UINT16)PyLong_AsLong(PyTuple_GetItem(value, 1))
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_SHORT) {
 | 
			
		||||
                UINT16 *av;
 | 
			
		||||
                /* malloc check ok, calloc checks for overflow */
 | 
			
		||||
| 
						 | 
				
			
			@ -838,7 +839,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (UINT16)PyLong_AsLong(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_LONG) {
 | 
			
		||||
| 
						 | 
				
			
			@ -850,7 +852,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (UINT32)PyLong_AsLong(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_SBYTE) {
 | 
			
		||||
| 
						 | 
				
			
			@ -862,7 +865,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (INT8)PyLong_AsLong(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_SSHORT) {
 | 
			
		||||
| 
						 | 
				
			
			@ -874,7 +878,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (INT16)PyLong_AsLong(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_SLONG) {
 | 
			
		||||
| 
						 | 
				
			
			@ -886,7 +891,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (INT32)PyLong_AsLong(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_FLOAT) {
 | 
			
		||||
| 
						 | 
				
			
			@ -898,7 +904,8 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = (FLOAT32)PyFloat_AsDouble(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            } else if (type == TIFF_DOUBLE) {
 | 
			
		||||
| 
						 | 
				
			
			@ -910,43 +917,54 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
                        av[i] = PyFloat_AsDouble(PyTuple_GetItem(value, i));
 | 
			
		||||
                    }
 | 
			
		||||
                    status = ImagingLibTiffSetField(
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av);
 | 
			
		||||
                        &encoder->state, (ttag_t)key_int, len, av
 | 
			
		||||
                    );
 | 
			
		||||
                    free(av);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            if (type == TIFF_SHORT) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (UINT16)PyLong_AsLong(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (UINT16)PyLong_AsLong(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_LONG) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, PyLong_AsLongLong(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, PyLong_AsLongLong(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_SSHORT) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT16)PyLong_AsLong(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT16)PyLong_AsLong(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_SLONG) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT32)PyLong_AsLong(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT32)PyLong_AsLong(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_FLOAT) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT32)PyFloat_AsDouble(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT32)PyFloat_AsDouble(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_DOUBLE) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_SBYTE) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT8)PyLong_AsLong(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (INT8)PyLong_AsLong(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_ASCII) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, PyBytes_AsString(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, PyBytes_AsString(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else if (type == TIFF_RATIONAL) {
 | 
			
		||||
                status = ImagingLibTiffSetField(
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value));
 | 
			
		||||
                    &encoder->state, (ttag_t)key_int, (FLOAT64)PyFloat_AsDouble(value)
 | 
			
		||||
                );
 | 
			
		||||
            } else {
 | 
			
		||||
                TRACE(
 | 
			
		||||
                    ("Unhandled type for key %d : %s \n",
 | 
			
		||||
                     key_int,
 | 
			
		||||
                     PyBytes_AsString(PyObject_Str(value))));
 | 
			
		||||
                     PyBytes_AsString(PyObject_Str(value)))
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!status) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1007,7 +1025,8 @@ get_qtables_arrays(PyObject *qtables, int *qtablesLen) {
 | 
			
		|||
    if (num_tables < 1 || num_tables > NUM_QUANT_TBLS) {
 | 
			
		||||
        PyErr_SetString(
 | 
			
		||||
            PyExc_ValueError,
 | 
			
		||||
            "Not a valid number of quantization tables. Should be between 1 and 4.");
 | 
			
		||||
            "Not a valid number of quantization tables. Should be between 1 and 4."
 | 
			
		||||
        );
 | 
			
		||||
        Py_DECREF(tables);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1096,7 +1115,8 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
            &extra,
 | 
			
		||||
            &extra_size,
 | 
			
		||||
            &rawExif,
 | 
			
		||||
            &rawExifLen)) {
 | 
			
		||||
            &rawExifLen
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1266,7 +1286,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
            &fd,
 | 
			
		||||
            &comment,
 | 
			
		||||
            &comment_size,
 | 
			
		||||
            &plt)) {
 | 
			
		||||
            &plt
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1323,7 +1344,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
    j2k_decode_coord_tuple(offset, &context->offset_x, &context->offset_y);
 | 
			
		||||
    j2k_decode_coord_tuple(
 | 
			
		||||
        tile_offset, &context->tile_offset_x, &context->tile_offset_y);
 | 
			
		||||
        tile_offset, &context->tile_offset_x, &context->tile_offset_y
 | 
			
		||||
    );
 | 
			
		||||
    j2k_decode_coord_tuple(tile_size, &context->tile_size_x, &context->tile_size_y);
 | 
			
		||||
 | 
			
		||||
    /* Error on illegal tile offsets */
 | 
			
		||||
| 
						 | 
				
			
			@ -1333,7 +1355,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
            PyErr_SetString(
 | 
			
		||||
                PyExc_ValueError,
 | 
			
		||||
                "JPEG 2000 tile offset too small; top left tile must "
 | 
			
		||||
                "intersect image area");
 | 
			
		||||
                "intersect image area"
 | 
			
		||||
            );
 | 
			
		||||
            Py_DECREF(encoder);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1341,8 +1364,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
        if (context->tile_offset_x > context->offset_x ||
 | 
			
		||||
            context->tile_offset_y > context->offset_y) {
 | 
			
		||||
            PyErr_SetString(
 | 
			
		||||
                PyExc_ValueError,
 | 
			
		||||
                "JPEG 2000 tile offset too large to cover image area");
 | 
			
		||||
                PyExc_ValueError, "JPEG 2000 tile offset too large to cover image area"
 | 
			
		||||
            );
 | 
			
		||||
            Py_DECREF(encoder);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1376,7 +1399,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
 | 
			
		|||
 | 
			
		||||
    j2k_decode_coord_tuple(cblk_size, &context->cblk_width, &context->cblk_height);
 | 
			
		||||
    j2k_decode_coord_tuple(
 | 
			
		||||
        precinct_size, &context->precinct_width, &context->precinct_height);
 | 
			
		||||
        precinct_size, &context->precinct_width, &context->precinct_height
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    context->irreversible = PyObject_IsTrue(irreversible);
 | 
			
		||||
    context->progression = prog_order;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,8 @@ add_item(const char *mode) {
 | 
			
		|||
            "AccessInit: hash collision: %d for both %s and %s\n",
 | 
			
		||||
            i,
 | 
			
		||||
            mode,
 | 
			
		||||
            access_table[i].mode);
 | 
			
		||||
            access_table[i].mode
 | 
			
		||||
        );
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
    access_table[i].mode = mode;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -243,7 +243,8 @@ static const bc7_mode_info bc7_modes[] = {
 | 
			
		|||
    {1, 0, 2, 1, 5, 6, 0, 0, 2, 3},
 | 
			
		||||
    {1, 0, 2, 0, 7, 8, 0, 0, 2, 2},
 | 
			
		||||
    {1, 0, 0, 0, 7, 7, 1, 0, 4, 0},
 | 
			
		||||
    {2, 6, 0, 0, 5, 5, 1, 0, 2, 0}};
 | 
			
		||||
    {2, 6, 0, 0, 5, 5, 1, 0, 2, 0}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Subset indices:
 | 
			
		||||
   Table.P2, 1 bit per index */
 | 
			
		||||
| 
						 | 
				
			
			@ -254,7 +255,8 @@ static const UINT16 bc7_si2[] = {
 | 
			
		|||
    0x718e, 0x399c, 0xaaaa, 0xf0f0, 0x5a5a, 0x33cc, 0x3c3c, 0x55aa, 0x9696, 0xa55a,
 | 
			
		||||
    0x73ce, 0x13c8, 0x324c, 0x3bdc, 0x6996, 0xc33c, 0x9966, 0x0660, 0x0272, 0x04e4,
 | 
			
		||||
    0x4e40, 0x2720, 0xc936, 0x936c, 0x39c6, 0x639c, 0x9336, 0x9cc6, 0x817e, 0xe718,
 | 
			
		||||
    0xccf0, 0x0fcc, 0x7744, 0xee22};
 | 
			
		||||
    0xccf0, 0x0fcc, 0x7744, 0xee22
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Table.P3, 2 bits per index */
 | 
			
		||||
static const UINT32 bc7_si3[] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -267,20 +269,23 @@ static const UINT32 bc7_si3[] = {
 | 
			
		|||
    0x66660000, 0xa5a0a5a0, 0x50a050a0, 0x69286928, 0x44aaaa44, 0x66666600, 0xaa444444,
 | 
			
		||||
    0x54a854a8, 0x95809580, 0x96969600, 0xa85454a8, 0x80959580, 0xaa141414, 0x96960000,
 | 
			
		||||
    0xaaaa1414, 0xa05050a0, 0xa0a5a5a0, 0x96000000, 0x40804080, 0xa9a8a9a8, 0xaaaaaa44,
 | 
			
		||||
    0x2a4a5254};
 | 
			
		||||
    0x2a4a5254
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Anchor indices:
 | 
			
		||||
   Table.A2 */
 | 
			
		||||
static const char bc7_ai0[] = {
 | 
			
		||||
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 2,  8, 2, 2, 8,
 | 
			
		||||
    8,  15, 2,  8,  2,  2,  8,  8,  2,  2,  15, 15, 6,  8,  2,  8,  15, 15, 2, 8, 2, 2,
 | 
			
		||||
    2,  15, 15, 6,  6,  2,  6,  8,  15, 15, 2,  2,  15, 15, 15, 15, 15, 2,  2, 15};
 | 
			
		||||
static const char bc7_ai0[] = {15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
 | 
			
		||||
                               15, 15, 15, 15, 2,  8,  2,  2,  8,  8,  15, 2,  8,
 | 
			
		||||
                               2,  2,  8,  8,  2,  2,  15, 15, 6,  8,  2,  8,  15,
 | 
			
		||||
                               15, 2,  8,  2,  2,  2,  15, 15, 6,  6,  2,  6,  8,
 | 
			
		||||
                               15, 15, 2,  2,  15, 15, 15, 15, 15, 2,  2,  15};
 | 
			
		||||
 | 
			
		||||
/* Table.A3a */
 | 
			
		||||
static const char bc7_ai1[] = {
 | 
			
		||||
    3,  3,  15, 15, 8, 3,  15, 15, 8,  8,  6, 6,  6, 5,  3, 3,  3,  3,  8,  15, 3,  3,
 | 
			
		||||
    6,  10, 5,  8,  8, 6,  8,  5,  15, 15, 8, 15, 3, 5,  6, 10, 8,  15, 15, 3,  15, 5,
 | 
			
		||||
    15, 15, 15, 15, 3, 15, 5,  5,  5,  8,  5, 10, 5, 10, 8, 13, 15, 12, 3,  3};
 | 
			
		||||
static const char bc7_ai1[] = {3,  3,  15, 15, 8,  3,  15, 15, 8,  8,  6,  6,  6,
 | 
			
		||||
                               5,  3,  3,  3,  3,  8,  15, 3,  3,  6,  10, 5,  8,
 | 
			
		||||
                               8,  6,  8,  5,  15, 15, 8,  15, 3,  5,  6,  10, 8,
 | 
			
		||||
                               15, 15, 3,  15, 5,  15, 15, 15, 15, 3,  15, 5,  5,
 | 
			
		||||
                               5,  8,  5,  10, 5,  10, 8,  13, 15, 12, 3,  3};
 | 
			
		||||
 | 
			
		||||
/* Table.A3b */
 | 
			
		||||
static const char bc7_ai2[] = {15, 8,  8,  3,  15, 15, 3,  8,  15, 15, 15, 15, 15,
 | 
			
		||||
| 
						 | 
				
			
			@ -293,7 +298,8 @@ static const char bc7_ai2[] = {15, 8,  8,  3,  15, 15, 3,  8,  15, 15, 15, 15, 1
 | 
			
		|||
static const char bc7_weights2[] = {0, 21, 43, 64};
 | 
			
		||||
static const char bc7_weights3[] = {0, 9, 18, 27, 37, 46, 55, 64};
 | 
			
		||||
static const char bc7_weights4[] = {
 | 
			
		||||
    0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64};
 | 
			
		||||
    0, 4, 9, 13, 17, 21, 26, 30, 34, 38, 43, 47, 51, 55, 60, 64
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static const char *
 | 
			
		||||
bc7_get_weights(int n) {
 | 
			
		||||
| 
						 | 
				
			
			@ -526,7 +532,8 @@ static const bc6_mode_info bc6_modes[] = {
 | 
			
		|||
    {1, 0, 0, 10, 10, 10, 10},
 | 
			
		||||
    {1, 1, 0, 11, 9, 9, 9},
 | 
			
		||||
    {1, 1, 0, 12, 8, 8, 8},
 | 
			
		||||
    {1, 1, 0, 16, 4, 4, 4}};
 | 
			
		||||
    {1, 1, 0, 16, 4, 4, 4}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Table.F, encoded as a sequence of bit indices */
 | 
			
		||||
static const UINT8 bc6_bit_packings[][75] = {
 | 
			
		||||
| 
						 | 
				
			
			@ -591,7 +598,8 @@ static const UINT8 bc6_bit_packings[][75] = {
 | 
			
		|||
     64, 65, 66, 67, 68, 69, 70, 71, 27, 26, 80, 81, 82, 83, 84, 85, 86, 87, 43, 42},
 | 
			
		||||
    {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
 | 
			
		||||
     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 48, 49, 50, 51, 15, 14, 13, 12, 11, 10,
 | 
			
		||||
     64, 65, 66, 67, 31, 30, 29, 28, 27, 26, 80, 81, 82, 83, 47, 46, 45, 44, 43, 42}};
 | 
			
		||||
     64, 65, 66, 67, 31, 30, 29, 28, 27, 26, 80, 81, 82, 83, 47, 46, 45, 44, 43, 42}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
bc6_sign_extend(UINT16 *v, int prec) {
 | 
			
		||||
| 
						 | 
				
			
			@ -830,7 +838,8 @@ decode_bcn(
 | 
			
		|||
    int bytes,
 | 
			
		||||
    int N,
 | 
			
		||||
    int C,
 | 
			
		||||
    char *pixel_format) {
 | 
			
		||||
    char *pixel_format
 | 
			
		||||
) {
 | 
			
		||||
    int ymax = state->ysize + state->yoff;
 | 
			
		||||
    const UINT8 *ptr = src;
 | 
			
		||||
    switch (N) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,8 @@ void static inline ImagingLineBoxBlur32(
 | 
			
		|||
    int edgeA,
 | 
			
		||||
    int edgeB,
 | 
			
		||||
    UINT32 ww,
 | 
			
		||||
    UINT32 fw) {
 | 
			
		||||
    UINT32 fw
 | 
			
		||||
) {
 | 
			
		||||
    int x;
 | 
			
		||||
    UINT32 acc[4];
 | 
			
		||||
    UINT32 bulk[4];
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +110,8 @@ void static inline ImagingLineBoxBlur8(
 | 
			
		|||
    int edgeA,
 | 
			
		||||
    int edgeB,
 | 
			
		||||
    UINT32 ww,
 | 
			
		||||
    UINT32 fw) {
 | 
			
		||||
    UINT32 fw
 | 
			
		||||
) {
 | 
			
		||||
    int x;
 | 
			
		||||
    UINT32 acc;
 | 
			
		||||
    UINT32 bulk;
 | 
			
		||||
| 
						 | 
				
			
			@ -198,7 +200,8 @@ ImagingHorizontalBoxBlur(Imaging imOut, Imaging imIn, float floatRadius) {
 | 
			
		|||
                edgeA,
 | 
			
		||||
                edgeB,
 | 
			
		||||
                ww,
 | 
			
		||||
                fw);
 | 
			
		||||
                fw
 | 
			
		||||
            );
 | 
			
		||||
            if (imIn == imOut) {
 | 
			
		||||
                // Commit.
 | 
			
		||||
                memcpy(imOut->image8[y], lineOut, imIn->xsize);
 | 
			
		||||
| 
						 | 
				
			
			@ -214,7 +217,8 @@ ImagingHorizontalBoxBlur(Imaging imOut, Imaging imIn, float floatRadius) {
 | 
			
		|||
                edgeA,
 | 
			
		||||
                edgeB,
 | 
			
		||||
                ww,
 | 
			
		||||
                fw);
 | 
			
		||||
                fw
 | 
			
		||||
            );
 | 
			
		||||
            if (imIn == imOut) {
 | 
			
		||||
                // Commit.
 | 
			
		||||
                memcpy(imOut->image32[y], lineOut, imIn->xsize * 4);
 | 
			
		||||
| 
						 | 
				
			
			@ -314,11 +318,13 @@ _gaussian_blur_radius(float radius, int passes) {
 | 
			
		|||
 | 
			
		||||
Imaging
 | 
			
		||||
ImagingGaussianBlur(
 | 
			
		||||
    Imaging imOut, Imaging imIn, float xradius, float yradius, int passes) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, float xradius, float yradius, int passes
 | 
			
		||||
) {
 | 
			
		||||
    return ImagingBoxBlur(
 | 
			
		||||
        imOut,
 | 
			
		||||
        imIn,
 | 
			
		||||
        _gaussian_blur_radius(xradius, passes),
 | 
			
		||||
        _gaussian_blur_radius(yradius, passes),
 | 
			
		||||
        passes);
 | 
			
		||||
        passes
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -142,7 +142,8 @@ ImagingChopSoftLight(Imaging imIn1, Imaging imIn2) {
 | 
			
		|||
    CHOP2(
 | 
			
		||||
        (((255 - in1[x]) * (in1[x] * in2[x])) / 65536) +
 | 
			
		||||
            (in1[x] * (255 - ((255 - in1[x]) * (255 - in2[x]) / 255))) / 255,
 | 
			
		||||
        NULL);
 | 
			
		||||
        NULL
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +151,8 @@ ImagingChopHardLight(Imaging imIn1, Imaging imIn2) {
 | 
			
		|||
    CHOP2(
 | 
			
		||||
        (in2[x] < 128) ? ((in1[x] * in2[x]) / 127)
 | 
			
		||||
                       : 255 - (((255 - in2[x]) * (255 - in1[x])) / 127),
 | 
			
		||||
        NULL);
 | 
			
		||||
        NULL
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -158,5 +160,6 @@ ImagingOverlay(Imaging imIn1, Imaging imIn2) {
 | 
			
		|||
    CHOP2(
 | 
			
		||||
        (in1[x] < 128) ? ((in1[x] * in2[x]) / 127)
 | 
			
		||||
                       : 255 - (((255 - in1[x]) * (255 - in2[x])) / 127),
 | 
			
		||||
        NULL);
 | 
			
		||||
        NULL
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,7 +63,8 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
    int size1D,
 | 
			
		||||
    int size2D,
 | 
			
		||||
    int size3D,
 | 
			
		||||
    INT16 *table) {
 | 
			
		||||
    INT16 *table
 | 
			
		||||
) {
 | 
			
		||||
    /* This float to int conversion doesn't have rounding
 | 
			
		||||
       error compensation (+0.5) for two reasons:
 | 
			
		||||
       1. As we don't hit the highest value,
 | 
			
		||||
| 
						 | 
				
			
			@ -112,7 +113,8 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
                                           index2D >> SCALE_BITS,
 | 
			
		||||
                                           index3D >> SCALE_BITS,
 | 
			
		||||
                                           size1D,
 | 
			
		||||
                                           size1D_2D);
 | 
			
		||||
                                           size1D_2D
 | 
			
		||||
                                       );
 | 
			
		||||
            INT16 result[4], left[4], right[4];
 | 
			
		||||
            INT16 leftleft[4], leftright[4], rightleft[4], rightright[4];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -123,19 +125,22 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
                    leftright,
 | 
			
		||||
                    &table[idx + size1D * 3],
 | 
			
		||||
                    &table[idx + size1D * 3 + 3],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate3(left, leftleft, leftright, shift2D);
 | 
			
		||||
 | 
			
		||||
                interpolate3(
 | 
			
		||||
                    rightleft,
 | 
			
		||||
                    &table[idx + size1D_2D * 3],
 | 
			
		||||
                    &table[idx + size1D_2D * 3 + 3],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate3(
 | 
			
		||||
                    rightright,
 | 
			
		||||
                    &table[idx + size1D_2D * 3 + size1D * 3],
 | 
			
		||||
                    &table[idx + size1D_2D * 3 + size1D * 3 + 3],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate3(right, rightleft, rightright, shift2D);
 | 
			
		||||
 | 
			
		||||
                interpolate3(result, left, right, shift3D);
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +149,8 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
                    clip8(result[0]),
 | 
			
		||||
                    clip8(result[1]),
 | 
			
		||||
                    clip8(result[2]),
 | 
			
		||||
                    rowIn[x * 4 + 3]);
 | 
			
		||||
                    rowIn[x * 4 + 3]
 | 
			
		||||
                );
 | 
			
		||||
                memcpy(rowOut + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -155,19 +161,22 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
                    leftright,
 | 
			
		||||
                    &table[idx + size1D * 4],
 | 
			
		||||
                    &table[idx + size1D * 4 + 4],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate4(left, leftleft, leftright, shift2D);
 | 
			
		||||
 | 
			
		||||
                interpolate4(
 | 
			
		||||
                    rightleft,
 | 
			
		||||
                    &table[idx + size1D_2D * 4],
 | 
			
		||||
                    &table[idx + size1D_2D * 4 + 4],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate4(
 | 
			
		||||
                    rightright,
 | 
			
		||||
                    &table[idx + size1D_2D * 4 + size1D * 4],
 | 
			
		||||
                    &table[idx + size1D_2D * 4 + size1D * 4 + 4],
 | 
			
		||||
                    shift1D);
 | 
			
		||||
                    shift1D
 | 
			
		||||
                );
 | 
			
		||||
                interpolate4(right, rightleft, rightright, shift2D);
 | 
			
		||||
 | 
			
		||||
                interpolate4(result, left, right, shift3D);
 | 
			
		||||
| 
						 | 
				
			
			@ -176,7 +185,8 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
                    clip8(result[0]),
 | 
			
		||||
                    clip8(result[1]),
 | 
			
		||||
                    clip8(result[2]),
 | 
			
		||||
                    clip8(result[3]));
 | 
			
		||||
                    clip8(result[3])
 | 
			
		||||
                );
 | 
			
		||||
                memcpy(rowOut + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1044,7 +1044,8 @@ static struct {
 | 
			
		|||
    {"I;16L", "F", I16L_F},
 | 
			
		||||
    {"I;16B", "F", I16B_F},
 | 
			
		||||
 | 
			
		||||
    {NULL}};
 | 
			
		||||
    {NULL}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* FIXME: translate indexed versions to pointer versions below this line */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1316,7 +1317,8 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
 | 
			
		|||
            (UINT8 *)imOut->image[y],
 | 
			
		||||
            (UINT8 *)imIn->image[y],
 | 
			
		||||
            imIn->xsize,
 | 
			
		||||
            imIn->palette);
 | 
			
		||||
            imIn->palette
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
    ImagingSectionLeave(&cookie);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1328,11 +1330,8 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
 | 
			
		|||
#endif
 | 
			
		||||
static Imaging
 | 
			
		||||
topalette(
 | 
			
		||||
    Imaging imOut,
 | 
			
		||||
    Imaging imIn,
 | 
			
		||||
    const char *mode,
 | 
			
		||||
    ImagingPalette inpalette,
 | 
			
		||||
    int dither) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, const char *mode, ImagingPalette inpalette, int dither
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    int alpha;
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -1623,7 +1622,8 @@ tobilevel(Imaging imOut, Imaging imIn) {
 | 
			
		|||
 | 
			
		||||
static Imaging
 | 
			
		||||
convert(
 | 
			
		||||
    Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, const char *mode, ImagingPalette palette, int dither
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    ImagingShuffler convert;
 | 
			
		||||
    int y;
 | 
			
		||||
| 
						 | 
				
			
			@ -1677,7 +1677,8 @@ convert(
 | 
			
		|||
#else
 | 
			
		||||
        static char buf[100];
 | 
			
		||||
        snprintf(
 | 
			
		||||
            buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode);
 | 
			
		||||
            buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode
 | 
			
		||||
        );
 | 
			
		||||
        return (Imaging)ImagingError_ValueError(buf);
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1727,18 +1728,16 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
 | 
			
		|||
        if (strcmp(mode, "RGBa") == 0) {
 | 
			
		||||
            premultiplied = 1;
 | 
			
		||||
        }
 | 
			
		||||
    } else if (
 | 
			
		||||
        strcmp(imIn->mode, "RGB") == 0 &&
 | 
			
		||||
        (strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
 | 
			
		||||
    } else if (strcmp(imIn->mode, "RGB") == 0 &&
 | 
			
		||||
               (strcmp(mode, "LA") == 0 || strcmp(mode, "La") == 0)) {
 | 
			
		||||
        convert = rgb2la;
 | 
			
		||||
        source_transparency = 1;
 | 
			
		||||
        if (strcmp(mode, "La") == 0) {
 | 
			
		||||
            premultiplied = 1;
 | 
			
		||||
        }
 | 
			
		||||
    } else if (
 | 
			
		||||
        (strcmp(imIn->mode, "1") == 0 || strcmp(imIn->mode, "I") == 0 ||
 | 
			
		||||
         strcmp(imIn->mode, "I;16") == 0 || strcmp(imIn->mode, "L") == 0) &&
 | 
			
		||||
        (strcmp(mode, "RGBA") == 0 || strcmp(mode, "LA") == 0)) {
 | 
			
		||||
    } else if ((strcmp(imIn->mode, "1") == 0 || strcmp(imIn->mode, "I") == 0 ||
 | 
			
		||||
                strcmp(imIn->mode, "I;16") == 0 || strcmp(imIn->mode, "L") == 0) &&
 | 
			
		||||
               (strcmp(mode, "RGBA") == 0 || strcmp(mode, "LA") == 0)) {
 | 
			
		||||
        if (strcmp(imIn->mode, "1") == 0) {
 | 
			
		||||
            convert = bit2rgb;
 | 
			
		||||
        } else if (strcmp(imIn->mode, "I") == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1756,7 +1755,8 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
 | 
			
		|||
            100,
 | 
			
		||||
            "conversion from %.10s to %.10s not supported in convert_transparent",
 | 
			
		||||
            imIn->mode,
 | 
			
		||||
            mode);
 | 
			
		||||
            mode
 | 
			
		||||
        );
 | 
			
		||||
        return (Imaging)ImagingError_ValueError(buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,7 +47,8 @@ static INT16 Y_R[] = {
 | 
			
		|||
    4019, 4038, 4057, 4076, 4095, 4114, 4133, 4153, 4172, 4191, 4210, 4229, 4248, 4267,
 | 
			
		||||
    4286, 4306, 4325, 4344, 4363, 4382, 4401, 4420, 4440, 4459, 4478, 4497, 4516, 4535,
 | 
			
		||||
    4554, 4574, 4593, 4612, 4631, 4650, 4669, 4688, 4707, 4727, 4746, 4765, 4784, 4803,
 | 
			
		||||
    4822, 4841, 4861, 4880};
 | 
			
		||||
    4822, 4841, 4861, 4880
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Y_G[] = {
 | 
			
		||||
    0,    38,   75,   113,  150,  188,  225,  263,  301,  338,  376,  413,  451,  488,
 | 
			
		||||
| 
						 | 
				
			
			@ -68,7 +69,8 @@ static INT16 Y_G[] = {
 | 
			
		|||
    7889, 7927, 7964, 8002, 8040, 8077, 8115, 8152, 8190, 8227, 8265, 8303, 8340, 8378,
 | 
			
		||||
    8415, 8453, 8490, 8528, 8566, 8603, 8641, 8678, 8716, 8753, 8791, 8828, 8866, 8904,
 | 
			
		||||
    8941, 8979, 9016, 9054, 9091, 9129, 9167, 9204, 9242, 9279, 9317, 9354, 9392, 9430,
 | 
			
		||||
    9467, 9505, 9542, 9580};
 | 
			
		||||
    9467, 9505, 9542, 9580
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Y_B[] = {
 | 
			
		||||
    0,    7,    15,   22,   29,   36,   44,   51,   58,   66,   73,   80,   88,   95,
 | 
			
		||||
| 
						 | 
				
			
			@ -89,7 +91,8 @@ static INT16 Y_B[] = {
 | 
			
		|||
    1532, 1539, 1547, 1554, 1561, 1569, 1576, 1583, 1591, 1598, 1605, 1612, 1620, 1627,
 | 
			
		||||
    1634, 1642, 1649, 1656, 1663, 1671, 1678, 1685, 1693, 1700, 1707, 1715, 1722, 1729,
 | 
			
		||||
    1736, 1744, 1751, 1758, 1766, 1773, 1780, 1788, 1795, 1802, 1809, 1817, 1824, 1831,
 | 
			
		||||
    1839, 1846, 1853, 1860};
 | 
			
		||||
    1839, 1846, 1853, 1860
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Cb_R[] = {
 | 
			
		||||
    0,     -10,   -21,   -31,   -42,   -53,   -64,   -75,   -85,   -96,   -107,  -118,
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +116,8 @@ static INT16 Cb_R[] = {
 | 
			
		|||
    -2332, -2342, -2353, -2364, -2375, -2386, -2396, -2407, -2418, -2429, -2440, -2450,
 | 
			
		||||
    -2461, -2472, -2483, -2494, -2504, -2515, -2526, -2537, -2548, -2558, -2569, -2580,
 | 
			
		||||
    -2591, -2602, -2612, -2623, -2634, -2645, -2656, -2666, -2677, -2688, -2699, -2710,
 | 
			
		||||
    -2720, -2731, -2742, -2753};
 | 
			
		||||
    -2720, -2731, -2742, -2753
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Cb_G[] = {
 | 
			
		||||
    0,     -20,   -41,   -63,   -84,   -105,  -126,  -147,  -169,  -190,  -211,  -232,
 | 
			
		||||
| 
						 | 
				
			
			@ -137,7 +141,8 @@ static INT16 Cb_G[] = {
 | 
			
		|||
    -4578, -4600, -4621, -4642, -4663, -4684, -4706, -4727, -4748, -4769, -4790, -4812,
 | 
			
		||||
    -4833, -4854, -4875, -4896, -4918, -4939, -4960, -4981, -5002, -5024, -5045, -5066,
 | 
			
		||||
    -5087, -5108, -5130, -5151, -5172, -5193, -5214, -5236, -5257, -5278, -5299, -5320,
 | 
			
		||||
    -5342, -5363, -5384, -5405};
 | 
			
		||||
    -5342, -5363, -5384, -5405
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Cb_B[] = {
 | 
			
		||||
    0,    32,   64,   96,   128,  160,  192,  224,  256,  288,  320,  352,  384,  416,
 | 
			
		||||
| 
						 | 
				
			
			@ -158,7 +163,8 @@ static INT16 Cb_B[] = {
 | 
			
		|||
    6720, 6752, 6784, 6816, 6848, 6880, 6912, 6944, 6976, 7008, 7040, 7072, 7104, 7136,
 | 
			
		||||
    7168, 7200, 7232, 7264, 7296, 7328, 7360, 7392, 7424, 7456, 7488, 7520, 7552, 7584,
 | 
			
		||||
    7616, 7648, 7680, 7712, 7744, 7776, 7808, 7840, 7872, 7904, 7936, 7968, 8000, 8032,
 | 
			
		||||
    8064, 8096, 8128, 8160};
 | 
			
		||||
    8064, 8096, 8128, 8160
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define Cr_R Cb_B
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -184,7 +190,8 @@ static INT16 Cr_G[] = {
 | 
			
		|||
    -5787, -5814, -5841, -5867, -5894, -5921, -5948, -5975, -6001, -6028, -6055, -6082,
 | 
			
		||||
    -6109, -6135, -6162, -6189, -6216, -6243, -6269, -6296, -6323, -6350, -6376, -6403,
 | 
			
		||||
    -6430, -6457, -6484, -6510, -6537, -6564, -6591, -6618, -6644, -6671, -6698, -6725,
 | 
			
		||||
    -6752, -6778, -6805, -6832};
 | 
			
		||||
    -6752, -6778, -6805, -6832
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 Cr_B[] = {
 | 
			
		||||
    0,     -4,    -9,    -15,   -20,   -25,   -30,   -35,   -41,   -46,   -51,   -56,
 | 
			
		||||
| 
						 | 
				
			
			@ -208,7 +215,8 @@ static INT16 Cr_B[] = {
 | 
			
		|||
    -1123, -1128, -1133, -1139, -1144, -1149, -1154, -1159, -1165, -1170, -1175, -1180,
 | 
			
		||||
    -1185, -1191, -1196, -1201, -1206, -1211, -1217, -1222, -1227, -1232, -1238, -1243,
 | 
			
		||||
    -1248, -1253, -1258, -1264, -1269, -1274, -1279, -1284, -1290, -1295, -1300, -1305,
 | 
			
		||||
    -1310, -1316, -1321, -1326};
 | 
			
		||||
    -1310, -1316, -1321, -1326
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 R_Cr[] = {
 | 
			
		||||
    -11484, -11394, -11305, -11215, -11125, -11036, -10946, -10856, -10766, -10677,
 | 
			
		||||
| 
						 | 
				
			
			@ -236,7 +244,8 @@ static INT16 R_Cr[] = {
 | 
			
		|||
    8255,   8345,   8434,   8524,   8614,   8704,   8793,   8883,   8973,   9063,
 | 
			
		||||
    9152,   9242,   9332,   9421,   9511,   9601,   9691,   9780,   9870,   9960,
 | 
			
		||||
    10050,  10139,  10229,  10319,  10408,  10498,  10588,  10678,  10767,  10857,
 | 
			
		||||
    10947,  11037,  11126,  11216,  11306,  11395};
 | 
			
		||||
    10947,  11037,  11126,  11216,  11306,  11395
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 G_Cb[] = {
 | 
			
		||||
    2819,  2797,  2775,  2753,  2731,  2709,  2687,  2665,  2643,  2621,  2599,  2577,
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +269,8 @@ static INT16 G_Cb[] = {
 | 
			
		|||
    -1937, -1959, -1981, -2003, -2025, -2047, -2069, -2091, -2113, -2135, -2157, -2179,
 | 
			
		||||
    -2201, -2224, -2246, -2268, -2290, -2312, -2334, -2356, -2378, -2400, -2422, -2444,
 | 
			
		||||
    -2466, -2488, -2510, -2532, -2554, -2576, -2598, -2620, -2642, -2664, -2686, -2708,
 | 
			
		||||
    -2730, -2752, -2774, -2796};
 | 
			
		||||
    -2730, -2752, -2774, -2796
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 G_Cr[] = {
 | 
			
		||||
    5850,  5805,  5759,  5713,  5667,  5622,  5576,  5530,  5485,  5439,  5393,  5347,
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +294,8 @@ static INT16 G_Cr[] = {
 | 
			
		|||
    -4021, -4067, -4112, -4158, -4204, -4250, -4295, -4341, -4387, -4432, -4478, -4524,
 | 
			
		||||
    -4569, -4615, -4661, -4707, -4752, -4798, -4844, -4889, -4935, -4981, -5027, -5072,
 | 
			
		||||
    -5118, -5164, -5209, -5255, -5301, -5346, -5392, -5438, -5484, -5529, -5575, -5621,
 | 
			
		||||
    -5666, -5712, -5758, -5804};
 | 
			
		||||
    -5666, -5712, -5758, -5804
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 B_Cb[] = {
 | 
			
		||||
    -14515, -14402, -14288, -14175, -14062, -13948, -13835, -13721, -13608, -13495,
 | 
			
		||||
| 
						 | 
				
			
			@ -312,7 +323,8 @@ static INT16 B_Cb[] = {
 | 
			
		|||
    10434,  10547,  10660,  10774,  10887,  11001,  11114,  11227,  11341,  11454,
 | 
			
		||||
    11568,  11681,  11794,  11908,  12021,  12135,  12248,  12361,  12475,  12588,
 | 
			
		||||
    12702,  12815,  12929,  13042,  13155,  13269,  13382,  13496,  13609,  13722,
 | 
			
		||||
    13836,  13949,  14063,  14176,  14289,  14403};
 | 
			
		||||
    13836,  13949,  14063,  14176,  14289,  14403
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
ImagingConvertRGB2YCbCr(UINT8 *out, const UINT8 *in, int pixels) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -95,7 +95,8 @@ ImagingNewDIB(const char *mode, int xsize, int ysize) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    dib->bitmap = CreateDIBSection(
 | 
			
		||||
        dib->dc, dib->info, DIB_RGB_COLORS, (void **)&dib->bits, NULL, 0);
 | 
			
		||||
        dib->dc, dib->info, DIB_RGB_COLORS, (void **)&dib->bits, NULL, 0
 | 
			
		||||
    );
 | 
			
		||||
    if (!dib->bitmap) {
 | 
			
		||||
        free(dib->info);
 | 
			
		||||
        free(dib);
 | 
			
		||||
| 
						 | 
				
			
			@ -218,7 +219,8 @@ ImagingPasteDIB(ImagingDIB dib, Imaging im, int xy[4]) {
 | 
			
		|||
            dib->bits + dib->linesize * (dib->ysize - (xy[1] + y) - 1) +
 | 
			
		||||
                xy[0] * dib->pixelsize,
 | 
			
		||||
            im->image[y],
 | 
			
		||||
            im->xsize);
 | 
			
		||||
            im->xsize
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -251,7 +253,8 @@ ImagingDrawDIB(ImagingDIB dib, void *dc, int dst[4], int src[4]) {
 | 
			
		|||
            dib->bits,
 | 
			
		||||
            dib->info,
 | 
			
		||||
            DIB_RGB_COLORS,
 | 
			
		||||
            SRCCOPY);
 | 
			
		||||
            SRCCOPY
 | 
			
		||||
        );
 | 
			
		||||
    } else {
 | 
			
		||||
        /* stretchblt (displays) */
 | 
			
		||||
        if (dib->palette != 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -268,7 +271,8 @@ ImagingDrawDIB(ImagingDIB dib, void *dc, int dst[4], int src[4]) {
 | 
			
		|||
            src[1],
 | 
			
		||||
            src[2] - src[0],
 | 
			
		||||
            src[3] - src[1],
 | 
			
		||||
            SRCCOPY);
 | 
			
		||||
            SRCCOPY
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -120,9 +120,8 @@ hline8(Imaging im, int x0, int y0, int x1, int ink) {
 | 
			
		|||
        if (x0 <= x1) {
 | 
			
		||||
            pixelwidth = strncmp(im->mode, "I;16", 4) == 0 ? 2 : 1;
 | 
			
		||||
            memset(
 | 
			
		||||
                im->image8[y0] + x0 * pixelwidth,
 | 
			
		||||
                (UINT8)ink,
 | 
			
		||||
                (x1 - x0 + 1) * pixelwidth);
 | 
			
		||||
                im->image8[y0] + x0 * pixelwidth, (UINT8)ink, (x1 - x0 + 1) * pixelwidth
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -408,7 +407,8 @@ x_cmp(const void *x0, const void *x1) {
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
draw_horizontal_lines(
 | 
			
		||||
    Imaging im, int n, Edge *e, int ink, int *x_pos, int y, hline_handler hline) {
 | 
			
		||||
    Imaging im, int n, Edge *e, int ink, int *x_pos, int y, hline_handler hline
 | 
			
		||||
) {
 | 
			
		||||
    int i;
 | 
			
		||||
    for (i = 0; i < n; i++) {
 | 
			
		||||
        if (e[i].ymin == y && e[i].ymin == e[i].ymax) {
 | 
			
		||||
| 
						 | 
				
			
			@ -440,13 +440,8 @@ draw_horizontal_lines(
 | 
			
		|||
 */
 | 
			
		||||
static inline int
 | 
			
		||||
polygon_generic(
 | 
			
		||||
    Imaging im,
 | 
			
		||||
    int n,
 | 
			
		||||
    Edge *e,
 | 
			
		||||
    int ink,
 | 
			
		||||
    int eofill,
 | 
			
		||||
    hline_handler hline,
 | 
			
		||||
    int hasAlpha) {
 | 
			
		||||
    Imaging im, int n, Edge *e, int ink, int eofill, hline_handler hline, int hasAlpha
 | 
			
		||||
) {
 | 
			
		||||
    Edge **edge_table;
 | 
			
		||||
    float *xx;
 | 
			
		||||
    int edge_count = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -530,25 +525,29 @@ polygon_generic(
 | 
			
		|||
                                other_edge->x0;
 | 
			
		||||
                            if (ymin == current->ymax) {
 | 
			
		||||
                                if (current->dx > 0) {
 | 
			
		||||
                                    xx[k] = fmax(
 | 
			
		||||
                                                adjacent_line_x,
 | 
			
		||||
                                                adjacent_line_x_other_edge) +
 | 
			
		||||
                                            1;
 | 
			
		||||
                                    xx[k] =
 | 
			
		||||
                                        fmax(
 | 
			
		||||
                                            adjacent_line_x, adjacent_line_x_other_edge
 | 
			
		||||
                                        ) +
 | 
			
		||||
                                        1;
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    xx[k] = fmin(
 | 
			
		||||
                                                adjacent_line_x,
 | 
			
		||||
                                                adjacent_line_x_other_edge) -
 | 
			
		||||
                                            1;
 | 
			
		||||
                                    xx[k] =
 | 
			
		||||
                                        fmin(
 | 
			
		||||
                                            adjacent_line_x, adjacent_line_x_other_edge
 | 
			
		||||
                                        ) -
 | 
			
		||||
                                        1;
 | 
			
		||||
                                }
 | 
			
		||||
                            } else {
 | 
			
		||||
                                if (current->dx > 0) {
 | 
			
		||||
                                    xx[k] = fmin(
 | 
			
		||||
                                        adjacent_line_x, adjacent_line_x_other_edge);
 | 
			
		||||
                                        adjacent_line_x, adjacent_line_x_other_edge
 | 
			
		||||
                                    );
 | 
			
		||||
                                } else {
 | 
			
		||||
                                    xx[k] = fmax(
 | 
			
		||||
                                                adjacent_line_x,
 | 
			
		||||
                                                adjacent_line_x_other_edge) +
 | 
			
		||||
                                            1;
 | 
			
		||||
                                    xx[k] =
 | 
			
		||||
                                        fmax(
 | 
			
		||||
                                            adjacent_line_x, adjacent_line_x_other_edge
 | 
			
		||||
                                        ) +
 | 
			
		||||
                                        1;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            break;
 | 
			
		||||
| 
						 | 
				
			
			@ -699,7 +698,8 @@ ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink_, in
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingDrawWideLine(
 | 
			
		||||
    Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int width, int op) {
 | 
			
		||||
    Imaging im, int x0, int y0, int x1, int y1, const void *ink_, int width, int op
 | 
			
		||||
) {
 | 
			
		||||
    DRAW *draw;
 | 
			
		||||
    INT32 ink;
 | 
			
		||||
    int dx, dy;
 | 
			
		||||
| 
						 | 
				
			
			@ -730,7 +730,8 @@ ImagingDrawWideLine(
 | 
			
		|||
            {x0 - dxmin, y0 + dymax},
 | 
			
		||||
            {x1 - dxmin, y1 + dymax},
 | 
			
		||||
            {x1 + dxmax, y1 - dymin},
 | 
			
		||||
            {x0 + dxmax, y0 - dymin}};
 | 
			
		||||
            {x0 + dxmax, y0 - dymin}
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        add_edge(e + 0, vertices[0][0], vertices[0][1], vertices[1][0], vertices[1][1]);
 | 
			
		||||
        add_edge(e + 1, vertices[1][0], vertices[1][1], vertices[2][0], vertices[2][1]);
 | 
			
		||||
| 
						 | 
				
			
			@ -752,7 +753,8 @@ ImagingDrawRectangle(
 | 
			
		|||
    const void *ink_,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    int i;
 | 
			
		||||
    int y;
 | 
			
		||||
    int tmp;
 | 
			
		||||
| 
						 | 
				
			
			@ -800,7 +802,8 @@ ImagingDrawRectangle(
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingDrawPolygon(
 | 
			
		||||
    Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op) {
 | 
			
		||||
    Imaging im, int count, int *xy, const void *ink_, int fill, int width, int op
 | 
			
		||||
) {
 | 
			
		||||
    int i, n, x0, y0, x1, y1;
 | 
			
		||||
    DRAW *draw;
 | 
			
		||||
    INT32 ink;
 | 
			
		||||
| 
						 | 
				
			
			@ -851,7 +854,8 @@ ImagingDrawPolygon(
 | 
			
		|||
        if (width == 1) {
 | 
			
		||||
            for (i = 0; i < count - 1; i++) {
 | 
			
		||||
                draw->line(
 | 
			
		||||
                    im, xy[i * 2], xy[i * 2 + 1], xy[i * 2 + 2], xy[i * 2 + 3], ink);
 | 
			
		||||
                    im, xy[i * 2], xy[i * 2 + 1], xy[i * 2 + 2], xy[i * 2 + 3], ink
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            draw->line(im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink);
 | 
			
		||||
        } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -864,10 +868,12 @@ ImagingDrawPolygon(
 | 
			
		|||
                    xy[i * 2 + 3],
 | 
			
		||||
                    ink_,
 | 
			
		||||
                    width,
 | 
			
		||||
                    op);
 | 
			
		||||
                    op
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            ImagingDrawWideLine(
 | 
			
		||||
                im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink_, width, op);
 | 
			
		||||
                im, xy[i * 2], xy[i * 2 + 1], xy[0], xy[1], ink_, width, op
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -877,7 +883,8 @@ ImagingDrawPolygon(
 | 
			
		|||
int
 | 
			
		||||
ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void *ink, int op) {
 | 
			
		||||
    return ImagingFill2(
 | 
			
		||||
        im, ink, bitmap, x0, y0, x0 + bitmap->xsize, y0 + bitmap->ysize);
 | 
			
		||||
        im, ink, bitmap, x0, y0, x0 + bitmap->xsize, y0 + bitmap->ysize
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* -------------------------------------------------------------------- */
 | 
			
		||||
| 
						 | 
				
			
			@ -1086,7 +1093,8 @@ clip_tree_transpose(clip_node *root) {
 | 
			
		|||
// segments, i.e. something like correct bracket sequences.
 | 
			
		||||
int
 | 
			
		||||
clip_tree_do_clip(
 | 
			
		||||
    clip_node *root, int32_t x0, int32_t y, int32_t x1, event_list **ret) {
 | 
			
		||||
    clip_node *root, int32_t x0, int32_t y, int32_t x1, event_list **ret
 | 
			
		||||
) {
 | 
			
		||||
    if (root == NULL) {
 | 
			
		||||
        event_list *start = malloc(sizeof(event_list));
 | 
			
		||||
        if (!start) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1223,7 +1231,8 @@ typedef struct {
 | 
			
		|||
} clip_ellipse_state;
 | 
			
		||||
 | 
			
		||||
typedef void (*clip_ellipse_init)(
 | 
			
		||||
    clip_ellipse_state *, int32_t, int32_t, int32_t, float, float);
 | 
			
		||||
    clip_ellipse_state *, int32_t, int32_t, int32_t, float, float
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
debug_clip_tree(clip_node *root, int space) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1335,7 +1344,8 @@ arc_init(clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float
 | 
			
		|||
// A chord line.
 | 
			
		||||
void
 | 
			
		||||
chord_line_init(
 | 
			
		||||
    clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar) {
 | 
			
		||||
    clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float ar
 | 
			
		||||
) {
 | 
			
		||||
    ellipse_init(&s->st, a, b, a + b + 1);
 | 
			
		||||
 | 
			
		||||
    s->head = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -1362,7 +1372,8 @@ chord_line_init(
 | 
			
		|||
// Pie side.
 | 
			
		||||
void
 | 
			
		||||
pie_side_init(
 | 
			
		||||
    clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float _) {
 | 
			
		||||
    clip_ellipse_state *s, int32_t a, int32_t b, int32_t w, float al, float _
 | 
			
		||||
) {
 | 
			
		||||
    ellipse_init(&s->st, a, b, a + b + 1);
 | 
			
		||||
 | 
			
		||||
    s->head = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -1478,7 +1489,8 @@ clip_ellipse_free(clip_ellipse_state *s) {
 | 
			
		|||
 | 
			
		||||
int8_t
 | 
			
		||||
clip_ellipse_next(
 | 
			
		||||
    clip_ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1) {
 | 
			
		||||
    clip_ellipse_state *s, int32_t *ret_x0, int32_t *ret_y, int32_t *ret_x1
 | 
			
		||||
) {
 | 
			
		||||
    int32_t x0, y, x1;
 | 
			
		||||
    while (s->head == NULL && ellipse_next(&s->st, &x0, &y, &x1) >= 0) {
 | 
			
		||||
        if (clip_tree_do_clip(s->root, x0, y, x1, &s->head) < 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1512,7 +1524,8 @@ ellipseNew(
 | 
			
		|||
    const void *ink_,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    DRAW *draw;
 | 
			
		||||
    INT32 ink;
 | 
			
		||||
    DRAWINIT();
 | 
			
		||||
| 
						 | 
				
			
			@ -1547,7 +1560,8 @@ clipEllipseNew(
 | 
			
		|||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op,
 | 
			
		||||
    clip_ellipse_init init) {
 | 
			
		||||
    clip_ellipse_init init
 | 
			
		||||
) {
 | 
			
		||||
    DRAW *draw;
 | 
			
		||||
    INT32 ink;
 | 
			
		||||
    DRAWINIT();
 | 
			
		||||
| 
						 | 
				
			
			@ -1580,7 +1594,8 @@ arcNew(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, arc_init);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1595,7 +1610,8 @@ chordNew(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, chord_init);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1610,9 +1626,11 @@ chordLineNew(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return clipEllipseNew(
 | 
			
		||||
        im, x0, y0, x1, y1, start, end, ink_, width, op, chord_line_init);
 | 
			
		||||
        im, x0, y0, x1, y1, start, end, ink_, width, op, chord_line_init
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
| 
						 | 
				
			
			@ -1626,7 +1644,8 @@ pieNew(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return clipEllipseNew(im, x0, y0, x1, y1, start, end, ink_, width, op, pie_init);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1640,7 +1659,8 @@ pieSideNew(
 | 
			
		|||
    float start,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return clipEllipseNew(im, x0, y0, x1, y1, start, 0, ink_, width, op, pie_side_init);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1654,7 +1674,8 @@ ImagingDrawEllipse(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1669,7 +1690,8 @@ ImagingDrawArc(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    normalize_angles(&start, &end);
 | 
			
		||||
    if (start + 360 == end) {
 | 
			
		||||
        return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, 0, width, op);
 | 
			
		||||
| 
						 | 
				
			
			@ -1692,7 +1714,8 @@ ImagingDrawChord(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    normalize_angles(&start, &end);
 | 
			
		||||
    if (start + 360 == end) {
 | 
			
		||||
        return ImagingDrawEllipse(im, x0, y0, x1, y1, ink, fill, width, op);
 | 
			
		||||
| 
						 | 
				
			
			@ -1722,7 +1745,8 @@ ImagingDrawPieslice(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op) {
 | 
			
		||||
    int op
 | 
			
		||||
) {
 | 
			
		||||
    normalize_angles(&start, &end);
 | 
			
		||||
    if (start + 360 == end) {
 | 
			
		||||
        return ellipseNew(im, x0, y0, x1, y1, ink, fill, width, op);
 | 
			
		||||
| 
						 | 
				
			
			@ -1850,13 +1874,8 @@ ImagingOutlineLine(ImagingOutline outline, float x1, float y1) {
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingOutlineCurve(
 | 
			
		||||
    ImagingOutline outline,
 | 
			
		||||
    float x1,
 | 
			
		||||
    float y1,
 | 
			
		||||
    float x2,
 | 
			
		||||
    float y2,
 | 
			
		||||
    float x3,
 | 
			
		||||
    float y3) {
 | 
			
		||||
    ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3
 | 
			
		||||
) {
 | 
			
		||||
    Edge *e;
 | 
			
		||||
    int i;
 | 
			
		||||
    float xo, yo;
 | 
			
		||||
| 
						 | 
				
			
			@ -1970,7 +1989,8 @@ ImagingOutlineTransform(ImagingOutline outline, double a[6]) {
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingDrawOutline(
 | 
			
		||||
    Imaging im, ImagingOutline outline, const void *ink_, int fill, int op) {
 | 
			
		||||
    Imaging im, ImagingOutline outline, const void *ink_, int fill, int op
 | 
			
		||||
) {
 | 
			
		||||
    DRAW *draw;
 | 
			
		||||
    INT32 ink;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -118,8 +118,8 @@ ImagingFillRadialGradient(const char *mode) {
 | 
			
		|||
 | 
			
		||||
    for (y = 0; y < 256; y++) {
 | 
			
		||||
        for (x = 0; x < 256; x++) {
 | 
			
		||||
            d = (int)sqrt(
 | 
			
		||||
                (double)((x - 128) * (x - 128) + (y - 128) * (y - 128)) * 2.0);
 | 
			
		||||
            d = (int
 | 
			
		||||
            )sqrt((double)((x - 128) * (x - 128) + (y - 128) * (y - 128)) * 2.0);
 | 
			
		||||
            if (d >= 255) {
 | 
			
		||||
                d = 255;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,7 +59,8 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    imOut = ImagingNewDirty(
 | 
			
		||||
        imIn->mode, imIn->xsize + 2 * xmargin, imIn->ysize + 2 * ymargin);
 | 
			
		||||
        imIn->mode, imIn->xsize + 2 * xmargin, imIn->ysize + 2 * ymargin
 | 
			
		||||
    );
 | 
			
		||||
    if (!imOut) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -369,7 +370,8 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float *kernel, float offset) {
 | 
			
		|||
                }
 | 
			
		||||
            }
 | 
			
		||||
            memcpy(
 | 
			
		||||
                out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32) * 2);
 | 
			
		||||
                out + x * sizeof(UINT32), in0 + x * sizeof(UINT32), sizeof(UINT32) * 2
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    memcpy(imOut->image[y], im->image[y], im->linesize);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -781,7 +781,8 @@ ImagingGenericTransform(
 | 
			
		|||
    ImagingTransformMap transform,
 | 
			
		||||
    void *transform_data,
 | 
			
		||||
    int filterid,
 | 
			
		||||
    int fill) {
 | 
			
		||||
    int fill
 | 
			
		||||
) {
 | 
			
		||||
    /* slow generic transformation.  use ImagingTransformAffine or
 | 
			
		||||
       ImagingScaleAffine where possible. */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -836,14 +837,8 @@ ImagingGenericTransform(
 | 
			
		|||
 | 
			
		||||
static Imaging
 | 
			
		||||
ImagingScaleAffine(
 | 
			
		||||
    Imaging imOut,
 | 
			
		||||
    Imaging imIn,
 | 
			
		||||
    int x0,
 | 
			
		||||
    int y0,
 | 
			
		||||
    int x1,
 | 
			
		||||
    int y1,
 | 
			
		||||
    double a[6],
 | 
			
		||||
    int fill) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int x0, int y0, int x1, int y1, double a[6], int fill
 | 
			
		||||
) {
 | 
			
		||||
    /* scale, nearest neighbour resampling */
 | 
			
		||||
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
| 
						 | 
				
			
			@ -936,7 +931,8 @@ static inline int
 | 
			
		|||
check_fixed(double a[6], int x, int y) {
 | 
			
		||||
    return (
 | 
			
		||||
        fabs(x * a[0] + y * a[1] + a[2]) < 32768.0 &&
 | 
			
		||||
        fabs(x * a[3] + y * a[4] + a[5]) < 32768.0);
 | 
			
		||||
        fabs(x * a[3] + y * a[4] + a[5]) < 32768.0
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -949,7 +945,8 @@ affine_fixed(
 | 
			
		|||
    int y1,
 | 
			
		||||
    double a[6],
 | 
			
		||||
    int filterid,
 | 
			
		||||
    int fill) {
 | 
			
		||||
    int fill
 | 
			
		||||
) {
 | 
			
		||||
    /* affine transform, nearest neighbour resampling, fixed point
 | 
			
		||||
       arithmetics */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1026,7 +1023,8 @@ ImagingTransformAffine(
 | 
			
		|||
    int y1,
 | 
			
		||||
    double a[6],
 | 
			
		||||
    int filterid,
 | 
			
		||||
    int fill) {
 | 
			
		||||
    int fill
 | 
			
		||||
) {
 | 
			
		||||
    /* affine transform, nearest neighbour resampling, floating point
 | 
			
		||||
       arithmetics*/
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1039,7 +1037,8 @@ ImagingTransformAffine(
 | 
			
		|||
 | 
			
		||||
    if (filterid || imIn->type == IMAGING_TYPE_SPECIAL) {
 | 
			
		||||
        return ImagingGenericTransform(
 | 
			
		||||
            imOut, imIn, x0, y0, x1, y1, affine_transform, a, filterid, fill);
 | 
			
		||||
            imOut, imIn, x0, y0, x1, y1, affine_transform, a, filterid, fill
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (a[1] == 0 && a[3] == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1134,13 +1133,15 @@ ImagingTransform(
 | 
			
		|||
    int y1,
 | 
			
		||||
    double a[8],
 | 
			
		||||
    int filterid,
 | 
			
		||||
    int fill) {
 | 
			
		||||
    int fill
 | 
			
		||||
) {
 | 
			
		||||
    ImagingTransformMap transform;
 | 
			
		||||
 | 
			
		||||
    switch (method) {
 | 
			
		||||
        case IMAGING_TRANSFORM_AFFINE:
 | 
			
		||||
            return ImagingTransformAffine(
 | 
			
		||||
                imOut, imIn, x0, y0, x1, y1, a, filterid, fill);
 | 
			
		||||
                imOut, imIn, x0, y0, x1, y1, a, filterid, fill
 | 
			
		||||
            );
 | 
			
		||||
            break;
 | 
			
		||||
        case IMAGING_TRANSFORM_PERSPECTIVE:
 | 
			
		||||
            transform = perspective_transform;
 | 
			
		||||
| 
						 | 
				
			
			@ -1153,5 +1154,6 @@ ImagingTransform(
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    return ImagingGenericTransform(
 | 
			
		||||
        imOut, imIn, x0, y0, x1, y1, transform, a, filterid, fill);
 | 
			
		||||
        imOut, imIn, x0, y0, x1, y1, transform, a, filterid, fill
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,11 +58,10 @@ ImagingGetBBox(Imaging im, int bbox[4], int alpha_only) {
 | 
			
		|||
        INT32 mask = 0xffffffff;
 | 
			
		||||
        if (im->bands == 3) {
 | 
			
		||||
            ((UINT8 *)&mask)[3] = 0;
 | 
			
		||||
        } else if (
 | 
			
		||||
            alpha_only &&
 | 
			
		||||
            (strcmp(im->mode, "RGBa") == 0 || strcmp(im->mode, "RGBA") == 0 ||
 | 
			
		||||
             strcmp(im->mode, "La") == 0 || strcmp(im->mode, "LA") == 0 ||
 | 
			
		||||
             strcmp(im->mode, "PA") == 0)) {
 | 
			
		||||
        } else if (alpha_only &&
 | 
			
		||||
                   (strcmp(im->mode, "RGBa") == 0 || strcmp(im->mode, "RGBA") == 0 ||
 | 
			
		||||
                    strcmp(im->mode, "La") == 0 || strcmp(im->mode, "LA") == 0 ||
 | 
			
		||||
                    strcmp(im->mode, "PA") == 0)) {
 | 
			
		||||
#ifdef WORDS_BIGENDIAN
 | 
			
		||||
            mask = 0x000000ff;
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -246,13 +245,14 @@ getcolors32(Imaging im, int maxcolors, int *size) {
 | 
			
		|||
       code in Python 2.1.3; the exact implementation is borrowed from
 | 
			
		||||
       Python's Unicode property database (written by yours truly) /F */
 | 
			
		||||
 | 
			
		||||
    static int SIZES[] = {
 | 
			
		||||
        4,         3,  8,         3,  16,        3,  32,         5,  64,       3,
 | 
			
		||||
        128,       3,  256,       29, 512,       17, 1024,       9,  2048,     5,
 | 
			
		||||
        4096,      83, 8192,      27, 16384,     43, 32768,      3,  65536,    45,
 | 
			
		||||
        131072,    9,  262144,    39, 524288,    39, 1048576,    9,  2097152,  5,
 | 
			
		||||
        4194304,   3,  8388608,   33, 16777216,  27, 33554432,   9,  67108864, 71,
 | 
			
		||||
        134217728, 39, 268435456, 9,  536870912, 5,  1073741824, 83, 0};
 | 
			
		||||
    static int SIZES[] = {4,          3,  8,         3,  16,        3,  32,        5,
 | 
			
		||||
                          64,         3,  128,       3,  256,       29, 512,       17,
 | 
			
		||||
                          1024,       9,  2048,      5,  4096,      83, 8192,      27,
 | 
			
		||||
                          16384,      43, 32768,     3,  65536,     45, 131072,    9,
 | 
			
		||||
                          262144,     39, 524288,    39, 1048576,   9,  2097152,   5,
 | 
			
		||||
                          4194304,    3,  8388608,   33, 16777216,  27, 33554432,  9,
 | 
			
		||||
                          67108864,   71, 134217728, 39, 268435456, 9,  536870912, 5,
 | 
			
		||||
                          1073741824, 83, 0};
 | 
			
		||||
 | 
			
		||||
    code_size = code_poly = code_mask = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,7 +79,8 @@ glzwe(
 | 
			
		|||
    UINT8 *out_ptr,
 | 
			
		||||
    UINT32 *in_avail,
 | 
			
		||||
    UINT32 *out_avail,
 | 
			
		||||
    UINT32 end_of_data) {
 | 
			
		||||
    UINT32 end_of_data
 | 
			
		||||
) {
 | 
			
		||||
    switch (st->entry_state) {
 | 
			
		||||
        case LZW_TRY_IN1:
 | 
			
		||||
get_first_byte:
 | 
			
		||||
| 
						 | 
				
			
			@ -312,7 +313,8 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                state->buffer,
 | 
			
		||||
                (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
            state->x = 0;
 | 
			
		||||
 | 
			
		||||
            /* step forward, according to the interlace settings */
 | 
			
		||||
| 
						 | 
				
			
			@ -348,7 +350,8 @@ ImagingGifEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
            ptr,
 | 
			
		||||
            &in_avail,
 | 
			
		||||
            &out_avail,
 | 
			
		||||
            state->state == FINISH);
 | 
			
		||||
            state->state == FINISH
 | 
			
		||||
        );
 | 
			
		||||
        out_used = sub_block_limit - ptr - out_avail;
 | 
			
		||||
        *sub_block_ptr += out_used;
 | 
			
		||||
        ptr += out_used;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,7 +49,8 @@ ImagingHexDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
            if (++state->x >= state->bytes) {
 | 
			
		||||
                /* Got a full line, unpack it */
 | 
			
		||||
                state->shuffle(
 | 
			
		||||
                    (UINT8 *)im->image[state->y], state->buffer, state->xsize);
 | 
			
		||||
                    (UINT8 *)im->image[state->y], state->buffer, state->xsize
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                state->x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -295,7 +295,8 @@ extern Imaging
 | 
			
		|||
ImagingFill(Imaging im, const void *ink);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingFill2(
 | 
			
		||||
    Imaging into, const void *ink, Imaging mask, int x0, int y0, int x1, int y1);
 | 
			
		||||
    Imaging into, const void *ink, Imaging mask, int x0, int y0, int x1, int y1
 | 
			
		||||
);
 | 
			
		||||
extern Imaging
 | 
			
		||||
ImagingFillBand(Imaging im, int band, int color);
 | 
			
		||||
extern Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -310,7 +311,8 @@ extern Imaging
 | 
			
		|||
ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
 | 
			
		||||
extern Imaging
 | 
			
		||||
ImagingGaussianBlur(
 | 
			
		||||
    Imaging imOut, Imaging imIn, float xradius, float yradius, int passes);
 | 
			
		||||
    Imaging imOut, Imaging imIn, float xradius, float yradius, int passes
 | 
			
		||||
);
 | 
			
		||||
extern Imaging
 | 
			
		||||
ImagingGetBand(Imaging im, int band);
 | 
			
		||||
extern Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -373,7 +375,8 @@ ImagingTransform(
 | 
			
		|||
    int y1,
 | 
			
		||||
    double a[8],
 | 
			
		||||
    int filter,
 | 
			
		||||
    int fill);
 | 
			
		||||
    int fill
 | 
			
		||||
);
 | 
			
		||||
extern Imaging
 | 
			
		||||
ImagingUnsharpMask(Imaging imOut, Imaging im, float radius, int percent, int threshold);
 | 
			
		||||
extern Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -386,7 +389,8 @@ ImagingColorLUT3D_linear(
 | 
			
		|||
    int size1D,
 | 
			
		||||
    int size2D,
 | 
			
		||||
    int size3D,
 | 
			
		||||
    INT16 *table);
 | 
			
		||||
    INT16 *table
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
extern Imaging
 | 
			
		||||
ImagingCopy2(Imaging imOut, Imaging imIn);
 | 
			
		||||
| 
						 | 
				
			
			@ -440,7 +444,8 @@ ImagingDrawArc(
 | 
			
		|||
    float end,
 | 
			
		||||
    const void *ink,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op);
 | 
			
		||||
    int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawBitmap(Imaging im, int x0, int y0, Imaging bitmap, const void *ink, int op);
 | 
			
		||||
extern int
 | 
			
		||||
| 
						 | 
				
			
			@ -455,7 +460,8 @@ ImagingDrawChord(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op);
 | 
			
		||||
    int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawEllipse(
 | 
			
		||||
    Imaging im,
 | 
			
		||||
| 
						 | 
				
			
			@ -466,12 +472,14 @@ ImagingDrawEllipse(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op);
 | 
			
		||||
    int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1, const void *ink, int op);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawWideLine(
 | 
			
		||||
    Imaging im, int x0, int y0, int x1, int y1, const void *ink, int width, int op);
 | 
			
		||||
    Imaging im, int x0, int y0, int x1, int y1, const void *ink, int width, int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawPieslice(
 | 
			
		||||
    Imaging im,
 | 
			
		||||
| 
						 | 
				
			
			@ -484,12 +492,14 @@ ImagingDrawPieslice(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op);
 | 
			
		||||
    int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawPoint(Imaging im, int x, int y, const void *ink, int op);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawPolygon(
 | 
			
		||||
    Imaging im, int points, int *xy, const void *ink, int fill, int width, int op);
 | 
			
		||||
    Imaging im, int points, int *xy, const void *ink, int fill, int width, int op
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawRectangle(
 | 
			
		||||
    Imaging im,
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +510,8 @@ ImagingDrawRectangle(
 | 
			
		|||
    const void *ink,
 | 
			
		||||
    int fill,
 | 
			
		||||
    int width,
 | 
			
		||||
    int op);
 | 
			
		||||
    int op
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
/* Level 2 graphics (WORK IN PROGRESS) */
 | 
			
		||||
extern ImagingOutline
 | 
			
		||||
| 
						 | 
				
			
			@ -510,7 +521,8 @@ ImagingOutlineDelete(ImagingOutline outline);
 | 
			
		|||
 | 
			
		||||
extern int
 | 
			
		||||
ImagingDrawOutline(
 | 
			
		||||
    Imaging im, ImagingOutline outline, const void *ink, int fill, int op);
 | 
			
		||||
    Imaging im, ImagingOutline outline, const void *ink, int fill, int op
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
extern int
 | 
			
		||||
ImagingOutlineMove(ImagingOutline outline, float x, float y);
 | 
			
		||||
| 
						 | 
				
			
			@ -518,7 +530,8 @@ extern int
 | 
			
		|||
ImagingOutlineLine(ImagingOutline outline, float x, float y);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingOutlineCurve(
 | 
			
		||||
    ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3);
 | 
			
		||||
    ImagingOutline outline, float x1, float y1, float x2, float y2, float x3, float y3
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingOutlineTransform(ImagingOutline outline, double a[6]);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -545,7 +558,8 @@ ImagingSavePPM(Imaging im, const char *filename);
 | 
			
		|||
/* Codecs */
 | 
			
		||||
typedef struct ImagingCodecStateInstance *ImagingCodecState;
 | 
			
		||||
typedef int (*ImagingCodec)(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
extern int
 | 
			
		||||
ImagingBcnDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
| 
						 | 
				
			
			@ -575,7 +589,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes)
 | 
			
		|||
#ifdef HAVE_OPENJPEG
 | 
			
		||||
extern int
 | 
			
		||||
ImagingJpeg2KDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingJpeg2KDecodeCleanup(ImagingCodecState state);
 | 
			
		||||
extern int
 | 
			
		||||
| 
						 | 
				
			
			@ -586,7 +601,8 @@ ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
 | 
			
		|||
#ifdef HAVE_LIBTIFF
 | 
			
		||||
extern int
 | 
			
		||||
ImagingLibTiffDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -598,7 +614,8 @@ extern int
 | 
			
		|||
ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingPackbitsDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingPcdDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
extern int
 | 
			
		||||
| 
						 | 
				
			
			@ -611,13 +628,16 @@ extern int
 | 
			
		|||
ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingSgiRleDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingSunRleDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingTgaRleDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
 | 
			
		||||
extern int
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -67,7 +67,8 @@ j2k_skip(OPJ_OFF_T p_nb_bytes, void *p_user_data) {
 | 
			
		|||
/* -------------------------------------------------------------------- */
 | 
			
		||||
 | 
			
		||||
typedef void (*j2k_unpacker_t)(
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileInfo, const UINT8 *data, Imaging im);
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileInfo, const UINT8 *data, Imaging im
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
struct j2k_decode_unpacker {
 | 
			
		||||
    const char *mode;
 | 
			
		||||
| 
						 | 
				
			
			@ -89,10 +90,8 @@ j2ku_shift(unsigned x, int n) {
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_gray_l(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -145,10 +144,8 @@ j2ku_gray_l(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_gray_i(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -204,10 +201,8 @@ j2ku_gray_i(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_gray_rgb(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -268,10 +263,8 @@ j2ku_gray_rgb(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_graya_la(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -347,10 +340,8 @@ j2ku_graya_la(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_srgb_rgb(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -413,10 +404,8 @@ j2ku_srgb_rgb(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_sycc_rgb(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -482,10 +471,8 @@ j2ku_sycc_rgb(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_srgba_rgba(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -547,10 +534,8 @@ j2ku_srgba_rgba(
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2ku_sycca_rgba(
 | 
			
		||||
    opj_image_t *in,
 | 
			
		||||
    const JPEG2KTILEINFO *tileinfo,
 | 
			
		||||
    const UINT8 *tiledata,
 | 
			
		||||
    Imaging im) {
 | 
			
		||||
    opj_image_t *in, const JPEG2KTILEINFO *tileinfo, const UINT8 *tiledata, Imaging im
 | 
			
		||||
) {
 | 
			
		||||
    unsigned x0 = tileinfo->x0 - in->x0, y0 = tileinfo->y0 - in->y0;
 | 
			
		||||
    unsigned w = tileinfo->x1 - tileinfo->x0;
 | 
			
		||||
    unsigned h = tileinfo->y1 - tileinfo->y0;
 | 
			
		||||
| 
						 | 
				
			
			@ -815,7 +800,8 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
 | 
			
		|||
                &tile_info.x1,
 | 
			
		||||
                &tile_info.y1,
 | 
			
		||||
                &tile_info.nb_comps,
 | 
			
		||||
                &should_continue)) {
 | 
			
		||||
                &should_continue
 | 
			
		||||
            )) {
 | 
			
		||||
            state->errcode = IMAGING_CODEC_BROKEN;
 | 
			
		||||
            state->state = J2K_STATE_FAILED;
 | 
			
		||||
            goto quick_exit;
 | 
			
		||||
| 
						 | 
				
			
			@ -906,7 +892,8 @@ j2k_decode_entry(Imaging im, ImagingCodecState state) {
 | 
			
		|||
                tile_info.tile_index,
 | 
			
		||||
                (OPJ_BYTE *)state->buffer,
 | 
			
		||||
                tile_info.data_size,
 | 
			
		||||
                stream)) {
 | 
			
		||||
                stream
 | 
			
		||||
            )) {
 | 
			
		||||
            state->errcode = IMAGING_CODEC_BROKEN;
 | 
			
		||||
            state->state = J2K_STATE_FAILED;
 | 
			
		||||
            goto quick_exit;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -89,7 +89,8 @@ j2k_seek(OPJ_OFF_T p_nb_bytes, void *p_user_data) {
 | 
			
		|||
/* -------------------------------------------------------------------- */
 | 
			
		||||
 | 
			
		||||
typedef void (*j2k_pack_tile_t)(
 | 
			
		||||
    Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h);
 | 
			
		||||
    Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
j2k_pack_l(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) {
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +158,8 @@ j2k_pack_rgb(Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsig
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
j2k_pack_rgba(
 | 
			
		||||
    Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h) {
 | 
			
		||||
    Imaging im, UINT8 *buf, unsigned x0, unsigned y0, unsigned w, unsigned h
 | 
			
		||||
) {
 | 
			
		||||
    UINT8 *pr = buf;
 | 
			
		||||
    UINT8 *pg = pr + w * h;
 | 
			
		||||
    UINT8 *pb = pg + w * h;
 | 
			
		||||
| 
						 | 
				
			
			@ -205,8 +207,8 @@ j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params) {
 | 
			
		|||
 | 
			
		||||
    if (params->cp_cinema == OPJ_CINEMA4K_24) {
 | 
			
		||||
        float max_rate =
 | 
			
		||||
            ((float)(components * im->xsize * im->ysize * 8) /
 | 
			
		||||
             (CINEMA_24_CS_LENGTH * 8));
 | 
			
		||||
            ((float)(components * im->xsize * im->ysize * 8) / (CINEMA_24_CS_LENGTH * 8)
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        params->POC[0].tile = 1;
 | 
			
		||||
        params->POC[0].resno0 = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -241,8 +243,8 @@ j2k_set_cinema_params(Imaging im, int components, opj_cparameters_t *params) {
 | 
			
		|||
        params->max_comp_size = COMP_24_CS_MAX_LENGTH;
 | 
			
		||||
    } else {
 | 
			
		||||
        float max_rate =
 | 
			
		||||
            ((float)(components * im->xsize * im->ysize * 8) /
 | 
			
		||||
             (CINEMA_48_CS_LENGTH * 8));
 | 
			
		||||
            ((float)(components * im->xsize * im->ysize * 8) / (CINEMA_48_CS_LENGTH * 8)
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        for (n = 0; n < params->tcp_numlayers; ++n) {
 | 
			
		||||
            rate = 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -206,9 +206,8 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by
 | 
			
		|||
                context->cinfo.out_color_space = JCS_EXT_RGBX;
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
            else if (
 | 
			
		||||
                strcmp(context->rawmode, "CMYK") == 0 ||
 | 
			
		||||
                strcmp(context->rawmode, "CMYK;I") == 0) {
 | 
			
		||||
            else if (strcmp(context->rawmode, "CMYK") == 0 ||
 | 
			
		||||
                     strcmp(context->rawmode, "CMYK;I") == 0) {
 | 
			
		||||
                context->cinfo.out_color_space = JCS_CMYK;
 | 
			
		||||
            } else if (strcmp(context->rawmode, "YCbCr") == 0) {
 | 
			
		||||
                context->cinfo.out_color_space = JCS_YCbCr;
 | 
			
		||||
| 
						 | 
				
			
			@ -256,7 +255,8 @@ ImagingJpegDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t by
 | 
			
		|||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->buffer,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
                state->y++;
 | 
			
		||||
            }
 | 
			
		||||
            if (ok != 1) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -175,7 +175,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                        i,
 | 
			
		||||
                        &context->qtables[i * DCTSIZE2],
 | 
			
		||||
                        quality,
 | 
			
		||||
                        FALSE);
 | 
			
		||||
                        FALSE
 | 
			
		||||
                    );
 | 
			
		||||
                    context->cinfo.comp_info[i].quant_tbl_no = i;
 | 
			
		||||
                    last_q = i;
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +184,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                    // jpeg_set_defaults created two qtables internally, but we only
 | 
			
		||||
                    // wanted one.
 | 
			
		||||
                    jpeg_add_quant_table(
 | 
			
		||||
                        &context->cinfo, 1, &context->qtables[0], quality, FALSE);
 | 
			
		||||
                        &context->cinfo, 1, &context->qtables[0], quality, FALSE
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
                for (i = last_q; i < context->cinfo.num_components; i++) {
 | 
			
		||||
                    context->cinfo.comp_info[i].quant_tbl_no = last_q;
 | 
			
		||||
| 
						 | 
				
			
			@ -273,7 +275,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                    &context->cinfo,
 | 
			
		||||
                    JPEG_APP0 + 1,
 | 
			
		||||
                    (unsigned char *)context->rawExif,
 | 
			
		||||
                    context->rawExifLen);
 | 
			
		||||
                    context->rawExifLen
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            state->state++;
 | 
			
		||||
| 
						 | 
				
			
			@ -289,7 +292,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                memcpy(
 | 
			
		||||
                    context->destination.pub.next_output_byte,
 | 
			
		||||
                    context->extra + context->extra_offset,
 | 
			
		||||
                    n);
 | 
			
		||||
                    n
 | 
			
		||||
                );
 | 
			
		||||
                context->destination.pub.next_output_byte += n;
 | 
			
		||||
                context->destination.pub.free_in_buffer -= n;
 | 
			
		||||
                context->extra_offset += n;
 | 
			
		||||
| 
						 | 
				
			
			@ -309,7 +313,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                    &context->cinfo,
 | 
			
		||||
                    JPEG_COM,
 | 
			
		||||
                    (unsigned char *)context->comment,
 | 
			
		||||
                    context->comment_size);
 | 
			
		||||
                    context->comment_size
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            state->state++;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -324,7 +329,8 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                    state->buffer,
 | 
			
		||||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
                ok = jpeg_write_scanlines(&context->cinfo, &state->buffer, 1);
 | 
			
		||||
                if (ok != 1) {
 | 
			
		||||
                    break;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,8 @@
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingPackbitsDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes) {
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t bytes
 | 
			
		||||
) {
 | 
			
		||||
    UINT8 n;
 | 
			
		||||
    UINT8 *ptr;
 | 
			
		||||
    int i;
 | 
			
		||||
| 
						 | 
				
			
			@ -79,7 +80,8 @@ ImagingPackbitsDecode(
 | 
			
		|||
                (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->buffer,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            state->x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,8 @@ paste(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* paste opaque region */
 | 
			
		||||
 | 
			
		||||
    int y;
 | 
			
		||||
| 
						 | 
				
			
			@ -59,7 +60,8 @@ paste_mask_1(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* paste with mode "1" mask */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -120,7 +122,8 @@ paste_mask_L(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* paste with mode "L" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -167,7 +170,8 @@ paste_mask_RGBA(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* paste with mode "RGBA" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -214,7 +218,8 @@ paste_mask_RGBa(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* paste with mode "RGBa" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -252,7 +257,8 @@ paste_mask_RGBa(
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingPaste(
 | 
			
		||||
    Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, Imaging imMask, int dx0, int dy0, int dx1, int dy1
 | 
			
		||||
) {
 | 
			
		||||
    int xsize, ysize;
 | 
			
		||||
    int pixelsize;
 | 
			
		||||
    int sx0, sy0;
 | 
			
		||||
| 
						 | 
				
			
			@ -315,13 +321,15 @@ ImagingPaste(
 | 
			
		|||
    } else if (strcmp(imMask->mode, "LA") == 0 || strcmp(imMask->mode, "RGBA") == 0) {
 | 
			
		||||
        ImagingSectionEnter(&cookie);
 | 
			
		||||
        paste_mask_RGBA(
 | 
			
		||||
            imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
 | 
			
		||||
            imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize
 | 
			
		||||
        );
 | 
			
		||||
        ImagingSectionLeave(&cookie);
 | 
			
		||||
 | 
			
		||||
    } else if (strcmp(imMask->mode, "RGBa") == 0) {
 | 
			
		||||
        ImagingSectionEnter(&cookie);
 | 
			
		||||
        paste_mask_RGBa(
 | 
			
		||||
            imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize);
 | 
			
		||||
            imOut, imIn, imMask, dx0, dy0, sx0, sy0, xsize, ysize, pixelsize
 | 
			
		||||
        );
 | 
			
		||||
        ImagingSectionLeave(&cookie);
 | 
			
		||||
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -334,13 +342,8 @@ ImagingPaste(
 | 
			
		|||
 | 
			
		||||
static inline void
 | 
			
		||||
fill(
 | 
			
		||||
    Imaging imOut,
 | 
			
		||||
    const void *ink_,
 | 
			
		||||
    int dx,
 | 
			
		||||
    int dy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    Imaging imOut, const void *ink_, int dx, int dy, int xsize, int ysize, int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* fill opaque region */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -378,7 +381,8 @@ fill_mask_1(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* fill with mode "1" mask */
 | 
			
		||||
 | 
			
		||||
    int x, y;
 | 
			
		||||
| 
						 | 
				
			
			@ -425,7 +429,8 @@ fill_mask_L(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* fill with mode "L" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y, i;
 | 
			
		||||
| 
						 | 
				
			
			@ -484,7 +489,8 @@ fill_mask_RGBA(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* fill with mode "RGBA" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y, i;
 | 
			
		||||
| 
						 | 
				
			
			@ -529,7 +535,8 @@ fill_mask_RGBa(
 | 
			
		|||
    int sy,
 | 
			
		||||
    int xsize,
 | 
			
		||||
    int ysize,
 | 
			
		||||
    int pixelsize) {
 | 
			
		||||
    int pixelsize
 | 
			
		||||
) {
 | 
			
		||||
    /* fill with mode "RGBa" matte */
 | 
			
		||||
 | 
			
		||||
    int x, y, i;
 | 
			
		||||
| 
						 | 
				
			
			@ -565,13 +572,8 @@ fill_mask_RGBa(
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingFill2(
 | 
			
		||||
    Imaging imOut,
 | 
			
		||||
    const void *ink,
 | 
			
		||||
    Imaging imMask,
 | 
			
		||||
    int dx0,
 | 
			
		||||
    int dy0,
 | 
			
		||||
    int dx1,
 | 
			
		||||
    int dy1) {
 | 
			
		||||
    Imaging imOut, const void *ink, Imaging imMask, int dx0, int dy0, int dx1, int dy1
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    int xsize, ysize;
 | 
			
		||||
    int pixelsize;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,8 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
                    memmove(
 | 
			
		||||
                        &state->buffer[i * state->xsize],
 | 
			
		||||
                        &state->buffer[i * stride],
 | 
			
		||||
                        state->xsize);
 | 
			
		||||
                        state->xsize
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            /* Got a full line, unpack it */
 | 
			
		||||
| 
						 | 
				
			
			@ -76,7 +77,8 @@ ImagingPcxDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
                (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->buffer,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            state->x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,7 +71,8 @@ ImagingPcxEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                    state->buffer,
 | 
			
		||||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                state->y += 1;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -197,8 +197,8 @@ ImagingPoint(Imaging imIn, const char *mode, const void *table) {
 | 
			
		|||
    return imOut;
 | 
			
		||||
 | 
			
		||||
mode_mismatch:
 | 
			
		||||
    return (Imaging)ImagingError_ValueError(
 | 
			
		||||
        "point operation not supported for this mode");
 | 
			
		||||
    return (Imaging
 | 
			
		||||
    )ImagingError_ValueError("point operation not supported for this mode");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -103,7 +103,8 @@ static uint32_t
 | 
			
		|||
pixel_hash(const HashTable *h, const Pixel pixel) {
 | 
			
		||||
    PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
 | 
			
		||||
    return PIXEL_HASH(
 | 
			
		||||
        pixel.c.r >> d->scale, pixel.c.g >> d->scale, pixel.c.b >> d->scale);
 | 
			
		||||
        pixel.c.r >> d->scale, pixel.c.g >> d->scale, pixel.c.b >> d->scale
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int
 | 
			
		||||
| 
						 | 
				
			
			@ -111,9 +112,11 @@ pixel_cmp(const HashTable *h, const Pixel pixel1, const Pixel pixel2) {
 | 
			
		|||
    PixelHashData *d = (PixelHashData *)hashtable_get_user_data(h);
 | 
			
		||||
    uint32_t A, B;
 | 
			
		||||
    A = PIXEL_HASH(
 | 
			
		||||
        pixel1.c.r >> d->scale, pixel1.c.g >> d->scale, pixel1.c.b >> d->scale);
 | 
			
		||||
        pixel1.c.r >> d->scale, pixel1.c.g >> d->scale, pixel1.c.b >> d->scale
 | 
			
		||||
    );
 | 
			
		||||
    B = PIXEL_HASH(
 | 
			
		||||
        pixel2.c.r >> d->scale, pixel2.c.g >> d->scale, pixel2.c.b >> d->scale);
 | 
			
		||||
        pixel2.c.r >> d->scale, pixel2.c.g >> d->scale, pixel2.c.b >> d->scale
 | 
			
		||||
    );
 | 
			
		||||
    return (A == B) ? 0 : ((A < B) ? -1 : 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -129,7 +132,8 @@ new_count_func(const HashTable *h, const Pixel key, uint32_t *val) {
 | 
			
		|||
 | 
			
		||||
static void
 | 
			
		||||
rehash_collide(
 | 
			
		||||
    const HashTable *h, Pixel *keyp, uint32_t *valp, Pixel newkey, uint32_t newval) {
 | 
			
		||||
    const HashTable *h, Pixel *keyp, uint32_t *valp, Pixel newkey, uint32_t newval
 | 
			
		||||
) {
 | 
			
		||||
    *valp += newval;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +161,8 @@ create_pixel_hash(Pixel *pixelData, uint32_t nPixels) {
 | 
			
		|||
#endif
 | 
			
		||||
    for (i = 0; i < nPixels; i++) {
 | 
			
		||||
        if (!hashtable_insert_or_update_computed(
 | 
			
		||||
                hash, pixelData[i], new_count_func, exists_count_func)) {
 | 
			
		||||
                hash, pixelData[i], new_count_func, exists_count_func
 | 
			
		||||
            )) {
 | 
			
		||||
            ;
 | 
			
		||||
        }
 | 
			
		||||
        while (hashtable_get_count(hash) > MAX_HASH_ENTRIES) {
 | 
			
		||||
| 
						 | 
				
			
			@ -335,7 +340,8 @@ splitlists(
 | 
			
		|||
    PixelList *nt[2][3],
 | 
			
		||||
    uint32_t nCount[2],
 | 
			
		||||
    int axis,
 | 
			
		||||
    uint32_t pixelCount) {
 | 
			
		||||
    uint32_t pixelCount
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t left;
 | 
			
		||||
 | 
			
		||||
    PixelList *l, *r, *c, *n;
 | 
			
		||||
| 
						 | 
				
			
			@ -387,7 +393,8 @@ splitlists(
 | 
			
		|||
                    _prevCount[2],
 | 
			
		||||
                    _nextCount[0],
 | 
			
		||||
                    _nextCount[1],
 | 
			
		||||
                    _nextCount[2]);
 | 
			
		||||
                    _nextCount[2]
 | 
			
		||||
                );
 | 
			
		||||
                exit(1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -531,12 +538,14 @@ split(BoxNode *node) {
 | 
			
		|||
            if (node->tail[_i]->next[_i]) {
 | 
			
		||||
                printf("tail is not tail\n");
 | 
			
		||||
                printf(
 | 
			
		||||
                    "node->tail[%d]->next[%d]=%p\n", _i, _i, node->tail[_i]->next[_i]);
 | 
			
		||||
                    "node->tail[%d]->next[%d]=%p\n", _i, _i, node->tail[_i]->next[_i]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            if (node->head[_i]->prev[_i]) {
 | 
			
		||||
                printf("head is not head\n");
 | 
			
		||||
                printf(
 | 
			
		||||
                    "node->head[%d]->prev[%d]=%p\n", _i, _i, node->head[_i]->prev[_i]);
 | 
			
		||||
                    "node->head[%d]->prev[%d]=%p\n", _i, _i, node->head[_i]->prev[_i]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -573,14 +582,16 @@ split(BoxNode *node) {
 | 
			
		|||
                    _prevCount[2],
 | 
			
		||||
                    _nextCount[0],
 | 
			
		||||
                    _nextCount[1],
 | 
			
		||||
                    _nextCount[2]);
 | 
			
		||||
                    _nextCount[2]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    node->axis = axis;
 | 
			
		||||
    if (!splitlists(
 | 
			
		||||
            node->head, node->tail, heads, tails, newCounts, axis, node->pixelCount)) {
 | 
			
		||||
            node->head, node->tail, heads, tails, newCounts, axis, node->pixelCount
 | 
			
		||||
        )) {
 | 
			
		||||
#ifndef NO_OUTPUT
 | 
			
		||||
        printf("list split failed.\n");
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -772,7 +783,8 @@ _distance_index_cmp(const void *a, const void *b) {
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
resort_distance_tables(
 | 
			
		||||
    uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries) {
 | 
			
		||||
    uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t i, j, k;
 | 
			
		||||
    uint32_t **skRow;
 | 
			
		||||
    uint32_t *skElt;
 | 
			
		||||
| 
						 | 
				
			
			@ -801,7 +813,8 @@ resort_distance_tables(
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
build_distance_tables(
 | 
			
		||||
    uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries) {
 | 
			
		||||
    uint32_t *avgDist, uint32_t **avgDistSortKey, Pixel *p, uint32_t nEntries
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t i, j;
 | 
			
		||||
    DistanceWithIndex *dwi;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -841,7 +854,8 @@ map_image_pixels(
 | 
			
		|||
    uint32_t nPaletteEntries,
 | 
			
		||||
    uint32_t *avgDist,
 | 
			
		||||
    uint32_t **avgDistSortKey,
 | 
			
		||||
    uint32_t *pixelArray) {
 | 
			
		||||
    uint32_t *pixelArray
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t *aD, **aDSK;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
    uint32_t i, j;
 | 
			
		||||
| 
						 | 
				
			
			@ -888,7 +902,8 @@ map_image_pixels_from_quantized_pixels(
 | 
			
		|||
    uint32_t **avgDistSortKey,
 | 
			
		||||
    uint32_t *pixelArray,
 | 
			
		||||
    uint32_t *avg[3],
 | 
			
		||||
    uint32_t *count) {
 | 
			
		||||
    uint32_t *count
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t *aD, **aDSK;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
    uint32_t i, j;
 | 
			
		||||
| 
						 | 
				
			
			@ -946,7 +961,8 @@ map_image_pixels_from_median_box(
 | 
			
		|||
    HashTable *medianBoxHash,
 | 
			
		||||
    uint32_t *avgDist,
 | 
			
		||||
    uint32_t **avgDistSortKey,
 | 
			
		||||
    uint32_t *pixelArray) {
 | 
			
		||||
    uint32_t *pixelArray
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t *aD, **aDSK;
 | 
			
		||||
    uint32_t idx;
 | 
			
		||||
    uint32_t i, j;
 | 
			
		||||
| 
						 | 
				
			
			@ -998,7 +1014,8 @@ compute_palette_from_median_cut(
 | 
			
		|||
    uint32_t nPixels,
 | 
			
		||||
    HashTable *medianBoxHash,
 | 
			
		||||
    Pixel **palette,
 | 
			
		||||
    uint32_t nPaletteEntries) {
 | 
			
		||||
    uint32_t nPaletteEntries
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
    uint32_t paletteEntry;
 | 
			
		||||
    Pixel *p;
 | 
			
		||||
| 
						 | 
				
			
			@ -1055,7 +1072,8 @@ compute_palette_from_median_cut(
 | 
			
		|||
            printf(
 | 
			
		||||
                "panic - paletteEntry>=nPaletteEntries (%d>=%d)\n",
 | 
			
		||||
                (int)paletteEntry,
 | 
			
		||||
                (int)nPaletteEntries);
 | 
			
		||||
                (int)nPaletteEntries
 | 
			
		||||
            );
 | 
			
		||||
#endif
 | 
			
		||||
            for (i = 0; i < 3; i++) {
 | 
			
		||||
                free(avg[i]);
 | 
			
		||||
| 
						 | 
				
			
			@ -1092,7 +1110,8 @@ compute_palette_from_median_cut(
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
recompute_palette_from_averages(
 | 
			
		||||
    Pixel *palette, uint32_t nPaletteEntries, uint32_t *avg[3], uint32_t *count) {
 | 
			
		||||
    Pixel *palette, uint32_t nPaletteEntries, uint32_t *avg[3], uint32_t *count
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < nPaletteEntries; i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1111,7 +1130,8 @@ compute_palette_from_quantized_pixels(
 | 
			
		|||
    uint32_t nPaletteEntries,
 | 
			
		||||
    uint32_t *avg[3],
 | 
			
		||||
    uint32_t *count,
 | 
			
		||||
    uint32_t *qp) {
 | 
			
		||||
    uint32_t *qp
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
 | 
			
		||||
    memset(count, 0, sizeof(uint32_t) * nPaletteEntries);
 | 
			
		||||
| 
						 | 
				
			
			@ -1145,7 +1165,8 @@ k_means(
 | 
			
		|||
    Pixel *paletteData,
 | 
			
		||||
    uint32_t nPaletteEntries,
 | 
			
		||||
    uint32_t *qp,
 | 
			
		||||
    int threshold) {
 | 
			
		||||
    int threshold
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t *avg[3];
 | 
			
		||||
    uint32_t *count;
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
| 
						 | 
				
			
			@ -1194,16 +1215,19 @@ k_means(
 | 
			
		|||
    while (1) {
 | 
			
		||||
        if (!built) {
 | 
			
		||||
            compute_palette_from_quantized_pixels(
 | 
			
		||||
                pixelData, nPixels, paletteData, nPaletteEntries, avg, count, qp);
 | 
			
		||||
                pixelData, nPixels, paletteData, nPaletteEntries, avg, count, qp
 | 
			
		||||
            );
 | 
			
		||||
            if (!build_distance_tables(
 | 
			
		||||
                    avgDist, avgDistSortKey, paletteData, nPaletteEntries)) {
 | 
			
		||||
                    avgDist, avgDistSortKey, paletteData, nPaletteEntries
 | 
			
		||||
                )) {
 | 
			
		||||
                goto error_3;
 | 
			
		||||
            }
 | 
			
		||||
            built = 1;
 | 
			
		||||
        } else {
 | 
			
		||||
            recompute_palette_from_averages(paletteData, nPaletteEntries, avg, count);
 | 
			
		||||
            resort_distance_tables(
 | 
			
		||||
                avgDist, avgDistSortKey, paletteData, nPaletteEntries);
 | 
			
		||||
                avgDist, avgDistSortKey, paletteData, nPaletteEntries
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        changes = map_image_pixels_from_quantized_pixels(
 | 
			
		||||
            pixelData,
 | 
			
		||||
| 
						 | 
				
			
			@ -1214,7 +1238,8 @@ k_means(
 | 
			
		|||
            avgDistSortKey,
 | 
			
		||||
            qp,
 | 
			
		||||
            avg,
 | 
			
		||||
            count);
 | 
			
		||||
            count
 | 
			
		||||
        );
 | 
			
		||||
        if (changes < 0) {
 | 
			
		||||
            goto error_3;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1273,7 +1298,8 @@ quantize(
 | 
			
		|||
    Pixel **palette,
 | 
			
		||||
    uint32_t *paletteLength,
 | 
			
		||||
    uint32_t **quantizedPixels,
 | 
			
		||||
    int kmeans) {
 | 
			
		||||
    int kmeans
 | 
			
		||||
) {
 | 
			
		||||
    PixelList *hl[3];
 | 
			
		||||
    HashTable *h;
 | 
			
		||||
    BoxNode *root;
 | 
			
		||||
| 
						 | 
				
			
			@ -1399,7 +1425,8 @@ quantize(
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (!map_image_pixels_from_median_box(
 | 
			
		||||
            pixelData, nPixels, p, nPaletteEntries, h, avgDist, avgDistSortKey, qp)) {
 | 
			
		||||
            pixelData, nPixels, p, nPaletteEntries, h, avgDist, avgDistSortKey, qp
 | 
			
		||||
        )) {
 | 
			
		||||
        goto error_7;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1445,7 +1472,8 @@ quantize(
 | 
			
		|||
                                  _SQR(pixelData[i].c.b - p[qp[i]].c.b))),
 | 
			
		||||
                    sqrt((double)(_SQR(pixelData[i].c.r - p[bestmatch].c.r) +
 | 
			
		||||
                                  _SQR(pixelData[i].c.g - p[bestmatch].c.g) +
 | 
			
		||||
                                  _SQR(pixelData[i].c.b - p[bestmatch].c.b))));
 | 
			
		||||
                                  _SQR(pixelData[i].c.b - p[bestmatch].c.b)))
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        hashtable_free(h2);
 | 
			
		||||
| 
						 | 
				
			
			@ -1545,7 +1573,8 @@ quantize2(
 | 
			
		|||
    Pixel **palette,
 | 
			
		||||
    uint32_t *paletteLength,
 | 
			
		||||
    uint32_t **quantizedPixels,
 | 
			
		||||
    int kmeans) {
 | 
			
		||||
    int kmeans
 | 
			
		||||
) {
 | 
			
		||||
    HashTable *h;
 | 
			
		||||
    uint32_t i;
 | 
			
		||||
    uint32_t mean[3];
 | 
			
		||||
| 
						 | 
				
			
			@ -1609,7 +1638,8 @@ quantize2(
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    if (!map_image_pixels(
 | 
			
		||||
            pixelData, nPixels, p, nQuantPixels, avgDist, avgDistSortKey, qp)) {
 | 
			
		||||
            pixelData, nPixels, p, nQuantPixels, avgDist, avgDistSortKey, qp
 | 
			
		||||
        )) {
 | 
			
		||||
        goto error_4;
 | 
			
		||||
    }
 | 
			
		||||
    if (kmeans > 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1752,7 +1782,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
 | 
			
		|||
                &palette,
 | 
			
		||||
                &paletteLength,
 | 
			
		||||
                &newData,
 | 
			
		||||
                kmeans);
 | 
			
		||||
                kmeans
 | 
			
		||||
            );
 | 
			
		||||
            break;
 | 
			
		||||
        case 1:
 | 
			
		||||
            /* maximum coverage */
 | 
			
		||||
| 
						 | 
				
			
			@ -1763,7 +1794,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
 | 
			
		|||
                &palette,
 | 
			
		||||
                &paletteLength,
 | 
			
		||||
                &newData,
 | 
			
		||||
                kmeans);
 | 
			
		||||
                kmeans
 | 
			
		||||
            );
 | 
			
		||||
            break;
 | 
			
		||||
        case 2:
 | 
			
		||||
            result = quantize_octree(
 | 
			
		||||
| 
						 | 
				
			
			@ -1773,7 +1805,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
 | 
			
		|||
                &palette,
 | 
			
		||||
                &paletteLength,
 | 
			
		||||
                &newData,
 | 
			
		||||
                withAlpha);
 | 
			
		||||
                withAlpha
 | 
			
		||||
            );
 | 
			
		||||
            break;
 | 
			
		||||
        case 3:
 | 
			
		||||
#ifdef HAVE_LIBIMAGEQUANT
 | 
			
		||||
| 
						 | 
				
			
			@ -1785,7 +1818,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
 | 
			
		|||
                &palette,
 | 
			
		||||
                &paletteLength,
 | 
			
		||||
                &newData,
 | 
			
		||||
                withAlpha);
 | 
			
		||||
                withAlpha
 | 
			
		||||
            );
 | 
			
		||||
#else
 | 
			
		||||
            result = -1;
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -1836,7 +1870,8 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans) {
 | 
			
		|||
        if (result == -1) {
 | 
			
		||||
            return (Imaging)ImagingError_ValueError(
 | 
			
		||||
                "dependency required by this method was not "
 | 
			
		||||
                "enabled at compile time");
 | 
			
		||||
                "enabled at compile time"
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return (Imaging)ImagingError_ValueError("quantization error");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -132,7 +132,8 @@ _hashtable_resize(HashTable *h) {
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
_hashtable_insert_node(
 | 
			
		||||
    HashTable *h, HashNode *node, int resize, int update, CollisionFunc cf) {
 | 
			
		||||
    HashTable *h, HashNode *node, int resize, int update, CollisionFunc cf
 | 
			
		||||
) {
 | 
			
		||||
    uint32_t hash = h->hashFunc(h, node->key) % h->length;
 | 
			
		||||
    HashNode **n, *nv;
 | 
			
		||||
    int i;
 | 
			
		||||
| 
						 | 
				
			
			@ -207,7 +208,8 @@ _hashtable_insert(HashTable *h, HashKey_t key, HashVal_t val, int resize, int up
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
hashtable_insert_or_update_computed(
 | 
			
		||||
    HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc) {
 | 
			
		||||
    HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc
 | 
			
		||||
) {
 | 
			
		||||
    HashNode **n, *nv;
 | 
			
		||||
    HashNode *t;
 | 
			
		||||
    int i;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,13 +20,12 @@ typedef uint32_t HashVal_t;
 | 
			
		|||
 | 
			
		||||
typedef uint32_t (*HashFunc)(const HashTable *, const HashKey_t);
 | 
			
		||||
typedef int (*HashCmpFunc)(const HashTable *, const HashKey_t, const HashKey_t);
 | 
			
		||||
typedef void (*IteratorFunc)(
 | 
			
		||||
    const HashTable *, const HashKey_t, const HashVal_t, void *);
 | 
			
		||||
typedef void (*IteratorUpdateFunc)(
 | 
			
		||||
    const HashTable *, const HashKey_t, HashVal_t *, void *);
 | 
			
		||||
typedef void (*IteratorFunc)(const HashTable *, const HashKey_t, const HashVal_t, void *);
 | 
			
		||||
typedef void (*IteratorUpdateFunc)(const HashTable *, const HashKey_t, HashVal_t *, void *);
 | 
			
		||||
typedef void (*ComputeFunc)(const HashTable *, const HashKey_t, HashVal_t *);
 | 
			
		||||
typedef void (*CollisionFunc)(
 | 
			
		||||
    const HashTable *, HashKey_t *, HashVal_t *, HashKey_t, HashVal_t);
 | 
			
		||||
    const HashTable *, HashKey_t *, HashVal_t *, HashKey_t, HashVal_t
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
HashTable *
 | 
			
		||||
hashtable_new(HashFunc hf, HashCmpFunc cf);
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +41,8 @@ int
 | 
			
		|||
hashtable_lookup(const HashTable *h, const HashKey_t key, HashVal_t *valp);
 | 
			
		||||
int
 | 
			
		||||
hashtable_insert_or_update_computed(
 | 
			
		||||
    HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc);
 | 
			
		||||
    HashTable *h, HashKey_t key, ComputeFunc newFunc, ComputeFunc existsFunc
 | 
			
		||||
);
 | 
			
		||||
void *
 | 
			
		||||
hashtable_set_user_data(HashTable *h, void *data);
 | 
			
		||||
void *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -107,11 +107,8 @@ free_color_cube(ColorCube cube) {
 | 
			
		|||
 | 
			
		||||
static long
 | 
			
		||||
color_bucket_offset_pos(
 | 
			
		||||
    const ColorCube cube,
 | 
			
		||||
    unsigned int r,
 | 
			
		||||
    unsigned int g,
 | 
			
		||||
    unsigned int b,
 | 
			
		||||
    unsigned int a) {
 | 
			
		||||
    const ColorCube cube, unsigned int r, unsigned int g, unsigned int b, unsigned int a
 | 
			
		||||
) {
 | 
			
		||||
    return r << cube->rOffset | g << cube->gOffset | b << cube->bOffset |
 | 
			
		||||
           a << cube->aOffset;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -191,7 +188,8 @@ create_sorted_color_palette(const ColorCube cube) {
 | 
			
		|||
        buckets,
 | 
			
		||||
        cube->size,
 | 
			
		||||
        sizeof(struct _ColorBucket),
 | 
			
		||||
        (int (*)(void const *, void const *)) & compare_bucket_count);
 | 
			
		||||
        (int (*)(void const *, void const *)) & compare_bucket_count
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    return buckets;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -212,7 +210,8 @@ copy_color_cube(
 | 
			
		|||
    unsigned int rBits,
 | 
			
		||||
    unsigned int gBits,
 | 
			
		||||
    unsigned int bBits,
 | 
			
		||||
    unsigned int aBits) {
 | 
			
		||||
    unsigned int aBits
 | 
			
		||||
) {
 | 
			
		||||
    unsigned int r, g, b, a;
 | 
			
		||||
    long src_pos, dst_pos;
 | 
			
		||||
    unsigned int src_reduce[4] = {0}, dst_reduce[4] = {0};
 | 
			
		||||
| 
						 | 
				
			
			@ -262,15 +261,18 @@ copy_color_cube(
 | 
			
		|||
                        r >> src_reduce[0],
 | 
			
		||||
                        g >> src_reduce[1],
 | 
			
		||||
                        b >> src_reduce[2],
 | 
			
		||||
                        a >> src_reduce[3]);
 | 
			
		||||
                        a >> src_reduce[3]
 | 
			
		||||
                    );
 | 
			
		||||
                    dst_pos = color_bucket_offset_pos(
 | 
			
		||||
                        result,
 | 
			
		||||
                        r >> dst_reduce[0],
 | 
			
		||||
                        g >> dst_reduce[1],
 | 
			
		||||
                        b >> dst_reduce[2],
 | 
			
		||||
                        a >> dst_reduce[3]);
 | 
			
		||||
                        a >> dst_reduce[3]
 | 
			
		||||
                    );
 | 
			
		||||
                    add_bucket_values(
 | 
			
		||||
                        &cube->buckets[src_pos], &result->buckets[dst_pos]);
 | 
			
		||||
                        &cube->buckets[src_pos], &result->buckets[dst_pos]
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -328,7 +330,8 @@ combined_palette(
 | 
			
		|||
    ColorBucket bucketsA,
 | 
			
		||||
    unsigned long nBucketsA,
 | 
			
		||||
    ColorBucket bucketsB,
 | 
			
		||||
    unsigned long nBucketsB) {
 | 
			
		||||
    unsigned long nBucketsB
 | 
			
		||||
) {
 | 
			
		||||
    ColorBucket result;
 | 
			
		||||
    if (nBucketsA > LONG_MAX - nBucketsB ||
 | 
			
		||||
        (nBucketsA + nBucketsB) > LONG_MAX / sizeof(struct _ColorBucket)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -366,7 +369,8 @@ map_image_pixels(
 | 
			
		|||
    const Pixel *pixelData,
 | 
			
		||||
    uint32_t nPixels,
 | 
			
		||||
    const ColorCube lookupCube,
 | 
			
		||||
    uint32_t *pixelArray) {
 | 
			
		||||
    uint32_t *pixelArray
 | 
			
		||||
) {
 | 
			
		||||
    long i;
 | 
			
		||||
    for (i = 0; i < nPixels; i++) {
 | 
			
		||||
        pixelArray[i] = lookup_color(lookupCube, &pixelData[i]);
 | 
			
		||||
| 
						 | 
				
			
			@ -384,7 +388,8 @@ quantize_octree(
 | 
			
		|||
    Pixel **palette,
 | 
			
		||||
    uint32_t *paletteLength,
 | 
			
		||||
    uint32_t **quantizedPixels,
 | 
			
		||||
    int withAlpha) {
 | 
			
		||||
    int withAlpha
 | 
			
		||||
) {
 | 
			
		||||
    ColorCube fineCube = NULL;
 | 
			
		||||
    ColorCube coarseCube = NULL;
 | 
			
		||||
    ColorCube lookupCube = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -461,7 +466,8 @@ quantize_octree(
 | 
			
		|||
        subtract_color_buckets(
 | 
			
		||||
            coarseCube,
 | 
			
		||||
            &paletteBucketsFine[nAlreadySubtracted],
 | 
			
		||||
            nFineColors - nAlreadySubtracted);
 | 
			
		||||
            nFineColors - nAlreadySubtracted
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* create our palette buckets with fine and coarse combined */
 | 
			
		||||
| 
						 | 
				
			
			@ -470,7 +476,8 @@ quantize_octree(
 | 
			
		|||
        goto error;
 | 
			
		||||
    }
 | 
			
		||||
    paletteBuckets = combined_palette(
 | 
			
		||||
        paletteBucketsCoarse, nCoarseColors, paletteBucketsFine, nFineColors);
 | 
			
		||||
        paletteBucketsCoarse, nCoarseColors, paletteBucketsFine, nFineColors
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    free(paletteBucketsFine);
 | 
			
		||||
    paletteBucketsFine = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -491,7 +498,8 @@ quantize_octree(
 | 
			
		|||
    /* expand coarse cube (64) to larger fine cube (4k). the value of each
 | 
			
		||||
       coarse bucket is then present in the according 64 fine buckets. */
 | 
			
		||||
    lookupCube = copy_color_cube(
 | 
			
		||||
        coarseLookupCube, cubeBits[0], cubeBits[1], cubeBits[2], cubeBits[3]);
 | 
			
		||||
        coarseLookupCube, cubeBits[0], cubeBits[1], cubeBits[2], cubeBits[3]
 | 
			
		||||
    );
 | 
			
		||||
    if (!lookupCube) {
 | 
			
		||||
        goto error;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,7 +26,8 @@ quantize_pngquant(
 | 
			
		|||
    Pixel **palette,
 | 
			
		||||
    uint32_t *paletteLength,
 | 
			
		||||
    uint32_t **quantizedPixels,
 | 
			
		||||
    int withAlpha) {
 | 
			
		||||
    int withAlpha
 | 
			
		||||
) {
 | 
			
		||||
    int result = 0;
 | 
			
		||||
    liq_image *image = NULL;
 | 
			
		||||
    liq_attr *attr = NULL;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@ quantize_pngquant(
 | 
			
		|||
    Pixel **,
 | 
			
		||||
    uint32_t *,
 | 
			
		||||
    uint32_t **,
 | 
			
		||||
    int);
 | 
			
		||||
    int
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,7 +102,8 @@ MakeRankFunction(UINT8) MakeRankFunction(INT32) MakeRankFunction(FLOAT32)
 | 
			
		|||
                    memcpy(                                                       \
 | 
			
		||||
                        buf + i * size,                                           \
 | 
			
		||||
                        &IMAGING_PIXEL_##type(im, x, y + i),                      \
 | 
			
		||||
                        size * sizeof(type));                                     \
 | 
			
		||||
                        size * sizeof(type)                                       \
 | 
			
		||||
                    );                                                            \
 | 
			
		||||
                }                                                                 \
 | 
			
		||||
                IMAGING_PIXEL_##type(imOut, x, y) = Rank##type(buf, size2, rank); \
 | 
			
		||||
            }                                                                     \
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -74,7 +74,8 @@ ImagingRawDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
        state->shuffle(
 | 
			
		||||
            (UINT8 *)im->image[state->y + state->yoff] + state->xoff * im->pixelsize,
 | 
			
		||||
            ptr,
 | 
			
		||||
            state->xsize);
 | 
			
		||||
            state->xsize
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        ptr += state->bytes;
 | 
			
		||||
        bytes -= state->bytes;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -65,7 +65,8 @@ ImagingRawEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
        state->shuffle(
 | 
			
		||||
            ptr,
 | 
			
		||||
            (UINT8 *)im->image[state->y + state->yoff] + state->xoff * im->pixelsize,
 | 
			
		||||
            state->xsize);
 | 
			
		||||
            state->xsize
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if (state->bytes > state->count) {
 | 
			
		||||
            /* zero-pad the buffer, if necessary */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -82,7 +82,8 @@ ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
 | 
			
		|||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -124,7 +125,8 @@ ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -171,7 +173,8 @@ ImagingReduceNxN(Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +229,8 @@ ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale) {
 | 
			
		|||
                        ss3 += line[xx * 4 + 3];
 | 
			
		||||
                    }
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -251,7 +255,8 @@ ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale) {
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -278,7 +283,8 @@ ImagingReduce1xN(Imaging imOut, Imaging imIn, int box[4], int yscale) {
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -329,7 +335,8 @@ ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale) {
 | 
			
		|||
                        ss3 += line[xx * 4 + 3];
 | 
			
		||||
                    }
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss0 * multiplier) >> 24, 0, 0, (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -351,7 +358,8 @@ ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale) {
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -375,7 +383,8 @@ ImagingReduceNx1(Imaging imOut, Imaging imIn, int box[4], int xscale) {
 | 
			
		|||
                        (ss0 * multiplier) >> 24,
 | 
			
		||||
                        (ss1 * multiplier) >> 24,
 | 
			
		||||
                        (ss2 * multiplier) >> 24,
 | 
			
		||||
                        (ss3 * multiplier) >> 24);
 | 
			
		||||
                        (ss3 * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -425,7 +434,8 @@ ImagingReduce1x2(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                    ss1 = line0[xx * 4 + 1] + line1[xx * 4 + 1];
 | 
			
		||||
                    ss2 = line0[xx * 4 + 2] + line1[xx * 4 + 2];
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 + amend) >> 1, (ss1 + amend) >> 1, (ss2 + amend) >> 1, 0);
 | 
			
		||||
                        (ss0 + amend) >> 1, (ss1 + amend) >> 1, (ss2 + amend) >> 1, 0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -440,7 +450,8 @@ ImagingReduce1x2(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        (ss0 + amend) >> 1,
 | 
			
		||||
                        (ss1 + amend) >> 1,
 | 
			
		||||
                        (ss2 + amend) >> 1,
 | 
			
		||||
                        (ss3 + amend) >> 1);
 | 
			
		||||
                        (ss3 + amend) >> 1
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -488,7 +499,8 @@ ImagingReduce2x1(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                    ss1 = line0[xx * 4 + 1] + line0[xx * 4 + 5];
 | 
			
		||||
                    ss2 = line0[xx * 4 + 2] + line0[xx * 4 + 6];
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 + amend) >> 1, (ss1 + amend) >> 1, (ss2 + amend) >> 1, 0);
 | 
			
		||||
                        (ss0 + amend) >> 1, (ss1 + amend) >> 1, (ss2 + amend) >> 1, 0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -503,7 +515,8 @@ ImagingReduce2x1(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        (ss0 + amend) >> 1,
 | 
			
		||||
                        (ss1 + amend) >> 1,
 | 
			
		||||
                        (ss2 + amend) >> 1,
 | 
			
		||||
                        (ss3 + amend) >> 1);
 | 
			
		||||
                        (ss3 + amend) >> 1
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -558,7 +571,8 @@ ImagingReduce2x2(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                    ss2 = line0[xx * 4 + 2] + line0[xx * 4 + 6] + line1[xx * 4 + 2] +
 | 
			
		||||
                          line1[xx * 4 + 6];
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 + amend) >> 2, (ss1 + amend) >> 2, (ss2 + amend) >> 2, 0);
 | 
			
		||||
                        (ss0 + amend) >> 2, (ss1 + amend) >> 2, (ss2 + amend) >> 2, 0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -577,7 +591,8 @@ ImagingReduce2x2(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        (ss0 + amend) >> 2,
 | 
			
		||||
                        (ss1 + amend) >> 2,
 | 
			
		||||
                        (ss2 + amend) >> 2,
 | 
			
		||||
                        (ss3 + amend) >> 2);
 | 
			
		||||
                        (ss3 + amend) >> 2
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -623,7 +638,8 @@ ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0,
 | 
			
		||||
                        0,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -637,7 +653,8 @@ ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -652,7 +669,8 @@ ImagingReduce1x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -694,7 +712,8 @@ ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0,
 | 
			
		||||
                        0,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -708,7 +727,8 @@ ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -723,7 +743,8 @@ ImagingReduce3x1(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -775,7 +796,8 @@ ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0,
 | 
			
		||||
                        0,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -795,7 +817,8 @@ ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -818,7 +841,8 @@ ImagingReduce3x3(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -900,7 +924,8 @@ ImagingReduce4x4(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                          line3[xx * 4 + 2] + line3[xx * 4 + 6] + line3[xx * 4 + 10] +
 | 
			
		||||
                          line3[xx * 4 + 14];
 | 
			
		||||
                    v = MAKE_UINT32(
 | 
			
		||||
                        (ss0 + amend) >> 4, (ss1 + amend) >> 4, (ss2 + amend) >> 4, 0);
 | 
			
		||||
                        (ss0 + amend) >> 4, (ss1 + amend) >> 4, (ss2 + amend) >> 4, 0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -935,7 +960,8 @@ ImagingReduce4x4(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        (ss0 + amend) >> 4,
 | 
			
		||||
                        (ss1 + amend) >> 4,
 | 
			
		||||
                        (ss2 + amend) >> 4,
 | 
			
		||||
                        (ss3 + amend) >> 4);
 | 
			
		||||
                        (ss3 + amend) >> 4
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -1007,7 +1033,8 @@ ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0,
 | 
			
		||||
                        0,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else if (imIn->bands == 3) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1045,7 +1072,8 @@ ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        0);
 | 
			
		||||
                        0
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            } else {  // bands == 4
 | 
			
		||||
| 
						 | 
				
			
			@ -1092,7 +1120,8 @@ ImagingReduce5x5(Imaging imOut, Imaging imIn, int box[4]) {
 | 
			
		|||
                        ((ss0 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss1 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss2 + amend) * multiplier) >> 24,
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24);
 | 
			
		||||
                        ((ss3 + amend) * multiplier) >> 24
 | 
			
		||||
                    );
 | 
			
		||||
                    memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -1181,7 +1210,8 @@ ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int ys
 | 
			
		|||
                    (ss0 * multiplier) >> 24,
 | 
			
		||||
                    (ss1 * multiplier) >> 24,
 | 
			
		||||
                    (ss2 * multiplier) >> 24,
 | 
			
		||||
                    (ss3 * multiplier) >> 24);
 | 
			
		||||
                    (ss3 * multiplier) >> 24
 | 
			
		||||
                );
 | 
			
		||||
                memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1207,7 +1237,8 @@ ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int ys
 | 
			
		|||
                    (ss0 * multiplier) >> 24,
 | 
			
		||||
                    (ss1 * multiplier) >> 24,
 | 
			
		||||
                    (ss2 * multiplier) >> 24,
 | 
			
		||||
                    (ss3 * multiplier) >> 24);
 | 
			
		||||
                    (ss3 * multiplier) >> 24
 | 
			
		||||
                );
 | 
			
		||||
                memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1232,7 +1263,8 @@ ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int ys
 | 
			
		|||
                (ss0 * multiplier) >> 24,
 | 
			
		||||
                (ss1 * multiplier) >> 24,
 | 
			
		||||
                (ss2 * multiplier) >> 24,
 | 
			
		||||
                (ss3 * multiplier) >> 24);
 | 
			
		||||
                (ss3 * multiplier) >> 24
 | 
			
		||||
            );
 | 
			
		||||
            memcpy(imOut->image[y] + x * sizeof(v), &v, sizeof(v));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1240,7 +1272,8 @@ ImagingReduceCorners(Imaging imOut, Imaging imIn, int box[4], int xscale, int ys
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingReduceNxN_32bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
 | 
			
		||||
) {
 | 
			
		||||
    /* The most general implementation for any xscale and yscale
 | 
			
		||||
     */
 | 
			
		||||
    int x, y, xx, yy;
 | 
			
		||||
| 
						 | 
				
			
			@ -1313,7 +1346,8 @@ ImagingReduceNxN_32bpc(
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingReduceCorners_32bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int box[4], int xscale, int yscale
 | 
			
		||||
) {
 | 
			
		||||
    /* Fill the last row and the last column for any xscale and yscale.
 | 
			
		||||
     */
 | 
			
		||||
    int x, y, xx, yy;
 | 
			
		||||
| 
						 | 
				
			
			@ -1427,7 +1461,8 @@ ImagingReduce(Imaging imIn, int xscale, int yscale, int box[4]) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    imOut = ImagingNewDirty(
 | 
			
		||||
        imIn->mode, (box[2] + xscale - 1) / xscale, (box[3] + yscale - 1) / yscale);
 | 
			
		||||
        imIn->mode, (box[2] + xscale - 1) / xscale, (box[3] + yscale - 1) / yscale
 | 
			
		||||
    );
 | 
			
		||||
    if (!imOut) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -186,7 +186,8 @@ precompute_coeffs(
 | 
			
		|||
    int outSize,
 | 
			
		||||
    struct filter *filterp,
 | 
			
		||||
    int **boundsp,
 | 
			
		||||
    double **kkp) {
 | 
			
		||||
    double **kkp
 | 
			
		||||
) {
 | 
			
		||||
    double support, scale, filterscale;
 | 
			
		||||
    double center, ww, ss;
 | 
			
		||||
    int xx, x, ksize, xmin, xmax;
 | 
			
		||||
| 
						 | 
				
			
			@ -284,7 +285,8 @@ normalize_coeffs_8bpc(int outSize, int ksize, double *prekk) {
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingResampleHorizontal_8bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    int ss0, ss1, ss2, ss3;
 | 
			
		||||
    int xx, yy, x, xmin, xmax;
 | 
			
		||||
| 
						 | 
				
			
			@ -376,7 +378,8 @@ ImagingResampleHorizontal_8bpc(
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingResampleVertical_8bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *prekk
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    int ss0, ss1, ss2, ss3;
 | 
			
		||||
    int xx, yy, y, ymin, ymax;
 | 
			
		||||
| 
						 | 
				
			
			@ -459,7 +462,8 @@ ImagingResampleVertical_8bpc(
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingResampleHorizontal_32bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    double ss;
 | 
			
		||||
    int xx, yy, x, xmin, xmax;
 | 
			
		||||
| 
						 | 
				
			
			@ -502,7 +506,8 @@ ImagingResampleHorizontal_32bpc(
 | 
			
		|||
 | 
			
		||||
void
 | 
			
		||||
ImagingResampleVertical_32bpc(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    double ss;
 | 
			
		||||
    int xx, yy, y, ymin, ymax;
 | 
			
		||||
| 
						 | 
				
			
			@ -544,7 +549,8 @@ ImagingResampleVertical_32bpc(
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
typedef void (*ResampleFunction)(
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk);
 | 
			
		||||
    Imaging imOut, Imaging imIn, int offset, int ksize, int *bounds, double *kk
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
ImagingResampleInner(
 | 
			
		||||
| 
						 | 
				
			
			@ -554,7 +560,8 @@ ImagingResampleInner(
 | 
			
		|||
    struct filter *filterp,
 | 
			
		||||
    float box[4],
 | 
			
		||||
    ResampleFunction ResampleHorizontal,
 | 
			
		||||
    ResampleFunction ResampleVertical);
 | 
			
		||||
    ResampleFunction ResampleVertical
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]) {
 | 
			
		||||
| 
						 | 
				
			
			@ -609,7 +616,8 @@ ImagingResample(Imaging imIn, int xsize, int ysize, int filter, float box[4]) {
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    return ImagingResampleInner(
 | 
			
		||||
        imIn, xsize, ysize, filterp, box, ResampleHorizontal, ResampleVertical);
 | 
			
		||||
        imIn, xsize, ysize, filterp, box, ResampleHorizontal, ResampleVertical
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Imaging
 | 
			
		||||
| 
						 | 
				
			
			@ -620,7 +628,8 @@ ImagingResampleInner(
 | 
			
		|||
    struct filter *filterp,
 | 
			
		||||
    float box[4],
 | 
			
		||||
    ResampleFunction ResampleHorizontal,
 | 
			
		||||
    ResampleFunction ResampleVertical) {
 | 
			
		||||
    ResampleFunction ResampleVertical
 | 
			
		||||
) {
 | 
			
		||||
    Imaging imTemp = NULL;
 | 
			
		||||
    Imaging imOut = NULL;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -634,13 +643,15 @@ ImagingResampleInner(
 | 
			
		|||
    need_vertical = ysize != imIn->ysize || box[1] || box[3] != ysize;
 | 
			
		||||
 | 
			
		||||
    ksize_horiz = precompute_coeffs(
 | 
			
		||||
        imIn->xsize, box[0], box[2], xsize, filterp, &bounds_horiz, &kk_horiz);
 | 
			
		||||
        imIn->xsize, box[0], box[2], xsize, filterp, &bounds_horiz, &kk_horiz
 | 
			
		||||
    );
 | 
			
		||||
    if (!ksize_horiz) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ksize_vert = precompute_coeffs(
 | 
			
		||||
        imIn->ysize, box[1], box[3], ysize, filterp, &bounds_vert, &kk_vert);
 | 
			
		||||
        imIn->ysize, box[1], box[3], ysize, filterp, &bounds_vert, &kk_vert
 | 
			
		||||
    );
 | 
			
		||||
    if (!ksize_vert) {
 | 
			
		||||
        free(bounds_horiz);
 | 
			
		||||
        free(kk_horiz);
 | 
			
		||||
| 
						 | 
				
			
			@ -662,7 +673,8 @@ ImagingResampleInner(
 | 
			
		|||
        imTemp = ImagingNewDirty(imIn->mode, xsize, ybox_last - ybox_first);
 | 
			
		||||
        if (imTemp) {
 | 
			
		||||
            ResampleHorizontal(
 | 
			
		||||
                imTemp, imIn, ybox_first, ksize_horiz, bounds_horiz, kk_horiz);
 | 
			
		||||
                imTemp, imIn, ybox_first, ksize_horiz, bounds_horiz, kk_horiz
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        free(bounds_horiz);
 | 
			
		||||
        free(kk_horiz);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -114,7 +114,8 @@ expandrow(UINT8 *dest, UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer
 | 
			
		|||
 | 
			
		||||
static int
 | 
			
		||||
expandrow2(
 | 
			
		||||
    UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer) {
 | 
			
		||||
    UINT8 *dest, const UINT8 *src, int n, int z, int xsize, UINT8 *end_of_buffer
 | 
			
		||||
) {
 | 
			
		||||
    UINT8 pixel, count;
 | 
			
		||||
    int x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -252,7 +253,8 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
 | 
			
		|||
                    c->rlelength,
 | 
			
		||||
                    im->bands,
 | 
			
		||||
                    im->xsize,
 | 
			
		||||
                    &ptr[c->bufsize - 1]);
 | 
			
		||||
                    &ptr[c->bufsize - 1]
 | 
			
		||||
                );
 | 
			
		||||
            } else {
 | 
			
		||||
                status = expandrow2(
 | 
			
		||||
                    &state->buffer[c->channo * 2],
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +262,8 @@ ImagingSgiRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
 | 
			
		|||
                    c->rlelength,
 | 
			
		||||
                    im->bands,
 | 
			
		||||
                    im->xsize,
 | 
			
		||||
                    &ptr[c->bufsize - 1]);
 | 
			
		||||
                    &ptr[c->bufsize - 1]
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            if (status == -1) {
 | 
			
		||||
                state->errcode = IMAGING_CODEC_OVERRUN;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -110,9 +110,8 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
 | 
			
		|||
        im->linesize = xsize * 4;
 | 
			
		||||
        im->type = IMAGING_TYPE_INT32;
 | 
			
		||||
 | 
			
		||||
    } else if (
 | 
			
		||||
        strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16L") == 0 ||
 | 
			
		||||
        strcmp(mode, "I;16B") == 0 || strcmp(mode, "I;16N") == 0) {
 | 
			
		||||
    } else if (strcmp(mode, "I;16") == 0 || strcmp(mode, "I;16L") == 0 ||
 | 
			
		||||
               strcmp(mode, "I;16B") == 0 || strcmp(mode, "I;16N") == 0) {
 | 
			
		||||
        /* EXPERIMENTAL */
 | 
			
		||||
        /* 16-bit raw integer images */
 | 
			
		||||
        im->bands = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -227,7 +226,8 @@ ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int size) {
 | 
			
		|||
Imaging
 | 
			
		||||
ImagingNewPrologue(const char *mode, int xsize, int ysize) {
 | 
			
		||||
    return ImagingNewPrologueSubtype(
 | 
			
		||||
        mode, xsize, ysize, sizeof(struct ImagingMemoryInstance));
 | 
			
		||||
        mode, xsize, ysize, sizeof(struct ImagingMemoryInstance)
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -107,7 +107,8 @@ ImagingSunRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
 | 
			
		|||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->buffer,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                state->x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -93,7 +93,8 @@ ImagingTgaRleDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t
 | 
			
		|||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->buffer,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                state->x = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -63,7 +63,8 @@ ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
 | 
			
		|||
                    state->buffer,
 | 
			
		||||
                    (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            row = state->buffer;
 | 
			
		||||
| 
						 | 
				
			
			@ -146,7 +147,8 @@ ImagingTgaRleEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes)
 | 
			
		|||
        }
 | 
			
		||||
 | 
			
		||||
        memcpy(
 | 
			
		||||
            dst, state->buffer + (state->x * bytesPerPixel - state->count), flushCount);
 | 
			
		||||
            dst, state->buffer + (state->x * bytesPerPixel - state->count), flushCount
 | 
			
		||||
        );
 | 
			
		||||
        dst += flushCount;
 | 
			
		||||
        bytes -= flushCount;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,7 +44,8 @@ dump_state(const TIFFSTATE *state) {
 | 
			
		|||
         (int)state->size,
 | 
			
		||||
         (uint)state->eof,
 | 
			
		||||
         state->data,
 | 
			
		||||
         state->ifd));
 | 
			
		||||
         state->ifd)
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +65,8 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
 | 
			
		|||
            "_tiffReadProc",
 | 
			
		||||
            "Invalid Read at loc %" PRIu64 ", eof: %" PRIu64,
 | 
			
		||||
            state->loc,
 | 
			
		||||
            state->eof);
 | 
			
		||||
            state->eof
 | 
			
		||||
        );
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
 | 
			
		||||
| 
						 | 
				
			
			@ -200,13 +202,15 @@ ImagingLibTiffInit(ImagingCodecState state, int fp, uint32_t offset) {
 | 
			
		|||
         state->state,
 | 
			
		||||
         state->x,
 | 
			
		||||
         state->y,
 | 
			
		||||
         state->ystep));
 | 
			
		||||
         state->ystep)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State: xsize %d, ysize %d, xoff %d, yoff %d \n",
 | 
			
		||||
         state->xsize,
 | 
			
		||||
         state->ysize,
 | 
			
		||||
         state->xoff,
 | 
			
		||||
         state->yoff));
 | 
			
		||||
         state->yoff)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes));
 | 
			
		||||
    TRACE(("State: context %p \n", state->context));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -226,7 +230,8 @@ _pickUnpackers(
 | 
			
		|||
    ImagingCodecState state,
 | 
			
		||||
    TIFF *tiff,
 | 
			
		||||
    uint16_t planarconfig,
 | 
			
		||||
    ImagingShuffler *unpackers) {
 | 
			
		||||
    ImagingShuffler *unpackers
 | 
			
		||||
) {
 | 
			
		||||
    // if number of bands is 1, there is no difference with contig case
 | 
			
		||||
    if (planarconfig == PLANARCONFIG_SEPARATE && im->bands > 1) {
 | 
			
		||||
        uint16_t bits_per_sample = 8;
 | 
			
		||||
| 
						 | 
				
			
			@ -356,7 +361,8 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
 | 
			
		|||
                (UINT8 *)im->image[state->y + state->yoff + current_row] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->buffer + current_row * row_byte_size,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -374,7 +380,8 @@ _decodeTile(
 | 
			
		|||
    ImagingCodecState state,
 | 
			
		||||
    TIFF *tiff,
 | 
			
		||||
    int planes,
 | 
			
		||||
    ImagingShuffler *unpackers) {
 | 
			
		||||
    ImagingShuffler *unpackers
 | 
			
		||||
) {
 | 
			
		||||
    INT32 x, y, tile_y, current_tile_length, current_tile_width;
 | 
			
		||||
    UINT32 tile_width, tile_length;
 | 
			
		||||
    tsize_t tile_bytes_size, row_byte_size;
 | 
			
		||||
| 
						 | 
				
			
			@ -453,7 +460,8 @@ _decodeTile(
 | 
			
		|||
                        ("Writing tile data at %dx%d using tile_width: %d; \n",
 | 
			
		||||
                         tile_y + y,
 | 
			
		||||
                         x,
 | 
			
		||||
                         current_tile_width));
 | 
			
		||||
                         current_tile_width)
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                    // UINT8 * bbb = state->buffer + tile_y * row_byte_size;
 | 
			
		||||
                    // TRACE(("chars: %x%x%x%x\n", ((UINT8 *)bbb)[0], ((UINT8 *)bbb)[1],
 | 
			
		||||
| 
						 | 
				
			
			@ -462,7 +470,8 @@ _decodeTile(
 | 
			
		|||
                    shuffler(
 | 
			
		||||
                        (UINT8 *)im->image[tile_y + y] + x * im->pixelsize,
 | 
			
		||||
                        state->buffer + tile_y * row_byte_size,
 | 
			
		||||
                        current_tile_width);
 | 
			
		||||
                        current_tile_width
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -477,7 +486,8 @@ _decodeStrip(
 | 
			
		|||
    ImagingCodecState state,
 | 
			
		||||
    TIFF *tiff,
 | 
			
		||||
    int planes,
 | 
			
		||||
    ImagingShuffler *unpackers) {
 | 
			
		||||
    ImagingShuffler *unpackers
 | 
			
		||||
) {
 | 
			
		||||
    INT32 strip_row = 0;
 | 
			
		||||
    UINT8 *new_data;
 | 
			
		||||
    UINT32 rows_per_strip;
 | 
			
		||||
| 
						 | 
				
			
			@ -544,9 +554,10 @@ _decodeStrip(
 | 
			
		|||
                    tiff,
 | 
			
		||||
                    TIFFComputeStrip(tiff, state->y, plane),
 | 
			
		||||
                    (tdata_t)state->buffer,
 | 
			
		||||
                    strip_size) == -1) {
 | 
			
		||||
                TRACE(
 | 
			
		||||
                    ("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0)));
 | 
			
		||||
                    strip_size
 | 
			
		||||
                ) == -1) {
 | 
			
		||||
                TRACE(("Decode Error, strip %d\n", TIFFComputeStrip(tiff, state->y, 0))
 | 
			
		||||
                );
 | 
			
		||||
                state->errcode = IMAGING_CODEC_BROKEN;
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -567,7 +578,8 @@ _decodeStrip(
 | 
			
		|||
                    (UINT8 *)im->image[state->y + state->yoff + strip_row] +
 | 
			
		||||
                        state->xoff * im->pixelsize,
 | 
			
		||||
                    state->buffer + strip_row * row_byte_size,
 | 
			
		||||
                    state->xsize);
 | 
			
		||||
                    state->xsize
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -577,7 +589,8 @@ _decodeStrip(
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingLibTiffDecode(
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes) {
 | 
			
		||||
    Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes
 | 
			
		||||
) {
 | 
			
		||||
    TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
 | 
			
		||||
    char *filename = "tempfile.tif";
 | 
			
		||||
    char *mode = "rC";
 | 
			
		||||
| 
						 | 
				
			
			@ -602,13 +615,15 @@ ImagingLibTiffDecode(
 | 
			
		|||
         state->state,
 | 
			
		||||
         state->x,
 | 
			
		||||
         state->y,
 | 
			
		||||
         state->ystep));
 | 
			
		||||
         state->ystep)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State: xsize %d, ysize %d, xoff %d, yoff %d \n",
 | 
			
		||||
         state->xsize,
 | 
			
		||||
         state->ysize,
 | 
			
		||||
         state->xoff,
 | 
			
		||||
         state->yoff));
 | 
			
		||||
         state->yoff)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes));
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Buffer: %p: %c%c%c%c\n",
 | 
			
		||||
| 
						 | 
				
			
			@ -616,26 +631,30 @@ ImagingLibTiffDecode(
 | 
			
		|||
         (char)buffer[0],
 | 
			
		||||
         (char)buffer[1],
 | 
			
		||||
         (char)buffer[2],
 | 
			
		||||
         (char)buffer[3]));
 | 
			
		||||
         (char)buffer[3])
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State->Buffer: %c%c%c%c\n",
 | 
			
		||||
         (char)state->buffer[0],
 | 
			
		||||
         (char)state->buffer[1],
 | 
			
		||||
         (char)state->buffer[2],
 | 
			
		||||
         (char)state->buffer[3]));
 | 
			
		||||
         (char)state->buffer[3])
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Image: mode %s, type %d, bands: %d, xsize %d, ysize %d \n",
 | 
			
		||||
         im->mode,
 | 
			
		||||
         im->type,
 | 
			
		||||
         im->bands,
 | 
			
		||||
         im->xsize,
 | 
			
		||||
         im->ysize));
 | 
			
		||||
         im->ysize)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Image: image8 %p, image32 %p, image %p, block %p \n",
 | 
			
		||||
         im->image8,
 | 
			
		||||
         im->image32,
 | 
			
		||||
         im->image,
 | 
			
		||||
         im->block));
 | 
			
		||||
         im->block)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("Image: pixelsize: %d, linesize %d \n", im->pixelsize, im->linesize));
 | 
			
		||||
 | 
			
		||||
    dump_state(clientstate);
 | 
			
		||||
| 
						 | 
				
			
			@ -665,7 +684,8 @@ ImagingLibTiffDecode(
 | 
			
		|||
            _tiffCloseProc,
 | 
			
		||||
            _tiffSizeProc,
 | 
			
		||||
            _tiffMapProc,
 | 
			
		||||
            _tiffUnmapProc);
 | 
			
		||||
            _tiffUnmapProc
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!tiff) {
 | 
			
		||||
| 
						 | 
				
			
			@ -694,7 +714,8 @@ ImagingLibTiffDecode(
 | 
			
		|||
             state->xsize,
 | 
			
		||||
             img_width,
 | 
			
		||||
             state->ysize,
 | 
			
		||||
             img_height));
 | 
			
		||||
             img_height)
 | 
			
		||||
        );
 | 
			
		||||
        state->errcode = IMAGING_CODEC_BROKEN;
 | 
			
		||||
        goto decode_err;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -739,7 +760,8 @@ ImagingLibTiffDecode(
 | 
			
		|||
                INT32 y;
 | 
			
		||||
 | 
			
		||||
                TIFFGetFieldDefaulted(
 | 
			
		||||
                    tiff, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo);
 | 
			
		||||
                    tiff, TIFFTAG_EXTRASAMPLES, &extrasamples, &sampleinfo
 | 
			
		||||
                );
 | 
			
		||||
 | 
			
		||||
                if (extrasamples >= 1 && (sampleinfo[0] == EXTRASAMPLE_UNSPECIFIED ||
 | 
			
		||||
                                          sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -793,13 +815,15 @@ ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
 | 
			
		|||
         state->state,
 | 
			
		||||
         state->x,
 | 
			
		||||
         state->y,
 | 
			
		||||
         state->ystep));
 | 
			
		||||
         state->ystep)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State: xsize %d, ysize %d, xoff %d, yoff %d \n",
 | 
			
		||||
         state->xsize,
 | 
			
		||||
         state->ysize,
 | 
			
		||||
         state->xoff,
 | 
			
		||||
         state->yoff));
 | 
			
		||||
         state->yoff)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes));
 | 
			
		||||
    TRACE(("State: context %p \n", state->context));
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -839,7 +863,8 @@ ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
 | 
			
		|||
            _tiffCloseProc,
 | 
			
		||||
            _tiffSizeProc,
 | 
			
		||||
            _tiffNullMapProc,
 | 
			
		||||
            _tiffUnmapProc); /*force no mmap*/
 | 
			
		||||
            _tiffUnmapProc
 | 
			
		||||
        ); /*force no mmap*/
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!clientstate->tiff) {
 | 
			
		||||
| 
						 | 
				
			
			@ -852,7 +877,8 @@ ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp) {
 | 
			
		|||
 | 
			
		||||
int
 | 
			
		||||
ImagingLibTiffMergeFieldInfo(
 | 
			
		||||
    ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length) {
 | 
			
		||||
    ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length
 | 
			
		||||
) {
 | 
			
		||||
    // Refer to libtiff docs (http://www.simplesystems.org/libtiff/addingtags.html)
 | 
			
		||||
    TIFFSTATE *clientstate = (TIFFSTATE *)state->context;
 | 
			
		||||
    uint32_t n;
 | 
			
		||||
| 
						 | 
				
			
			@ -874,7 +900,8 @@ ImagingLibTiffMergeFieldInfo(
 | 
			
		|||
         FIELD_CUSTOM,
 | 
			
		||||
         1,
 | 
			
		||||
         passcount,
 | 
			
		||||
         "CustomField"}};
 | 
			
		||||
         "CustomField"}
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    n = sizeof(info) / sizeof(info[0]);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -922,13 +949,15 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
 | 
			
		|||
         state->state,
 | 
			
		||||
         state->x,
 | 
			
		||||
         state->y,
 | 
			
		||||
         state->ystep));
 | 
			
		||||
         state->ystep)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State: xsize %d, ysize %d, xoff %d, yoff %d \n",
 | 
			
		||||
         state->xsize,
 | 
			
		||||
         state->ysize,
 | 
			
		||||
         state->xoff,
 | 
			
		||||
         state->yoff));
 | 
			
		||||
         state->yoff)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("State: bits %d, bytes %d \n", state->bits, state->bytes));
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Buffer: %p: %c%c%c%c\n",
 | 
			
		||||
| 
						 | 
				
			
			@ -936,26 +965,30 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
 | 
			
		|||
         (char)buffer[0],
 | 
			
		||||
         (char)buffer[1],
 | 
			
		||||
         (char)buffer[2],
 | 
			
		||||
         (char)buffer[3]));
 | 
			
		||||
         (char)buffer[3])
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("State->Buffer: %c%c%c%c\n",
 | 
			
		||||
         (char)state->buffer[0],
 | 
			
		||||
         (char)state->buffer[1],
 | 
			
		||||
         (char)state->buffer[2],
 | 
			
		||||
         (char)state->buffer[3]));
 | 
			
		||||
         (char)state->buffer[3])
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Image: mode %s, type %d, bands: %d, xsize %d, ysize %d \n",
 | 
			
		||||
         im->mode,
 | 
			
		||||
         im->type,
 | 
			
		||||
         im->bands,
 | 
			
		||||
         im->xsize,
 | 
			
		||||
         im->ysize));
 | 
			
		||||
         im->ysize)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(
 | 
			
		||||
        ("Image: image8 %p, image32 %p, image %p, block %p \n",
 | 
			
		||||
         im->image8,
 | 
			
		||||
         im->image32,
 | 
			
		||||
         im->image,
 | 
			
		||||
         im->block));
 | 
			
		||||
         im->block)
 | 
			
		||||
    );
 | 
			
		||||
    TRACE(("Image: pixelsize: %d, linesize %d \n", im->pixelsize, im->linesize));
 | 
			
		||||
 | 
			
		||||
    dump_state(clientstate);
 | 
			
		||||
| 
						 | 
				
			
			@ -967,10 +1000,12 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
 | 
			
		|||
                state->buffer,
 | 
			
		||||
                (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if (TIFFWriteScanline(
 | 
			
		||||
                    tiff, (tdata_t)(state->buffer), (uint32_t)state->y, 0) == -1) {
 | 
			
		||||
                    tiff, (tdata_t)(state->buffer), (uint32_t)state->y, 0
 | 
			
		||||
                ) == -1) {
 | 
			
		||||
                TRACE(("Encode Error, row %d\n", state->y));
 | 
			
		||||
                state->errcode = IMAGING_CODEC_BROKEN;
 | 
			
		||||
                TIFFClose(tiff);
 | 
			
		||||
| 
						 | 
				
			
			@ -1013,7 +1048,8 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
 | 
			
		|||
             (char)buffer[0],
 | 
			
		||||
             (char)buffer[1],
 | 
			
		||||
             (char)buffer[2],
 | 
			
		||||
             (char)buffer[3]));
 | 
			
		||||
             (char)buffer[3])
 | 
			
		||||
        );
 | 
			
		||||
        if (clientstate->loc == clientstate->eof) {
 | 
			
		||||
            TRACE(("Hit EOF, calling an end, freeing data"));
 | 
			
		||||
            state->errcode = IMAGING_CODEC_END;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,7 +41,8 @@ extern int
 | 
			
		|||
ImagingLibTiffEncodeInit(ImagingCodecState state, char *filename, int fp);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingLibTiffMergeFieldInfo(
 | 
			
		||||
    ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length);
 | 
			
		||||
    ImagingCodecState state, TIFFDataType field_type, int key, int is_var_length
 | 
			
		||||
);
 | 
			
		||||
extern int
 | 
			
		||||
ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -104,7 +104,8 @@ static UINT8 BITFLIP[] = {
 | 
			
		|||
    3,  131, 67, 195, 35, 163, 99,  227, 19, 147, 83, 211, 51, 179, 115, 243,
 | 
			
		||||
    11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251,
 | 
			
		||||
    7,  135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247,
 | 
			
		||||
    15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255};
 | 
			
		||||
    15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Unpack to "1" image */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -882,7 +883,8 @@ unpackRGBa16L(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[1] * 255 / a),
 | 
			
		||||
                CLIP8(in[3] * 255 / a),
 | 
			
		||||
                CLIP8(in[5] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        memcpy(_out, &iv, sizeof(iv));
 | 
			
		||||
        in += 8;
 | 
			
		||||
| 
						 | 
				
			
			@ -906,7 +908,8 @@ unpackRGBa16B(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[0] * 255 / a),
 | 
			
		||||
                CLIP8(in[2] * 255 / a),
 | 
			
		||||
                CLIP8(in[4] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        memcpy(_out, &iv, sizeof(iv));
 | 
			
		||||
        in += 8;
 | 
			
		||||
| 
						 | 
				
			
			@ -930,7 +933,8 @@ unpackRGBa(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[0] * 255 / a),
 | 
			
		||||
                CLIP8(in[1] * 255 / a),
 | 
			
		||||
                CLIP8(in[2] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        memcpy(_out, &iv, sizeof(iv));
 | 
			
		||||
        in += 4;
 | 
			
		||||
| 
						 | 
				
			
			@ -954,7 +958,8 @@ unpackRGBaskip1(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[0] * 255 / a),
 | 
			
		||||
                CLIP8(in[1] * 255 / a),
 | 
			
		||||
                CLIP8(in[2] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        in += 5;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -976,7 +981,8 @@ unpackRGBaskip2(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[0] * 255 / a),
 | 
			
		||||
                CLIP8(in[1] * 255 / a),
 | 
			
		||||
                CLIP8(in[2] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        in += 6;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -998,7 +1004,8 @@ unpackBGRa(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
                CLIP8(in[2] * 255 / a),
 | 
			
		||||
                CLIP8(in[1] * 255 / a),
 | 
			
		||||
                CLIP8(in[0] * 255 / a),
 | 
			
		||||
                a);
 | 
			
		||||
                a
 | 
			
		||||
            );
 | 
			
		||||
        }
 | 
			
		||||
        memcpy(_out, &iv, sizeof(iv));
 | 
			
		||||
        in += 4;
 | 
			
		||||
| 
						 | 
				
			
			@ -1029,7 +1036,8 @@ unpackRGBAL(UINT8 *_out, const UINT8 *in, int pixels) {
 | 
			
		|||
            in[i],
 | 
			
		||||
            in[i + pixels],
 | 
			
		||||
            in[i + pixels + pixels],
 | 
			
		||||
            in[i + pixels + pixels + pixels]);
 | 
			
		||||
            in[i + pixels + pixels + pixels]
 | 
			
		||||
        );
 | 
			
		||||
        memcpy(_out, &iv, sizeof(iv));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,7 +34,8 @@ static INT16 L[] = {
 | 
			
		|||
    261, 262, 264, 265, 266, 268, 269, 270, 272, 273, 274, 276, 277, 278, 280, 281,
 | 
			
		||||
    283, 284, 285, 287, 288, 289, 291, 292, 293, 295, 296, 297, 299, 300, 302, 303,
 | 
			
		||||
    304, 306, 307, 308, 310, 311, 312, 314, 315, 317, 318, 319, 321, 322, 323, 325,
 | 
			
		||||
    326, 327, 329, 330, 331, 333, 334, 336, 337, 338, 340, 341, 342, 344, 345, 346};
 | 
			
		||||
    326, 327, 329, 330, 331, 333, 334, 336, 337, 338, 340, 341, 342, 344, 345, 346
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 CB[] = {
 | 
			
		||||
    -345, -343, -341, -338, -336, -334, -332, -329, -327, -325, -323, -321, -318, -316,
 | 
			
		||||
| 
						 | 
				
			
			@ -55,7 +56,8 @@ static INT16 CB[] = {
 | 
			
		|||
    120,  122,  124,  126,  129,  131,  133,  135,  138,  140,  142,  144,  146,  149,
 | 
			
		||||
    151,  153,  155,  157,  160,  162,  164,  166,  169,  171,  173,  175,  177,  180,
 | 
			
		||||
    182,  184,  186,  189,  191,  193,  195,  197,  200,  202,  204,  206,  208,  211,
 | 
			
		||||
    213,  215,  217,  220};
 | 
			
		||||
    213,  215,  217,  220
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 GB[] = {
 | 
			
		||||
    67,  67,  66,  66,  65,  65,  65,  64,  64,  63,  63,  62,  62,  62,  61,  61,
 | 
			
		||||
| 
						 | 
				
			
			@ -73,7 +75,8 @@ static INT16 GB[] = {
 | 
			
		|||
    -14, -15, -15, -16, -16, -17, -17, -18, -18, -18, -19, -19, -20, -20, -21, -21,
 | 
			
		||||
    -21, -22, -22, -23, -23, -24, -24, -24, -25, -25, -26, -26, -27, -27, -27, -28,
 | 
			
		||||
    -28, -29, -29, -30, -30, -30, -31, -31, -32, -32, -33, -33, -33, -34, -34, -35,
 | 
			
		||||
    -35, -36, -36, -36, -37, -37, -38, -38, -39, -39, -39, -40, -40, -41, -41, -42};
 | 
			
		||||
    -35, -36, -36, -36, -37, -37, -38, -38, -39, -39, -39, -40, -40, -41, -41, -42
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 CR[] = {
 | 
			
		||||
    -249, -247, -245, -243, -241, -239, -238, -236, -234, -232, -230, -229, -227, -225,
 | 
			
		||||
| 
						 | 
				
			
			@ -94,7 +97,8 @@ static INT16 CR[] = {
 | 
			
		|||
    133,  135,  137,  138,  140,  142,  144,  146,  148,  149,  151,  153,  155,  157,
 | 
			
		||||
    158,  160,  162,  164,  166,  168,  169,  171,  173,  175,  177,  179,  180,  182,
 | 
			
		||||
    184,  186,  188,  189,  191,  193,  195,  197,  199,  200,  202,  204,  206,  208,
 | 
			
		||||
    209,  211,  213,  215};
 | 
			
		||||
    209,  211,  213,  215
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static INT16 GR[] = {
 | 
			
		||||
    127, 126, 125, 124, 123, 122, 121,  121,  120,  119,  118,  117,  116,  115,  114,
 | 
			
		||||
| 
						 | 
				
			
			@ -114,7 +118,8 @@ static INT16 GR[] = {
 | 
			
		|||
    -67, -68, -69, -69, -70, -71, -72,  -73,  -74,  -75,  -76,  -77,  -78,  -79,  -80,
 | 
			
		||||
    -81, -82, -82, -83, -84, -85, -86,  -87,  -88,  -89,  -90,  -91,  -92,  -93,  -94,
 | 
			
		||||
    -94, -95, -96, -97, -98, -99, -100, -101, -102, -103, -104, -105, -106, -107, -107,
 | 
			
		||||
    -108};
 | 
			
		||||
    -108
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define R 0
 | 
			
		||||
#define G 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,8 @@ clip8(int in) {
 | 
			
		|||
 | 
			
		||||
Imaging
 | 
			
		||||
ImagingUnsharpMask(
 | 
			
		||||
    Imaging imOut, Imaging imIn, float radius, int percent, int threshold) {
 | 
			
		||||
    Imaging imOut, Imaging imIn, float radius, int percent, int threshold
 | 
			
		||||
) {
 | 
			
		||||
    ImagingSectionCookie cookie;
 | 
			
		||||
    Imaging result;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,7 +40,8 @@ ImagingXbmEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
        state->shuffle(
 | 
			
		||||
            state->buffer,
 | 
			
		||||
            (UINT8 *)im->image[state->y + state->yoff] + state->xoff * im->pixelsize,
 | 
			
		||||
            state->xsize);
 | 
			
		||||
            state->xsize
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        if (state->y < state->ysize - 1) {
 | 
			
		||||
            /* any line but the last */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -217,7 +217,8 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
                    state->shuffle(
 | 
			
		||||
                        (UINT8 *)im->image[state->y] + col * im->pixelsize,
 | 
			
		||||
                        state->buffer + context->prefix + i,
 | 
			
		||||
                        1);
 | 
			
		||||
                        1
 | 
			
		||||
                    );
 | 
			
		||||
                    col += COL_INCREMENT[context->pass];
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -229,7 +230,8 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
                    UINT8 byte = *(state->buffer + context->prefix + (i / 8));
 | 
			
		||||
                    byte <<= (i % 8);
 | 
			
		||||
                    state->shuffle(
 | 
			
		||||
                        (UINT8 *)im->image[state->y] + col * im->pixelsize, &byte, 1);
 | 
			
		||||
                        (UINT8 *)im->image[state->y] + col * im->pixelsize, &byte, 1
 | 
			
		||||
                    );
 | 
			
		||||
                    col += COL_INCREMENT[context->pass];
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			@ -253,7 +255,8 @@ ImagingZipDecode(Imaging im, ImagingCodecState state, UINT8 *buf, Py_ssize_t byt
 | 
			
		|||
                (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                    state->xoff * im->pixelsize,
 | 
			
		||||
                state->buffer + context->prefix,
 | 
			
		||||
                state->xsize);
 | 
			
		||||
                state->xsize
 | 
			
		||||
            );
 | 
			
		||||
            state->y++;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -98,7 +98,8 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
            15,
 | 
			
		||||
            9,
 | 
			
		||||
            /* compression strategy (image data are filtered)*/
 | 
			
		||||
            compress_type);
 | 
			
		||||
            compress_type
 | 
			
		||||
        );
 | 
			
		||||
        if (err < 0) {
 | 
			
		||||
            state->errcode = IMAGING_CODEC_CONFIG;
 | 
			
		||||
            return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +109,8 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
            err = deflateSetDictionary(
 | 
			
		||||
                &context->z_stream,
 | 
			
		||||
                (unsigned char *)context->dictionary,
 | 
			
		||||
                context->dictionary_size);
 | 
			
		||||
                context->dictionary_size
 | 
			
		||||
            );
 | 
			
		||||
            if (err < 0) {
 | 
			
		||||
                state->errcode = IMAGING_CODEC_CONFIG;
 | 
			
		||||
                return -1;
 | 
			
		||||
| 
						 | 
				
			
			@ -163,7 +165,8 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
 | 
			
		|||
                        state->buffer + 1,
 | 
			
		||||
                        (UINT8 *)im->image[state->y + state->yoff] +
 | 
			
		||||
                            state->xoff * im->pixelsize,
 | 
			
		||||
                        state->xsize);
 | 
			
		||||
                        state->xsize
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                    state->y++;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -72,7 +72,8 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
 | 
			
		|||
            &offset,
 | 
			
		||||
            &mode,
 | 
			
		||||
            &stride,
 | 
			
		||||
            &ystep)) {
 | 
			
		||||
            &ystep
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -489,7 +489,8 @@ path_transform(PyPathObject *self, PyObject *args) {
 | 
			
		|||
    double wrap = 0.0;
 | 
			
		||||
 | 
			
		||||
    if (!PyArg_ParseTuple(
 | 
			
		||||
            args, "(dddddd)|d:transform", &a, &b, &c, &d, &e, &f, &wrap)) {
 | 
			
		||||
            args, "(dddddd)|d:transform", &a, &b, &c, &d, &e, &f, &wrap
 | 
			
		||||
        )) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -570,7 +571,8 @@ path_subscript(PyPathObject *self, PyObject *item) {
 | 
			
		|||
        PyErr_Format(
 | 
			
		||||
            PyExc_TypeError,
 | 
			
		||||
            "Path indices must be integers, not %.200s",
 | 
			
		||||
            Py_TYPE(item)->tp_name);
 | 
			
		||||
            Py_TYPE(item)->tp_name
 | 
			
		||||
        );
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -586,7 +588,8 @@ static PySequenceMethods path_as_sequence = {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
static PyMappingMethods path_as_mapping = {
 | 
			
		||||
    (lenfunc)path_len, (binaryfunc)path_subscript, NULL};
 | 
			
		||||
    (lenfunc)path_len, (binaryfunc)path_subscript, NULL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static PyTypeObject PyPathType = {
 | 
			
		||||
    PyVarObject_HEAD_INIT(NULL, 0) "Path", /*tp_name*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user