pike.git
/
src
/
modules
/
Image
/
dct.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/Image/dct.c:7:
/* **! module Image **! class Image */ #include "global.h" #include <math.h> #include <ctype.h>
-
#include "global.h"
+
#include "pike_macros.h" #include "object.h" #include "interpret.h" #include "svalue.h" #include "pike_error.h"
-
+
#include "module_support.h"
#include "image.h" #define sp Pike_sp extern struct program *image_program; #ifdef THIS #undef THIS /* Needed for NT */ #endif #define THIS ((struct image *)(Pike_fp->current_storage))
-
#define THISOBJ (Pike_fp->current_object)
+
-
#define testrange(x) MAXIMUM(MINIMUM((x),255),0)
-
+
static const double c0=0.70710678118654752440; static const double pi=3.14159265358979323846; /* **! method object dct(int newx,int newy) **! Scales the image to a new size. **! **! Method for scaling is rather complex; **! the image is transformed via a cosine transform, **! and then resampled back.
pike.git/src/modules/Image/dct.c:71:
void image_dct(INT32 args) { rgbd_group *area,*val; struct object *o; struct image *img; INT32 x,y,u,v; double xsz2,ysz2,enh,xp,yp,dx,dy; double *costbl; rgb_group *pix;
-
if (!THIS->img)
-
Pike
_
error
(
"Called Image.Image object is not initialized\n"
);
+
CHECK
_
INIT
();
-
+
get_all_args(NULL, args, "%d%d", &x, &y);
+
x = MAXIMUM(1, x);
+
y = MAXIMUM(1, y);
+
#ifdef DCT_DEBUG fprintf(stderr,"%lu bytes, %lu bytes\n",
-
DO_NOT_WARN
(
(
unsigned long)(sizeof(rgbd_group)*THIS->xsize*THIS->ysize)
)
,
-
DO_NOT_WARN
(
(
unsigned long)(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1))
)
;
+
(unsigned long)(sizeof(rgbd_group)*THIS->xsize*THIS->ysize),
+
(unsigned long)(sizeof(rgb_group)*THIS->xsize*THIS->ysize+1));
#endif area=xalloc(sizeof(rgbd_group)*THIS->xsize*THIS->ysize+1); if (!(costbl=malloc(sizeof(double)*THIS->xsize+1))) { free(area);
-
resource
_error(NULL,
0
,
0,"memory",0,"Out
of memory.\n"
);
+
out
_
of_memory_
error(NULL,
-1
,
0);
} o=clone_object(image_program,0); img=(struct image*)(o->storage); *img=*THIS;
-
+
img->xsize = x;
+
img->ysize = y;
-
if (
args>=2
-
&& TYPEOF(sp[-args]) == T_INT
-
&& TYPEOF(sp[1-args]) == T_INT)
-
{
-
img->xsize=MAXIMUM(1,sp[-args].u.integer);
-
img->ysize=MAXIMUM(1,sp[1-args].u.integer);
-
}
-
else {
-
free(area);
-
free(costbl);
-
free_object(o);
-
bad_arg_error("image->dct",sp-args,args,0,"",sp-args,
-
"Bad arguments to image->dct()\n");
-
}
-
-
if (
!(img->img=
(rgb_group*)
malloc(sizeof(rgb_group)*
+
if (!(img->img=malloc(sizeof(rgb_group)*
img->xsize*img->ysize+RGB_VEC_PAD))) { free(area); free(costbl); free_object(o);
-
resource
_error(NULL,
0
,
0,"memory",0,"Out
of memory.\n"
);
+
out
_
of_memory_
error(NULL,
-1
,
0);
} xsz2=THIS->xsize*2.0; ysz2=THIS->ysize*2.0; enh=(8.0/THIS->xsize)*(8.0/THIS->ysize); for (u=0; u<THIS->xsize; u++) { double d,z0;
pike.git/src/modules/Image/dct.c:185:
for (u=0; u<THIS->xsize; u++) costbl[u]=cos( (2*xp+1)*u*pi/xsz2 ); for (v=0; v<THIS->ysize; v++) { z0=cos( (2*yp+1)*v*pi/ysz2 )*(v?1:c0)/4.0; for (u=0; u<THIS->xsize; u++) { double z; z = (u?1:c0) * costbl[u] * z0;
-
sum.r +=
DO_NOT_WARN
(
(
float)(val->r*z)
)
;
-
sum.g +=
DO_NOT_WARN
(
(
float)(val->g*z)
)
;
-
sum.b +=
DO_NOT_WARN
(
(
float)(val->b*z)
)
;
+
sum.r += (float)(val->r*z);
+
sum.g += (float)(val->g*z);
+
sum.b += (float)(val->b*z);
val++; } } sum.r *= (float)enh; sum.g *= (float)enh; sum.b *= (float)enh;
-
pix->r=testrange((
DOUBLE_TO_INT
(sum.r+0.5))
)
;
-
pix->g=testrange((
DOUBLE_TO_INT
(sum.g+0.5))
)
;
-
pix->b=testrange((
DOUBLE_TO_INT
(sum.b+0.5))
)
;
+
pix->r=testrange((
int)
(sum.r+0.5));
+
pix->g=testrange((
int)
(sum.g+0.5));
+
pix->b=testrange((
int)
(sum.b+0.5));
pix++; } #ifdef DCT_DEBUG fprintf(stderr,"."); fflush(stderr); #endif } free(area); free(costbl); pop_n_elems(args); push_object(o); }