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++) { 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]) { if ( ! bands[i]) {
for (j = 0; j < i; ++j) { for (j = 0; j < i; ++j) {
ImagingDelete(bands[j]); ImagingDelete(bands[j]);

View File

@ -72,7 +72,7 @@ create(Imaging im1, Imaging im2, char* mode)
xsize = (im1->xsize < im2->xsize) ? im1->xsize : im2->xsize; xsize = (im1->xsize < im2->xsize) ? im1->xsize : im2->xsize;
ysize = (im1->ysize < im2->ysize) ? im1->ysize : im2->ysize; ysize = (im1->ysize < im2->ysize) ? im1->ysize : im2->ysize;
return ImagingNew(im1->mode, xsize, ysize); return ImagingNewDirty(im1->mode, xsize, ysize);
} }
Imaging 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) if (width < 0.0 || height < 0.0 || quality < 2)
return (Imaging) ImagingError_ValueError(NULL); return (Imaging) ImagingError_ValueError(NULL);
im = ImagingNew("L", xsize, ysize); im = ImagingNewDirty("L", xsize, ysize);
if (!im) if (!im)
return NULL; return NULL;
@ -81,7 +81,7 @@ ImagingEffectNoise(int xsize, int ysize, float sigma)
int nextok; int nextok;
double this, next; double this, next;
imOut = ImagingNew("L", xsize, ysize); imOut = ImagingNewDirty("L", xsize, ysize);
if (!imOut) if (!imOut)
return NULL; return NULL;
@ -121,14 +121,14 @@ ImagingEffectSpread(Imaging imIn, int distance)
Imaging imOut; Imaging imOut;
int x, y; int x, y;
imOut = ImagingNew(imIn->mode, imIn->xsize, imIn->ysize); imOut = ImagingNewDirty(imIn->mode, imIn->xsize, imIn->ysize);
if (!imOut) if (!imOut)
return NULL; return NULL;
#define SPREAD(type, image)\ #define SPREAD(type, image)\
for (y = 0; y < imIn->ysize; y++)\ for (y = 0; y < imOut->ysize; y++)\
for (x = 0; x < imIn->xsize; x++) {\ for (x = 0; x < imOut->xsize; x++) {\
int xx = x + (rand() % distance) - distance/2;\ int xx = x + (rand() % distance) - distance/2;\
int yy = y + (rand() % distance) - distance/2;\ int yy = y + (rand() % distance) - distance/2;\
if (xx >= 0 && xx < imIn->xsize && yy >= 0 && yy < imIn->ysize) {\ if (xx >= 0 && xx < imIn->xsize && yy >= 0 && yy < imIn->ysize) {\

View File

@ -27,13 +27,6 @@
#include "Imaging.h" #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) static inline UINT8 clip8(float in)
{ {
if (in <= 0.0) 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 void
ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel, ImagingFilter3x3(Imaging imOut, Imaging im, const float* kernel,
float offset) float offset)
{ {
#define KERNEL1x3(in0, x, kernel, d) ( \ #define KERNEL1x3(in0, x, kernel, d) ( \
i2f((UINT8) in0[x-d]) * (kernel)[0] + \ _i2f((UINT8) in0[x-d]) * (kernel)[0] + \
i2f((UINT8) in0[x]) * (kernel)[1] + \ _i2f((UINT8) in0[x]) * (kernel)[1] + \
i2f((UINT8) in0[x+d]) * (kernel)[2]) _i2f((UINT8) in0[x+d]) * (kernel)[2])
int x = 0, y = 0; int x = 0, y = 0;
@ -210,11 +188,11 @@ ImagingFilter5x5(Imaging imOut, Imaging im, const float* kernel,
float offset) float offset)
{ {
#define KERNEL1x5(in0, x, kernel, d) ( \ #define KERNEL1x5(in0, x, kernel, d) ( \
i2f((UINT8) in0[x-d-d]) * (kernel)[0] + \ _i2f((UINT8) in0[x-d-d]) * (kernel)[0] + \
i2f((UINT8) in0[x-d]) * (kernel)[1] + \ _i2f((UINT8) in0[x-d]) * (kernel)[1] + \
i2f((UINT8) in0[x]) * (kernel)[2] + \ _i2f((UINT8) in0[x]) * (kernel)[2] + \
i2f((UINT8) in0[x+d]) * (kernel)[3] + \ _i2f((UINT8) in0[x+d]) * (kernel)[3] + \
i2f((UINT8) in0[x+d+d]) * (kernel)[4]) _i2f((UINT8) in0[x+d+d]) * (kernel)[4])
int x = 0, y = 0; int x = 0, y = 0;

View File

@ -182,8 +182,6 @@ extern void ImagingAccessInit(void);
extern ImagingAccess ImagingAccessNew(Imaging im); extern ImagingAccess ImagingAccessNew(Imaging im);
extern void _ImagingAccessDelete(Imaging im, ImagingAccess access); extern void _ImagingAccessDelete(Imaging im, ImagingAccess access);
#define ImagingAccessDelete(im, access) /* nop, for now */ #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 ImagingPaletteNew(const char *mode);
extern ImagingPalette ImagingPaletteNewBrowser(void); extern ImagingPalette ImagingPaletteNewBrowser(void);

View File

@ -28,3 +28,18 @@
#define PREBLEND(mask, in1, in2, tmp1)\ #define PREBLEND(mask, in1, in2, tmp1)\
(MULDIV255(in1, (255 - mask), tmp1) + in2) (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

@ -28,7 +28,7 @@ ImagingModeFilter(Imaging im, int size)
if (!im || im->bands != 1 || im->type != IMAGING_TYPE_UINT8) 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) if (!imOut)
return NULL; return NULL;

View File

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