From bec01d3b0deb545b04c9377678fe1d4dfdbed159 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 17 Aug 2017 03:23:13 +0300 Subject: [PATCH] Use ImagingNewDirty when possible --- libImaging/Bands.c | 2 +- libImaging/Chops.c | 50 ++++++++++++++++++++--------------------- libImaging/Effects.c | 14 ++++++------ libImaging/ModeFilter.c | 6 ++--- libImaging/Quant.c | 4 ++-- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/libImaging/Bands.c b/libImaging/Bands.c index ef4b2225d..7b1b9231a 100644 --- a/libImaging/Bands.c +++ b/libImaging/Bands.c @@ -91,7 +91,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]); diff --git a/libImaging/Chops.c b/libImaging/Chops.c index 73d961231..8059b6ffb 100644 --- a/libImaging/Chops.c +++ b/libImaging/Chops.c @@ -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 diff --git a/libImaging/Effects.c b/libImaging/Effects.c index 899fbe637..aeef9d6ca 100644 --- a/libImaging/Effects.c +++ b/libImaging/Effects.c @@ -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) {\ diff --git a/libImaging/ModeFilter.c b/libImaging/ModeFilter.c index b1fc7e8e6..692da86db 100644 --- a/libImaging/ModeFilter.c +++ b/libImaging/ModeFilter.c @@ -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; diff --git a/libImaging/Quant.c b/libImaging/Quant.c index 25aa7f079..df3138162 100644 --- a/libImaging/Quant.c +++ b/libImaging/Quant.c @@ -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);