mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-29 09:29:46 +03:00
Merge b627fb97c7
into a4f976ca27
This commit is contained in:
commit
82f87de33d
|
@ -282,7 +282,7 @@ class TestEmbeddable:
|
||||||
home = sys.prefix.replace("\\", "\\\\")
|
home = sys.prefix.replace("\\", "\\\\")
|
||||||
fh.write(
|
fh.write(
|
||||||
f"""
|
f"""
|
||||||
#include "Python.h"
|
#include <Python.h>
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{{
|
{{
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -347,7 +347,6 @@ class pil_build_ext(build_ext):
|
||||||
("disable-platform-guessing", None, "Disable platform guessing"),
|
("disable-platform-guessing", None, "Disable platform guessing"),
|
||||||
("debug", None, "Debug logging"),
|
("debug", None, "Debug logging"),
|
||||||
]
|
]
|
||||||
+ [("add-imaging-libs=", None, "Add libs to _imaging build")]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -358,7 +357,6 @@ class pil_build_ext(build_ext):
|
||||||
self.disable_platform_guessing = self.check_configuration(
|
self.disable_platform_guessing = self.check_configuration(
|
||||||
"platform-guessing", "disable"
|
"platform-guessing", "disable"
|
||||||
)
|
)
|
||||||
self.add_imaging_libs = ""
|
|
||||||
build_ext.initialize_options(self)
|
build_ext.initialize_options(self)
|
||||||
for x in self.feature:
|
for x in self.feature:
|
||||||
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
|
setattr(self, f"disable_{x}", self.check_configuration(x, "disable"))
|
||||||
|
@ -855,7 +853,6 @@ class pil_build_ext(build_ext):
|
||||||
# core library
|
# core library
|
||||||
|
|
||||||
libs: list[str | bool | None] = []
|
libs: list[str | bool | None] = []
|
||||||
libs.extend(self.add_imaging_libs.split())
|
|
||||||
defs: list[tuple[str, str | None]] = []
|
defs: list[tuple[str, str | None]] = []
|
||||||
if feature.get("tiff"):
|
if feature.get("tiff"):
|
||||||
libs.append(feature.get("tiff"))
|
libs.append(feature.get("tiff"))
|
||||||
|
|
|
@ -181,7 +181,7 @@ class PhotoImage:
|
||||||
image = im.im
|
image = im.im
|
||||||
if not image.isblock() or im.mode != self.__mode:
|
if not image.isblock() or im.mode != self.__mode:
|
||||||
block = Image.core.new_block(self.__mode, im.size)
|
block = Image.core.new_block(self.__mode, im.size)
|
||||||
image.convert2(block, image) # convert directly between buffers
|
image.convert2(block) # convert directly between buffers
|
||||||
ptr = block.ptr
|
ptr = block.ptr
|
||||||
|
|
||||||
_pyimagingtkcall("PyImagingPhoto", self.__photo, ptr)
|
_pyimagingtkcall("PyImagingPhoto", self.__photo, ptr)
|
||||||
|
|
|
@ -243,13 +243,9 @@ _dfunc(HMODULE lib_handle, const char *func_name) {
|
||||||
* Set Python exception if we can't find `func_name` in `lib_handle`.
|
* Set Python exception if we can't find `func_name` in `lib_handle`.
|
||||||
* Returns function pointer or NULL if not present.
|
* Returns function pointer or NULL if not present.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char message[100];
|
|
||||||
|
|
||||||
FARPROC func = GetProcAddress(lib_handle, func_name);
|
FARPROC func = GetProcAddress(lib_handle, func_name);
|
||||||
if (func == NULL) {
|
if (func == NULL) {
|
||||||
sprintf(message, "Cannot load function %s", func_name);
|
PyErr_Format(PyExc_RuntimeError, "Cannot load function %s", func_name);
|
||||||
PyErr_SetString(PyExc_RuntimeError, message);
|
|
||||||
}
|
}
|
||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
178
src/_imaging.c
178
src/_imaging.c
|
@ -71,29 +71,20 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBJPEG
|
#ifdef HAVE_LIBJPEG
|
||||||
#include "jconfig.h"
|
#include <jconfig.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBZ
|
#ifdef HAVE_LIBZ
|
||||||
#include "zlib.h"
|
#include <zlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_LIBTIFF
|
#ifdef HAVE_LIBTIFF
|
||||||
#ifndef _TIFFIO_
|
|
||||||
#include <tiffio.h>
|
#include <tiffio.h>
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#define _USE_MATH_DEFINES
|
|
||||||
#include <math.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
|
|
||||||
#undef VERBOSE
|
#undef VERBOSE
|
||||||
|
|
||||||
#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i) + 1])
|
#define B16(p, i) ((((int)p[(i)]) << 8) + p[(i) + 1])
|
||||||
|
@ -101,7 +92,7 @@
|
||||||
#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536))
|
#define S16(v) ((v) < 32768 ? (v) : ((v) - 65536))
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* OBJECT ADMINISTRATION */
|
/* OBJECT ADMINISTRATION */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -207,22 +198,6 @@ ImagingSectionLeave(ImagingSectionCookie *cookie) {
|
||||||
PyEval_RestoreThread((PyThreadState *)*cookie);
|
PyEval_RestoreThread((PyThreadState *)*cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/* BUFFER HANDLING */
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/* Python compatibility API */
|
|
||||||
|
|
||||||
int
|
|
||||||
PyImaging_CheckBuffer(PyObject *buffer) {
|
|
||||||
return PyObject_CheckBuffer(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view) {
|
|
||||||
/* must call check_buffer first! */
|
|
||||||
return PyObject_GetBuffer(buffer, view, PyBUF_SIMPLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* EXCEPTION REROUTING */
|
/* EXCEPTION REROUTING */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -244,12 +219,6 @@ static const char *no_palette = "image has no palette";
|
||||||
static const char *readonly = "image is readonly";
|
static const char *readonly = "image is readonly";
|
||||||
/* static const char* no_content = "image has no content"; */
|
/* static const char* no_content = "image has no content"; */
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_OSError(void) {
|
|
||||||
PyErr_SetString(PyExc_OSError, "error when accessing file");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ImagingError_MemoryError(void) {
|
ImagingError_MemoryError(void) {
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
@ -275,13 +244,8 @@ ImagingError_ValueError(const char *message) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ImagingError_Clear(void) {
|
|
||||||
PyErr_Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* HELPERS */
|
/* HELPERS */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -466,8 +430,7 @@ getpixel(Imaging im, ImagingAccess access, int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* unknown type */
|
/* unknown type */
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
|
@ -631,7 +594,7 @@ getink(PyObject *color, Imaging im, char *ink) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* FACTORIES */
|
/* FACTORIES */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -714,7 +677,7 @@ _radial_gradient(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_alpha_composite(ImagingObject *self, PyObject *args) {
|
_alpha_composite(PyObject *self, PyObject *args) {
|
||||||
ImagingObject *imagep1;
|
ImagingObject *imagep1;
|
||||||
ImagingObject *imagep2;
|
ImagingObject *imagep2;
|
||||||
|
|
||||||
|
@ -728,7 +691,7 @@ _alpha_composite(ImagingObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_blend(ImagingObject *self, PyObject *args) {
|
_blend(PyObject *self, PyObject *args) {
|
||||||
ImagingObject *imagep1;
|
ImagingObject *imagep1;
|
||||||
ImagingObject *imagep2;
|
ImagingObject *imagep2;
|
||||||
double alpha;
|
double alpha;
|
||||||
|
@ -922,17 +885,12 @@ _convert(ImagingObject *self, PyObject *args) {
|
||||||
int dither = 0;
|
int dither = 0;
|
||||||
ImagingObject *paletteimage = NULL;
|
ImagingObject *paletteimage = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s|iO", &mode, &dither, &paletteimage)) {
|
if (!PyArg_ParseTuple(
|
||||||
|
args, "s|iO!", &mode, &dither, &Imaging_Type, &paletteimage
|
||||||
|
)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (paletteimage != NULL) {
|
if (paletteimage != NULL) {
|
||||||
if (!PyImaging_Check(paletteimage)) {
|
|
||||||
PyObject_Print((PyObject *)paletteimage, stderr, 0);
|
|
||||||
PyErr_SetString(
|
|
||||||
PyExc_ValueError, "palette argument must be image with mode 'P'"
|
|
||||||
);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
if (paletteimage->image->palette == NULL) {
|
if (paletteimage->image->palette == NULL) {
|
||||||
PyErr_SetString(PyExc_ValueError, "null palette");
|
PyErr_SetString(PyExc_ValueError, "null palette");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -946,20 +904,16 @@ _convert(ImagingObject *self, PyObject *args) {
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_convert2(ImagingObject *self, PyObject *args) {
|
_convert2(ImagingObject *self, PyObject *args) {
|
||||||
ImagingObject *imagep1;
|
ImagingObject *imagep;
|
||||||
ImagingObject *imagep2;
|
if (!PyArg_ParseTuple(args, "O!", &Imaging_Type, &imagep)) {
|
||||||
if (!PyArg_ParseTuple(
|
|
||||||
args, "O!O!", &Imaging_Type, &imagep1, &Imaging_Type, &imagep2
|
|
||||||
)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ImagingConvert2(imagep1->image, imagep2->image)) {
|
if (!ImagingConvert2(imagep->image, self->image)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1207,8 +1161,7 @@ _getpixel(ImagingObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->access == NULL) {
|
if (self->access == NULL) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getpixel(self->image, self->access, x, y);
|
return getpixel(self->image, self->access, x, y);
|
||||||
|
@ -1410,8 +1363,7 @@ _paste(ImagingObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1571,7 +1523,6 @@ _putdata(ImagingObject *self, PyObject *args) {
|
||||||
} else {
|
} else {
|
||||||
seq = PySequence_Fast(data, must_be_sequence);
|
seq = PySequence_Fast(data, must_be_sequence);
|
||||||
if (!seq) {
|
if (!seq) {
|
||||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
double value;
|
double value;
|
||||||
|
@ -1630,7 +1581,6 @@ _putdata(ImagingObject *self, PyObject *args) {
|
||||||
/* 32-bit images */
|
/* 32-bit images */
|
||||||
seq = PySequence_Fast(data, must_be_sequence);
|
seq = PySequence_Fast(data, must_be_sequence);
|
||||||
if (!seq) {
|
if (!seq) {
|
||||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
switch (image->type) {
|
switch (image->type) {
|
||||||
|
@ -1684,8 +1634,7 @@ _putdata(ImagingObject *self, PyObject *args) {
|
||||||
|
|
||||||
Py_XDECREF(seq);
|
Py_XDECREF(seq);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1745,8 +1694,7 @@ _putpalette(ImagingObject *self, PyObject *args) {
|
||||||
self->image->palette->size = palettesize * 8 / bits;
|
self->image->palette->size = palettesize * 8 / bits;
|
||||||
unpack(self->image->palette->palette, palette, self->image->palette->size);
|
unpack(self->image->palette->palette, palette, self->image->palette->size);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1770,8 +1718,7 @@ _putpalettealpha(ImagingObject *self, PyObject *args) {
|
||||||
strcpy(self->image->palette->mode, "RGBA");
|
strcpy(self->image->palette->mode, "RGBA");
|
||||||
self->image->palette->palette[index * 4 + 3] = (UINT8)alpha;
|
self->image->palette->palette[index * 4 + 3] = (UINT8)alpha;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1798,8 +1745,7 @@ _putpalettealphas(ImagingObject *self, PyObject *args) {
|
||||||
self->image->palette->palette[i * 4 + 3] = (UINT8)values[i];
|
self->image->palette->palette[i * 4 + 3] = (UINT8)values[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1835,8 +1781,7 @@ _putpixel(ImagingObject *self, PyObject *args) {
|
||||||
self->access->put_pixel(im, x, y, ink);
|
self->access->put_pixel(im, x, y, ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2003,8 +1948,7 @@ im_setmode(ImagingObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
self->access = ImagingAccessNew(im);
|
self->access = ImagingAccessNew(im);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2067,8 +2011,7 @@ _transform(ImagingObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2195,8 +2138,7 @@ _getbbox(ImagingObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ImagingGetBBox(self->image, bbox, alpha_only)) {
|
if (!ImagingGetBBox(self->image, bbox, alpha_only)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]);
|
return Py_BuildValue("iiii", bbox[0], bbox[1], bbox[2], bbox[3]);
|
||||||
|
@ -2276,8 +2218,7 @@ _getextrema(ImagingObject *self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2340,8 +2281,7 @@ _fillband(ImagingObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2356,8 +2296,7 @@ _putband(ImagingObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2943,8 +2882,7 @@ _draw_arc(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -2981,8 +2919,7 @@ _draw_bitmap(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3038,8 +2975,7 @@ _draw_chord(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3093,8 +3029,7 @@ _draw_ellipse(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3157,8 +3092,7 @@ _draw_lines(ImagingDrawObject *self, PyObject *args) {
|
||||||
|
|
||||||
free(xy);
|
free(xy);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3189,8 +3123,7 @@ _draw_points(ImagingDrawObject *self, PyObject *args) {
|
||||||
|
|
||||||
free(xy);
|
free(xy);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* from outline.c */
|
/* from outline.c */
|
||||||
|
@ -3218,8 +3151,7 @@ _draw_outline(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3275,8 +3207,7 @@ _draw_pieslice(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3327,8 +3258,7 @@ _draw_polygon(ImagingDrawObject *self, PyObject *args) {
|
||||||
|
|
||||||
free(ixy);
|
free(ixy);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3382,8 +3312,7 @@ _draw_rectangle(ImagingDrawObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct PyMethodDef _draw_methods[] = {
|
static struct PyMethodDef _draw_methods[] = {
|
||||||
|
@ -3537,7 +3466,7 @@ _effect_spread(ImagingObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* UTILITIES */
|
/* UTILITIES */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3573,7 +3502,7 @@ _getcodecstatus(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* DEBUGGING HELPERS */
|
/* DEBUGGING HELPERS */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -3588,8 +3517,7 @@ _save_ppm(ImagingObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -3977,8 +3905,7 @@ _reset_stats(PyObject *self, PyObject *args) {
|
||||||
arena->stats_freed_blocks = 0;
|
arena->stats_freed_blocks = 0;
|
||||||
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -4038,8 +3965,7 @@ _set_alignment(PyObject *self, PyObject *args) {
|
||||||
ImagingDefaultArena.alignment = alignment;
|
ImagingDefaultArena.alignment = alignment;
|
||||||
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -4063,8 +3989,7 @@ _set_block_size(PyObject *self, PyObject *args) {
|
||||||
ImagingDefaultArena.block_size = block_size;
|
ImagingDefaultArena.block_size = block_size;
|
||||||
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -4092,8 +4017,7 @@ _set_blocks_max(PyObject *self, PyObject *args) {
|
||||||
return ImagingError_MemoryError();
|
return ImagingError_MemoryError();
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -4108,8 +4032,7 @@ _clear_cache(PyObject *self, PyObject *args) {
|
||||||
ImagingMemoryClearCache(&ImagingDefaultArena, i);
|
ImagingMemoryClearCache(&ImagingDefaultArena, i);
|
||||||
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
MUTEX_UNLOCK(&ImagingDefaultArena.mutex);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -4197,19 +4120,19 @@ extern PyObject *
|
||||||
PyImaging_GrabScreenX11(PyObject *self, PyObject *args);
|
PyImaging_GrabScreenX11(PyObject *self, PyObject *args);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Experimental path stuff (in path.c) */
|
/* Path object (in path.c) */
|
||||||
extern PyObject *
|
extern PyObject *
|
||||||
PyPath_Create(ImagingObject *self, PyObject *args);
|
PyPath_Create(ImagingObject *self, PyObject *args);
|
||||||
|
|
||||||
/* Experimental outline stuff (in outline.c) */
|
/* Outline object (in outline.c) */
|
||||||
extern PyObject *
|
extern PyObject *
|
||||||
PyOutline_Create(ImagingObject *self, PyObject *args);
|
PyOutline_Create(ImagingObject *self, PyObject *args);
|
||||||
|
|
||||||
|
/* MapBuffer implementation (in map.c) */
|
||||||
extern PyObject *
|
extern PyObject *
|
||||||
PyImaging_MapBuffer(PyObject *self, PyObject *args);
|
PyImaging_MapBuffer(PyObject *self, PyObject *args);
|
||||||
|
|
||||||
static PyMethodDef functions[] = {
|
static PyMethodDef functions[] = {
|
||||||
|
|
||||||
/* Object factories */
|
/* Object factories */
|
||||||
{"alpha_composite", (PyCFunction)_alpha_composite, METH_VARARGS},
|
{"alpha_composite", (PyCFunction)_alpha_composite, METH_VARARGS},
|
||||||
{"blend", (PyCFunction)_blend, METH_VARARGS},
|
{"blend", (PyCFunction)_blend, METH_VARARGS},
|
||||||
|
@ -4218,9 +4141,6 @@ static PyMethodDef functions[] = {
|
||||||
{"new_block", (PyCFunction)_new_block, METH_VARARGS},
|
{"new_block", (PyCFunction)_new_block, METH_VARARGS},
|
||||||
{"merge", (PyCFunction)_merge, METH_VARARGS},
|
{"merge", (PyCFunction)_merge, METH_VARARGS},
|
||||||
|
|
||||||
/* Functions */
|
|
||||||
{"convert", (PyCFunction)_convert2, METH_VARARGS},
|
|
||||||
|
|
||||||
/* Codecs */
|
/* Codecs */
|
||||||
{"bcn_decoder", (PyCFunction)PyImaging_BcnDecoderNew, METH_VARARGS},
|
{"bcn_decoder", (PyCFunction)PyImaging_BcnDecoderNew, METH_VARARGS},
|
||||||
{"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, METH_VARARGS},
|
{"bit_decoder", (PyCFunction)PyImaging_BitDecoderNew, METH_VARARGS},
|
||||||
|
|
|
@ -26,15 +26,11 @@ kevin@cazabon.com\n\
|
||||||
https://www.cazabon.com\n\
|
https://www.cazabon.com\n\
|
||||||
"
|
"
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
#include "libImaging/Imaging.h" // Set _GNU_SOURCE in Python.h before wchar.h
|
||||||
#include "Python.h" // Include before wchar.h so _GNU_SOURCE is set
|
|
||||||
#include "wchar.h"
|
|
||||||
#include "datetime.h"
|
|
||||||
|
|
||||||
#include "lcms2.h"
|
#include <wchar.h>
|
||||||
#include "libImaging/Imaging.h"
|
#include <datetime.h>
|
||||||
|
#include <lcms2.h>
|
||||||
#define PYCMSVERSION "1.0.0 pil"
|
|
||||||
|
|
||||||
/* version history */
|
/* version history */
|
||||||
|
|
||||||
|
@ -620,12 +616,6 @@ cms_profile_is_intent_supported(CmsProfileObject *self, PyObject *args) {
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#ifdef _WIN64
|
|
||||||
#define F_HANDLE "K"
|
|
||||||
#else
|
|
||||||
#define F_HANDLE "k"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cms_get_display_profile_win32(PyObject *self, PyObject *args) {
|
cms_get_display_profile_win32(PyObject *self, PyObject *args) {
|
||||||
char filename[MAX_PATH];
|
char filename[MAX_PATH];
|
||||||
|
@ -654,8 +644,7 @@ cms_get_display_profile_win32(PyObject *self, PyObject *args) {
|
||||||
return PyUnicode_FromStringAndSize(filename, filename_size - 1);
|
return PyUnicode_FromStringAndSize(filename, filename_size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -672,20 +661,17 @@ _profile_read_mlu(CmsProfileObject *self, cmsTagSignature info) {
|
||||||
wchar_t *buf;
|
wchar_t *buf;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mlu = cmsReadTag(self->profile, info);
|
mlu = cmsReadTag(self->profile, info);
|
||||||
if (!mlu) {
|
if (!mlu) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
len = cmsMLUgetWide(mlu, lc, cc, NULL, 0);
|
len = cmsMLUgetWide(mlu, lc, cc, NULL, 0);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
|
@ -723,14 +709,12 @@ _profile_read_signature(CmsProfileObject *self, cmsTagSignature info) {
|
||||||
unsigned int *sig;
|
unsigned int *sig;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sig = (unsigned int *)cmsReadTag(self->profile, info);
|
sig = (unsigned int *)cmsReadTag(self->profile, info);
|
||||||
if (!sig) {
|
if (!sig) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _profile_read_int_as_string(*sig);
|
return _profile_read_int_as_string(*sig);
|
||||||
|
@ -780,14 +764,12 @@ _profile_read_ciexyz(CmsProfileObject *self, cmsTagSignature info, int multi) {
|
||||||
cmsCIEXYZ *XYZ;
|
cmsCIEXYZ *XYZ;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info);
|
XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info);
|
||||||
if (!XYZ) {
|
if (!XYZ) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
if (multi) {
|
if (multi) {
|
||||||
return _xyz3_py(XYZ);
|
return _xyz3_py(XYZ);
|
||||||
|
@ -801,14 +783,12 @@ _profile_read_ciexyy_triple(CmsProfileObject *self, cmsTagSignature info) {
|
||||||
cmsCIExyYTRIPLE *triple;
|
cmsCIExyYTRIPLE *triple;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
triple = (cmsCIExyYTRIPLE *)cmsReadTag(self->profile, info);
|
triple = (cmsCIExyYTRIPLE *)cmsReadTag(self->profile, info);
|
||||||
if (!triple) {
|
if (!triple) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: lcms does all the heavy lifting and error checking (nr of
|
/* Note: lcms does all the heavy lifting and error checking (nr of
|
||||||
|
@ -835,21 +815,18 @@ _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) {
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ncl = (cmsNAMEDCOLORLIST *)cmsReadTag(self->profile, info);
|
ncl = (cmsNAMEDCOLORLIST *)cmsReadTag(self->profile, info);
|
||||||
if (ncl == NULL) {
|
if (ncl == NULL) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = cmsNamedColorCount(ncl);
|
n = cmsNamedColorCount(ncl);
|
||||||
result = PyList_New(n);
|
result = PyList_New(n);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
@ -858,8 +835,7 @@ _profile_read_named_color_list(CmsProfileObject *self, cmsTagSignature info) {
|
||||||
str = PyUnicode_FromString(name);
|
str = PyUnicode_FromString(name);
|
||||||
if (str == NULL) {
|
if (str == NULL) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
PyList_SET_ITEM(result, i, str);
|
PyList_SET_ITEM(result, i, str);
|
||||||
}
|
}
|
||||||
|
@ -926,8 +902,7 @@ _is_intent_supported(CmsProfileObject *self, int clut) {
|
||||||
|
|
||||||
result = PyDict_New();
|
result = PyDict_New();
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
n = cmsGetSupportedIntents(INTENTS, intent_ids, intent_descs);
|
n = cmsGetSupportedIntents(INTENTS, intent_ids, intent_descs);
|
||||||
|
@ -957,8 +932,7 @@ _is_intent_supported(CmsProfileObject *self, int clut) {
|
||||||
Py_XDECREF(id);
|
Py_XDECREF(id);
|
||||||
Py_XDECREF(entry);
|
Py_XDECREF(entry);
|
||||||
Py_XDECREF(result);
|
Py_XDECREF(result);
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
PyDict_SetItem(result, id, entry);
|
PyDict_SetItem(result, id, entry);
|
||||||
Py_DECREF(id);
|
Py_DECREF(id);
|
||||||
|
@ -1042,8 +1016,7 @@ cms_profile_getattr_creation_date(CmsProfileObject *self, void *closure) {
|
||||||
|
|
||||||
result = cmsGetHeaderCreationDateTime(self->profile, &ct);
|
result = cmsGetHeaderCreationDateTime(self->profile, &ct);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyDateTime_FromDateAndTime(
|
return PyDateTime_FromDateAndTime(
|
||||||
|
@ -1141,8 +1114,7 @@ cms_profile_getattr_saturation_rendering_intent_gamut(
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) {
|
cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) {
|
||||||
if (!cmsIsMatrixShaper(self->profile)) {
|
if (!cmsIsMatrixShaper(self->profile)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
return _profile_read_ciexyz(self, cmsSigRedColorantTag, 0);
|
return _profile_read_ciexyz(self, cmsSigRedColorantTag, 0);
|
||||||
}
|
}
|
||||||
|
@ -1150,8 +1122,7 @@ cms_profile_getattr_red_colorant(CmsProfileObject *self, void *closure) {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) {
|
cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) {
|
||||||
if (!cmsIsMatrixShaper(self->profile)) {
|
if (!cmsIsMatrixShaper(self->profile)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
return _profile_read_ciexyz(self, cmsSigGreenColorantTag, 0);
|
return _profile_read_ciexyz(self, cmsSigGreenColorantTag, 0);
|
||||||
}
|
}
|
||||||
|
@ -1159,8 +1130,7 @@ cms_profile_getattr_green_colorant(CmsProfileObject *self, void *closure) {
|
||||||
static PyObject *
|
static PyObject *
|
||||||
cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) {
|
cms_profile_getattr_blue_colorant(CmsProfileObject *self, void *closure) {
|
||||||
if (!cmsIsMatrixShaper(self->profile)) {
|
if (!cmsIsMatrixShaper(self->profile)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
return _profile_read_ciexyz(self, cmsSigBlueColorantTag, 0);
|
return _profile_read_ciexyz(self, cmsSigBlueColorantTag, 0);
|
||||||
}
|
}
|
||||||
|
@ -1176,21 +1146,18 @@ cms_profile_getattr_media_white_point_temperature(
|
||||||
cmsBool result;
|
cmsBool result;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info);
|
XYZ = (cmsCIEXYZ *)cmsReadTag(self->profile, info);
|
||||||
if (XYZ == NULL || XYZ->X == 0) {
|
if (XYZ == NULL || XYZ->X == 0) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsXYZ2xyY(&xyY, XYZ);
|
cmsXYZ2xyY(&xyY, XYZ);
|
||||||
result = cmsTempFromWhitePoint(&tempK, &xyY);
|
result = cmsTempFromWhitePoint(&tempK, &xyY);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
return PyFloat_FromDouble(tempK);
|
return PyFloat_FromDouble(tempK);
|
||||||
}
|
}
|
||||||
|
@ -1229,8 +1196,7 @@ cms_profile_getattr_red_primary(CmsProfileObject *self, void *closure) {
|
||||||
result = _calculate_rgb_primaries(self, &primaries);
|
result = _calculate_rgb_primaries(self, &primaries);
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _xyz_py(&primaries.Red);
|
return _xyz_py(&primaries.Red);
|
||||||
|
@ -1245,8 +1211,7 @@ cms_profile_getattr_green_primary(CmsProfileObject *self, void *closure) {
|
||||||
result = _calculate_rgb_primaries(self, &primaries);
|
result = _calculate_rgb_primaries(self, &primaries);
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _xyz_py(&primaries.Green);
|
return _xyz_py(&primaries.Green);
|
||||||
|
@ -1261,8 +1226,7 @@ cms_profile_getattr_blue_primary(CmsProfileObject *self, void *closure) {
|
||||||
result = _calculate_rgb_primaries(self, &primaries);
|
result = _calculate_rgb_primaries(self, &primaries);
|
||||||
}
|
}
|
||||||
if (!result) {
|
if (!result) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _xyz_py(&primaries.Blue);
|
return _xyz_py(&primaries.Blue);
|
||||||
|
@ -1321,14 +1285,12 @@ cms_profile_getattr_icc_measurement_condition(CmsProfileObject *self, void *clos
|
||||||
const char *geo;
|
const char *geo;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mc = (cmsICCMeasurementConditions *)cmsReadTag(self->profile, info);
|
mc = (cmsICCMeasurementConditions *)cmsReadTag(self->profile, info);
|
||||||
if (!mc) {
|
if (!mc) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mc->Geometry == 1) {
|
if (mc->Geometry == 1) {
|
||||||
|
@ -1362,14 +1324,12 @@ cms_profile_getattr_icc_viewing_condition(CmsProfileObject *self, void *closure)
|
||||||
cmsTagSignature info = cmsSigViewingConditionsTag;
|
cmsTagSignature info = cmsSigViewingConditionsTag;
|
||||||
|
|
||||||
if (!cmsIsTag(self->profile, info)) {
|
if (!cmsIsTag(self->profile, info)) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vc = (cmsICCViewingConditions *)cmsReadTag(self->profile, info);
|
vc = (cmsICCViewingConditions *)cmsReadTag(self->profile, info);
|
||||||
if (!vc) {
|
if (!vc) {
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Py_BuildValue(
|
return Py_BuildValue(
|
||||||
|
|
|
@ -18,10 +18,8 @@
|
||||||
* Copyright (c) 1998-2007 by Secret Labs AB
|
* Copyright (c) 1998-2007 by Secret Labs AB
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include "Python.h"
|
|
||||||
#include "thirdparty/pythoncapi_compat.h"
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_FREETYPE_H
|
#include FT_FREETYPE_H
|
||||||
|
@ -1377,8 +1375,7 @@ font_setvarname(FontObject *self, PyObject *args) {
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1432,8 +1429,7 @@ font_setvaraxes(FontObject *self, PyObject *args) {
|
||||||
return geterror(error);
|
return geterror(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,12 +13,9 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include "math.h"
|
#include <float.h>
|
||||||
#include "float.h"
|
|
||||||
|
|
||||||
#define MAX_INT32 2147483647.0
|
#define MAX_INT32 2147483647.0
|
||||||
#define MIN_INT32 -2147483648.0
|
#define MIN_INT32 -2147483648.0
|
||||||
|
@ -63,8 +60,8 @@
|
||||||
#define SUB(type, v1, v2) (v1) - (v2)
|
#define SUB(type, v1, v2) (v1) - (v2)
|
||||||
#define MUL(type, v1, v2) (v1) * (v2)
|
#define MUL(type, v1, v2) (v1) * (v2)
|
||||||
|
|
||||||
#define MIN(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
|
#define MINOP(type, v1, v2) ((v1) < (v2)) ? (v1) : (v2)
|
||||||
#define MAX(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
|
#define MAXOP(type, v1, v2) ((v1) > (v2)) ? (v1) : (v2)
|
||||||
|
|
||||||
#define AND(type, v1, v2) (v1) & (v2)
|
#define AND(type, v1, v2) (v1) & (v2)
|
||||||
#define OR(type, v1, v2) (v1) | (v2)
|
#define OR(type, v1, v2) (v1) | (v2)
|
||||||
|
@ -134,8 +131,8 @@ BINOP(xor_I, XOR, INT32)
|
||||||
BINOP(lshift_I, LSHIFT, INT32)
|
BINOP(lshift_I, LSHIFT, INT32)
|
||||||
BINOP(rshift_I, RSHIFT, INT32)
|
BINOP(rshift_I, RSHIFT, INT32)
|
||||||
|
|
||||||
BINOP(min_I, MIN, INT32)
|
BINOP(min_I, MINOP, INT32)
|
||||||
BINOP(max_I, MAX, INT32)
|
BINOP(max_I, MAXOP, INT32)
|
||||||
|
|
||||||
BINOP(eq_I, EQ, INT32)
|
BINOP(eq_I, EQ, INT32)
|
||||||
BINOP(ne_I, NE, INT32)
|
BINOP(ne_I, NE, INT32)
|
||||||
|
@ -155,8 +152,8 @@ BINOP(mod_F, MOD_F, FLOAT32)
|
||||||
BINOP(pow_F, POW_F, FLOAT32)
|
BINOP(pow_F, POW_F, FLOAT32)
|
||||||
BINOP(diff_F, DIFF_F, FLOAT32)
|
BINOP(diff_F, DIFF_F, FLOAT32)
|
||||||
|
|
||||||
BINOP(min_F, MIN, FLOAT32)
|
BINOP(min_F, MINOP, FLOAT32)
|
||||||
BINOP(max_F, MAX, FLOAT32)
|
BINOP(max_F, MAXOP, FLOAT32)
|
||||||
|
|
||||||
BINOP(eq_F, EQ, FLOAT32)
|
BINOP(eq_F, EQ, FLOAT32)
|
||||||
BINOP(ne_F, NE, FLOAT32)
|
BINOP(ne_F, NE, FLOAT32)
|
||||||
|
@ -192,8 +189,7 @@ _unop(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
unop(out, im1);
|
unop(out, im1);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -226,8 +222,7 @@ _binop(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
binop(out, im1, im2);
|
binop(out, im1, im2);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef _functions[] = {
|
static PyMethodDef _functions[] = {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include "Tk/_tkmini.h"
|
#include "Tk/_tkmini.h"
|
||||||
|
@ -37,8 +36,7 @@ _tkinit(PyObject *self, PyObject *args) {
|
||||||
/* This will bomb if interp is invalid... */
|
/* This will bomb if interp is invalid... */
|
||||||
TkImaging_Init(interp);
|
TkImaging_Init(interp);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef functions[] = {
|
static PyMethodDef functions[] = {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include <Python.h>
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include <webp/encode.h>
|
#include <webp/encode.h>
|
||||||
#include <webp/decode.h>
|
#include <webp/decode.h>
|
||||||
#include <webp/types.h>
|
#include <webp/types.h>
|
||||||
|
|
136
src/decode.c
136
src/decode.c
|
@ -29,11 +29,7 @@
|
||||||
|
|
||||||
/* FIXME: make these pluggable! */
|
/* FIXME: make these pluggable! */
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
#include "libImaging/Bit.h"
|
#include "libImaging/Bit.h"
|
||||||
#include "libImaging/Bcn.h"
|
#include "libImaging/Bcn.h"
|
||||||
#include "libImaging/Gif.h"
|
#include "libImaging/Gif.h"
|
||||||
|
@ -213,8 +209,7 @@ _setimage(ImagingDecoderObject *decoder, PyObject *args) {
|
||||||
Py_XDECREF(decoder->lock);
|
Py_XDECREF(decoder->lock);
|
||||||
decoder->lock = op;
|
decoder->lock = op;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -231,8 +226,7 @@ _setfd(ImagingDecoderObject *decoder, PyObject *args) {
|
||||||
Py_XINCREF(fd);
|
Py_XINCREF(fd);
|
||||||
state->fd = fd;
|
state->fd = fd;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -800,74 +794,6 @@ PyImaging_ZipDecoderNew(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/* JPEG */
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBJPEG
|
|
||||||
|
|
||||||
/* We better define this decoder last in this file, so the following
|
|
||||||
undef's won't mess things up for the Imaging library proper. */
|
|
||||||
|
|
||||||
#undef HAVE_PROTOTYPES
|
|
||||||
#undef HAVE_STDDEF_H
|
|
||||||
#undef HAVE_STDLIB_H
|
|
||||||
#undef UINT8
|
|
||||||
#undef UINT16
|
|
||||||
#undef UINT32
|
|
||||||
#undef INT8
|
|
||||||
#undef INT16
|
|
||||||
#undef INT32
|
|
||||||
|
|
||||||
#include "libImaging/Jpeg.h"
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
|
||||||
ImagingDecoderObject *decoder;
|
|
||||||
|
|
||||||
char *mode;
|
|
||||||
char *rawmode; /* what we want from the decoder */
|
|
||||||
char *jpegmode; /* what's in the file */
|
|
||||||
int scale = 1;
|
|
||||||
int draft = 0;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!jpegmode) {
|
|
||||||
jpegmode = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE));
|
|
||||||
if (decoder == NULL) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// libjpeg-turbo supports different output formats.
|
|
||||||
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
|
||||||
// to avoid extra conversion in Unpack.c.
|
|
||||||
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
|
|
||||||
rawmode = "RGBX";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get_unpacker(decoder, mode, rawmode) < 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
decoder->decode = ImagingJpegDecode;
|
|
||||||
decoder->cleanup = ImagingJpegDecodeCleanup;
|
|
||||||
|
|
||||||
strncpy(((JPEGSTATE *)decoder->state.context)->rawmode, rawmode, 8);
|
|
||||||
strncpy(((JPEGSTATE *)decoder->state.context)->jpegmode, jpegmode, 8);
|
|
||||||
|
|
||||||
((JPEGSTATE *)decoder->state.context)->scale = scale;
|
|
||||||
((JPEGSTATE *)decoder->state.context)->draft = draft;
|
|
||||||
|
|
||||||
return (PyObject *)decoder;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* JPEG 2000 */
|
/* JPEG 2000 */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -925,3 +851,61 @@ PyImaging_Jpeg2KDecoderNew(PyObject *self, PyObject *args) {
|
||||||
return (PyObject *)decoder;
|
return (PyObject *)decoder;
|
||||||
}
|
}
|
||||||
#endif /* HAVE_OPENJPEG */
|
#endif /* HAVE_OPENJPEG */
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
/* JPEG */
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBJPEG
|
||||||
|
|
||||||
|
/* We better define this decoder last in this file, so the undef's
|
||||||
|
in Jpeg.h won't mess things up for the Imaging library proper. */
|
||||||
|
|
||||||
|
#include "libImaging/Jpeg.h"
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
PyImaging_JpegDecoderNew(PyObject *self, PyObject *args) {
|
||||||
|
ImagingDecoderObject *decoder;
|
||||||
|
|
||||||
|
char *mode;
|
||||||
|
char *rawmode; /* what we want from the decoder */
|
||||||
|
char *jpegmode; /* what's in the file */
|
||||||
|
int scale = 1;
|
||||||
|
int draft = 0;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "ssz|ii", &mode, &rawmode, &jpegmode, &scale, &draft)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!jpegmode) {
|
||||||
|
jpegmode = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder = PyImaging_DecoderNew(sizeof(JPEGSTATE));
|
||||||
|
if (decoder == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// libjpeg-turbo supports different output formats.
|
||||||
|
// We are choosing Pillow's native format (3 color bytes + 1 padding)
|
||||||
|
// to avoid extra conversion in Unpack.c.
|
||||||
|
if (ImagingJpegUseJCSExtensions() && strcmp(rawmode, "RGB") == 0) {
|
||||||
|
rawmode = "RGBX";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (get_unpacker(decoder, mode, rawmode) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
decoder->decode = ImagingJpegDecode;
|
||||||
|
decoder->cleanup = ImagingJpegDecodeCleanup;
|
||||||
|
|
||||||
|
strncpy(((JPEGSTATE *)decoder->state.context)->rawmode, rawmode, 8);
|
||||||
|
strncpy(((JPEGSTATE *)decoder->state.context)->jpegmode, jpegmode, 8);
|
||||||
|
|
||||||
|
((JPEGSTATE *)decoder->state.context)->scale = scale;
|
||||||
|
((JPEGSTATE *)decoder->state.context)->draft = draft;
|
||||||
|
|
||||||
|
return (PyObject *)decoder;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -22,9 +22,6 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -34,12 +31,6 @@
|
||||||
|
|
||||||
#include "libImaging/ImDib.h"
|
#include "libImaging/ImDib.h"
|
||||||
|
|
||||||
#if SIZEOF_VOID_P == 8
|
|
||||||
#define F_HANDLE "K"
|
|
||||||
#else
|
|
||||||
#define F_HANDLE "k"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD ImagingDIB dib;
|
PyObject_HEAD ImagingDIB dib;
|
||||||
} ImagingDisplayObject;
|
} ImagingDisplayObject;
|
||||||
|
@ -85,8 +76,7 @@ _expose(ImagingDisplayObject *display, PyObject *args) {
|
||||||
|
|
||||||
ImagingExposeDIB(display->dib, hdc);
|
ImagingExposeDIB(display->dib, hdc);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -112,8 +102,7 @@ _draw(ImagingDisplayObject *display, PyObject *args) {
|
||||||
|
|
||||||
ImagingDrawDIB(display->dib, hdc, dst, src);
|
ImagingDrawDIB(display->dib, hdc, dst, src);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern Imaging
|
extern Imaging
|
||||||
|
@ -143,8 +132,7 @@ _paste(ImagingDisplayObject *display, PyObject *args) {
|
||||||
|
|
||||||
ImagingPasteDIB(display->dib, im, xy);
|
ImagingPasteDIB(display->dib, im, xy);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -190,8 +178,7 @@ _releasedc(ImagingDisplayObject *display, PyObject *args) {
|
||||||
|
|
||||||
ReleaseDC(window, dc);
|
ReleaseDC(window, dc);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -211,8 +198,7 @@ _frombytes(ImagingDisplayObject *display, PyObject *args) {
|
||||||
memcpy(display->dib->bits, buffer.buf, buffer.len);
|
memcpy(display->dib->bits, buffer.buf, buffer.len);
|
||||||
|
|
||||||
PyBuffer_Release(&buffer);
|
PyBuffer_Release(&buffer);
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -709,8 +695,7 @@ PyImaging_EventLoopWin32(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
Py_END_ALLOW_THREADS;
|
Py_END_ALLOW_THREADS;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
423
src/encode.c
423
src/encode.c
|
@ -22,11 +22,8 @@
|
||||||
|
|
||||||
/* FIXME: make these pluggable! */
|
/* FIXME: make these pluggable! */
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "thirdparty/pythoncapi_compat.h"
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
#include "libImaging/Gif.h"
|
#include "libImaging/Gif.h"
|
||||||
|
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
|
@ -278,8 +275,7 @@ _setimage(ImagingEncoderObject *encoder, PyObject *args) {
|
||||||
Py_XDECREF(encoder->lock);
|
Py_XDECREF(encoder->lock);
|
||||||
encoder->lock = op;
|
encoder->lock = op;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -296,8 +292,7 @@ _setfd(ImagingEncoderObject *encoder, PyObject *args) {
|
||||||
Py_XINCREF(fd);
|
Py_XINCREF(fd);
|
||||||
state->fd = fd;
|
state->fd = fd;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -986,24 +981,213 @@ PyImaging_LibTiffEncoderNew(PyObject *self, PyObject *args) {
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
/* JPEG 2000 */
|
||||||
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#ifdef HAVE_OPENJPEG
|
||||||
|
|
||||||
|
#include "libImaging/Jpeg2K.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) {
|
||||||
|
*x = *y = 0;
|
||||||
|
|
||||||
|
if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) {
|
||||||
|
*x = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 0));
|
||||||
|
*y = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 1));
|
||||||
|
|
||||||
|
if (*x < 0) {
|
||||||
|
*x = 0;
|
||||||
|
}
|
||||||
|
if (*y < 0) {
|
||||||
|
*y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *
|
||||||
|
PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
|
||||||
|
ImagingEncoderObject *encoder;
|
||||||
|
JPEG2KENCODESTATE *context;
|
||||||
|
|
||||||
|
char *mode;
|
||||||
|
char *format;
|
||||||
|
OPJ_CODEC_FORMAT codec_format;
|
||||||
|
PyObject *offset = NULL, *tile_offset = NULL, *tile_size = NULL;
|
||||||
|
char *quality_mode = "rates";
|
||||||
|
PyObject *quality_layers = NULL;
|
||||||
|
Py_ssize_t num_resolutions = 0;
|
||||||
|
PyObject *cblk_size = NULL, *precinct_size = NULL;
|
||||||
|
PyObject *irreversible = NULL;
|
||||||
|
char *progression = "LRCP";
|
||||||
|
OPJ_PROG_ORDER prog_order;
|
||||||
|
char *cinema_mode = "no";
|
||||||
|
OPJ_CINEMA_MODE cine_mode;
|
||||||
|
char mct = 0;
|
||||||
|
int sgnd = 0;
|
||||||
|
Py_ssize_t fd = -1;
|
||||||
|
char *comment;
|
||||||
|
Py_ssize_t comment_size;
|
||||||
|
int plt = 0;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(
|
||||||
|
args,
|
||||||
|
"ss|OOOsOnOOOssbbnz#p",
|
||||||
|
&mode,
|
||||||
|
&format,
|
||||||
|
&offset,
|
||||||
|
&tile_offset,
|
||||||
|
&tile_size,
|
||||||
|
&quality_mode,
|
||||||
|
&quality_layers,
|
||||||
|
&num_resolutions,
|
||||||
|
&cblk_size,
|
||||||
|
&precinct_size,
|
||||||
|
&irreversible,
|
||||||
|
&progression,
|
||||||
|
&cinema_mode,
|
||||||
|
&mct,
|
||||||
|
&sgnd,
|
||||||
|
&fd,
|
||||||
|
&comment,
|
||||||
|
&comment_size,
|
||||||
|
&plt
|
||||||
|
)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(format, "j2k") == 0) {
|
||||||
|
codec_format = OPJ_CODEC_J2K;
|
||||||
|
} else if (strcmp(format, "jpt") == 0) {
|
||||||
|
codec_format = OPJ_CODEC_JPT;
|
||||||
|
} else if (strcmp(format, "jp2") == 0) {
|
||||||
|
codec_format = OPJ_CODEC_JP2;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(progression, "LRCP") == 0) {
|
||||||
|
prog_order = OPJ_LRCP;
|
||||||
|
} else if (strcmp(progression, "RLCP") == 0) {
|
||||||
|
prog_order = OPJ_RLCP;
|
||||||
|
} else if (strcmp(progression, "RPCL") == 0) {
|
||||||
|
prog_order = OPJ_RPCL;
|
||||||
|
} else if (strcmp(progression, "PCRL") == 0) {
|
||||||
|
prog_order = OPJ_PCRL;
|
||||||
|
} else if (strcmp(progression, "CPRL") == 0) {
|
||||||
|
prog_order = OPJ_CPRL;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strcmp(cinema_mode, "no") == 0) {
|
||||||
|
cine_mode = OPJ_OFF;
|
||||||
|
} else if (strcmp(cinema_mode, "cinema2k-24") == 0) {
|
||||||
|
cine_mode = OPJ_CINEMA2K_24;
|
||||||
|
} else if (strcmp(cinema_mode, "cinema2k-48") == 0) {
|
||||||
|
cine_mode = OPJ_CINEMA2K_48;
|
||||||
|
} else if (strcmp(cinema_mode, "cinema4k-24") == 0) {
|
||||||
|
cine_mode = OPJ_CINEMA4K_24;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
encoder = PyImaging_EncoderNew(sizeof(JPEG2KENCODESTATE));
|
||||||
|
if (!encoder) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
encoder->encode = ImagingJpeg2KEncode;
|
||||||
|
encoder->cleanup = ImagingJpeg2KEncodeCleanup;
|
||||||
|
encoder->pushes_fd = 1;
|
||||||
|
|
||||||
|
context = (JPEG2KENCODESTATE *)encoder->state.context;
|
||||||
|
|
||||||
|
context->fd = fd;
|
||||||
|
context->format = codec_format;
|
||||||
|
context->offset_x = context->offset_y = 0;
|
||||||
|
|
||||||
|
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
|
||||||
|
);
|
||||||
|
j2k_decode_coord_tuple(tile_size, &context->tile_size_x, &context->tile_size_y);
|
||||||
|
|
||||||
|
/* Error on illegal tile offsets */
|
||||||
|
if (context->tile_size_x && context->tile_size_y) {
|
||||||
|
if (context->tile_offset_x <= context->offset_x - context->tile_size_x ||
|
||||||
|
context->tile_offset_y <= context->offset_y - context->tile_size_y) {
|
||||||
|
PyErr_SetString(
|
||||||
|
PyExc_ValueError,
|
||||||
|
"JPEG 2000 tile offset too small; top left tile must "
|
||||||
|
"intersect image area"
|
||||||
|
);
|
||||||
|
Py_DECREF(encoder);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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"
|
||||||
|
);
|
||||||
|
Py_DECREF(encoder);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comment && comment_size > 0) {
|
||||||
|
/* Size is stored as as an uint16, subtract 4 bytes for the header */
|
||||||
|
if (comment_size >= 65532) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "JPEG 2000 comment is too long");
|
||||||
|
Py_DECREF(encoder);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *p = malloc(comment_size + 1);
|
||||||
|
if (!p) {
|
||||||
|
Py_DECREF(encoder);
|
||||||
|
return ImagingError_MemoryError();
|
||||||
|
}
|
||||||
|
memcpy(p, comment, comment_size);
|
||||||
|
p[comment_size] = '\0';
|
||||||
|
context->comment = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quality_layers && PySequence_Check(quality_layers)) {
|
||||||
|
context->quality_is_in_db = strcmp(quality_mode, "dB") == 0;
|
||||||
|
context->quality_layers = quality_layers;
|
||||||
|
Py_INCREF(quality_layers);
|
||||||
|
}
|
||||||
|
|
||||||
|
context->num_resolutions = num_resolutions;
|
||||||
|
|
||||||
|
j2k_decode_coord_tuple(cblk_size, &context->cblk_width, &context->cblk_height);
|
||||||
|
j2k_decode_coord_tuple(
|
||||||
|
precinct_size, &context->precinct_width, &context->precinct_height
|
||||||
|
);
|
||||||
|
|
||||||
|
context->irreversible = PyObject_IsTrue(irreversible);
|
||||||
|
context->progression = prog_order;
|
||||||
|
context->cinema_mode = cine_mode;
|
||||||
|
context->mct = mct;
|
||||||
|
context->sgnd = sgnd;
|
||||||
|
context->plt = plt;
|
||||||
|
|
||||||
|
return (PyObject *)encoder;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* JPEG */
|
/* JPEG */
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
#ifdef HAVE_LIBJPEG
|
#ifdef HAVE_LIBJPEG
|
||||||
|
|
||||||
/* We better define this encoder last in this file, so the following
|
/* We better define this decoder last in this file, so the undef's
|
||||||
undef's won't mess things up for the Imaging library proper. */
|
in Jpeg.h won't mess things up for the Imaging library proper. */
|
||||||
|
|
||||||
#undef HAVE_PROTOTYPES
|
|
||||||
#undef HAVE_STDDEF_H
|
|
||||||
#undef HAVE_STDLIB_H
|
|
||||||
#undef UINT8
|
|
||||||
#undef UINT16
|
|
||||||
#undef UINT32
|
|
||||||
#undef INT8
|
|
||||||
#undef INT16
|
|
||||||
#undef INT32
|
|
||||||
|
|
||||||
#include "libImaging/Jpeg.h"
|
#include "libImaging/Jpeg.h"
|
||||||
|
|
||||||
|
@ -1216,202 +1400,3 @@ PyImaging_JpegEncoderNew(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
/* JPEG 2000 */
|
|
||||||
/* -------------------------------------------------------------------- */
|
|
||||||
|
|
||||||
#ifdef HAVE_OPENJPEG
|
|
||||||
|
|
||||||
#include "libImaging/Jpeg2K.h"
|
|
||||||
|
|
||||||
static void
|
|
||||||
j2k_decode_coord_tuple(PyObject *tuple, int *x, int *y) {
|
|
||||||
*x = *y = 0;
|
|
||||||
|
|
||||||
if (tuple && PyTuple_Check(tuple) && PyTuple_GET_SIZE(tuple) == 2) {
|
|
||||||
*x = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 0));
|
|
||||||
*y = (int)PyLong_AsLong(PyTuple_GET_ITEM(tuple, 1));
|
|
||||||
|
|
||||||
if (*x < 0) {
|
|
||||||
*x = 0;
|
|
||||||
}
|
|
||||||
if (*y < 0) {
|
|
||||||
*y = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PyObject *
|
|
||||||
PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) {
|
|
||||||
ImagingEncoderObject *encoder;
|
|
||||||
JPEG2KENCODESTATE *context;
|
|
||||||
|
|
||||||
char *mode;
|
|
||||||
char *format;
|
|
||||||
OPJ_CODEC_FORMAT codec_format;
|
|
||||||
PyObject *offset = NULL, *tile_offset = NULL, *tile_size = NULL;
|
|
||||||
char *quality_mode = "rates";
|
|
||||||
PyObject *quality_layers = NULL;
|
|
||||||
Py_ssize_t num_resolutions = 0;
|
|
||||||
PyObject *cblk_size = NULL, *precinct_size = NULL;
|
|
||||||
PyObject *irreversible = NULL;
|
|
||||||
char *progression = "LRCP";
|
|
||||||
OPJ_PROG_ORDER prog_order;
|
|
||||||
char *cinema_mode = "no";
|
|
||||||
OPJ_CINEMA_MODE cine_mode;
|
|
||||||
char mct = 0;
|
|
||||||
int sgnd = 0;
|
|
||||||
Py_ssize_t fd = -1;
|
|
||||||
char *comment;
|
|
||||||
Py_ssize_t comment_size;
|
|
||||||
int plt = 0;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(
|
|
||||||
args,
|
|
||||||
"ss|OOOsOnOOOssbbnz#p",
|
|
||||||
&mode,
|
|
||||||
&format,
|
|
||||||
&offset,
|
|
||||||
&tile_offset,
|
|
||||||
&tile_size,
|
|
||||||
&quality_mode,
|
|
||||||
&quality_layers,
|
|
||||||
&num_resolutions,
|
|
||||||
&cblk_size,
|
|
||||||
&precinct_size,
|
|
||||||
&irreversible,
|
|
||||||
&progression,
|
|
||||||
&cinema_mode,
|
|
||||||
&mct,
|
|
||||||
&sgnd,
|
|
||||||
&fd,
|
|
||||||
&comment,
|
|
||||||
&comment_size,
|
|
||||||
&plt
|
|
||||||
)) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(format, "j2k") == 0) {
|
|
||||||
codec_format = OPJ_CODEC_J2K;
|
|
||||||
} else if (strcmp(format, "jpt") == 0) {
|
|
||||||
codec_format = OPJ_CODEC_JPT;
|
|
||||||
} else if (strcmp(format, "jp2") == 0) {
|
|
||||||
codec_format = OPJ_CODEC_JP2;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(progression, "LRCP") == 0) {
|
|
||||||
prog_order = OPJ_LRCP;
|
|
||||||
} else if (strcmp(progression, "RLCP") == 0) {
|
|
||||||
prog_order = OPJ_RLCP;
|
|
||||||
} else if (strcmp(progression, "RPCL") == 0) {
|
|
||||||
prog_order = OPJ_RPCL;
|
|
||||||
} else if (strcmp(progression, "PCRL") == 0) {
|
|
||||||
prog_order = OPJ_PCRL;
|
|
||||||
} else if (strcmp(progression, "CPRL") == 0) {
|
|
||||||
prog_order = OPJ_CPRL;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strcmp(cinema_mode, "no") == 0) {
|
|
||||||
cine_mode = OPJ_OFF;
|
|
||||||
} else if (strcmp(cinema_mode, "cinema2k-24") == 0) {
|
|
||||||
cine_mode = OPJ_CINEMA2K_24;
|
|
||||||
} else if (strcmp(cinema_mode, "cinema2k-48") == 0) {
|
|
||||||
cine_mode = OPJ_CINEMA2K_48;
|
|
||||||
} else if (strcmp(cinema_mode, "cinema4k-24") == 0) {
|
|
||||||
cine_mode = OPJ_CINEMA4K_24;
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
encoder = PyImaging_EncoderNew(sizeof(JPEG2KENCODESTATE));
|
|
||||||
if (!encoder) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
encoder->encode = ImagingJpeg2KEncode;
|
|
||||||
encoder->cleanup = ImagingJpeg2KEncodeCleanup;
|
|
||||||
encoder->pushes_fd = 1;
|
|
||||||
|
|
||||||
context = (JPEG2KENCODESTATE *)encoder->state.context;
|
|
||||||
|
|
||||||
context->fd = fd;
|
|
||||||
context->format = codec_format;
|
|
||||||
context->offset_x = context->offset_y = 0;
|
|
||||||
|
|
||||||
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
|
|
||||||
);
|
|
||||||
j2k_decode_coord_tuple(tile_size, &context->tile_size_x, &context->tile_size_y);
|
|
||||||
|
|
||||||
/* Error on illegal tile offsets */
|
|
||||||
if (context->tile_size_x && context->tile_size_y) {
|
|
||||||
if (context->tile_offset_x <= context->offset_x - context->tile_size_x ||
|
|
||||||
context->tile_offset_y <= context->offset_y - context->tile_size_y) {
|
|
||||||
PyErr_SetString(
|
|
||||||
PyExc_ValueError,
|
|
||||||
"JPEG 2000 tile offset too small; top left tile must "
|
|
||||||
"intersect image area"
|
|
||||||
);
|
|
||||||
Py_DECREF(encoder);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
Py_DECREF(encoder);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (comment && comment_size > 0) {
|
|
||||||
/* Size is stored as as an uint16, subtract 4 bytes for the header */
|
|
||||||
if (comment_size >= 65532) {
|
|
||||||
PyErr_SetString(PyExc_ValueError, "JPEG 2000 comment is too long");
|
|
||||||
Py_DECREF(encoder);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *p = malloc(comment_size + 1);
|
|
||||||
if (!p) {
|
|
||||||
Py_DECREF(encoder);
|
|
||||||
return ImagingError_MemoryError();
|
|
||||||
}
|
|
||||||
memcpy(p, comment, comment_size);
|
|
||||||
p[comment_size] = '\0';
|
|
||||||
context->comment = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (quality_layers && PySequence_Check(quality_layers)) {
|
|
||||||
context->quality_is_in_db = strcmp(quality_mode, "dB") == 0;
|
|
||||||
context->quality_layers = quality_layers;
|
|
||||||
Py_INCREF(quality_layers);
|
|
||||||
}
|
|
||||||
|
|
||||||
context->num_resolutions = num_resolutions;
|
|
||||||
|
|
||||||
j2k_decode_coord_tuple(cblk_size, &context->cblk_width, &context->cblk_height);
|
|
||||||
j2k_decode_coord_tuple(
|
|
||||||
precinct_size, &context->precinct_width, &context->precinct_height
|
|
||||||
);
|
|
||||||
|
|
||||||
context->irreversible = PyObject_IsTrue(irreversible);
|
|
||||||
context->progression = prog_order;
|
|
||||||
context->cinema_mode = cine_mode;
|
|
||||||
context->mct = mct;
|
|
||||||
context->sgnd = sgnd;
|
|
||||||
context->plt = plt;
|
|
||||||
|
|
||||||
return (PyObject *)encoder;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
|
||||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
|
||||||
|
|
||||||
typedef UINT8 pixel[4];
|
typedef UINT8 pixel[4];
|
||||||
|
|
||||||
void static inline ImagingLineBoxBlur32(
|
void static inline ImagingLineBoxBlur32(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* 8 bits for result. Table can overflow [0, 1.0] range,
|
/* 8 bits for result. Table can overflow [0, 1.0] range,
|
||||||
so we need extra bits for overflow and negative values.
|
so we need extra bits for overflow and negative values.
|
||||||
|
|
|
@ -34,9 +34,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#define MAX(a, b) (a) > (b) ? (a) : (b)
|
|
||||||
#define MIN(a, b) (a) < (b) ? (a) : (b)
|
|
||||||
|
|
||||||
#define CLIP16(v) ((v) <= 0 ? 0 : (v) >= 65535 ? 65535 : (v))
|
#define CLIP16(v) ((v) <= 0 ? 0 : (v) >= 65535 ? 65535 : (v))
|
||||||
|
|
||||||
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
|
/* ITU-R Recommendation 601-2 (assuming nonlinear RGB) */
|
||||||
|
@ -1672,15 +1669,9 @@ convert(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!convert) {
|
if (!convert) {
|
||||||
#ifdef notdef
|
return (Imaging)PyErr_Format(
|
||||||
return (Imaging)ImagingError_ValueError("conversion not supported");
|
PyExc_ValueError, "conversion from %s to %s not supported", imIn->mode, mode
|
||||||
#else
|
|
||||||
static char buf[100];
|
|
||||||
snprintf(
|
|
||||||
buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode
|
|
||||||
);
|
);
|
||||||
return (Imaging)ImagingError_ValueError(buf);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imOut = ImagingNew2Dirty(mode, imOut, imIn);
|
imOut = ImagingNew2Dirty(mode, imOut, imIn);
|
||||||
|
@ -1749,15 +1740,12 @@ ImagingConvertTransparent(Imaging imIn, const char *mode, int r, int g, int b) {
|
||||||
}
|
}
|
||||||
g = b = r;
|
g = b = r;
|
||||||
} else {
|
} else {
|
||||||
static char buf[100];
|
return (Imaging)PyErr_Format(
|
||||||
snprintf(
|
PyExc_ValueError,
|
||||||
buf,
|
"conversion from %s to %s not supported in convert_transparent",
|
||||||
100,
|
|
||||||
"conversion from %.10s to %.10s not supported in convert_transparent",
|
|
||||||
imIn->mode,
|
imIn->mode,
|
||||||
mode
|
mode
|
||||||
);
|
);
|
||||||
return (Imaging)ImagingError_ValueError(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imOut = ImagingNew2Dirty(mode, imOut, imIn);
|
imOut = ImagingNew2Dirty(mode, imOut, imIn);
|
||||||
|
|
|
@ -19,10 +19,9 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Imaging.h"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
#include "Imaging.h"
|
||||||
#include "ImDib.h"
|
#include "ImDib.h"
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
|
|
@ -34,9 +34,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define CEIL(v) (int)ceil(v)
|
#define CEIL(v) (int)ceil(v)
|
||||||
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))
|
#define FLOOR(v) ((v) >= 0.0 ? (int)(v) : (int)floor(v))
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) {
|
ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality) {
|
||||||
/* Generate a Mandelbrot set covering the given extent */
|
/* Generate a Mandelbrot set covering the given extent */
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* The Python Imaging Library
|
|
||||||
* $Id$
|
|
||||||
*
|
|
||||||
* default exception handling
|
|
||||||
*
|
|
||||||
* This module is usually overridden by application code (e.g.
|
|
||||||
* _imaging.c for PIL's standard Python bindings). If you get
|
|
||||||
* linking errors, remove this file from your project/library.
|
|
||||||
*
|
|
||||||
* history:
|
|
||||||
* 1995-06-15 fl Created
|
|
||||||
* 1998-12-29 fl Minor tweaks
|
|
||||||
* 2003-09-13 fl Added ImagingEnter/LeaveSection()
|
|
||||||
*
|
|
||||||
* Copyright (c) 1997-2003 by Secret Labs AB.
|
|
||||||
* Copyright (c) 1995-2003 by Fredrik Lundh.
|
|
||||||
*
|
|
||||||
* See the README file for information on usage and redistribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Imaging.h"
|
|
||||||
|
|
||||||
/* exception state */
|
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_OSError(void) {
|
|
||||||
fprintf(stderr, "*** exception: file access error\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_MemoryError(void) {
|
|
||||||
fprintf(stderr, "*** exception: out of memory\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_ModeError(void) {
|
|
||||||
return ImagingError_ValueError("bad image mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_Mismatch(void) {
|
|
||||||
return ImagingError_ValueError("images don't match");
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
|
||||||
ImagingError_ValueError(const char *message) {
|
|
||||||
if (!message) {
|
|
||||||
message = "exception: bad argument to function";
|
|
||||||
}
|
|
||||||
fprintf(stderr, "*** %s\n", message);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ImagingError_Clear(void) {
|
|
||||||
/* nop */;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* thread state */
|
|
||||||
|
|
||||||
void
|
|
||||||
ImagingSectionEnter(ImagingSectionCookie *cookie) {
|
|
||||||
/* pass */
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ImagingSectionLeave(ImagingSectionCookie *cookie) {
|
|
||||||
/* pass */
|
|
||||||
}
|
|
|
@ -54,7 +54,7 @@ ImagingSavePPM(Imaging im, const char *outfile) {
|
||||||
|
|
||||||
fp = fopen(outfile, "wb");
|
fp = fopen(outfile, "wb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
(void)ImagingError_OSError();
|
PyErr_SetString(PyExc_OSError, "error when accessing file");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include "math.h"
|
|
||||||
|
|
||||||
Imaging
|
Imaging
|
||||||
ImagingFill(Imaging im, const void *colour) {
|
ImagingFill(Imaging im, const void *colour) {
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include "ImPlatform.h"
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,16 +10,12 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ImPlatform.h"
|
#include "ImagingPlatform.h"
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef M_PI
|
|
||||||
#define M_PI 3.1415926535897932384626433832795
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -241,8 +237,6 @@ ImagingSectionLeave(ImagingSectionCookie *cookie);
|
||||||
/* Exceptions */
|
/* Exceptions */
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
|
|
||||||
extern void *
|
|
||||||
ImagingError_OSError(void);
|
|
||||||
extern void *
|
extern void *
|
||||||
ImagingError_MemoryError(void);
|
ImagingError_MemoryError(void);
|
||||||
extern void *
|
extern void *
|
||||||
|
@ -251,8 +245,6 @@ extern void *
|
||||||
ImagingError_Mismatch(void); /* maps to ValueError by default */
|
ImagingError_Mismatch(void); /* maps to ValueError by default */
|
||||||
extern void *
|
extern void *
|
||||||
ImagingError_ValueError(const char *message);
|
ImagingError_ValueError(const char *message);
|
||||||
extern void
|
|
||||||
ImagingError_Clear(void);
|
|
||||||
|
|
||||||
/* Transform callbacks */
|
/* Transform callbacks */
|
||||||
/* ------------------- */
|
/* ------------------- */
|
||||||
|
@ -609,10 +601,6 @@ ImagingLibTiffDecode(
|
||||||
extern int
|
extern int
|
||||||
ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
|
ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int bytes);
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_LIBMPEG
|
|
||||||
extern int
|
|
||||||
ImagingMpegDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
|
|
||||||
#endif
|
|
||||||
extern int
|
extern int
|
||||||
ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
|
ImagingMspDecode(Imaging im, ImagingCodecState state, UINT8 *buffer, Py_ssize_t bytes);
|
||||||
extern int
|
extern int
|
||||||
|
|
|
@ -8,7 +8,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include "Python.h"
|
#include <Python.h>
|
||||||
|
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
/* Check that we have an ANSI compliant compiler */
|
/* Check that we have an ANSI compliant compiler */
|
||||||
#ifndef HAVE_PROTOTYPES
|
#ifndef HAVE_PROTOTYPES
|
||||||
|
@ -18,36 +21,25 @@
|
||||||
#error Sorry, this library requires ANSI header files.
|
#error Sorry, this library requires ANSI header files.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PIL_NO_INLINE)
|
|
||||||
#define inline
|
|
||||||
#else
|
|
||||||
#if defined(_MSC_VER) && !defined(__GNUC__)
|
#if defined(_MSC_VER) && !defined(__GNUC__)
|
||||||
#define inline __inline
|
#define inline __inline
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#ifdef _WIN64
|
||||||
#ifdef __CYGWIN__
|
#define F_HANDLE "K"
|
||||||
#undef _WIN64
|
#else
|
||||||
#undef _WIN32
|
#define F_HANDLE "k"
|
||||||
#undef __WIN32__
|
|
||||||
#undef WIN32
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* _WIN32 */
|
||||||
#else /* not WIN */
|
|
||||||
/* For System that are not Windows, we'll need to define these. */
|
|
||||||
/* We have to define them instead of using typedef because the JPEG lib also
|
|
||||||
defines their own types with the same names, so we need to be able to undef
|
|
||||||
ours before including the JPEG code. */
|
|
||||||
|
|
||||||
#if __STDC_VERSION__ >= 199901L /* C99+ */
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/* We have to define types instead of using typedef because the JPEG lib also
|
||||||
|
defines their own types with the same names, so we need to be able to undef
|
||||||
|
ours before including the JPEG code. */
|
||||||
#define INT8 int8_t
|
#define INT8 int8_t
|
||||||
#define UINT8 uint8_t
|
#define UINT8 uint8_t
|
||||||
#define INT16 int16_t
|
#define INT16 int16_t
|
||||||
|
@ -55,45 +47,11 @@
|
||||||
#define INT32 int32_t
|
#define INT32 int32_t
|
||||||
#define UINT32 uint32_t
|
#define UINT32 uint32_t
|
||||||
|
|
||||||
#else /* < C99 */
|
|
||||||
|
|
||||||
#define INT8 signed char
|
|
||||||
|
|
||||||
#if SIZEOF_SHORT == 2
|
|
||||||
#define INT16 short
|
|
||||||
#elif SIZEOF_INT == 2
|
|
||||||
#define INT16 int
|
|
||||||
#else
|
|
||||||
#error Cannot find required 16-bit integer type
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if SIZEOF_SHORT == 4
|
|
||||||
#define INT32 short
|
|
||||||
#elif SIZEOF_INT == 4
|
|
||||||
#define INT32 int
|
|
||||||
#elif SIZEOF_LONG == 4
|
|
||||||
#define INT32 long
|
|
||||||
#else
|
|
||||||
#error Cannot find required 32-bit integer type
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define UINT8 unsigned char
|
|
||||||
#define UINT16 unsigned INT16
|
|
||||||
#define UINT32 unsigned INT32
|
|
||||||
|
|
||||||
#endif /* < C99 */
|
|
||||||
|
|
||||||
#endif /* not WIN */
|
|
||||||
|
|
||||||
/* assume IEEE; tweak if necessary (patches are welcome) */
|
/* assume IEEE; tweak if necessary (patches are welcome) */
|
||||||
#define FLOAT16 UINT16
|
#define FLOAT16 UINT16
|
||||||
#define FLOAT32 float
|
#define FLOAT32 float
|
||||||
#define FLOAT64 double
|
#define FLOAT64 double
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
typedef signed __int64 int64_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
||||||
#endif
|
#endif
|
|
@ -14,6 +14,9 @@
|
||||||
#define MASK_UINT32_CHANNEL_3 0xff000000
|
#define MASK_UINT32_CHANNEL_3 0xff000000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
|
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||||
|
|
||||||
#define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8)
|
#define SHIFTFORDIV255(a) ((((a) >> 8) + a) >> 8)
|
||||||
|
|
||||||
/* like (a * b + 127) / 255), but much faster on most platforms */
|
/* like (a * b + 127) / 255), but much faster on most platforms */
|
||||||
|
|
|
@ -8,7 +8,16 @@
|
||||||
* Copyright (c) 1995-1996 by Fredrik Lundh
|
* Copyright (c) 1995-1996 by Fredrik Lundh
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "jpeglib.h"
|
/* These undefs are required for libjpeg v8 and below */
|
||||||
|
|
||||||
|
#undef UINT8
|
||||||
|
#undef UINT16
|
||||||
|
#undef UINT32
|
||||||
|
#undef INT8
|
||||||
|
#undef INT16
|
||||||
|
#undef INT32
|
||||||
|
|
||||||
|
#include <jpeglib.h>
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
#ifdef HAVE_OPENJPEG
|
#ifdef HAVE_OPENJPEG
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include "Jpeg2K.h"
|
#include "Jpeg2K.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -25,15 +25,6 @@
|
||||||
|
|
||||||
#ifdef HAVE_LIBJPEG
|
#ifdef HAVE_LIBJPEG
|
||||||
|
|
||||||
#undef HAVE_PROTOTYPES
|
|
||||||
#undef HAVE_STDLIB_H
|
|
||||||
#undef HAVE_STDDEF_H
|
|
||||||
#undef UINT8
|
|
||||||
#undef UINT16
|
|
||||||
#undef UINT32
|
|
||||||
#undef INT16
|
|
||||||
#undef INT32
|
|
||||||
|
|
||||||
#include "Jpeg.h"
|
#include "Jpeg.h"
|
||||||
|
|
||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
|
|
|
@ -23,15 +23,6 @@
|
||||||
|
|
||||||
#ifdef HAVE_LIBJPEG
|
#ifdef HAVE_LIBJPEG
|
||||||
|
|
||||||
#undef HAVE_PROTOTYPES
|
|
||||||
#undef HAVE_STDLIB_H
|
|
||||||
#undef HAVE_STDDEF_H
|
|
||||||
#undef UINT8
|
|
||||||
#undef UINT16
|
|
||||||
#undef UINT32
|
|
||||||
#undef INT16
|
|
||||||
#undef INT32
|
|
||||||
|
|
||||||
#include "Jpeg.h"
|
#include "Jpeg.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
ImagingPalette
|
ImagingPalette
|
||||||
ImagingPaletteNew(const char *mode) {
|
ImagingPaletteNew(const char *mode) {
|
||||||
/* Create a palette object */
|
/* Create a palette object */
|
||||||
|
|
|
@ -1428,7 +1428,6 @@ quantize(
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_NEAREST_NEIGHBOUR
|
#ifdef TEST_NEAREST_NEIGHBOUR
|
||||||
#include <math.h>
|
|
||||||
{
|
{
|
||||||
uint32_t bestmatch, bestdist, dist;
|
uint32_t bestmatch, bestdist, dist;
|
||||||
HashTable *h2;
|
HashTable *h2;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "ImagingUtils.h"
|
#include "Imaging.h"
|
||||||
#include "QuantOctree.h"
|
#include "QuantOctree.h"
|
||||||
|
|
||||||
typedef struct _ColorBucket {
|
typedef struct _ColorBucket {
|
||||||
|
@ -49,8 +49,6 @@ typedef struct _ColorCube {
|
||||||
ColorBucket buckets;
|
ColorBucket buckets;
|
||||||
} *ColorCube;
|
} *ColorCube;
|
||||||
|
|
||||||
#define MAX(a, b) (a) > (b) ? (a) : (b)
|
|
||||||
|
|
||||||
static ColorCube
|
static ColorCube
|
||||||
new_color_cube(int r, int g, int b, int a) {
|
new_color_cube(int r, int g, int b, int a) {
|
||||||
ColorCube cube;
|
ColorCube cube;
|
||||||
|
|
|
@ -8,15 +8,15 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBIMAGEQUANT
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <libimagequant.h>
|
||||||
|
|
||||||
#include "QuantPngQuant.h"
|
#include "QuantPngQuant.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBIMAGEQUANT
|
|
||||||
#include "libimagequant.h"
|
|
||||||
|
|
||||||
int
|
int
|
||||||
quantize_pngquant(
|
quantize_pngquant(
|
||||||
Pixel *pixelData,
|
Pixel *pixelData,
|
||||||
|
|
|
@ -9,15 +9,10 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __TYPES_H__
|
#ifndef __QUANTTYPES_H__
|
||||||
#define __TYPES_H__
|
#define __QUANTTYPES_H__
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
typedef unsigned __int32 uint32_t;
|
|
||||||
typedef unsigned __int64 uint64_t;
|
|
||||||
#else
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
#define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
||||||
|
|
||||||
UINT32
|
UINT32
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
#define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
#define ROUND_UP(f) ((int)((f) >= 0.0 ? (f) + 0.5F : (f) - 0.5F))
|
||||||
|
|
||||||
struct filter {
|
struct filter {
|
||||||
|
|
|
@ -513,7 +513,7 @@ ImagingNewInternal(const char *mode, int xsize, int ysize, int dirty) {
|
||||||
return im;
|
return im;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImagingError_Clear();
|
PyErr_Clear();
|
||||||
|
|
||||||
// Try to allocate the image once more with smallest possible block size
|
// Try to allocate the image once more with smallest possible block size
|
||||||
MUTEX_LOCK(&ImagingDefaultArena.mutex);
|
MUTEX_LOCK(&ImagingDefaultArena.mutex);
|
||||||
|
|
|
@ -69,7 +69,7 @@ _tiffReadProc(thandle_t hdata, tdata_t buf, tsize_t size) {
|
||||||
);
|
);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
to_read = min(size, min(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
|
to_read = MIN(size, MIN(state->size, (tsize_t)state->eof) - (tsize_t)state->loc);
|
||||||
TRACE(("to_read: %d\n", (int)to_read));
|
TRACE(("to_read: %d\n", (int)to_read));
|
||||||
|
|
||||||
_TIFFmemcpy(buf, (UINT8 *)state->data + state->loc, to_read);
|
_TIFFmemcpy(buf, (UINT8 *)state->data + state->loc, to_read);
|
||||||
|
@ -87,7 +87,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
|
||||||
TRACE(("_tiffWriteProc: %d \n", (int)size));
|
TRACE(("_tiffWriteProc: %d \n", (int)size));
|
||||||
dump_state(state);
|
dump_state(state);
|
||||||
|
|
||||||
to_write = min(size, state->size - (tsize_t)state->loc);
|
to_write = MIN(size, state->size - (tsize_t)state->loc);
|
||||||
if (state->flrealloc && size > to_write) {
|
if (state->flrealloc && size > to_write) {
|
||||||
tdata_t new_data;
|
tdata_t new_data;
|
||||||
tsize_t newsize = state->size;
|
tsize_t newsize = state->size;
|
||||||
|
@ -114,7 +114,7 @@ _tiffWriteProc(thandle_t hdata, tdata_t buf, tsize_t size) {
|
||||||
|
|
||||||
_TIFFmemcpy((UINT8 *)state->data + state->loc, buf, to_write);
|
_TIFFmemcpy((UINT8 *)state->data + state->loc, buf, to_write);
|
||||||
state->loc += (toff_t)to_write;
|
state->loc += (toff_t)to_write;
|
||||||
state->eof = max(state->loc, state->eof);
|
state->eof = MAX(state->loc, state->eof);
|
||||||
|
|
||||||
dump_state(state);
|
dump_state(state);
|
||||||
return to_write;
|
return to_write;
|
||||||
|
@ -333,7 +333,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
|
||||||
|
|
||||||
for (; state->y < state->ysize; state->y += rows_per_block) {
|
for (; state->y < state->ysize; state->y += rows_per_block) {
|
||||||
img.row_offset = state->y;
|
img.row_offset = state->y;
|
||||||
rows_to_read = min(rows_per_block, img.height - state->y);
|
rows_to_read = MIN(rows_per_block, img.height - state->y);
|
||||||
|
|
||||||
if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read)) {
|
if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read)) {
|
||||||
TRACE(("Decode Error, y: %d\n", state->y));
|
TRACE(("Decode Error, y: %d\n", state->y));
|
||||||
|
@ -349,7 +349,7 @@ _decodeAsRGBA(Imaging im, ImagingCodecState state, TIFF *tiff) {
|
||||||
|
|
||||||
// iterate over each row in the strip and stuff data into image
|
// iterate over each row in the strip and stuff data into image
|
||||||
for (current_row = 0;
|
for (current_row = 0;
|
||||||
current_row < min((INT32)rows_per_block, state->ysize - state->y);
|
current_row < MIN((INT32)rows_per_block, state->ysize - state->y);
|
||||||
current_row++) {
|
current_row++) {
|
||||||
TRACE(("Writing data into line %d ; \n", state->y + current_row));
|
TRACE(("Writing data into line %d ; \n", state->y + current_row));
|
||||||
|
|
||||||
|
@ -452,8 +452,8 @@ _decodeTile(
|
||||||
|
|
||||||
TRACE(("Read tile at %dx%d; \n\n", x, y));
|
TRACE(("Read tile at %dx%d; \n\n", x, y));
|
||||||
|
|
||||||
current_tile_width = min((INT32)tile_width, state->xsize - x);
|
current_tile_width = MIN((INT32)tile_width, state->xsize - x);
|
||||||
current_tile_length = min((INT32)tile_length, state->ysize - y);
|
current_tile_length = MIN((INT32)tile_length, state->ysize - y);
|
||||||
// iterate over each line in the tile and stuff data into image
|
// iterate over each line in the tile and stuff data into image
|
||||||
for (tile_y = 0; tile_y < current_tile_length; tile_y++) {
|
for (tile_y = 0; tile_y < current_tile_length; tile_y++) {
|
||||||
TRACE(
|
TRACE(
|
||||||
|
@ -566,7 +566,7 @@ _decodeStrip(
|
||||||
|
|
||||||
// iterate over each row in the strip and stuff data into image
|
// iterate over each row in the strip and stuff data into image
|
||||||
for (strip_row = 0;
|
for (strip_row = 0;
|
||||||
strip_row < min((INT32)rows_per_strip, state->ysize - state->y);
|
strip_row < MIN((INT32)rows_per_strip, state->ysize - state->y);
|
||||||
strip_row++) {
|
strip_row++) {
|
||||||
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
|
TRACE(("Writing data into line %d ; \n", state->y + strip_row));
|
||||||
|
|
||||||
|
|
|
@ -6,20 +6,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _TIFFIO_
|
|
||||||
#include <tiffio.h>
|
#include <tiffio.h>
|
||||||
#endif
|
|
||||||
#ifndef _TIFF_
|
|
||||||
#include <tiff.h>
|
#include <tiff.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef min
|
|
||||||
#define min(x, y) ((x > y) ? y : x)
|
|
||||||
#define max(x, y) ((x < y) ? y : x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef _PIL_LIBTIFF_
|
|
||||||
#define _PIL_LIBTIFF_
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
tdata_t data; /* tdata_t == void* */
|
tdata_t data; /* tdata_t == void* */
|
||||||
|
@ -57,5 +45,3 @@ ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define TRACE(args)
|
#define TRACE(args)
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
* Copyright (c) Fredrik Lundh 1996.
|
* Copyright (c) Fredrik Lundh 1996.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "zlib.h"
|
#include <zlib.h>
|
||||||
|
|
||||||
/* modes */
|
/* modes */
|
||||||
#define ZIP_PNG 0 /* continuous, filtered image data */
|
#define ZIP_PNG 0 /* continuous, filtered image data */
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#include "Python.h"
|
|
||||||
#include "Imaging.h"
|
#include "Imaging.h"
|
||||||
|
|
||||||
Py_ssize_t
|
Py_ssize_t
|
||||||
|
|
12
src/map.c
12
src/map.c
|
@ -18,16 +18,8 @@
|
||||||
* FIXME: should move the memory mapping primitives into libImaging!
|
* FIXME: should move the memory mapping primitives into libImaging!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
/* compatibility wrappers (defined in _imaging.c) */
|
|
||||||
extern int
|
|
||||||
PyImaging_CheckBuffer(PyObject *buffer);
|
|
||||||
extern int
|
|
||||||
PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view);
|
|
||||||
|
|
||||||
extern PyObject *
|
extern PyObject *
|
||||||
PyImagingNew(Imaging im);
|
PyImagingNew(Imaging im);
|
||||||
|
|
||||||
|
@ -77,7 +69,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!PyImaging_CheckBuffer(target)) {
|
if (!PyObject_CheckBuffer(target)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
|
PyErr_SetString(PyExc_TypeError, "expected string or buffer");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +97,7 @@ PyImaging_MapBuffer(PyObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check buffer size */
|
/* check buffer size */
|
||||||
if (PyImaging_GetBuffer(target, &view) < 0) {
|
if (PyObject_GetBuffer(target, &view, PyBUF_SIMPLE) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
|
@ -89,8 +87,7 @@ _outline_move(OutlineObject *self, PyObject *args) {
|
||||||
|
|
||||||
ImagingOutlineMove(self->outline, x0, y0);
|
ImagingOutlineMove(self->outline, x0, y0);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -102,8 +99,7 @@ _outline_line(OutlineObject *self, PyObject *args) {
|
||||||
|
|
||||||
ImagingOutlineLine(self->outline, x1, y1);
|
ImagingOutlineLine(self->outline, x1, y1);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -115,8 +111,7 @@ _outline_curve(OutlineObject *self, PyObject *args) {
|
||||||
|
|
||||||
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
|
ImagingOutlineCurve(self->outline, x1, y1, x2, y2, x3, y3);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -127,8 +122,7 @@ _outline_close(OutlineObject *self, PyObject *args) {
|
||||||
|
|
||||||
ImagingOutlineClose(self->outline);
|
ImagingOutlineClose(self->outline);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -140,8 +134,7 @@ _outline_transform(OutlineObject *self, PyObject *args) {
|
||||||
|
|
||||||
ImagingOutlineTransform(self->outline, a);
|
ImagingOutlineTransform(self->outline, a);
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct PyMethodDef _outline_methods[] = {
|
static struct PyMethodDef _outline_methods[] = {
|
||||||
|
|
21
src/path.c
21
src/path.c
|
@ -25,17 +25,8 @@
|
||||||
* See the README file for information on usage and redistribution.
|
* See the README file for information on usage and redistribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
#include "thirdparty/pythoncapi_compat.h"
|
|
||||||
#include "libImaging/Imaging.h"
|
#include "libImaging/Imaging.h"
|
||||||
|
#include "thirdparty/pythoncapi_compat.h"
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
/* compatibility wrappers (defined in _imaging.c) */
|
|
||||||
extern int
|
|
||||||
PyImaging_CheckBuffer(PyObject *buffer);
|
|
||||||
extern int
|
|
||||||
PyImaging_GetBuffer(PyObject *buffer, Py_buffer *view);
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/* Class */
|
/* Class */
|
||||||
|
@ -126,10 +117,10 @@ PyPath_Flatten(PyObject *data, double **pxy) {
|
||||||
return path->count;
|
return path->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyImaging_CheckBuffer(data)) {
|
if (PyObject_CheckBuffer(data)) {
|
||||||
/* Assume the buffer contains floats */
|
/* Assume the buffer contains floats */
|
||||||
Py_buffer buffer;
|
Py_buffer buffer;
|
||||||
if (PyImaging_GetBuffer(data, &buffer) == 0) {
|
if (PyObject_GetBuffer(data, &buffer, PyBUF_SIMPLE) == 0) {
|
||||||
float *ptr = (float *)buffer.buf;
|
float *ptr = (float *)buffer.buf;
|
||||||
n = buffer.len / (2 * sizeof(float));
|
n = buffer.len / (2 * sizeof(float));
|
||||||
xy = alloc_array(n);
|
xy = alloc_array(n);
|
||||||
|
@ -415,8 +406,7 @@ path_map(PyPathObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
self->mapping = 0;
|
self->mapping = 0;
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -528,8 +518,7 @@ path_transform(PyPathObject *self, PyObject *args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(Py_None);
|
Py_RETURN_NONE;
|
||||||
return Py_None;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct PyMethodDef methods[] = {
|
static struct PyMethodDef methods[] = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user