home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * enhance -
- * Enhance an image interactively
- *
- * Paul Haeberli - 1991
- *
- */
- #include "math.h"
- #include "stdio.h"
- #include "gl.h"
- #include "device.h"
- #include "image.h"
- #include "canvas.h"
- #include "vect.h"
- #include "showcaseui.h"
-
- float flerp();
- canvas *applyprocess();
-
- #define CBALSCALE (1.0)
- #define DUOTONESCALE (1.0)
-
- #define BLACKCOLOR (0x000000)
- #define BACKCOLOR (0xd0d0d0)
- #define REDCOLOR (0x0000c0)
-
- #define DRAW_BACK (1)
- #define DRAW_IMAGES (2)
- #define DRAW_CONTROLS (4)
- #define PROC_IMAGES (8)
-
- #define STDSIZE (200)
- #define STDSPACE (10)
- #define STDSKIP (STDSIZE+STDSPACE)
-
- #define CONX (STDSPACE+3*STDSKIP)
- #define CONWIDTH (250)
- #define RADIOY (183)
- #define RADIODY (26)
- #define BUTTONDY (32)
-
- #define WINYSIZE (3*STDSIZE+4*STDSPACE)
- #define WINXSIZE (WINYSIZE+CONWIDTH)
-
- #define MODE_GAMMA (0)
- #define MODE_COLOR (1)
- #define MODE_SHADOW (2)
- #define MODE_HIGHLIGHT (3)
- #define MODE_SATURATE (4)
- #define MODE_DUOTONE (5)
- #define MODE_ADDNOISE (6)
- #define MODE_QUANTIZE (7)
- #define MODE_SHARPEN (8)
-
- #define MAXSTEPS 500
-
- long xorg, yorg;
- int wxsize, wysize;
- int curmode, nops;
- int func[MAXSTEPS];
- float args[MAXSTEPS][3];
- canmap *map;
- char *origname, *procname;
- canvas *inimage, *new, *origimage;
- Button *butquit, *butgamma, *butcolor, *butshadow,
- *butbrightness, *butsaturate, *butduotone,
- *butaddnoise, *butquantize, *butsharpen,
- *butwrite, *butshoworig, *butrestart;
-
- int transfunc(in,out)
- vect *in, *out;
- {
- float cr, cg, cb;
- float sr, sg, sb;
-
- corone4(in->x,in->y,in->z,&cr,&cg,&cb);
- sproof4(cr,cg,cb,&sr,&sg,&sb);
- out->x = sr;
- out->y = sg;
- out->z = sb;
- }
-
- canvas *readimage(iname)
- char *iname;
- {
- int xsize, ysize, max;
- float zfactor;
- char cmd[256];
- char tempname[256];
- canvas *c;
-
- strcpy(tempname,"/usr/tmp/ENXXXXXX");
- mktemp(tempname);
- sizeofimage(iname,&xsize,&ysize);
- if(xsize>ysize)
- max = xsize;
- else
- max = ysize;
- if(max<(STDSIZE-4) || max>(STDSIZE+4)) {
- zfactor = STDSIZE/(float)max;
- sprintf(cmd,"izoom %s %s %f %f -b",iname,tempname,zfactor,zfactor);
- system(cmd);
- c = imagetocanvas(tempname);
- sprintf(cmd,"rm %s",tempname);
- system(cmd);
- return c;
- }
- return imagetocanvas(iname);
- }
-
- restart()
- {
- nops = 0;
- freecanvas(inimage);
- inimage = clonecanvas(origimage);
- activatebut(butgamma);
- curmode = MODE_GAMMA;
- drawscene(DRAW_IMAGES|DRAW_CONTROLS|PROC_IMAGES);
- }
-
- blat()
- {
- manifesto();
- }
-
-
- main(int argc, char **argv)
- {
- long dev, mx, my;
- short val, smx, smy;
-
- if( argc<3 ) {
- fprintf(stderr,"usage: enhance inimage.rgb outimage.rgb\n");
- exit(1);
- }
- origname = argv[1];
- procname = argv[2];
- initialize();
- activate();
- percentdone(50.0);
- drawscene(DRAW_BACK+DRAW_CONTROLS);
- drawboldlabel("Zooming source image down for display . . .",100,WINYSIZE/2);
- inimage = readimage(origname);
- cpack(BACKCOLOR);
- rectfi(0,0,CONX-4,WINYSIZE);
- drawscene(DRAW_IMAGES|PROC_IMAGES);
- origimage = clonecanvas(inimage);
- while (1) {
- switch (dev = qread(&val)) {
- case LEFTMOUSE:
- qread(&smx); qread(&smy);
- mx = smx - xorg;
- my = smy - yorg;
- if (val == UIBUTTONDOWN) {
- sginap(8);
- if (qtest() == dev) {
- short tmp;
- qread(&tmp); qread(&tmp); qread(&tmp);
- val = UIBUTTONCLICK;
- }
- }
- handleevents(mx, my, dev, (long) val);
- if(val != 1)
- locatemouseevents(mx,my);
- break;
- case MOUSEX:
- mx = val - xorg;
- break;
- case MOUSEY:
- my = val - yorg;
- if(!getbutton(LEFTMOUSE))
- locatemouseevents(mx,my);
- break;
- case REDRAW:
- getorigin(&xorg,&yorg);
- drawscene(DRAW_BACK+DRAW_CONTROLS+DRAW_IMAGES);
- break;
- }
- }
- }
-
- initialize()
- {
- wysize = 3*STDSIZE+4*STDSPACE;
- wxsize = wysize+CONWIDTH;
- autoprefsize(wxsize,wysize);
- winopen("Image Enhance");
- RGBmode();
- gconfig();
- drawback();
-
- butquit = newpushbut(wxsize-10-75,10);
- butgamma = newradiobut(CONX+40,RADIOY+8*RADIODY);
- butcolor = newradiobut(CONX+40,RADIOY+7*RADIODY);
- butshadow = newradiobut(CONX+40,RADIOY+6*RADIODY);
- butbrightness = newradiobut(CONX+40,RADIOY+5*RADIODY);
- butsaturate = newradiobut(CONX+40,RADIOY+4*RADIODY);
- butduotone = newradiobut(CONX+40,RADIOY+3*RADIODY);
- butaddnoise = newradiobut(CONX+40,RADIOY+2*RADIODY);
- butquantize = newradiobut(CONX+40,RADIOY+1*RADIODY);
- butsharpen = newradiobut(CONX+40,RADIOY+0*RADIODY);
-
- butwrite = newpushbut(CONX+40,20+RADIOY-3*BUTTONDY);
- butshoworig = newpushbut(CONX+40,20+RADIOY-4*BUTTONDY);
- butrestart = newpushbut(CONX+40,20+RADIOY-5*BUTTONDY);
-
- getorigin(&xorg,&yorg);
- }
-
- activate()
- {
- initbut();
-
- qdevice(LEFTMOUSE);
- qdevice(MOUSEX);
- qdevice(MOUSEY);
- tie(LEFTMOUSE, MOUSEX, MOUSEY);
-
- loadbut(butquit,"Quit");
- loadbut(butgamma,"Gamma");
- loadbut(butcolor,"Color Balance");
- linkbuttons(butgamma,butcolor);
- loadbut(butshadow,"Shadow Detail");
- linkbuttons(butgamma,butshadow);
- loadbut(butbrightness,"Brightness");
- linkbuttons(butgamma,butbrightness);
- loadbut(butsaturate,"Saturation");
- linkbuttons(butgamma,butsaturate);
- loadbut(butduotone,"Duotone");
- linkbuttons(butgamma,butduotone);
- loadbut(butaddnoise,"Add Noise");
- linkbuttons(butgamma,butaddnoise);
- loadbut(butquantize,"Quantize");
- linkbuttons(butgamma,butquantize);
- loadbut(butsharpen,"Sharpen");
- linkbuttons(butgamma,butsharpen);
-
- activatebut(butgamma);
-
- loadbut(butwrite,"Write Output");
- loadbut(butshoworig,"Show Original");
- loadbut(butrestart,"Start Over");
- }
-
- newmode(mode)
- int mode;
- {
- if(curmode != mode) {
- curmode = mode;
- drawscene(DRAW_IMAGES|PROC_IMAGES);
- }
- }
-
- handleevents(long mx, long my, long dev, long val)
- {
- char cmd[256];
-
- if (selectedpressbut(butquit,mx,my,val)) {
- exit(0);
- } else if(inimages(mx,my,val)) {
- return;
- } else if (selectedpressbut(butgamma,mx,my,val)) {
- newmode(MODE_GAMMA);
- } else if (selectedpressbut(butcolor,mx,my,val)) {
- newmode(MODE_COLOR);
- } else if (selectedpressbut(butshadow,mx,my,val)) {
- newmode(MODE_SHADOW);
- } else if (selectedpressbut(butbrightness,mx,my,val)) {
- newmode(MODE_HIGHLIGHT);
- } else if (selectedpressbut(butsaturate,mx,my,val)) {
- newmode(MODE_SATURATE);
- } else if (selectedpressbut(butduotone,mx,my,val)) {
- newmode(MODE_DUOTONE);
- } else if (selectedpressbut(butaddnoise,mx,my,val)) {
- newmode(MODE_ADDNOISE);
- } else if (selectedpressbut(butquantize,mx,my,val)) {
- newmode(MODE_QUANTIZE);
- } else if (selectedpressbut(butsharpen,mx,my,val)) {
- newmode(MODE_SHARPEN);
- } else if (selectedpressbut(butduotone,mx,my,val)) {
- newmode(MODE_DUOTONE);
- } else if (selectedpressbut(butwrite,mx,my,val)) {
- applytoimage(origname,procname);
- percentdone(50.0);
- sprintf(cmd,"ipaste %s",procname);
- system(cmd);
- percentdone(100.0);
- } else if (selectedpressbut(butshoworig,mx,my,val)) {
- percentdone(50.0);
- sprintf(cmd,"ipaste %s",origname);
- system(cmd);
- percentdone(100.0);
- } else if (selectedpressbut(butrestart,mx,my,val)) {
- restart();
- }
- }
-
- drawscene(how)
- long how;
- {
- char c[4];
- long ir, ig, ib;
- long tmp;
-
- if(how & DRAW_BACK) {
- drawback();
- }
- if(how & DRAW_CONTROLS) {
- drawbut(butquit);
- drawbut(butgamma);
- drawbut(butcolor);
- drawbut(butshadow);
- drawbut(butbrightness);
- drawbut(butsaturate);
- drawbut(butduotone);
- drawbut(butaddnoise);
- drawbut(butquantize);
- drawbut(butsharpen);
- drawbut(butwrite);
- drawbut(butshoworig);
- drawbut(butrestart);
- drawboldlabel("Pick from the images on the left.",CONX+10,RADIOY-1*RADIODY);
- }
- if(how & DRAW_IMAGES) {
- percentdone(50.0);
- showcur(inimage,0);
- if(how & PROC_IMAGES)
- showarray(inimage,curmode,1);
- else
- showarray(inimage,curmode,0);
- percentdone(100.0);
- }
- }
-
- long lastmx, lastmy;
-
- locatemouseevents(long mx, long my)
- {
- if((mx == lastmx) && (my == lastmy))
- return;
- locatebut(butquit,mx,my);
- locatebut(butgamma,mx,my);
- locatebut(butcolor,mx,my);
- locatebut(butshadow,mx,my);
- locatebut(butbrightness,mx,my);
- locatebut(butsaturate,mx,my);
- locatebut(butduotone,mx,my);
- locatebut(butaddnoise,mx,my);
- locatebut(butquantize,mx,my);
- locatebut(butsharpen,mx,my);
- locatebut(butwrite,mx,my);
- locatebut(butshoworig,mx,my);
- locatebut(butrestart,mx,my);
- }
-
- addop(mode,p1,p2,p3)
- int mode;
- float p1, p2, p3;
- {
- func[nops] = mode;
- args[nops][0] = p1;
- args[nops][1] = p2;
- args[nops][2] = p3;
- nops++;
- if(nops == MAXSTEPS) {
- nops--;
- fprintf(stderr,"nops exceed %d\n",MAXSTEPS);
- return;
- }
- }
-
- applytoimage(inname,outname)
- char *inname, *outname;
- {
- int ixsize, iysize, izsize, i, y;
- int r, sr, nr, nrows, oy, border;
- IMAGE *iimage, *oimage;
- short *rbuf, *gbuf, *bbuf;
- unsigned long *lbuf, *tbuf;
- float p1, p2, p3;
- canvas scan, dcan;
- int mat[3][3];
-
- /* open the input image file */
- iimage = iopen(inname,"r");
- if(!iimage) {
- fprintf(stderr,"applytoimage: can't open input image %s\n",inname);
- return;
- }
- ixsize = iimage->xsize;
- iysize = iimage->ysize;
- izsize = iimage->zsize;
- oimage = iopen(outname,"w",RLE(1),3,ixsize,iysize,3);
-
- /* see the width of the border that is needed */
- border = 0;
- for(i=0; i<nops; i++) {
- if(func[i] == MODE_SHARPEN)
- border++;
- }
-
- /* figure out how many rows to do each pass */
- nrows = 40;
- if(nrows<4*border)
- nrows = 4*border;
-
- /* malloc buffers */
- rbuf = (short *)malloc(ixsize*sizeof(short));
- gbuf = (short *)malloc(ixsize*sizeof(short));
- bbuf = (short *)malloc(ixsize*sizeof(short));
- lbuf = (unsigned long *)malloc(ixsize*sizeof(long)*nrows);
- tbuf = (unsigned long *)malloc(ixsize*sizeof(long)*nrows);
-
- /* read and transform the image */
- oy = 0;
- y = 0;
- percentdone(0.0);
- while(1) {
-
- /* read image data */
- nr = 0;
- for(i=0; i<nrows; i++) {
- getrow(iimage,rbuf,y,0%izsize);
- getrow(iimage,gbuf,y,1%izsize);
- getrow(iimage,bbuf,y,2%izsize);
- rgbtocpack(rbuf,gbuf,bbuf,lbuf+nr*ixsize,ixsize);
- y++;
- nr++;
- if(y == iysize)
- break;
- }
-
- /* process a block of rows */
- for(i=0; i<nops; i++) {
- p1 = args[i][0];
- p2 = args[i][1];
- p3 = args[i][2];
- switch(func[i]) {
- case MODE_GAMMA:
- gammaop(lbuf,nr*ixsize,p1);
- break;
- case MODE_COLOR:
- cscaleop(lbuf,nr*ixsize,p1,p2,p3);
- break;
- case MODE_SHADOW:
- imgexpop(lbuf,nr*ixsize,p1,p2);
- break;
- case MODE_HIGHLIGHT:
- imgexpop(lbuf,nr*ixsize,p1,p2);
- break;
- case MODE_SATURATE:
- saturateop(lbuf,nr*ixsize,p1);
- break;
- case MODE_DUOTONE:
- duotoneop(lbuf,nr*ixsize,p1,p2,p3);
- break;
- case MODE_ADDNOISE:
- addnoiseop(lbuf,nr*ixsize,p1);
- break;
- case MODE_QUANTIZE:
- quantop(lbuf,nr*ixsize,p1);
- break;
- case MODE_SHARPEN:
- scan.data = lbuf;
- scan.xsize = ixsize;
- scan.ysize = nr;
- scan.flushfunc = 0;
- dcan.data = tbuf;
- dcan.xsize = ixsize;
- dcan.ysize = nr;
- dcan.flushfunc = 0;
- blurcanvas(&scan,&dcan);
- blendcanvas(&scan,&dcan,&dcan,-p1);
- bcopy(tbuf,lbuf,nr*ixsize*sizeof(long));
- break;
- }
- }
- if(oy == 0)
- sr = 0;
- else
- sr = border;
- if(y != iysize)
- nr -= border;
- for(r=sr; r<nr; r++) {
- cpacktorgb(lbuf+ixsize*r,rbuf,gbuf,bbuf,ixsize);
- putrow(oimage,rbuf,oy,0);
- putrow(oimage,gbuf,oy,1);
- putrow(oimage,bbuf,oy,2);
- oy++;
- }
- if(oy == iysize)
- break;
- percentdone(100.0*y/(iysize-1));
- y = oy-border;
- }
- percentdone(100.0);
- iclose(iimage);
- iclose(oimage);
- free(rbuf);
- free(gbuf);
- free(bbuf);
- free(lbuf);
- free(tbuf);
- }
-
- inimages(mx,my,val)
- int mx, my, val;
- {
- if(mx<CONX && my < WINYSIZE) {
- if(val != UIBUTTONDOWN)
- return 1;
- percentdone(50.0);
- new = applyprocess(inimage,curmode,mx,my);
- freecanvas(inimage);
- inimage = new;
- showcur(inimage,1);
- showarray(inimage,curmode,1);
- percentdone(100.0);
- return 1;
- } else {
- return 0;
- }
- }
-
- drawback()
- {
- cpack(BACKCOLOR);
- clear();
- cpack(BLACKCOLOR);
- move2i(CONX,5);
- draw2i(CONX,WINYSIZE-5);
- }
-
- writecanvas(c,x,y)
- canvas *c;
- int x, y;
- {
- lrectwrite(x,y,x+c->xsize-1,y+c->ysize-1,c->data);
- }
-
- clearrect(c,x,y,off)
- canvas *c;
- int x, y, off;
- {
- rectfi(x-off,y-off,x+c->xsize-1+off,y+c->ysize-1+off);
- }
-
- outlinerect(c,x,y,off)
- canvas *c;
- int x, y, off;
- {
- recti(x-off,y-off,x+c->xsize-1+off,y+c->ysize-1+off);
- }
-
- canvas *tempimg;
-
- processcanvas(c,pc,mode,fx,fy,f,saveop,newimg)
- canvas *c, *pc;
- int mode;
- float fx , fy, f;
- int saveop, newimg;
- {
- float p1, p2, p3;
-
- p1 = p2 = p3 = 0.0;
- canvascopy(c,pc);
- switch(mode) {
- case MODE_GAMMA:
- p1 = flerp(0.5,2.0,f);
- canvasop(pc,gammaop,p1);
- break;
- case MODE_COLOR:
- pptorgb(fx,fy,CBALSCALE,&p1,&p2,&p3);
- canvasop(pc,cscaleop,p1,p2,p3);
- break;
- case MODE_SHADOW:
- p1 = flerp(-0.2,0.2,f);
- p2 = 1.0;
- canvasop(pc,imgexpop,p1,p2);
- break;
- case MODE_HIGHLIGHT:
- p1 = 0.0;
- p2 = flerp(1.4,0.6,f);
- canvasop(pc,imgexpop,p1,p2);
- break;
- case MODE_SATURATE:
- p1 = 2.0*f;
- if(p1<0.0)
- p1 = 0;
- canvasop(pc,saturateop,p1);
- break;
- case MODE_DUOTONE:
- pptorgb(fx,fy,DUOTONESCALE,&p1,&p2,&p3);
- canvasop(pc,duotoneop,p1,p2,p3);
- break;
- case MODE_ADDNOISE:
- p1 = f;
- canvasop(pc,addnoiseop,p1);
- break;
- case MODE_QUANTIZE:
- p1 = flerp(2.0,10.0,f);
- canvasop(pc,quantop,p1);
- break;
- case MODE_SHARPEN:
- if(newimg) {
- if(tempimg)
- freecanvas(tempimg);
- tempimg = newcanvas(c->xsize,c->ysize);
- blurcanvas(c,tempimg);
- }
- p1 = flerp(0.0,3.0,f);
- if(p1<0.0)
- p1 = 0.0;
- blendcanvas(c,tempimg,pc,-p1);
- break;
- }
- if(saveop)
- addop(mode,p1,p2,p3);
- }
-
- canvas *applyprocess(c,mode,mx,my)
- int mode, mx, my;
- {
- float fx, fy, f;
- canvas *pc;
-
- fx = 0.5+(mx-CONX/2)/(float)(2*STDSKIP);
- fy = 0.5+(my-CONX/2)/(float)(2*STDSKIP);
- fy = 1.0-fy;
- if(my>2*STDSKIP+STDSPACE/2)
- f = 0*CONX+mx;
- else if(my<1*STDSKIP+STDSPACE/2)
- f = 2*CONX+mx;
- else
- f = 1*CONX+mx;
- f = ((9.0*f/(3*CONX))-0.5)/8.0;
- pc = clonecanvas(c);
- processcanvas(c,pc,mode,fx,fy,f,1,1);
- return pc;
- }
-
- pptorgb(fx,fy,mag,r,g,b)
- float fx, fy, mag;
- float *r, *g, *b;
- {
- float min, max;
-
- *r = 1.0+mag*(fx-0.5);
- *g = 1.0;
- *b = 1.0+mag*(fy-0.5);
- min = *r;
- if(*g<min)
- min = *g;
- if(*b<min)
- min = *b;
- *r = *r/min;
- *g = *g/min;
- *b = *b/min;
- }
-
- canvas *cor;
-
- showcur(c,flash)
- canvas *c;
- {
- int xoff, yoff;
-
- xoff = (STDSIZE-c->xsize)/2+15;
- yoff = (STDSIZE-c->ysize)/2-10;
- if(!cor)
- cor = clonecanvas(c);
- else
- canvascopy(c,cor);
- writecanvas(cor,xoff+CONX+STDSPACE,yoff+WINYSIZE-STDSKIP);
- if(flash) {
- linewidth(2);
- cpack(REDCOLOR);
- outlinerect(c,xoff+CONX+STDSPACE,yoff+WINYSIZE-STDSKIP,4);
- sginap(20);
- cpack(BACKCOLOR);
- outlinerect(c,xoff+CONX+STDSPACE,yoff+WINYSIZE-STDSKIP,4);
- linewidth(1);
- }
- cpack(BLACKCOLOR);
- outlinerect(c,xoff+CONX+STDSPACE,yoff+WINYSIZE-STDSKIP,4);
- }
-
- cleararray()
- {
- cpack(BACKCOLOR);
- rectfi(0,0,CONX-5,WINYSIZE);
- }
-
- canvas *smallcan[3][3];
-
- showarray(c,mode,doproc)
- canvas *c;
- int mode, doproc;
- {
- int x, y;
- canvas *pc;
- float fx, fy, f;
- int xoff, yoff, xdel;
- int newimg;
-
- if(!smallcan[0][0]) {
- for(y=0; y<3; y++)
- for(x=0; x<3; x++)
- smallcan[y][x] = clonecanvas(c);
- }
- xoff = (STDSIZE-c->xsize)/2;
- yoff = (STDSIZE-c->ysize)/2;
- f = 0.0;
- if(mode == MODE_COLOR || mode == MODE_DUOTONE) {
- cpack(BLACKCOLOR);
- move2i(1*STDSKIP+STDSPACE/2,5);
- draw2i(1*STDSKIP+STDSPACE/2,WINYSIZE-5);
- move2i(2*STDSKIP+STDSPACE/2,5);
- draw2i(2*STDSKIP+STDSPACE/2,WINYSIZE-5);
- } else {
- cpack(BACKCOLOR);
- move2i(1*STDSKIP+STDSPACE/2,5);
- draw2i(1*STDSKIP+STDSPACE/2,WINYSIZE-5);
- move2i(2*STDSKIP+STDSPACE/2,5);
- draw2i(2*STDSKIP+STDSPACE/2,WINYSIZE-5);
- }
- cpack(BLACKCOLOR);
- move2i(5,1*STDSKIP+STDSPACE/2);
- draw2i(CONX-5,1*STDSKIP+STDSPACE/2);
- move2i(5,2*STDSKIP+STDSPACE/2);
- draw2i(CONX-5,2*STDSKIP+STDSPACE/2);
-
- cpack(BACKCOLOR);
- for(y=0; y<3; y++) {
- for(x=0; x<3; x++) {
- clearrect(c,xoff+STDSPACE+x*STDSKIP,yoff+STDSPACE+(2-y)*STDSKIP,2);
- }
- }
- for(y=0; y<3; y++) {
- for(x=0; x<3; x++) {
- if(doproc) {
- if(x==0 && y==0)
- newimg = 1;
- else
- newimg = 0;
- processcanvas(c,smallcan[y][x],mode,x/2.0,y/2.0,(y*3+x)/8.0,0,newimg);
- }
- writecanvas(smallcan[y][x],xoff+STDSPACE+x*STDSKIP,yoff+STDSPACE+(2-y)*STDSKIP);
- }
- }
- }
-
- blurcanvas(s,d)
- canvas *s, *d;
- {
- int mat[3][3];
-
- mat[0][0] = 2; mat[0][1] = 2; mat[0][2] = 2;
- mat[1][0] = 2; mat[1][1] = 2; mat[1][2] = 2;
- mat[2][0] = 2; mat[2][1] = 2; mat[2][2] = 2;
- convolve3(s,d,mat);
- }
-
- sharpenkernel(mat,mag)
- int mat[3][3];
- float mag;
- {
- float blur, sharp;
- int neg, pos;
-
- blur = 1.0/9.0;
- sharp = 1.0;
- neg = 1024*flerp(0.0,blur,-mag);
- pos = 1024*flerp(1.0,blur,-mag);
-
- mat[0][0] = neg; mat[0][1] = neg; mat[0][2] = neg;
- mat[1][0] = neg; mat[1][1] = pos; mat[1][2] = neg;
- mat[2][0] = neg; mat[2][1] = neg; mat[2][2] = neg;
- }
-
- sharpen(s,d,mag)
- canvas *s, *d;
- float mag;
- {
- int mat[3][3];
-
- sharpenkernel(mat,mag);
- convolve3(s,d,mat);
- }
-
-