Merge branch 'master' into block-storage

# Conflicts:
#	libImaging/Imaging.h
This commit is contained in:
Alexander 2017-09-16 22:21:56 +03:00
commit 63b925d74c
8 changed files with 136 additions and 145 deletions

View File

@ -84,7 +84,7 @@ ImagingSplit(Imaging imIn, Imaging bands[4])
}
for (i = 0; i < imIn->bands; i++) {
bands[i] = ImagingNew("L", imIn->xsize, imIn->ysize);
bands[i] = ImagingNewDirty("L", imIn->xsize, imIn->ysize);
if ( ! bands[i]) {
for (j = 0; j < i; ++j) {
ImagingDelete(bands[j]);

View File

@ -19,41 +19,41 @@
#include "Imaging.h"
#define CHOP(operation, mode)\
#define CHOP(operation, mode)\
int x, y;\
Imaging imOut;\
imOut = create(imIn1, imIn2, mode);\
if (!imOut)\
return NULL;\
return NULL;\
for (y = 0; y < imOut->ysize; y++) {\
UINT8* out = (UINT8*) imOut->image[y];\
UINT8* in1 = (UINT8*) imIn1->image[y];\
UINT8* in2 = (UINT8*) imIn2->image[y];\
for (x = 0; x < imOut->linesize; x++) {\
int temp = operation;\
if (temp <= 0)\
out[x] = 0;\
else if (temp >= 255)\
out[x] = 255;\
else\
out[x] = temp;\
}\
UINT8* out = (UINT8*) imOut->image[y];\
UINT8* in1 = (UINT8*) imIn1->image[y];\
UINT8* in2 = (UINT8*) imIn2->image[y];\
for (x = 0; x < imOut->linesize; x++) {\
int temp = operation;\
if (temp <= 0)\
out[x] = 0;\
else if (temp >= 255)\
out[x] = 255;\
else\
out[x] = temp;\
}\
}\
return imOut;
#define CHOP2(operation, mode)\
#define CHOP2(operation, mode)\
int x, y;\
Imaging imOut;\
imOut = create(imIn1, imIn2, mode);\
if (!imOut)\
return NULL;\
return NULL;\
for (y = 0; y < imOut->ysize; y++) {\
UINT8* out = (UINT8*) imOut->image[y];\
UINT8* in1 = (UINT8*) imIn1->image[y];\
UINT8* in2 = (UINT8*) imIn2->image[y];\
for (x = 0; x < imOut->linesize; x++) {\
out[x] = operation;\
}\
UINT8* out = (UINT8*) imOut->image[y];\
UINT8* in1 = (UINT8*) imIn1->image[y];\
UINT8* in2 = (UINT8*) imIn2->image[y];\
for (x = 0; x < imOut->linesize; x++) {\
out[x] = operation;\
}\
}\
return imOut;
@ -64,15 +64,15 @@ create(Imaging im1, Imaging im2, char* mode)
if (!im1 || !im2 || im1->type != IMAGING_TYPE_UINT8 ||
(mode != NULL && (strcmp(im1->mode, "1") || strcmp(im2->mode, "1"))))
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
if (im1->type != im2->type ||
im1->bands != im2->bands)
return (Imaging) ImagingError_Mismatch();
return (Imaging) ImagingError_Mismatch();
xsize = (im1->xsize < im2->xsize) ? im1->xsize : im2->xsize;
ysize = (im1->ysize < im2->ysize) ? im1->ysize : im2->ysize;
return ImagingNew(im1->mode, xsize, ysize);
return ImagingNewDirty(im1->mode, xsize, ysize);
}
Imaging

View File

@ -37,7 +37,7 @@ ImagingEffectMandelbrot(int xsize, int ysize, double extent[4], int quality)
if (width < 0.0 || height < 0.0 || quality < 2)
return (Imaging) ImagingError_ValueError(NULL);
im = ImagingNew("L", xsize, ysize);
im = ImagingNewDirty("L", xsize, ysize);
if (!im)
return NULL;
@ -81,7 +81,7 @@ ImagingEffectNoise(int xsize, int ysize, float sigma)
int nextok;
double this, next;
imOut = ImagingNew("L", xsize, ysize);
imOut = ImagingNewDirty("L", xsize, ysize);
if (!imOut)
return NULL;
@ -90,7 +90,7 @@ ImagingEffectNoise(int xsize, int ysize, float sigma)
for (y = 0; y < imOut->ysize; y++) {
UINT8* out = imOut->image8[y];
for (x = 0; x < imOut->xsize; x++) {
for (x = 0; x < imOut->xsize; x++) {
if (nextok) {
this = next;
nextok = 0;
@ -121,14 +121,14 @@ ImagingEffectSpread(Imaging imIn, int distance)
Imaging imOut;
int x, y;
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize);
imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize);
if (!imOut)
return NULL;
return NULL;
#define SPREAD(type, image)\
for (y = 0; y < imIn->ysize; y++)\
for (x = 0; x < imIn->xsize; x++) {\
for (y = 0; y < imOut->ysize; y++)\
for (x = 0; x < imOut->xsize; x++) {\
int xx = x + (rand() % distance) - distance/2;\
int yy = y + (rand() % distance) - distance/2;\
if (xx >= 0 && xx < imIn->xsize && yy >= 0 && yy < imIn->ysize) {\

View File

@ -27,13 +27,6 @@
#include "Imaging.h"
#ifdef WORDS_BIGENDIAN
#define MAKE_UINT32(u0, u1, u2, u3) (u3 | (u2<<8) | (u1<<16) | (u0<<24))
#else
#define MAKE_UINT32(u0, u1, u2, u3) (u0 | (u1<<8) | (u2<<16) | (u3<<24))
#endif
static inline UINT8 clip8(float in)
{
if (in <= 0.0)
@ -91,29 +84,14 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode)
}
/* This is work around bug in GCC prior 4.9 in 64 bit mode.
GCC generates code with partial dependency which 3 times slower.
See: http://stackoverflow.com/a/26588074/253146 */
#if defined(__x86_64__) && defined(__SSE__) && ! defined(__NO_INLINE__) && \
! defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900)
static float __attribute__((always_inline)) inline i2f(int v) {
float x;
__asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=X"(x) : "r"(v) );
return x;
}
#else
static float inline i2f(int v) { return (float) v; }
#endif
void
ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
float offset)
{
#define KERNEL1x3(in0, x, kernel, d) ( \
i2f((UINT8) in0[x-d]) * (kernel)[0] + \
i2f((UINT8) in0[x]) * (kernel)[1] + \
i2f((UINT8) in0[x+d]) * (kernel)[2])
_i2f((UINT8) in0[x-d]) * (kernel)[0] + \
_i2f((UINT8) in0[x]) * (kernel)[1] + \
_i2f((UINT8) in0[x+d]) * (kernel)[2])
int x = 0, y = 0;
@ -210,11 +188,11 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
float offset)
{
#define KERNEL1x5(in0, x, kernel, d) ( \
i2f((UINT8) in0[x-d-d]) * (kernel)[0] + \
i2f((UINT8) in0[x-d]) * (kernel)[1] + \
i2f((UINT8) in0[x]) * (kernel)[2] + \
i2f((UINT8) in0[x+d]) * (kernel)[3] + \
i2f((UINT8) in0[x+d+d]) * (kernel)[4])
_i2f((UINT8) in0[x-d-d]) * (kernel)[0] + \
_i2f((UINT8) in0[x-d]) * (kernel)[1] + \
_i2f((UINT8) in0[x]) * (kernel)[2] + \
_i2f((UINT8) in0[x+d]) * (kernel)[3] + \
_i2f((UINT8) in0[x+d+d]) * (kernel)[4])
int x = 0, y = 0;

View File

@ -20,7 +20,7 @@ extern "C" {
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#define M_PI 3.1415926535897932384626433832795
#endif
@ -29,18 +29,18 @@ extern "C" {
/*
* Image data organization:
*
* mode bytes byte order
* mode bytes byte order
* -------------------------------
* 1 1 1
* L 1 L
* P 1 P
* 1 1 1
* L 1 L
* P 1 P
* I 4 I (32-bit integer, native byte order)
* F 4 F (32-bit IEEE float, native byte order)
* RGB 4 R, G, B, -
* RGBA 4 R, G, B, A
* CMYK 4 C, M, Y, K
* YCbCr 4 Y, Cb, Cr, -
* Lab 4 L, a, b, -
* RGB 4 R, G, B, -
* RGBA 4 R, G, B, A
* CMYK 4 C, M, Y, K
* YCbCr 4 Y, Cb, Cr, -
* Lab 4 L, a, b, -
*
* experimental modes (incomplete):
* LA 4 L, -, -, A
@ -78,27 +78,27 @@ typedef struct ImagingPaletteInstance* ImagingPalette;
struct ImagingMemoryInstance {
/* Format */
char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
char mode[IMAGING_MODE_LENGTH]; /* Band names ("1", "L", "P", "RGB", "RGBA", "CMYK", "YCbCr", "BGR;xy") */
int type; /* Data type (IMAGING_TYPE_*) */
int depth; /* Depth (ignored in this version) */
int bands; /* Number of bands (1, 2, 3, or 4) */
int xsize; /* Image dimension. */
int ysize;
/* Colour palette (for "P" images only) */
ImagingPalette palette;
/* Data pointers */
UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
UINT8 **image8; /* Set for 8-bit images (pixelsize=1). */
INT32 **image32; /* Set for 32-bit images (pixelsize=4). */
/* Internals */
char **image; /* Actual raster data. */
char *block; /* Set if data is allocated in a single block. */
char **blocks; /* Memory blocks for pixel storage */
char **image; /* Actual raster data. */
char *block; /* Set if data is allocated in a single block. */
char **blocks; /* Memory blocks for pixel storage */
int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
int pixelsize; /* Size of a pixel, in bytes (1, 2 or 4) */
int linesize; /* Size of a line, in bytes (xsize * pixelsize) */
/* Virtual methods */
void (*destroy)(Imaging im);
@ -131,11 +131,11 @@ struct ImagingAccessInstance {
struct ImagingHistogramInstance {
/* Format */
char mode[IMAGING_MODE_LENGTH]; /* Band names (of corresponding source image) */
int bands; /* Number of bands (1, 3, or 4) */
char mode[IMAGING_MODE_LENGTH]; /* Band names (of corresponding source image) */
int bands; /* Number of bands (1, 3, or 4) */
/* Data */
long *histogram; /* Histogram (bands*256 longs) */
long *histogram; /* Histogram (bands*256 longs) */
};
@ -143,13 +143,13 @@ struct ImagingHistogramInstance {
struct ImagingPaletteInstance {
/* Format */
char mode[IMAGING_MODE_LENGTH]; /* Band names */
char mode[IMAGING_MODE_LENGTH]; /* Band names */
/* Data */
UINT8 palette[1024];/* Palette data (same format as image data) */
INT16* cache; /* Palette cache (used for predefined palettes) */
int keep_cache; /* This palette will be reused; keep cache */
INT16* cache; /* Palette cache (used for predefined palettes) */
int keep_cache; /* This palette will be reused; keep cache */
};
@ -171,8 +171,8 @@ extern Imaging ImagingNewMap(const char* filename, int readonly,
extern Imaging ImagingNewPrologue(const char *mode,
int xsize, int ysize);
extern Imaging ImagingNewPrologueSubtype(const char *mode,
int xsize, int ysize,
int structure_size);
int xsize, int ysize,
int structure_size);
extern void ImagingCopyInfo(Imaging destination, Imaging source);
@ -182,8 +182,6 @@ extern void ImagingAccessInit(void);
extern ImagingAccess ImagingAccessNew(Imaging im);
extern void _ImagingAccessDelete(Imaging im, ImagingAccess access);
#define ImagingAccessDelete(im, access) /* nop, for now */
/*#define ImagingAccessDelete(im, access) \
((access)->dynamic ? _ImagingAccessDelete((im), (access)), 0 : 0)) */
extern ImagingPalette ImagingPaletteNew(const char *mode);
extern ImagingPalette ImagingPaletteNewBrowser(void);
@ -192,10 +190,10 @@ extern void ImagingPaletteDelete(ImagingPalette palette);
extern int ImagingPaletteCachePrepare(ImagingPalette palette);
extern void ImagingPaletteCacheUpdate(ImagingPalette palette,
int r, int g, int b);
int r, int g, int b);
extern void ImagingPaletteCacheDelete(ImagingPalette palette);
#define ImagingPaletteCache(p, r, g, b)\
#define ImagingPaletteCache(p, r, g, b)\
p->cache[(r>>2) + (g>>2)*64 + (b>>2)*64*64]
extern Imaging ImagingQuantize(Imaging im, int colours, int mode, int kmeans);
@ -265,14 +263,14 @@ extern Imaging ImagingFilter(
extern Imaging ImagingFlipLeftRight(Imaging imOut, Imaging imIn);
extern Imaging ImagingFlipTopBottom(Imaging imOut, Imaging imIn);
extern Imaging ImagingGaussianBlur(Imaging imOut, Imaging imIn, float radius,
int passes);
int passes);
extern Imaging ImagingGetBand(Imaging im, int band);
extern Imaging ImagingMerge(const char* mode, Imaging bands[4]);
extern int ImagingSplit(Imaging im, Imaging bands[4]);
extern int ImagingGetBBox(Imaging im, int bbox[4]);
typedef struct { int x, y; INT32 count; INT32 pixel; } ImagingColorItem;
extern ImagingColorItem* ImagingGetColors(Imaging im, int maxcolors,
int *colors);
int *colors);
extern int ImagingGetExtrema(Imaging im, void *extrema);
extern int ImagingGetProjection(Imaging im, UINT8* xproj, UINT8* yproj);
extern ImagingHistogram ImagingGetHistogram(
@ -337,7 +335,7 @@ extern int ImagingDrawChord(Imaging im, int x0, int y0, int x1, int y1,
extern int ImagingDrawEllipse(Imaging im, int x0, int y0, int x1, int y1,
const void* ink, int fill, int op);
extern int ImagingDrawLine(Imaging im, int x0, int y0, int x1, int y1,
const void* ink, int op);
const void* ink, int op);
extern int ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1,
const void* ink, int width, int op);
extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
@ -345,9 +343,9 @@ extern int ImagingDrawPieslice(Imaging im, int x0, int y0, int x1, int y1,
int op);
extern int ImagingDrawPoint(Imaging im, int x, int y, const void* ink, int op);
extern int ImagingDrawPolygon(Imaging im, int points, int *xy,
const void* ink, int fill, int op);
const void* ink, int fill, int op);
extern int ImagingDrawRectangle(Imaging im, int x0, int y0, int x1, int y1,
const void* ink, int fill, int op);
const void* ink, int fill, int op);
/* Level 2 graphics (WORK IN PROGRESS) */
extern ImagingOutline ImagingOutlineNew(void);
@ -359,7 +357,7 @@ extern int ImagingDrawOutline(Imaging im, ImagingOutline outline,
extern int ImagingOutlineMove(ImagingOutline outline, float x, float y);
extern int ImagingOutlineLine(ImagingOutline outline, float x, float y);
extern int ImagingOutlineCurve(ImagingOutline outline, float x1, float y1,
float x2, float y2, float x3, float y3);
float x2, float y2, float x3, float y3);
extern int ImagingOutlineTransform(ImagingOutline outline, double a[6]);
extern int ImagingOutlineClose(ImagingOutline outline);
@ -388,30 +386,30 @@ extern UINT32 ImagingCRC32(UINT32 crc, UINT8* buffer, int bytes);
/* Codecs */
typedef struct ImagingCodecStateInstance *ImagingCodecState;
typedef int (*ImagingCodec)(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingBcnDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingBitDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingEpsEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingFliDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingGifDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingGifEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingHexDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
#ifdef HAVE_LIBJPEG
UINT8* buffer, int bytes);
#ifdef HAVE_LIBJPEG
extern int ImagingJpegDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingJpegDecodeCleanup(ImagingCodecState state);
extern int ImagingJpegUseJCSExtensions(void);
extern int ImagingJpegEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
#endif
#ifdef HAVE_OPENJPEG
extern int ImagingJpeg2KDecode(Imaging im, ImagingCodecState state,
@ -422,45 +420,45 @@ extern int ImagingJpeg2KEncode(Imaging im, ImagingCodecState state,
extern int ImagingJpeg2KEncodeCleanup(ImagingCodecState state);
#endif
extern int ImagingLzwDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
#ifdef HAVE_LIBTIFF
UINT8* buffer, int bytes);
#ifdef HAVE_LIBTIFF
extern int ImagingLibTiffDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingLibTiffEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
#endif
#ifdef HAVE_LIBMPEG
#ifdef HAVE_LIBMPEG
extern int ImagingMpegDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
#endif
extern int ImagingMspDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingPackbitsDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingPcdDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingPcxDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingPcxEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingRawDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingRawEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingSunRleDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingTgaRleDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingXbmDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingXbmEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
#ifdef HAVE_LIBZ
UINT8* buffer, int bytes);
#ifdef HAVE_LIBZ
extern int ImagingZipDecode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingZipDecodeCleanup(ImagingCodecState state);
extern int ImagingZipEncode(Imaging im, ImagingCodecState state,
UINT8* buffer, int bytes);
UINT8* buffer, int bytes);
extern int ImagingZipEncodeCleanup(ImagingCodecState state);
#endif
@ -504,12 +502,12 @@ extern Py_ssize_t _imaging_tell_pyFd(PyObject *fd);
/* Errcodes */
#define IMAGING_CODEC_END 1
#define IMAGING_CODEC_OVERRUN -1
#define IMAGING_CODEC_BROKEN -2
#define IMAGING_CODEC_UNKNOWN -3
#define IMAGING_CODEC_CONFIG -8
#define IMAGING_CODEC_MEMORY -9
#define IMAGING_CODEC_END 1
#define IMAGING_CODEC_OVERRUN -1
#define IMAGING_CODEC_BROKEN -2
#define IMAGING_CODEC_UNKNOWN -3
#define IMAGING_CODEC_CONFIG -8
#define IMAGING_CODEC_MEMORY -9

View File

@ -28,3 +28,18 @@
#define PREBLEND(mask, in1, in2, tmp1)\
(MULDIV255(in1, (255 - mask), tmp1) + in2)
/* This is to work around a bug in GCC prior 4.9 in 64 bit mode.
GCC generates code with partial dependency which is 3 times slower.
See: http://stackoverflow.com/a/26588074/253146 */
#if defined(__x86_64__) && defined(__SSE__) && ! defined(__NO_INLINE__) && \
! defined(__clang__) && defined(GCC_VERSION) && (GCC_VERSION < 40900)
static float __attribute__((always_inline)) inline _i2f(int v) {
float x;
__asm__("xorps %0, %0; cvtsi2ss %1, %0" : "=X"(x) : "r"(v) );
return x;
}
#else
static float inline _i2f(int v) { return (float) v; }
#endif

View File

@ -26,11 +26,11 @@ ImagingModeFilter(Imaging im, int size)
int histogram[256];
if (!im || im->bands != 1 || im->type != IMAGING_TYPE_UINT8)
return (Imaging) ImagingError_ModeError();
return (Imaging) ImagingError_ModeError();
imOut = ImagingNew(im->mode, im->xsize, im->ysize);
imOut = ImagingNewDirty(im->mode, im->xsize, im->ysize);
if (!imOut)
return NULL;
return NULL;
size = size / 2;

View File

@ -1642,11 +1642,11 @@ ImagingQuantize(Imaging im, int colors, int mode, int kmeans)
ImagingSectionLeave(&cookie);
if (result > 0) {
imOut = ImagingNew("P", im->xsize, im->ysize);
imOut = ImagingNewDirty("P", im->xsize, im->ysize);
ImagingSectionEnter(&cookie);
for (i = y = 0; y < im->ysize; y++)
for (x=0; x < im->xsize; x++)
for (x = 0; x < im->xsize; x++)
imOut->image8[y][x] = (unsigned char) newData[i++];
free(newData);