1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-07 14:24:14 +01:00

changed indentation to use spaces only

This commit is contained in:
dan
2004-10-12 21:28:27 +00:00
parent 5912898b06
commit 6830b05716
240 changed files with 35951 additions and 35773 deletions

View File

@@ -1,19 +1,19 @@
/* scale.c - image scaling
*
*
* Raster graphics library
*
*
* Copyright (c) 1997-2003 Alfredo K. Kojima
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -41,11 +41,11 @@
*----------------------------------------------------------------------
* RScaleImage--
* Creates a scaled copy of an image.
*
*
* Returns:
* The new scaled image.
*
*----------------------------------------------------------------------
*
*----------------------------------------------------------------------
*/
#ifndef broken_code
RImage*
@@ -62,69 +62,69 @@ RScaleImage(RImage *image, unsigned new_width, unsigned new_height)
assert(new_width >= 0 && new_height >= 0);
if (new_width == image->width && new_height == image->height)
return RCloneImage(image);
return RCloneImage(image);
img = RCreateImage(new_width, new_height, image->format==RRGBAFormat);
if (!img)
return NULL;
/* fixed point math idea taken from Imlib by
if (!img)
return NULL;
/* fixed point math idea taken from Imlib by
* Carsten Haitzler (Rasterman) */
dx = (image->width<<16)/new_width;
dy = (image->height<<16)/new_height;
py = 0;
d = img->data;
if (image->format == RRGBAFormat) {
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
s = image->data+(t<<2); /* image->data+t*4 */
s = image->data+(t<<2); /* image->data+t*4 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
*(d++) = *(s+3);
t = (px - ox)>>16;
ox += t<<16;
s += t<<2; /* t*4 */
}
py += dy;
}
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
*(d++) = *(s+3);
t = (px - ox)>>16;
ox += t<<16;
s += t<<2; /* t*4 */
}
py += dy;
}
} else {
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
for (y=0; y<new_height; y++) {
t = image->width*(py>>16);
s = image->data+(t<<1)+t; /* image->data+t*3 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
t = (px - ox)>>16;
ox += t<<16;
s += (t<<1)+t; /* t*3 */
}
py += dy;
}
s = image->data+(t<<1)+t; /* image->data+t*3 */
ox = 0;
px = 0;
for (x=0; x<new_width; x++) {
px += dx;
*(d++) = *(s);
*(d++) = *(s+1);
*(d++) = *(s+2);
t = (px - ox)>>16;
ox += t<<16;
s += (t<<1)+t; /* t*3 */
}
py += dy;
}
}
return img;
}
@@ -142,7 +142,7 @@ RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
unsigned char *dr, *dg, *db, *da;
int ys = 0;
dst = RCreateImage(new_width, new_height, src->data[3]!=NULL);
@@ -166,62 +166,62 @@ RScaleImage(RImage *src, unsigned new_width, unsigned new_height)
da = dst->data[3];
if (sa == NULL) {
for (yd = 0; yd < new_height; yd++) {
int x;
for (yd = 0; yd < new_height; yd++) {
int x;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
while (e >= 0) {
sr++;
sg++;
sb++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
while (e >= 0) {
sr++;
sg++;
sb++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
} else {
for (yd = 0; yd < new_height; yd++) {
int x;
for (yd = 0; yd < new_height; yd++) {
int x;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sa = src->data[3] + ys * src->width;
sr = src->data[0] + ys * src->width;
sg = src->data[1] + ys * src->width;
sb = src->data[2] + ys * src->width;
sa = src->data[3] + ys * src->width;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
*(da++) = *sa;
for (x = 0; x < xd; x++) {
*(dr++) = *sr;
*(dg++) = *sg;
*(db++) = *sb;
*(da++) = *sa;
while (e >= 0) {
sr++;
sg++;
sb++;
sa++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
while (e >= 0) {
sr++;
sg++;
sb++;
sa++;
e -= xd2;
}
e += xs;
}
while (ee >= 0) {
ys++;
ee -= h2;
}
ee += ddy;
}
}
return dst;
@@ -283,8 +283,8 @@ double t;
if(t < 0) t = -t;
if(t < .5) return(.75 - (t * t));
if(t < 1.5) {
t = (t - 1.5);
return(.5 * (t * t));
t = (t - 1.5);
return(.5 * (t * t));
}
return(0.0);
}
@@ -296,14 +296,14 @@ B_spline_filter(t) /* box (*) box (*) box (*) box */
double t;
{
double tt;
if(t < 0) t = -t;
if(t < 1) {
tt = t * t;
return((.5 * tt * t) - tt + (2.0 / 3.0));
tt = t * t;
return((.5 * tt * t) - tt + (2.0 / 3.0));
} else if(t < 2) {
t = 2 - t;
return((1.0 / 6.0) * (t * t * t));
t = 2 - t;
return((1.0 / 6.0) * (t * t * t));
}
return(0.0);
}
@@ -338,20 +338,20 @@ Mitchell_filter(t)
double t;
{
double tt;
tt = t * t;
if(t < 0) t = -t;
if(t < 1.0) {
t = (((12.0 - 9.0 * B - 6.0 * C) * (t * tt))
+ ((-18.0 + 12.0 * B + 6.0 * C) * tt)
+ (6.0 - 2 * B));
return(t / 6.0);
t = (((12.0 - 9.0 * B - 6.0 * C) * (t * tt))
+ ((-18.0 + 12.0 * B + 6.0 * C) * tt)
+ (6.0 - 2 * B));
return(t / 6.0);
} else if(t < 2.0) {
t = (((-1.0 * B - 6.0 * C) * (t * tt))
+ ((6.0 * B + 30.0 * C) * tt)
+ ((-12.0 * B - 48.0 * C) * t)
+ (8.0 * B + 24 * C));
return(t / 6.0);
t = (((-1.0 * B - 6.0 * C) * (t * tt))
+ ((6.0 * B + 30.0 * C) * tt)
+ ((-12.0 * B - 48.0 * C) * t)
+ (8.0 * B + 24 * C));
return(t / 6.0);
}
return(0.0);
}
@@ -363,31 +363,31 @@ void
_wraster_change_filter(int type)
{
switch (type) {
case RBoxFilter:
filterf = box_filter;
fwidth = box_support;
break;
case RTriangleFilter:
filterf = triangle_filter;
fwidth = triangle_support;
break;
case RBellFilter:
filterf = bell_filter;
fwidth = bell_support;
break;
case RBSplineFilter:
filterf = B_spline_filter;
fwidth = B_spline_support;
break;
case RLanczos3Filter:
filterf = Lanczos3_filter;
fwidth = Lanczos3_support;
break;
default:
case RMitchellFilter:
filterf = Mitchell_filter;
fwidth = Mitchell_support;
break;
case RBoxFilter:
filterf = box_filter;
fwidth = box_support;
break;
case RTriangleFilter:
filterf = triangle_filter;
fwidth = triangle_support;
break;
case RBellFilter:
filterf = bell_filter;
fwidth = bell_support;
break;
case RBSplineFilter:
filterf = B_spline_filter;
fwidth = B_spline_support;
break;
case RLanczos3Filter:
filterf = Lanczos3_filter;
fwidth = Lanczos3_support;
break;
default:
case RMitchellFilter:
filterf = Mitchell_filter;
fwidth = Mitchell_support;
break;
}
}
@@ -415,7 +415,7 @@ CLIST *contrib; /* array of contribution lists */
/* return of calloc is not checked if NULL in the function below! */
RImage*
RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
{
{
RImage *tmp; /* intermediate image */
double xscale, yscale; /* zoom scale factors */
int i, j, k; /* loop variables */
@@ -428,7 +428,7 @@ RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
unsigned char *sp;
int sch = src->format == RRGBAFormat ? 4 : 3;
dst = RCreateImage(new_width, new_height, False);
/* create intermediate image to hold horizontal zoom */
@@ -439,186 +439,186 @@ RSmoothScaleImage(RImage *src, unsigned new_width, unsigned new_height)
/* pre-calculate filter contributions for a row */
contrib = (CLIST *)calloc(new_width, sizeof(CLIST));
if (xscale < 1.0) {
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
width = fwidth / xscale;
fscale = 1.0 / xscale;
for (i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int)(width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
} else {
for(i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
for(i = 0; i < new_width; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / xscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= src->width) {
n = (src->width - j) + src->width - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*sch;
contrib[i].p[k].weight = rweight;
}
}
}
/* apply filter to zoom horizontally from src to tmp */
p = tmp->data;
for(k = 0; k < tmp->height; ++k) {
CONTRIB *pp;
CONTRIB *pp;
sp = src->data + src->width*k*sch;
sp = src->data + src->width*k*sch;
for(i = 0; i < tmp->width; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p++ = CLAMP(rweight, 0, 255);
*p++ = CLAMP(gweight, 0, 255);
*p++ = CLAMP(bweight, 0, 255);
}
for(i = 0; i < tmp->width; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p++ = CLAMP(rweight, 0, 255);
*p++ = CLAMP(gweight, 0, 255);
*p++ = CLAMP(bweight, 0, 255);
}
}
/* free the memory allocated for horizontal filter weights */
for(i = 0; i < tmp->width; ++i) {
free(contrib[i].p);
free(contrib[i].p);
}
free(contrib);
/* pre-calculate filter contributions for a column */
contrib = (CLIST *)calloc(dst->height, sizeof(CLIST));
if(yscale < 1.0) {
width = fwidth / yscale;
fscale = 1.0 / yscale;
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
width = fwidth / yscale;
fscale = 1.0 / yscale;
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (width * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - width);
right = floor(center + width);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight / fscale) / fscale;
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
} else {
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
for(i = 0; i < dst->height; ++i) {
contrib[i].n = 0;
contrib[i].p = (CONTRIB *)calloc((int) (fwidth * 2 + 1),
sizeof(CONTRIB));
center = (double) i / yscale;
left = ceil(center - fwidth);
right = floor(center + fwidth);
for(j = left; j <= right; ++j) {
rweight = center - (double) j;
rweight = (*filterf)(rweight);
if(j < 0) {
n = -j;
} else if(j >= tmp->height) {
n = (tmp->height - j) + tmp->height - 1;
} else {
n = j;
}
k = contrib[i].n++;
contrib[i].p[k].pixel = n*3;
contrib[i].p[k].weight = rweight;
}
}
}
/* apply filter to zoom vertically from tmp to dst */
sp = malloc(tmp->height*3);
for(k = 0; k < new_width; ++k) {
CONTRIB *pp;
p = dst->data + k*3;
CONTRIB *pp;
/* copy a column into a row */
{
int i;
unsigned char *p, *d;
p = dst->data + k*3;
d = sp;
for(i = tmp->height, p = tmp->data + k*3; i-- > 0;
p += tmp->width*3) {
*d++ = *p;
*d++ = *(p+1);
*d++ = *(p+2);
}
}
for(i = 0; i < new_height; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p = CLAMP(rweight, 0, 255);
*(p+1) = CLAMP(gweight, 0, 255);
*(p+2) = CLAMP(bweight, 0, 255);
p += new_width*3;
}
/* copy a column into a row */
{
int i;
unsigned char *p, *d;
d = sp;
for(i = tmp->height, p = tmp->data + k*3; i-- > 0;
p += tmp->width*3) {
*d++ = *p;
*d++ = *(p+1);
*d++ = *(p+2);
}
}
for(i = 0; i < new_height; ++i) {
rweight = gweight = bweight = 0.0;
pp = contrib[i].p;
for(j = 0; j < contrib[i].n; ++j) {
rweight += sp[pp[j].pixel] * pp[j].weight;
gweight += sp[pp[j].pixel+1] * pp[j].weight;
bweight += sp[pp[j].pixel+2] * pp[j].weight;
}
*p = CLAMP(rweight, 0, 255);
*(p+1) = CLAMP(gweight, 0, 255);
*(p+2) = CLAMP(bweight, 0, 255);
p += new_width*3;
}
}
free(sp);
/* free the memory allocated for vertical filter weights */
for(i = 0; i < dst->height; ++i) {
free(contrib[i].p);
free(contrib[i].p);
}
free(contrib);
RReleaseImage(tmp);
return dst;
}