Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0317a47

Browse files
committed
Added imageopmodule.c, also added them to Makefile and config.c.
Fixed a bug in Addmodule.sh that caused a crash in Configure.py. Fixed the crash in Configure.py...
1 parent a1b51f3 commit 0317a47

2 files changed

Lines changed: 184 additions & 0 deletions

File tree

Modules/config.c.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ extern void initcl();
220220
#ifdef USE_TIME
221221
extern void inittime();
222222
#endif
223+
#ifdef USE_IMAGEOP
224+
extern void initimageop();
225+
#endif
223226
/* -- ADDMODULE MARKER 1 -- */
224227

225228
struct {
@@ -351,6 +354,10 @@ struct {
351354
{"time", inittime},
352355
#endif
353356

357+
#ifdef USE_IMAGEOP
358+
{"imageop", initimageop},
359+
#endif
360+
354361
/* -- ADDMODULE MARKER 2 -- */
355362

356363
{0, 0} /* Sentinel */

Modules/imageop.c

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/***********************************************************
2+
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
3+
Netherlands.
4+
5+
All Rights Reserved
6+
7+
Permission to use, copy, modify, and distribute this software and its
8+
documentation for any purpose and without fee is hereby granted,
9+
provided that the above copyright notice appear in all copies and that
10+
both that copyright notice and this permission notice appear in
11+
supporting documentation, and that the names of Stichting Mathematisch
12+
Centrum or CWI not be used in advertising or publicity pertaining to
13+
distribution of the software without specific, written prior permission.
14+
15+
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16+
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17+
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18+
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21+
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22+
23+
******************************************************************/
24+
25+
/* imageopmodule - Various operations on pictures */
26+
27+
#ifdef sun
28+
#define signed
29+
#endif
30+
31+
#include "allobjects.h"
32+
#include "modsupport.h"
33+
34+
#define CHARP(cp, xmax, x, y) ((char *)(cp+y*xmax+x))
35+
#define LONGP(cp, xmax, x, y) ((long *)(cp+4*(y*xmax+x)))
36+
37+
static object *ImageopError;
38+
39+
static object *
40+
imageop_crop(self, args)
41+
object *self;
42+
object *args;
43+
{
44+
char *cp, *ncp;
45+
long *nlp;
46+
int len, size, x, y, newx1, newx2, newy1, newy2;
47+
int ix, iy, xstep, ystep;
48+
object *rv;
49+
50+
if ( !getargs(args, "(s#iiiiiii)", &cp, &len, &size, &x, &y,
51+
&newx1, &newy1, &newx2, &newy2) )
52+
return 0;
53+
54+
if ( size != 1 && size != 4 ) {
55+
err_setstr(ImageopError, "Size should be 1 or 4");
56+
return 0;
57+
}
58+
if ( len != size*x*y ) {
59+
err_setstr(ImageopError, "String has incorrect length");
60+
return 0;
61+
}
62+
xstep = (newx1 < newx2)? 1 : -1;
63+
ystep = (newy1 < newy2)? 1 : -1;
64+
65+
rv = newsizedstringobject(NULL, (abs(newx2-newx1)+1)*(abs(newy2-newy1)+1)*size);
66+
if ( rv == 0 )
67+
return 0;
68+
ncp = (char *)getstringvalue(rv);
69+
nlp = (long *)ncp;
70+
newy2 += ystep;
71+
newx2 += xstep;
72+
for( iy = newy1; iy != newy2; iy+=ystep ) {
73+
for ( ix = newx1; ix != newx2; ix+=xstep ) {
74+
if ( iy < 0 || iy >= y || ix < 0 || ix >= x ) {
75+
if ( size == 1 ) *ncp++ = 0;
76+
else *nlp++ = 0;
77+
} else {
78+
if ( size == 1 ) *ncp++ = *CHARP(cp, x, ix, iy);
79+
else *nlp++ = *LONGP(cp, x, ix, iy);
80+
}
81+
}
82+
}
83+
return rv;
84+
}
85+
86+
static object *
87+
imageop_scale(self, args)
88+
object *self;
89+
object *args;
90+
{
91+
char *cp, *ncp;
92+
long *nlp;
93+
int len, size, x, y, newx, newy;
94+
int ix, iy;
95+
int oix, oiy;
96+
object *rv;
97+
98+
if ( !getargs(args, "(s#iiiii)", &cp, &len, &size, &x, &y, &newx, &newy) )
99+
return 0;
100+
101+
if ( size != 1 && size != 4 ) {
102+
err_setstr(ImageopError, "Size should be 1 or 4");
103+
return 0;
104+
}
105+
if ( len != size*x*y ) {
106+
err_setstr(ImageopError, "String has incorrect length");
107+
return 0;
108+
}
109+
110+
rv = newsizedstringobject(NULL, newx*newy*size);
111+
if ( rv == 0 )
112+
return 0;
113+
ncp = (char *)getstringvalue(rv);
114+
nlp = (long *)ncp;
115+
for( iy = 0; iy < newy; iy++ ) {
116+
for ( ix = 0; ix < newx; ix++ ) {
117+
oix = ix * x / newx;
118+
oiy = iy * y / newy;
119+
if ( size == 1 ) *ncp++ = *CHARP(cp, x, oix, oiy);
120+
else *nlp++ = *LONGP(cp, x, oix, oiy);
121+
}
122+
}
123+
return rv;
124+
}
125+
126+
/*
127+
static object *
128+
imageop_mul(self, args)
129+
object *self;
130+
object *args;
131+
{
132+
char *cp, *ncp;
133+
int len, size, x, y;
134+
object *rv;
135+
int i;
136+
137+
if ( !getargs(args, "(s#iii)", &cp, &len, &size, &x, &y) )
138+
return 0;
139+
140+
if ( size != 1 && size != 4 ) {
141+
err_setstr(ImageopError, "Size should be 1 or 4");
142+
return 0;
143+
}
144+
if ( len != size*x*y ) {
145+
err_setstr(ImageopError, "String has incorrect length");
146+
return 0;
147+
}
148+
149+
rv = newsizedstringobject(NULL, XXXX);
150+
if ( rv == 0 )
151+
return 0;
152+
ncp = (char *)getstringvalue(rv);
153+
154+
155+
for ( i=0; i < len; i += size ) {
156+
}
157+
return rv;
158+
}
159+
*/
160+
161+
static struct methodlist imageop_methods[] = {
162+
{ "crop", imageop_crop },
163+
{ "scale", imageop_scale },
164+
{ 0, 0 }
165+
};
166+
167+
168+
void
169+
initimageop()
170+
{
171+
object *m, *d;
172+
m = initmodule("imageop", imageop_methods);
173+
d = getmoduledict(m);
174+
ImageopError = newstringobject("imageop.error");
175+
if ( ImageopError == NULL || dictinsert(d,"error",ImageopError) )
176+
fatal("can't define imageop.error");
177+
}

0 commit comments

Comments
 (0)