|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <X/Xlib.h> ! 3: ! 4: #include "wzoom.cursor" ! 5: #include "wzoom_mask.cursor" ! 6: ! 7: #define ZOOMFACT 4 /* zoom factor relative to parent window */ ! 8: ! 9: #define MIN(a,b) (((a) < (b)) ? (a) : (b)) ! 10: #define MAX(a,b) (((a) > (b)) ? (a) : (b)) ! 11: ! 12: static u_char *zimage = NULL; /* pointer to storage */ ! 13: static unsigned long zsize = 0; /* current storage size */ ! 14: static Bitmap wzmask = NULL; ! 15: static int xcur, ycur; ! 16: static int xnstatic = 0, ynstatic = 0; ! 17: static int xzoom = 0, yzoom = 0, f = 0; ! 18: ! 19: updatezoom(wzoom, xzoomsize, yzoomsize, ! 20: x, y, xsize, ysize, image, wzfactor) ! 21: ! 22: Window wzoom; /* zoom window ID */ ! 23: int xzoomsize, yzoomsize; /* zoom window size */ ! 24: register int x, y; /* center coord for zoom */ ! 25: int xsize, ysize; /* size of original image */ ! 26: unsigned char *image; /* 8-bit image */ ! 27: int wzfactor; /* parent window zoom factor */ ! 28: ! 29: { ! 30: unsigned char *malloc(), *free(); ! 31: int i; ! 32: register int j, xn = xnstatic, yn = ynstatic; ! 33: ! 34: if(x<0 || x>=xsize || y<0 || y>= ysize) return; ! 35: ! 36: /* recalculate the storage needed for nearest larger zoomed pixel */ ! 37: if((f != ZOOMFACT * wzfactor) || (xzoom != xzoomsize) || ! 38: (yzoom != yzoomsize)) { ! 39: f = ZOOMFACT * wzfactor; ! 40: xn = xnstatic = xzoomsize/f + 1; ! 41: yn = ynstatic = yzoomsize/f + 1; ! 42: xzoom = xn*f; ! 43: yzoom = yn*f; ! 44: xcur = (xzoom>>1) - wzoom_x_hot + ((f/ZOOMFACT)<<1); ! 45: ycur = (yzoom>>1) - wzoom_y_hot + ((f/ZOOMFACT)<<1); ! 46: } ! 47: ! 48: /* check available storage space */ ! 49: if( (xzoom*yzoom) > zsize) { ! 50: if(zimage != NULL) free(zimage); ! 51: zsize = xzoom*yzoom; ! 52: if((zimage = malloc(zsize)) == NULL) { ! 53: fprintf(stderr,"Can't allocate zoom image buffer!\n"); ! 54: exit(1); ! 55: } ! 56: } ! 57: ! 58: replicate(x-xn/2,y-yn/2,xsize,ysize,image,f, ! 59: 0,0,xzoom,yzoom,zimage); ! 60: ! 61: if( (y-yn/2) < 0) ! 62: bzero(zimage,xzoom*f*(yn/2-y)); ! 63: if( (y-yn/2+yn) > ysize) ! 64: bzero(zimage+xzoom*f*(ysize-y+yn/2), ! 65: xzoom*f*(y-yn/2+yn-ysize)); ! 66: if( (x-xn/2) < 0) ! 67: for(j=0;j<yzoom;j++) bzero(zimage+j*xzoom,f*(xn/2-x)); ! 68: if( (x-xn/2+xn) > xsize) ! 69: for(j=0;j<yzoom;j++) bzero(zimage+j*xzoom+f*(xsize-x+xn/2), ! 70: f*(x-xn/2+xn-xsize)); ! 71: ! 72: XPixmapBitsPutZ(wzoom,0,0,xzoom,yzoom,zimage,0,GXcopy,AllPlanes); ! 73: ! 74: if(wzmask == NULL) { ! 75: wzmask = XStoreBitmap(wzoom_mask_width, wzoom_mask_height, ! 76: wzoom_mask_bits); ! 77: } ! 78: XBitmapBitsPut(wzoom, xcur, ycur, ! 79: wzoom_width, wzoom_height, wzoom_bits, ! 80: WhitePixel, BlackPixel, wzmask, GXcopy, AllPlanes); ! 81: } ! 82: ! 83: replicate(x0,y0,w0,h0,from,f,x,y,w,h,to) ! 84: /* Fill array "to" with a piece of "from", each pixel mapping to fxf pixels */ ! 85: unsigned char *from, *to; /* Source array, destination array */ ! 86: int x0,y0,w0,h0; /* Source origin, dimensions */ ! 87: int x,y,w,h; /* Destination origin, dimensions */ ! 88: int f; /* Replication factor */ ! 89: { ! 90: register unsigned char *s, *d; ! 91: register int k, n, i; ! 92: int i0,i1,j0,j1,j; ! 93: ! 94: j0 = MAX(0,y0); ! 95: j1 = MIN(h0,y0+(h-y)/f); ! 96: i0 = MAX(0,x0); ! 97: i1 = MIN(w0,x0+(w-x)/f); ! 98: for(j=j0;j<j1;j++) { ! 99: s = from + w0*j + i0; ! 100: d = to + w*(f*(j-y0)+y) + x + f*(i0-x0); ! 101: i = i1 - i0; ! 102: n = f; ! 103: while(i--) { ! 104: k = n; ! 105: while(k--) *d++ = *s; ! 106: s++; ! 107: } ! 108: i = f-1; ! 109: n = f*(i1-i0); ! 110: s = d - f*(i1-i0); ! 111: d = s + w; ! 112: while(i--) { ! 113: bcopy(s,d,n); ! 114: d += w; ! 115: } ! 116: } ! 117: } ! 118:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.