GD-Image-CopyIFS
view release on metacpan or search on metacpan
#include "libIFS.h"
/*
************************************************************
copy an image from srcImg to dstImg via an IFS algorithm.
The source starts at (srcX, srcY), of size (srcW, srcH),
and is copied to the destination, starting at (dstX, dstY),
of size (dstW, dstH).
min_factor, between 0 and 1, determines the minimum fraction of
the destination points to be colored by the IFS algorthm. The
remainder simply use the nearest available pixel to determine
the colour. Values very close to 1 will produce better looking
images, but will take longer.
max_factor, greater than 1, determines the maximum number
of iterations that the IFS algorithm uses. A value of 1
will have this iteration number equal to the number of
pixels in the destination; increasing this value will
produce better looking images, but at the expense of speed.
Reasonable values are around 5.
**********************************************************
*/
void gdImageCopyIFS (gdImagePtr dstImg, gdImagePtr srcImg,
int dstX, int dstY, int srcX, int srcY,
int dstW, int dstH, int srcW, int srcH,
double min_factor, double max_factor) {
ifs **z;
int **seen, i, j, dstXend, dstYend;
if (min_factor < 0 || min_factor > 1)
Perl_croak(aTHX_ "min_factor must be between 0 and 1");
if (max_factor < 1)
Perl_croak(aTHX_ "max_factor must be larger than 1");
dstXend = dstX + dstW;
dstYend = dstY + dstH;
/* allocate some arrays */
z = ifsmatrix(srcX, srcX + srcW, srcY, srcY + srcH);
seen = imatrix(dstX, dstX + dstW, dstY, dstY + dstH);
/* initialize some arrays */
for (i=dstX; i<=dstXend; i++) {
for (j=dstY; j<=dstYend; j++) {
seen[i][j] = 0;
}
}
generate_ifs(srcImg, z, srcX, srcY, dstX, dstY,
srcW, srcH, dstW, dstH);
generate_ifs_image(dstImg, z, seen, srcX, srcY, dstX, dstY,
srcW, srcH, dstW, dstH, dstXend, dstYend,
min_factor, max_factor);
fill_in_blanks(dstImg, seen, dstX, dstY, dstXend, dstYend);
free_ifsmatrix(z, srcX, srcX+srcW, srcY, srcY+srcH);
free_imatrix(seen, dstX, dstX+dstW, dstY, dstY+dstH);
}
void generate_ifs (gdImagePtr srcImg, ifs **z,
int srcX, int srcY, int dstX, int dstY,
int srcW, int srcH, int dstW, int dstH) {
int srcXend, srcYend, i, j, index, srcIsTrue;
double scaleX, scaleY;
srcXend = srcX + srcW;
srcYend = srcY + srcH;
scaleX = (double) (dstW) / (double) (srcW);
scaleY = (double) (dstH) / (double) (srcH);
srcIsTrue = srcImg->trueColor;
( run in 0.964 second using v1.01-cache-2.11-cpan-71847e10f99 )