Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PIL/ImageTk.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def paste(self, im: Image.Image) -> None:
image = im.im
if not image.isblock() or im.mode != self.__mode:
block = Image.core.new_block(self.__mode, im.size)
image.convert2(block) # convert directly between buffers
image.convert_into(block) # convert directly between buffers
ptr = block.ptr

_pyimagingtkcall("PyImagingPhoto", self.__photo, ptr)
Expand Down
12 changes: 8 additions & 4 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,18 +1023,22 @@ _convert(ImagingObject *self, PyObject *args) {
const ModeID mode = findModeID(mode_name);

return PyImagingNew(ImagingConvert(
self->image, mode, paletteimage ? paletteimage->image->palette : NULL, dither
NULL,
self->image,
mode,
paletteimage ? paletteimage->image->palette : NULL,
dither
));
}

static PyObject *
_convert2(ImagingObject *self, PyObject *args) {
_convert_into(ImagingObject *self, PyObject *args) {
ImagingObject *imagep;
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) {
return NULL;
}

if (!ImagingConvert2(imagep->image, self->image)) {
if (!ImagingConvert(imagep->image, self->image, imagep->image->mode, NULL, 0)) {
return NULL;
}

Expand Down Expand Up @@ -3702,7 +3706,7 @@ static struct PyMethodDef methods[] = {
/* Standard processing methods (Image) */
{"color_lut_3d", (PyCFunction)_color_lut_3d, METH_VARARGS},
{"convert", (PyCFunction)_convert, METH_VARARGS},
{"convert2", (PyCFunction)_convert2, METH_VARARGS},
{"convert_into", (PyCFunction)_convert_into, METH_VARARGS},
{"convert_matrix", (PyCFunction)_convert_matrix, METH_VARARGS},
{"convert_transparent", (PyCFunction)_convert_transparent, METH_VARARGS},
{"copy", (PyCFunction)_copy, METH_VARARGS},
Expand Down
32 changes: 20 additions & 12 deletions src/libImaging/Convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1575,8 +1575,26 @@ static struct {
{IMAGING_MODE_I_16B, IMAGING_MODE_F, I16B_F}
};

static Imaging
convert(Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int dither) {
/**
* Convert imIn to `mode`.
* If imIn is already in `mode`, this performs a copy into imOut
* (or a newly allocated image if imOut is NULL).
*
* @param imOut Existing image to write into
* (must already be in `mode` and the same size as imIn),
* or NULL to allocate a new image for the result.
* @param imIn Source image to convert.
* @param mode Target mode.
* @param palette Target palette for conversions to "P" or "PA";
* NULL to use a default palette.
* @param dither Nonzero to dither when converting to "P", "PA" or "1".
* @return The resulting Imaging object,
* or NULL with a Python exception set on failure.
*/
Imaging
ImagingConvert(
Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int dither
) {
ImagingSectionCookie cookie;
ImagingShuffler convert;

Expand Down Expand Up @@ -1644,16 +1662,6 @@ convert(Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int di
return imOut;
}

Imaging
ImagingConvert(Imaging imIn, const ModeID mode, ImagingPalette palette, int dither) {
return convert(NULL, imIn, mode, palette, dither);
}

Imaging
ImagingConvert2(Imaging imOut, Imaging imIn) {
return convert(imOut, imIn, imOut->mode, NULL, 0);
}

Imaging
ImagingConvertTransparent(Imaging imIn, const ModeID mode, int r, int g, int b) {
ImagingSectionCookie cookie;
Expand Down
6 changes: 3 additions & 3 deletions src/libImaging/Imaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha);
extern Imaging
ImagingCopy(Imaging im);
extern Imaging
ImagingConvert(Imaging im, ModeID mode, ImagingPalette palette, int dither);
ImagingConvert(
Imaging imOut, Imaging imIn, ModeID mode, ImagingPalette palette, int dither
);
extern Imaging
ImagingConvertInPlace(Imaging im, ModeID mode);
extern Imaging
Expand Down Expand Up @@ -417,8 +419,6 @@ ImagingColorLUT3D_linear(

extern Imaging
ImagingCopy2(Imaging imOut, Imaging imIn);
extern Imaging
ImagingConvert2(Imaging imOut, Imaging imIn);

/* Channel operations */
/* any mode, except "F" */
Expand Down
Loading