Skip to content

Commit

Permalink
Merge pull request #2686 from uploadcare/new-dirty
Browse files Browse the repository at this point in the history
Use ImagingNewDirty when possible
  • Loading branch information
homm committed Sep 14, 2017
2 parents 51cee56 + dc143f7 commit 1f61c4e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion libImaging/Bands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
50 changes: 25 additions & 25 deletions libImaging/Chops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions libImaging/Effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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) {\
Expand Down
6 changes: 3 additions & 3 deletions libImaging/ModeFilter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions libImaging/Quant.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1f61c4e

Please sign in to comment.