//1999-02-09,鲍捷,浮雕效果 //只对灰度图像有效 BOOL VPicEx::TrueEmboss() { if( !IsValid() ) return FALSE; imgdes *srcimg=GetImgDes(); // colortogray(srcimg,srcimg); imgdes image1; imgdes image2; imgdes tmpsrc; int cols, rows, rcode; char kern1[10] = {-2,-2,0,-2,6,0,0,0,0,1}; char kern2[10] = {0,0,0,0,-6,2,0,2,2,1}; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 8); // Assumes 8-bit source image copyimage(srcimg, &tmpsrc); allocimage(&image1, cols, rows, 8); allocimage(&image2, cols, rows, 8); matrixconv(kern1, &tmpsrc, &image1); matrixconv(kern2, &tmpsrc, &image2); zeroimage(128, &tmpsrc); addimage(&tmpsrc, &image1, &tmpsrc); subimage(&tmpsrc, &image2, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); // Assumes 8-bit result image freeimage(&image2); freeimage(&image1); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
//1999-02-18,鲍捷,胶粒效果 BOOL VPicEx::Pointillistic() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc, tmp8; int cols, rows, rcode; static char kern1[10] = {0,-1,0,-1,5,-1,0,-1,0,1}; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 24); allocimage(&tmp8, cols, rows, 8); if(srcimg->bmh->biBitCount == 8) { convertpaltorgb(srcimg, &tmpsrc); } else { copyimage(srcimg, &tmpsrc); } removenoise(&tmpsrc, &tmpsrc); convertrgbtopalex(200, &tmpsrc, &tmp8, CR_OCTREEDIFF); convertpaltorgb(&tmp8, &tmpsrc); freeimage(&tmp8); matrixconv(kern1, &tmpsrc, &tmpsrc); if(srcimg->bmh->biBitCount == 8) { rcode = convertrgbtopal(256, &tmpsrc, srcimg); } else { rcode = copyimage(&tmpsrc, srcimg); } freeimage(&tmpsrc); return(rcode == NO_ERROR); }
//1999-02-19,鲍捷,阴影效果 BOOL VPicEx::DropShadow() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc, tmpmask; int rcode = NO_ERROR, j, shadow_width=20, shadow_height=20, cols, rows; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount); allocimage(&tmpmask, cols, rows, srcimg->bmh->biBitCount); zeroimage(255, &tmpsrc); tmpsrc.stx=shadow_width; tmpsrc.sty=shadow_width; copyimage(srcimg, &tmpsrc); tmpsrc.stx = 0; tmpsrc.sty = 0; kodalith(230, &tmpsrc, &tmpsrc);//二值化,门限230 //门限以上的像素被认为白色,不产生阴影 negative(&tmpsrc, &tmpmask); changebright(128, &tmpsrc, &tmpsrc); for(j=0; j<10; j++) blur(&tmpsrc, &tmpsrc); //使阴影模糊。循环越多越模糊,扩散越大 tmpmask.stx=shadow_width; tmpmask.sty=shadow_width; addimage(&tmpsrc, &tmpmask, &tmpsrc); andimage(srcimg, &tmpsrc, srcimg); freeimage(&tmpmask); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
void mkcol(int i, int c0, int c1, int c2) { cols[i][0] = allocimagemix(display, c0, DWhite); cols[i][1] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, c1); cols[i][2] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, c2); }
void frinittick(Frame *f) { Image *b; Font *ft; b = f->display->screenimage; ft = f->font; if(f->tick) freeimage(f->tick); f->tick = allocimage(f->display, Rect(0, 0, FRTICKW, ft->height), b->chan, 0, DWhite); if(f->tick == nil) return; if(f->tickback) freeimage(f->tickback); f->tickback = allocimage(f->display, f->tick->r, b->chan, 0, DWhite); if(f->tickback == 0){ freeimage(f->tick); f->tick = 0; return; } /* background color */ draw(f->tick, f->tick->r, f->cols[BACK], nil, ZP); /* vertical line */ draw(f->tick, Rect(FRTICKW/2, 0, FRTICKW/2+1, ft->height), f->display->black, nil, ZP); /* box on each end */ draw(f->tick, Rect(0, 0, FRTICKW, FRTICKW), f->cols[TEXT], nil, ZP); draw(f->tick, Rect(0, ft->height-FRTICKW, FRTICKW, ft->height), f->cols[TEXT], nil, ZP); }
void initcolor(int i) { neutral = allocimagemix(display, colors[i][0], DWhite); light = allocimage(display, Rect(0,0,1,1), CMAP8, 1, colors[i][1]); dark = allocimage(display, Rect(0,0,1,1), CMAP8, 1, colors[i][2]); txtcolor = display->black; }
void iconinit(void) { Rectangle r; Image *tmp; if(tagcols[BACK] == nil) { /* Blue */ tagcols[BACK] = allocimagemix(display, DPalebluegreen, DWhite); tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPalegreygreen); tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue); tagcols[TEXT] = display->black; tagcols[HTEXT] = display->black; /* Yellow */ textcols[BACK] = allocimagemix(display, DPaleyellow, DWhite); textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow); textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DYellowgreen); textcols[TEXT] = display->black; textcols[HTEXT] = display->black; } r = Rect(0, 0, Scrollwid+ButtonBorder, font->height+1); if(button && eqrect(r, button->r)) return; if(button){ freeimage(button); freeimage(modbutton); freeimage(colbutton); } button = allocimage(display, r, screen->chan, 0, DNofill); draw(button, r, tagcols[BACK], nil, r.min); r.max.x -= ButtonBorder; border(button, r, ButtonBorder, tagcols[BORD], ZP); r = button->r; modbutton = allocimage(display, r, screen->chan, 0, DNofill); draw(modbutton, r, tagcols[BACK], nil, r.min); r.max.x -= ButtonBorder; border(modbutton, r, ButtonBorder, tagcols[BORD], ZP); r = insetrect(r, ButtonBorder); tmp = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DMedblue); draw(modbutton, r, tmp, nil, ZP); freeimage(tmp); r = button->r; colbutton = allocimage(display, r, screen->chan, 0, DPurpleblue); but2col = allocimage(display, r, screen->chan, 1, 0xAA0000FF); but3col = allocimage(display, r, screen->chan, 1, 0x006600FF); }
void JvWindowAssistor::reset(int inq, int inw, int inh) { if (decompressing_) waitd(); /* * Make sure all outstanding putimage's finish. * Syncing with the first window, syncs the server, * and hence all of them. */ window_->sync(); Module::size(inw, inh); inw_ = inw; inh_ = inh; inq_ = inq; int w = window_->width(); int h = window_->height(); if (JvsSetDecomp(server_, inq_, inw_, inh_, &w, &h, 8, 0, 0, &pad_) < 0) fprintf(stderr, "vic: JvsSetDecomp failed\n"); if (w != rw_ || h != rh_) { rw_ = w; rh_ = h; allocimage(); } if (qh_ != 0) decompress(); }
void initcolor(void) { text = display->black; light = allocimagemix(display, DPalegreen, DWhite); dark = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DDarkgreen); }
char *pschar(char *s, char *hex, int *wid, int *ht) { Point chpt, spt; Image *b; uchar rowdata[100]; char *hp = hex; int y, i; chpt = stringsize(font, s); /* bounding box of char */ *wid = ((chpt.x+7) / 8) * 8; *ht = chpt.y; /* postscript is backwards to video, so draw white (ones) on black (zeros) */ b = allocimage(display, Rpt(ZP, chpt), GREY1, 0, DBlack); /* place to put it */ spt = string(b, Pt(0,0), display->white, ZP, font, s); /* put it there */ /* Bprint(&bout, "chpt %P, spt %P, wid,ht %d,%d\n", chpt, spt, *wid, *ht); /* Bflush(&bout); */ for (y = 0; y < chpt.y; y++) { /* read bits a row at a time */ memset(rowdata, 0, sizeof rowdata); unloadimage(b, Rect(0, y, chpt.x, y+1), rowdata, sizeof rowdata); for (i = 0; i < spt.x; i += 8) { /* 8 == byte */ sprint(hp, "%2.2x", rowdata[i/8]); hp += 2; } } *hp = 0; freeimage(b); return hex; }
Image* and2img(Icon *icon, uint8_t *and) { uint8_t *data; Image *img; int inxlen; int outxlen; uint8_t *from, *to; int x, y; inxlen = 4*((icon->w+31)/32); to = data = malloc(inxlen*icon->h); /* rotate around the y axis and invert bits */ outxlen = (icon->w+7)/8; for(y = 0; y < icon->h; y++){ from = and + (icon->h - 1 - y)*inxlen; for(x = 0; x < outxlen; x++){ *to++ = ~(*from++); } } /* stick in an image */ img = allocimage(display, Rect(0,0,icon->w,icon->h), GREY1, 0, DNofill); loadimage(img, Rect(0,0,icon->w,icon->h), data, icon->h*outxlen); free(data); return img; }
//int myfillpoly(Image *, Point [], int, Windrule, int, Fcode); //void mydrawpoly(Image *, Point [], int, int, Fcode); Image *eballoc(Rectangle r, int chan){ Image *b=allocimage(display, r, chan, 0, DWhite); if(b==0){ fprint(2, "catclock: can't allocate bitmap\n"); exits("allocimage"); } return b; }
void m_dblbuf(void){ if(offscreen==screen){ offscreen=allocimage(display, insetrect(screen->r, 4), screen->chan, 0, -1); if(offscreen==0){ fprintf(stderr, "Can't double buffer\n"); offscreen=screen; } } }
Subfont* getdefont(Display *d) { char *hdr, *p; int n; Fontchar *fc; Subfont *f; int ld; Rectangle r; Image *i; /* * make sure data is word-aligned. this is true with Plan 9 compilers * but not in general. the byte order is right because the data is * declared as char*, not ulong*. */ p = (char*)defontdata; n = (ulong)p & 3; if(n != 0){ memmove(p+(4-n), p, sizeofdefont-n); p += 4-n; } ld = atoi(p+0*12); r.min.x = atoi(p+1*12); r.min.y = atoi(p+2*12); r.max.x = atoi(p+3*12); r.max.y = atoi(p+4*12); i = allocimage(d, r, drawld2chan[ld], 0, 0); if(i == 0) return 0; p += 5*12; n = loadimage(i, r, (uchar*)p, (defontdata+sizeofdefont)-(uchar*)p); if(n < 0){ freeimage(i); return 0; } hdr = p+n; n = atoi(hdr); p = hdr+3*12; fc = malloc(sizeof(Fontchar)*(n+1)); if(fc == 0){ freeimage(i); return 0; } _unpackinfo(fc, (uchar*)p, n); f = allocsubfont("*default*", n, atoi(hdr+12), atoi(hdr+24), fc, i); if(f == 0){ freeimage(i); free(fc); return 0; } return f; }
Image * eallocimage(Rectangle r, int repl, uint chan, uint color) { Image *tmp; tmp = allocimage(display, r, chan, repl, color); if(tmp == nil) sysfatal("cannot allocate buffer image: %r"); return tmp; }
Image * eallocimage(Display *d, Rectangle r, ulong chan, int repl, int col) { Image *i; i = allocimage(d, r, chan, repl, col); if(i == nil) error("allocimage failed"); return i; }
void main(void) { int i; int ncolor; /* * A call to init draw populates extern variables found in draw.h * one of them is the display */ initdraw(0,0,"test"); /* * next part is based off of code from $PLAN9/src/cmd/draw/cmapcube.c */ ncolor=8; for(i = 0; i != ncolor; i++) { color[i] = allocimage(display, Rect(0, 0, 1, 1), CMAP8, 1, cmap2rgba(i)); } bg = allocimage(display, Rect(0,0,2,2), screen->chan, 1, DGreygreen); draw(bg, Rect(0, 0, 1, 1), color[0], nil, Pt(0,0)); exits(0); }
void colinit(void) { mediumfont = openfont(display, "/lib/font/bit/pelm/latin1.8.font"); if(mediumfont == nil) mediumfont = font; /* Peach */ mkcol(0, 0xFFAAAAFF, 0xFFAAAAFF, 0xBB5D5DFF); /* Aqua */ mkcol(1, DPalebluegreen, DPalegreygreen, DPurpleblue); /* Yellow */ mkcol(2, DPaleyellow, DDarkyellow, DYellowgreen); /* Green */ mkcol(3, DPalegreen, DMedgreen, DDarkgreen); /* Blue */ mkcol(4, 0x00AAFFFF, 0x00AAFFFF, 0x0088CCFF); /* Grey */ cols[5][0] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF); cols[5][1] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF); cols[5][2] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x888888FF); }
Image* allocimagemix(Display *d, ulong color1, ulong color3) { Image *t, *b; static Image *qmask; if(qmask == nil) qmask = allocimage(d, Rect(0,0,1,1), GREY8, 1, 0x3F3F3FFF); if(d->screenimage->depth <= 8){ /* create a 2×2 texture */ t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 0, color1); if(t == nil) return nil; b = allocimage(d, Rect(0,0,2,2), d->screenimage->chan, 1, color3); if(b == nil){ freeimage(t); return nil; } draw(b, Rect(0,0,1,1), t, nil, ZP); freeimage(t); return b; }else{ /* use a solid color, blended using alpha */ t = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color1); if(t == nil) return nil; b = allocimage(d, Rect(0,0,1,1), d->screenimage->chan, 1, color3); if(b == nil){ freeimage(t); return nil; } draw(b, b->r, t, qmask, ZP); freeimage(t); return b; } }
static void scrtemps(void) { int h; if(scrtmp) return; h = BIG*Dy(screen->r); scrtmp = allocimage(display, Rect(0, 0, 32, h), screen->chan, 0, DWhite); if(scrtmp == nil) error("scrtemps"); }
//1999-02-18,鲍捷,快速浮雕效果 //只对灰度图像有效 BOOL VPicEx::QuickEmboss() { imgdes *srcimg=GetImgDes(); imgdes image1; imgdes tmpsrc; int cols, rows, rcode; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, 8); copyimage(srcimg, &tmpsrc); allocimage(&image1, cols, rows, 8); negative(&tmpsrc, &image1); image1.stx = 1; image1.sty = 1; wtaverage(50, &tmpsrc, &image1, &tmpsrc); expandcontrast(100, 155, &tmpsrc, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); freeimage(&image1); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
void init(void) { mailfs = nsmount("mail", nil); if(mailfs == nil) sysfatal("mount mail: %r"); mousectl = initmouse(nil, screen); if(mousectl == nil) sysfatal("initmouse: %r"); initplumb(); /* make background color */ bgrnd = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DWhite); blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */ left = allocimage(display, leftright, GREY1, 0, DWhite); right = allocimage(display, leftright, GREY1, 0, DWhite); if(bgrnd==nil || blue==nil || left==nil || right==nil){ fprint(2, "faces: can't create images: %r\n"); threadexitsall("image"); } loadimage(left, leftright, leftdata, sizeof leftdata); loadimage(right, leftright, rightdata, sizeof rightdata); /* initialize little fonts */ tinyfont = openfont(display, "/lib/font/bit/misc/ascii.5x7.font"); if(tinyfont == nil) tinyfont = font; mediumfont = openfont(display, "/lib/font/bit/pelm/latin1.8.font"); if(mediumfont == nil) mediumfont = font; datefont = font; facep.y += datefont->height; if(datefont->height & 1) /* stipple parity */ facep.y++; faces = nil; }
Image* multichan(Image *i) { Image *ni; if(notrans(i->chan)) return i; ni = allocimage(display, i->r, RGB24, 0, DNofill); if(ni == nil) return ni; draw(ni, ni->r, i, nil, i->r.min); return ni; }
void initwin(void) { Rectangle r; int i, j; scr = allocscreen(screen, display->white, 0); if(scr == nil) sysfatal("allocscreen: %r"); for(i = 0; i < NTYPES; i++) for(j = 0; j < NCOLS; j++) tabs[i]->cols[j] = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, tabs[i]->hexcols[j]); invcol = allocimage(display, Rect(0, 0, 2, 2), screen->chan, 1, 0); draw(invcol, Rect(1, 0, 2, 1), display->white, nil, ZP); draw(invcol, Rect(0, 1, 1, 2), display->white, nil, ZP); wlist.next = wlist.prev = &wlist; flist.next = flist.prev = &flist; r = screen->r; r.max.y = r.min.y + Dy(r) / 5; cmdw = newwin(CMD, r, nil); if(cmdw == nil) sysfatal("newwin: %r"); }
void init(void) { mousefd = open("/dev/mouse", OREAD); if(mousefd < 0){ fprint(2, "faces: can't open mouse: %r\n"); exits("mouse"); } initplumb(); /* make background color */ bgrnd = allocimagemix(display, DPalebluegreen, DWhite); blue = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x008888FF); /* blue-green */ left = allocimage(display, leftright, GREY1, 0, DWhite); right = allocimage(display, leftright, GREY1, 0, DWhite); if(bgrnd==nil || blue==nil || left==nil || right==nil){ fprint(2, "faces: can't create images: %r\n"); exits("image"); } loadimage(left, leftright, leftdata, sizeof leftdata); loadimage(right, leftright, rightdata, sizeof rightdata); /* initialize little fonts */ tinyfont = openfont(display, "/lib/font/bit/misc/ascii.5x7.font"); if(tinyfont == nil) tinyfont = font; mediumfont = openfont(display, "/lib/font/bit/pelm/latin1.8.font"); if(mediumfont == nil) mediumfont = font; datefont = font; facep.y += datefont->height; if(datefont->height & 1) /* stipple parity */ facep.y++; faces = nil; }
static void menucolors(void) { /* Main tone is greenish, with negative selection */ back = allocimagemix(display, DPalegreen, DWhite); high = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkgreen); /* dark green */ bord = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DMedgreen); /* not as dark green */ if(back==nil || high==nil || bord==nil) goto Error; text = display->black; htext = back; return; Error: freeimage(back); freeimage(high); freeimage(bord); back = display->white; high = display->black; bord = display->black; text = display->black; htext = display->white; }
static void menuscrollpaint(Image *m, Rectangle scrollr, int off, int nitem, int nitemdrawn) { Rectangle r; draw(m, scrollr, back, nil, ZP); r.min.x = scrollr.min.x; r.max.x = scrollr.max.x; r.min.y = scrollr.min.y + (Dy(scrollr)*off)/nitem; r.max.y = scrollr.min.y + (Dy(scrollr)*(off+nitemdrawn))/nitem; if(r.max.y < r.min.y+2) r.max.y = r.min.y+2; border(m, r, 1, bord, ZP); if(menutxt == 0) menutxt = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DDarkgreen); /* border color; BUG? */ if(menutxt) draw(m, insetrect(r, 1), menutxt, nil, ZP); }
Image* tkitmp(TkEnv *e, Point p, int fillcol) { Image *i, **ip; TkTop *t; TkCtxt *ti; Display *d; Rectangle r; ulong pix; int alpha; t = e->top; ti = t->ctxt; d = t->display; pix = e->colors[fillcol]; alpha = (pix & 0xff) != 0xff; ip = alpha ? &ti->ia : &ti->i; if(*ip != nil) { i = *ip; if(p.x <= i->r.max.x && p.y <= i->r.max.y) { r.min = ZP; r.max = p; if (alpha) drawop(i, r, nil, nil, ZP, Clear); draw(i, r, tkgc(e, fillcol), nil, ZP); return i; } r = i->r; freeimage(i); if(p.x < r.max.x) p.x = r.max.x; if(p.y < r.max.y) p.y = r.max.y; } r.min = ZP; r.max = p; *ip = allocimage(d, r, alpha?RGBA32:d->image->chan, 0, pix); return *ip; }
/* 水彩效果平滑图像的不规则部分,然后强调色彩边界 (grayscale or color image, 8- or 24-bit. ) */ BOOL VPicEx::WaterColor() { imgdes *srcimg=GetImgDes(); imgdes tmpsrc; int cols, rows, rcode; double gamma = 0.7; cols = CALC_WIDTH(srcimg); rows = CALC_HEIGHT(srcimg); allocimage(&tmpsrc, cols, rows, srcimg->bmh->biBitCount); copyimage(srcimg, &tmpsrc); gammabrighten(gamma, &tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); removenoise(&tmpsrc, &tmpsrc); sharpen(&tmpsrc, &tmpsrc); rcode = copyimage(&tmpsrc, srcimg); freeimage(&tmpsrc); return(rcode == NO_ERROR); }
void main(int argc, char *argv[]) { int delay = 1000; setrules(".d.d..b..d.d.d.d.d"); /* regular rules */ ARGBEGIN { case '3': setrules(".d.d.db.b..d.d.d.d"); break; /* 34-life */ case 'o': setrules(".d.d.db.b.b..d.d.d"); break; /* lineosc? */ case 'r': /* rules from cmdline */ setrules(EARGF(usage())); break; default: usage(); } ARGEND if (argc != 1) usage(); initdraw(g9err, 0, argv0); einit(Emouse|Ekeyboard); /* implies rawon() */ cen = divpt(subpt(addpt(screen->r.min, screen->r.max), Pt(NLIFE * PX, NLIFE * PX)), 2); box = allocimage(display, Rect(0, 0, BX, BX), RGB24, 1, DBlack); assert(box != nil); redraw(); readlife(argv[0]); do { flushimage(display, 1); idle(); sleep(delay); idle(); } while (generate()); exits(nil); }