Re: waste of RAM/bug in render.c?
Wolfgang Spraul <[email protected]>
| Newsgroups | gmane.comp.video.graphicsmagick.core |
|---|---|
| Organization | Q AG |
| Message-ID | <[email protected]> |
Bob - the attached patch will improve SampleImage() by switching from double to long. I don't think there is any downside, the calculations result in exactly the same values. My patch makes SampleImage() use less RAM and less CPU, the output quality remains exactly the same. Please let me know what you think. Regards, Wolfgang
ws_sample_image_long.patch
(text/x-diff, 2.7 KB)
? ws_sample_image_long.patch
Index: magick/resize.c
===================================================================
RCS file: /GraphicsMagick/GraphicsMagick/magick/resize.c,v
retrieving revision 1.62
diff -u -r1.62 resize.c
--- magick/resize.c 3 Feb 2004 04:56:28 -0000 1.62
+++ magick/resize.c 4 Feb 2004 00:17:37 -0000
@@ -1243,7 +1243,7 @@
{
#define SampleImageText " Sample image... "
- double
+ long
*x_offset,
*y_offset;
@@ -1294,10 +1294,10 @@
Allocate scan line buffer and column offset buffers.
*/
pixels=MagickAllocateMemory(PixelPacket *,image->columns*sizeof(PixelPacket));
- x_offset=MagickAllocateMemory(double *,sample_image->columns*sizeof(double));
- y_offset=MagickAllocateMemory(double *,sample_image->rows*sizeof(double));
- if ((pixels == (PixelPacket *) NULL) || (x_offset == (double *) NULL) ||
- (y_offset == (double *) NULL))
+ x_offset=MagickAllocateMemory(long *,sample_image->columns*sizeof(*x_offset));
+ y_offset=MagickAllocateMemory(long *,sample_image->rows*sizeof(*y_offset));
+ if ((pixels == (PixelPacket *) NULL) || (x_offset == (long *) NULL) ||
+ (y_offset == (long *) NULL))
{
DestroyImage(sample_image);
ThrowImageException3(ResourceLimitError,MemoryAllocationFailed,
@@ -1307,9 +1307,9 @@
Initialize pixel offsets.
*/
for (x=0; x < (long) sample_image->columns; x++)
- x_offset[x]=(double) x*image->columns/(double) sample_image->columns;
+ x_offset[x]= x * image->columns / sample_image->columns;
for (y=0; y < (long) sample_image->rows; y++)
- y_offset[y]=(double) y*image->rows/(double) sample_image->rows;
+ y_offset[y]= y * image->rows / sample_image->rows;
/*
Sample each row.
*/
@@ -1319,12 +1319,12 @@
q=SetImagePixels(sample_image,0,y,sample_image->columns,1);
if (q == (PixelPacket *) NULL)
break;
- if (j != (long) y_offset[y])
+ if (j != y_offset[y])
{
/*
Read a scan line.
*/
- j=(long) y_offset[y];
+ j= y_offset[y];
p=AcquireImagePixels(image,0,j,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
@@ -1334,13 +1334,13 @@
Sample each column.
*/
for (x=0; x < (long) sample_image->columns; x++)
- *q++=pixels[(long) x_offset[x]];
+ *q++=pixels[x_offset[x]];
indexes=GetIndexes(image);
sample_indexes=GetIndexes(sample_image);
if ((indexes != (IndexPacket *) NULL) &&
(sample_indexes != (IndexPacket *) NULL))
for (x=0; x < (long) sample_image->columns; x++)
- sample_indexes[x]=indexes[(long) x_offset[x]];
+ sample_indexes[x]=indexes[x_offset[x]];
if (!SyncImagePixels(sample_image))
break;
if (QuantumTick(y,sample_image->rows))