⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewfax.c

📁 涉及Fax/Mail/Voice通讯编程的一个程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		    case 3:			XDefineCursor(Disp, Win, MoveCursor);		    }		    XFlush(Disp);		    offx = Event.xbutton.x;		    offy = Event.xbutton.y;		    break;		case Button3:		Zoomin:		    if (oz < MAXZOOM && Image->width >= 64 && zfactor < 32) {			Image = Images[++oz];			zfactor <<= 1;			x /= 2;			y /= 2;			Resize = Refresh = 1;		    }		    break;		}		if (Image == NULL) {		    for (i = oz; i && (Images[i] == NULL); i--)			;		    for (; i != oz; i++)			Images[i+1] = ZoomImage(Images[i]);		    Image = Images[oz];		}		break;	    case MotionNotify:#ifdef USE_MOTIONHINT	    {		unsigned int Junk;		Window JunkW;		XQueryPointer(Disp, Event.xmotion.window, &JunkW, &JunkW,			      &Junk, &Junk, &nx, &ny, &Junk);	    }#else		do {		    nx = Event.xmotion.x;		    ny = Event.xmotion.y;		} while (XCheckTypedEvent(Disp, MotionNotify, &Event));#endif		x += offx - nx;		y += offy - ny;		offx = nx;		offy = ny;		break;	    case ButtonRelease:		if (Event.xbutton.button == Button2) {		    XDefineCursor(Disp, Win, ReadyCursor);		    XFlush(Disp);		}	    }	} while (XCheckWindowEvent(Disp, Win,				   KeyPressMask|ButtonPressMask, &Event));	/* if someone thinks we should resize the window and it is not	   already the right size, or if the window is too big and we	   have not already tried to make it smaller ... */	if ((Resize && !(Image->width == PaneWidth &&			 Image->height == PaneHeight)) ||	    (!Oversize && (Image->width < PaneWidth ||			   Image->height < PaneHeight))) {	    int PosX = AbsX - PaneWidth/2 - FrameX;	    int PosY = AbsY - PaneHeight/2 - FrameY;	    XWindowChanges New;	    int ChangeMask = 0;	    New.width = min(Area.w - FrameWidth, Image->width);	    New.height = min(Area.h - FrameHeight, Image->height);	    /* expect an expose if size must change */	    Refresh &= (New.width == PaneWidth && New.height == PaneHeight);	    New.x = max(Area.x, AbsX-New.width/2-FrameX);	    New.x = min(New.x, Area.w-(New.width+FrameWidth)+Area.x);	    New.y = max(Area.y, AbsY-New.height/2-FrameY);	    New.y = min(New.y, Area.h-(New.height+FrameHeight)+Area.y);	    /* mwm takes max_size very seriously! */	    size_hints.flags = 0;	    XSetNormalHints(Disp, Win, &size_hints);	    size_hints.flags = PMaxSize;	    size_hints.x = PosX;	    size_hints.y = PosY;	    size_hints.width = PaneWidth;	    size_hints.height = PaneHeight;	    /* only move a coordinate if the ideal new value is different	       from the current value and either the other dimension has	       changed or the current value is out of area */	    if (PosX != New.x &&		(New.height != PaneHeight || PosX < Area.x || 		 PosX > Area.w-New.width-FrameWidth-Area.x)) {		ChangeMask |= CWX;		size_hints.x = New.x;		size_hints.flags |= PPosition;	    }	    if (PosY != New.y &&		(New.width != PaneWidth || PosY < Area.y ||		 PosY > Area.h-New.height-FrameHeight-Area.y)) {		ChangeMask |= CWY;		size_hints.y = New.y;		size_hints.flags |= PPosition;	    }	    if (New.width != PaneWidth) {		ChangeMask |= CWWidth;		size_hints.width = New.width;		size_hints.flags |= PSize;		ExpectConfNotify = Reparented;	    }	    if (New.height != PaneHeight) {		ChangeMask |= CWHeight;		size_hints.height = New.height;		size_hints.flags |= PSize;		ExpectConfNotify = Reparented;	    }	    New.border_width = 1;	/* ICCCM 4.1.5 */	    ChangeMask |= CWBorderWidth;	    XConfigureWindow(Disp, Win, ChangeMask, &New);	    size_hints.max_width = Image->width;	    size_hints.max_height = Image->height;	    XSetNormalHints(Disp, Win, &size_hints);	}	x = max(x, PaneWidth/2);	x = min(x, Image->width-PaneWidth/2);	y = max(y, PaneHeight/2);	y = min(y, Image->height-PaneHeight/2);	if (x != ox || y != oy || Refresh)	    XPutImage(Disp, Win, PaintGC, Image,		      x-PaneWidth/2, y-PaneHeight/2,		      0, 0, PaneWidth, PaneHeight);	ox = x;	oy = y;	Resize = Refresh = 0;    }}/* run this region through perl to generate the zoom table:$lim = 1;@c = ("0", "1", "1", "2");print "static unsigned char Z[] = {\n";for ($i = 0; $i < 16; $i++) {    for ($j = 0; $j < 16; $j++) {	$b1 = ($c[$j&3]+$c[$i&3]) > $lim;	$b2 = ($c[($j>>2)&3]+$c[($i>>2)&3]) > $lim;	printf " %X,", ($b2 << 1) | $b1;    }    print "\n";}print "};\n";*/static unsigned char Z[] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 2, 2, 2, 3, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 2, 3, 3, 3, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 2, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 0, 0, 0, 1, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 0, 1, 1, 1, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 0, 1, 1, 1, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 1, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 0, 1, 1, 1, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 0, 1, 1, 1, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,};#define nib(n,w)	(((w)>>((n)<<2))&15)#define zak(a,b)	Z[(a<<4)|b]/* 2 -> 1 zoom, 4 pixels -> 1 pixel   if #pixels <= $lim (see above), new pixel is white,   else black.*/static XImage *ZoomImage(XImage *Big){    XImage *Small;    int w, h;    int i, j;    XDefineCursor(Disp, Win, WorkCursor);    XFlush(Disp);    w = (Big->width+1) / 2;    h = (Big->height+1) / 2;    Small = NewImage(w, h, NULL, Big->bitmap_bit_order);    Small->xoffset = (Big->xoffset+1)/2;    for (i = 0; i < Big->height; i += 2) {	t32bits *pb0 = (t32bits *) (Big->data + i * Big->bytes_per_line);	t32bits *pb1 = pb0 + ((i == Big->height-1) ? 0 : Big->bytes_per_line/4);	t32bits *ps = (t32bits *) (Small->data + i * Small->bytes_per_line / 2);	for (j = 0; j < Big->bytes_per_line/8; j++) {	    t32bits r1, r2;	    t32bits t0 = *pb0++;	    t32bits t1 = *pb1++;	    r1 = (zak(nib(7,t0),nib(7,t1))<<14) |		 (zak(nib(6,t0),nib(6,t1))<<12) |		 (zak(nib(5,t0),nib(5,t1))<<10) |		 (zak(nib(4,t0),nib(4,t1))<<8) |		 (zak(nib(3,t0),nib(3,t1))<<6) |		 (zak(nib(2,t0),nib(2,t1))<<4) |		 (zak(nib(1,t0),nib(1,t1))<<2) |		 (zak(nib(0,t0),nib(0,t1)));	    t0 = *pb0++;	    t1 = *pb1++;	    r2 = (zak(nib(7,t0),nib(7,t1))<<14) |		 (zak(nib(6,t0),nib(6,t1))<<12) |		 (zak(nib(5,t0),nib(5,t1))<<10) |		 (zak(nib(4,t0),nib(4,t1))<<8) |		 (zak(nib(3,t0),nib(3,t1))<<6) |		 (zak(nib(2,t0),nib(2,t1))<<4) |		 (zak(nib(1,t0),nib(1,t1))<<2) |		 (zak(nib(0,t0),nib(0,t1)));	    *ps++ = (Big->bitmap_bit_order) ?		(r1<<16)|r2 : (r2<<16)|r1;	}	for ( ; j < Small->bytes_per_line/4; j++) {	    t32bits r1;	    t32bits t0 = *pb0++;	    t32bits t1 = *pb1++;	    r1 = (zak(nib(7,t0),nib(7,t1))<<14) |		 (zak(nib(6,t0),nib(6,t1))<<12) |		 (zak(nib(5,t0),nib(5,t1))<<10) |		 (zak(nib(4,t0),nib(4,t1))<<8) |		 (zak(nib(3,t0),nib(3,t1))<<6) |		 (zak(nib(2,t0),nib(2,t1))<<4) |		 (zak(nib(1,t0),nib(1,t1))<<2) |		 (zak(nib(0,t0),nib(0,t1)));	    *ps++ = (Big->bitmap_bit_order) ?		(r1<<16) : r1;	}    }    XDefineCursor(Disp, Win, ReadyCursor);    return Small;}static XImage *FlipImage(XImage *Image){    XImage *New = NewImage(Image->width, Image->height,			   Image->data, !Image->bitmap_bit_order);    t32bits *p1 = (t32bits *) Image->data;    t32bits *p2 = (t32bits *) (Image->data + Image->height *			     Image->bytes_per_line - 4);    /* the first shall be last ... */    while (p1 < p2) {	t32bits t = *p1;	*p1++ = *p2;	*p2-- = t;    }    /* let Xlib twiddle the bits */    New->xoffset = 32 - (Image->width & 31) - Image->xoffset;    New->xoffset &= 31;    Image->data = NULL;    FreeImage(Image);    return New;}static XImage *MirrorImage(XImage *Image){    int i;    XImage *New = NewImage(Image->width, Image->height,			   Image->data, !Image->bitmap_bit_order);    /* reverse order of 32-bit words in each line */    for (i = 0; i < Image->height; i++) {	t32bits *p1 = (t32bits *) (Image->data + Image->bytes_per_line * i);	t32bits *p2 = p1 + Image->bytes_per_line/4 - 1;	while (p1 < p2) {	    t32bits t = *p1;	    *p1++ = *p2;	    *p2-- = t;	}    }    /* let Xlib twiddle the bits */    New->xoffset = 32 - (Image->width & 31) - Image->xoffset;    New->xoffset &= 31;    Image->data = NULL;    FreeImage(Image);    return New;}static XImage *RotImage(XImage *Image){    XImage *New;    int w = Image->height;    int h = Image->width;    int i, j, k, shift;    int order = Image->bitmap_bit_order;    int offs = h+Image->xoffset-1;    New = NewImage(w, h, NULL, 1);    k = (32 - Image->xoffset) & 3;    for (i = h - 1; i && k; i--, k--) {	t32bits *sp = (t32bits *) Image->data + (offs-i)/32;	t32bits *dp = (t32bits *) (New->data+i*New->bytes_per_line);	t32bits d0;	shift = (offs-i)&31;	if (order) shift = 31-shift;	for (j = 0; j < w; j++) {	    t32bits t = *sp;	    sp += Image->bytes_per_line/4;	    d0 |= ((t >> shift) & 1);	    if ((j & 31) == 31)		*dp++ = d0;	    d0 <<= 1;;	}	if (j & 31)	    *dp++ = d0<<(31-j);    }    for ( ; i >= 3; i-=4) {	t32bits *sp = (t32bits *) Image->data + (offs-i)/32;	t32bits *dp0 = (t32bits *) (New->data+i*New->bytes_per_line);	t32bits *dp1 = dp0 - New->bytes_per_line/4;	t32bits *dp2 = dp1 - New->bytes_per_line/4;	t32bits *dp3 = dp2 - New->bytes_per_line/4;	t32bits d0, d1, d2, d3;	shift = (offs-i)&31;	if (order) shift = 28-shift;	for (j = 0; j < w; j++) {	    t32bits t = *sp >> shift;	    sp += Image->bytes_per_line/4;	    d0 |= t & 1; t >>= 1;	    d1 |= t & 1; t >>= 1;	    d2 |= t & 1; t >>= 1;	    d3 |= t & 1; t >>= 1;	    if ((j & 31) == 31) {		if (order) {		    *dp0++ = d3;		    *dp1++ = d2;		    *dp2++ = d1;		    *dp3++ = d0;		}		else {		    *dp0++ = d0;		    *dp1++ = d1;		    *dp2++ = d2;		    *dp3++ = d3;		}	    }	    d0 <<= 1; d1 <<= 1; d2 <<= 1; d3 <<= 1;	}	if (j & 31) {	    if (order) {		*dp0++ = d3<<(31-j);		*dp1++ = d2<<(31-j);		*dp2++ = d1<<(31-j);		*dp3++ = d0<<(31-j);	    }	    else {		*dp0++ = d0<<(31-j);		*dp1++ = d1<<(31-j);		*dp2++ = d2<<(31-j);		*dp3++ = d3<<(31-j);	    }	}    }    for (; i >= 0; i--) {	t32bits *sp = (t32bits *) Image->data + (offs-i)/32;	t32bits *dp = (t32bits *) (New->data+i*New->bytes_per_line);	t32bits d0;	shift = (offs-i)&31;	if (order) shift = 31-shift;	for (j = 0; j < w; j++) {	    t32bits t = *sp;	    sp += Image->bytes_per_line/4;	    d0 |= ((t >> shift) & 1);	    if ((j & 31) == 31)		*dp++ = d0;	    d0 <<= 1;;	}	if (j & 31)	    *dp++ = d0<<(31-j);    }    FreeImage(Image);    return New;}/* release some non-essential memory or abort */#define Try(n)								\    if (n && n != thispage && n->extra) {				\	FreeImage(n->extra);						\	n->extra = NULL;						\	return 1;							\    }static intrelease(int quit){    struct pagenode *pn;    if (thispage) {	/* first consider "uninteresting" pages */	for (pn = firstpage->next; pn; pn = pn->next)	    if (pn->extra && pn != thispage && pn != thispage->prev &&		pn != thispage->next && pn != lastpage) {		FreeImage(Pimage(pn));		pn->extra = NULL;		return 1;	    }	Try(lastpage);	Try(firstpage);	Try(thispage->prev);	Try(thispage->next);    }    if (!quit)	return 0;    fprintf(stderr, "%s(release): insufficient memory\n", ProgName);    exit(EXIT_FAILURE);}static XImage *NewImage(int w, int h, char *data, int bit_order){    XImage *new;    /* This idea is taken from xwud/xpr.  Use a fake display with the       desired bit/byte order to get the image routines initialised       correctly */    Display fake;    fake = *Disp;    if (data == NULL)	data = xmalloc(((w + 31) & ~31) * h / 8);    fake.byte_order = ByteOrder;    fake.bitmap_unit = 32;    fake.bitmap_bit_order = bit_order;    while ((new = XCreateImage(&fake, DefaultVisual(Disp, Default_Screen),			       1, XYBitmap, 0, data, w, h, 32, 0)) == NULL)	(void) release(1);    Memused += new->bytes_per_line * new->height;    return new;}static voidFreeImage(XImage *Image){    if (Image->data)	Memused -= Image->bytes_per_line * Image->height;    XDestroyImage(Image);}#ifndef xmallocchar *xmalloc(unsigned int size){    char *p;    while (Memused + size > Memlimit && release(0))	;    while ((p = malloc(size)) == NULL)	(void) release(1);    return p;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -