{
if (xstart < 0 || ystart < 0 || xdest < 0 || ydest < 0)
return;
if (xext <= 0)
xext = source->xsize;
if (xext > source->xsize - xstart)
xext = source->xsize - xstart;
if (xext > (dest->xsize - xdest) * scale)
xext = (dest->xsize - xdest) * scale;
if (yext <= 0)
yext = source->ysize;
if (yext > source->ysize - ystart)
yext = source->ysize - ystart;
if (yext > (dest->ysize - ydest) * scale)
yext = (dest->ysize - ydest) * scale;
if (xext <= 0 || yext <= 0)
return;
xfactor = xext % scale;
if (xfactor == 0)
xfactor = scale;
destext = (xext + scale - 1) / scale;
if (adjust_grey)
shift = dest->bps - source->bps;
else
shift = 0;
linesums =
new inT32[destext * source->bytespp];
for (yoffset = 0; yoffset < yext; ydest++) {
for (xindex = 0; xindex < (destext) * source->bytespp; xindex++)
linesums[xindex] = 0;
for (yindex = 0; yindex < scale && ystart + yoffset < source->ysize;
yindex++) {
source->
fast_get_line (xstart, ystart + yoffset, xext, ©line);
if (source->bpp == 24) {
for (xcoord = 1, sums = linesums; xcoord < destext;
xcoord++, sums += 3) {
for (xindex = 0; xindex < scale; xindex++) {
*sums += *pixel++;
*(sums + 1) += *pixel++;
*(sums + 2) += *pixel++;
}
}
for (xindex = 0; xindex < xfactor; xindex++) {
*sums += *pixel++;
*(sums + 1) += *pixel++;
*(sums + 2) += *pixel++;
}
}
else {
for (xcoord = 1, sums = linesums; xcoord < destext;
xcoord++, sums++) {
for (xindex = 0; xindex < scale; xindex++)
*sums += *pixel++;
}
for (xindex = 0; xindex < xfactor; xindex++)
*sums += *pixel++;
}
yoffset++;
}
divisor = yindex * scale;
if (divisor == 0) {
("Impossible:divisor=0!, yindex=%d, scale=%d, yoffset=%d,yext=%d\n",
yindex, scale, yoffset, yext);
break;
}
if (shift <= 0) {
divisor <<= (-shift);
div2 = divisor / 2;
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
xindex > 0; xindex--)
*pixel++ = (
uinT8) ((div2 + *sums++) / divisor);
div2 = (yindex * xfactor << (-shift)) / 2;
for (xindex = source->bytespp; xindex > 0; xindex--)
*pixel++ =
(
uinT8) ((div2 + *sums++) / (yindex * xfactor << (-shift)));
}
else {
div2 = divisor / 2;
for (sums = linesums, xindex = (destext - 1) * source->bytespp;
xindex > 0; xindex--)
*pixel++ = (
uinT8) ((div2 + (*sums++ << shift)) / divisor);
div2 = (yindex * xfactor) / 2;
for (xindex = source->bytespp; xindex > 0; xindex--)
*pixel++ =
(
uinT8) ((div2 + (*sums++ << shift)) / (yindex * xfactor));
}
dest->
put_line (xdest, ydest, destext, ©line, 0);
}
delete [] linesums;
}