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

📄 xmovie.c

📁 su 的源代码库
💻 C
📖 第 1 页 / 共 3 页
字号:
		resizeCB(w,cd,ca);		/* clear window and force an expose event */	/*	if (cd->exposed) XClearArea(XtDisplay(w),XtWindow(w),0,0,0,0,True);	*/}static void adjustAxesValues (int n1, float d1, float f1,	int n2, float d2, float f2,	float *x1beg, float *x1end, float *x2beg, float *x2end)/*****************************************************************************Adjust axes values to nearest samples; ensure at least 2 by 2 samples.*****************************************************************************/{	int ix1beg,ix1end,ix2beg,ix2end;		ix1beg = NINT((*x1beg-f1)/d1);	ix1end = NINT((*x1end-f1)/d1);	ix1beg = MAX(0,MIN(n1-1,ix1beg));	ix1end = MAX(0,MIN(n1-1,ix1end));	if (ix1beg==ix1end) {		if (*x1beg<*x1end) {			if (ix1beg>0)				ix1beg--;			else				ix1end++;		} else {			if (ix1beg<n1-1)				ix1beg++;			else				ix1end--;		}	}	*x1beg = f1+ix1beg*d1;	*x1end = f1+ix1end*d1;	ix2beg = NINT((*x2beg-f2)/d2);	ix2end = NINT((*x2end-f2)/d2);	ix2beg = MAX(0,MIN(n2-1,ix2beg));	ix2end = MAX(0,MIN(n2-1,ix2end));	if (ix2beg==ix2end) {		if (*x2beg<*x2end) {			if (ix2beg>0)				ix2beg--;			else				ix2end++;		} else {			if (ix2beg<n2-1)				ix2beg++;			else				ix2end--;		}	}		*x2beg = f2+ix2beg*d2;	*x2end = f2+ix2end*d2;}static unsigned char *makeABytes (int style,	float x1beg, float x1end, float x2beg, float x2end,	float fmin, float fmax, unsigned char bmin, unsigned char bmax,	int n1, float d1, float f1, int n2, float d2, float f2, float *floats,	int *nxa, int *nya)/*****************************************************************************Makes a frame of bytes from a frame of floats.  This functionis responsible for making an initial (non-zoomed) frame ofbytes from a frame of floats.  Floats outside the range[fmin,fmax] are clipped in converting to bytes in thecorresponding range [bmin,bmax].  The output bytes are orderedas nxa samples left-to-right, nya scanlines top-to-bottom, wherenxa and nya are computed according to the window specifiedby x1beg, x1end, x2beg, and x2end.  Only floats inside thiswindow are converted.*****************************************************************************/{	int i1,i2,ix,iy,i1beg,i1end,i1step,i2beg,i2end,i2step,nx,ny;	unsigned char *b,*bp;	float fbmin,fbmax,fscale=0.0,foffset,fi,*f=floats;		/* determine coefficients to convert from floats to bytes */	fbmin = bmin;	fbmax = bmax;	if(fbmax==0.0) fbmax=255.0;	/*	if( fmax < fmin){float tmp=fmax; fmax=fmin; fmin=tmp;}*/	/* warn("fbmin=%f fbmax=%f fscale=%f",fbmin,fbmax,fscale); */        if(fbmax==0)fbmax=255;	fscale = (fmax!=fmin) ? (fbmax-fbmin)/(fmax-fmin) : 1.0e10;	foffset = fbmin-fmin*fscale;	/* warn("fbmin=%f fbmax=%f fscale=%f",fbmin,fbmax,fscale);	 */	/* adjust axes limits to nearest samples */	adjustAxesValues(n1,d1,f1,n2,d2,f2,&x1beg,&x1end,&x2beg,&x2end);		/* determine sample index limits and increments */	i1beg = NINT((x1beg-f1)/d1);	i1end = NINT((x1end-f1)/d1);	i1step = (i1end>i1beg) ? 1 : -1;	i2beg = NINT((x2beg-f2)/d2);	i2end = NINT((x2end-f2)/d2);	i2step = (i2end>i2beg) ? 1 : -1;		/* convert floats to bytes */	if (style==XtcwpNORMAL) {		nx = 1+ABS(i1end-i1beg);		ny = 1+ABS(i2end-i2beg);		b = ealloc1(nx*ny,sizeof(unsigned char));		for (iy=0,i2=i2beg; iy<ny; ++iy,i2+=i2step) {			bp = b+nx*ny-(iy+1)*nx;			for (ix=0,i1=i1beg; ix<nx; ++ix,i1+=i1step) {				fi = foffset+f[i1+i2*n1]*fscale;				if (fi<fbmin) fi = fbmin;				if (fi>fbmax) fi = fbmax;				*bp++ = (unsigned char)fi;			}		}	} else {		nx = 1+ABS(i2end-i2beg);		ny = 1+ABS(i1end-i1beg);		bp = b = ealloc1(nx*ny,sizeof(unsigned char));		for (iy=0,i1=i1beg; iy<ny; ++iy,i1+=i1step) {			for (ix=0,i2=i2beg; ix<nx; ++ix,i2+=i2step) {				fi = foffset+f[i1+i2*n1]*fscale;				if (fi<fbmin) fi = fbmin;				if (fi>fbmax) fi = fbmax;				*bp++ = (unsigned char)fi;			}		}	}		/* set output parameters and return */	*nxa = nx;	*nya = ny;	return b;}static unsigned char *makeBBytes (int nxa, int nya, unsigned char *abytes,	int nxb, int nyb, int ixb, int iyb)/*****************************************************************************Makes bytes (unsigned char) in zoom box, with bytes orderedas nxb samples left-to-right, nyb scanlines top-to-bottom.*****************************************************************************/{	int ix,iy;	unsigned char *b,*bp,*ap;		bp = b = ealloc1(nxb*nyb+0*nya,sizeof(unsigned char));	for (iy=0; iy<nyb; ++iy)		for (ix=0,ap=abytes+(iyb+iy)*nxa+ixb; ix<nxb; ++ix)			*bp++ = *ap++;	return b;}static XImage *makeImage (Display *dpy,  int width, int height,	int nx, int ny, int interp, unsigned char *bytes)/*****************************************************************************Makes image from bytes ordered as left-to-right, top-to-bottom scanlines.*****************************************************************************/{	int widthpad;	unsigned char *pixels;	unsigned char *data;	Colormap wcmap;	XColor color;	int i,j,k;	int scr;	int depth;	unsigned long truecolor_pixel[256];	XImage *xim;	int byte_perpixel;	int line, iline,jline;	int ih,half;	Screen *scr1;	# define RGB_BLACK      {0x00, 0x00, 0x00}# define RGB_WHITE      {0xff, 0xff, 0xff}# define RGB_GRAY       {0x80, 0x80, 0x80}        float c_rgb [3][3]  =         { RGB_BLACK,    RGB_GRAY,   RGB_WHITE  };half=128;byte_perpixel=4;	  scr1=XDefaultScreenOfDisplay(dpy);	xim=(XImage *) NULL;	scr=DefaultScreen(dpy);	wcmap=DefaultColormapOfScreen(scr1);        /* Build the 1st ramp                                           */        for (ih = 0; ih < 128; ++ih) {                color.red   = c_rgb[0][0] +                          (c_rgb[1][0] - c_rgb[0][0]) * ((float) ih)/((float) half);                color.green = c_rgb[0][1] +                        (c_rgb[1][1] - c_rgb[0][1]) * ((float) ih)/((float) half);                color.blue  = c_rgb[0][2] +                        (c_rgb[1][2] - c_rgb[0][2]) * ((float) ih)/((float) half);                 color.red   *= 257.0;                color.green *= 257.0;                color.blue  *= 257.0;                        color.flags = DoRed|DoGreen|DoBlue;XAllocColor(dpy,wcmap,&color);	  truecolor_pixel[ih]=(unsigned long )color.pixel;                        }                        /* Build the 2nd ramp                                           */        for (ih=128; ih<256; ++ih) {                color.red   = c_rgb[1][0] +                        (c_rgb[2][0] - c_rgb[1][0]) * ((float) (ih-half))/((float) half);                color.green = c_rgb[1][1] +                        (c_rgb[2][1] - c_rgb[1][1]) * ((float) (ih-half))/((float) half);                color.blue  = c_rgb[1][2] +                        (c_rgb[2][2] - c_rgb[1][2]) * ((float) (ih-half))/((float) half);                                color.red   *= 257.0;                color.green *= 257.0;                color.blue  *= 257.0;                color.flags = DoRed|DoGreen|DoBlue;                        		XAllocColor(dpy,wcmap,&color);		truecolor_pixel[ih]=(unsigned long )color.pixel;                                    }           	depth=(unsigned int)DefaultDepth(dpy,scr);	if(depth<=8) byte_perpixel=1;	else if(depth<=16) byte_perpixel=2;		/* determine scanline padding and allocate memory for pixels */	widthpad = (1+(width-1)/(BitmapPad(dpy)/8))*BitmapPad(dpy)/8;	pixels = ealloc1(widthpad*height,sizeof(unsigned char));	/* bilinearly interpolate bytes to pixels */	if (interp)	    intl2b(nx,1.0,0.0,ny,1.0,0.0,bytes,		   width,(float)(nx-1)/(float)(width-1),0.0,		   height,(float)(ny-1)/(float)(height-1),0.0,pixels);	else	    intn2b(nx,1.0,0.0,ny,1.0,0.0,bytes,		   width,(float)(nx-1)/(float)(width-1),0.0,		   height,(float)(ny-1)/(float)(height-1),0.0,pixels);	data = ealloc1(widthpad*height,byte_perpixel);	xim=XCreateImage(     (Display *) dpy,                           (Visual *) DefaultVisual(dpy,scr),                           (unsigned int) DefaultDepth(dpy,scr),                           (int) ZPixmap,                           (int) 0,                           (char *) data,                           (unsigned int) widthpad,                           (unsigned int) height,                           (int) BitmapPad(dpy),                           (int) widthpad*byte_perpixel);	byte_perpixel=xim->bits_per_pixel/8;/*	fprintf(stderr,"\nbyte_perpixel = %d, depth= %d\n", byte_perpixel,depth);*/	/* translate bytes to pixels, padding scanlines as necessary */	for (line=0; line<height; line++) {		iline = line*width;		jline = line*widthpad;		for (i=iline,j=jline,k=0; k<width; ++i,++j,++k)		{       if(byte_perpixel==1)			((unsigned char *)data)[j] =(unsigned char)pixels[i];			if(byte_perpixel==2)			  {			    int edn=xim->byte_order;			    if(edn==LSBFirst){			      ((unsigned char *)data)[j*2+0] =(unsigned char)(truecolor_pixel[pixels[i]]);			      ((unsigned char *)data)[j*2+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>8);			    }else{			      ((unsigned char *)data)[j*2+0] =(unsigned char)(truecolor_pixel[pixels[i]]>>24); 			      ((unsigned char *)data)[j*2+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>16);			      }			    /*((unsigned short *)data)[j] =(unsigned short)(truecolor_pixel[pixels[i]]);*/			    /*((unsigned short *)data)[j] =(unsigned short)(truecolor_pixel[pixels[i]]);*/			  }	                        if(byte_perpixel==3){			int edn=xim->byte_order;			if(edn==LSBFirst){                        ((unsigned char *)data)[j*3+0] =(unsigned char)(truecolor_pixel[pixels[i]]);			((unsigned char *)data)[j*3+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>8);			((unsigned char *)data)[j*3+2] =(unsigned char)(truecolor_pixel[pixels[i]]>>16);			}else{			((unsigned char *)data)[j*3+0] =(unsigned char)(truecolor_pixel[pixels[i]]>>24);                           ((unsigned char *)data)[j*3+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>16);                         ((unsigned char *)data)[j*3+2] =(unsigned char)(truecolor_pixel[pixels[i]]>>8);			}			}				if(byte_perpixel==4){			  int edn=xim->byte_order;			  if(edn==LSBFirst){			    ((unsigned char *)data)[j*4+0] =(unsigned char)(truecolor_pixel[pixels[i]]);			    ((unsigned char *)data)[j*4+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>8);			    ((unsigned char *)data)[j*4+2] =(unsigned char)(truecolor_pixel[pixels[i]]>>16);			    ((unsigned char *)data)[j*4+3] =(unsigned char)(truecolor_pixel[pixels[i]]>>24);			  }else{			    ((unsigned char *)data)[j*4+0] =(unsigned char)(truecolor_pixel[pixels[i]]>>24);			    ((unsigned char *)data)[j*4+1] =(unsigned char)(truecolor_pixel[pixels[i]]>>16);   			    ((unsigned char *)data)[j*4+2] =(unsigned char)(truecolor_pixel[pixels[i]]>>8); 			    ((unsigned char *)data)[j*4+3] =(unsigned char)(truecolor_pixel[pixels[i]]);			  }                        /*((unsigned long *)data)[j] =(unsigned long)truecolor_pixel[pixels[i]];*/			}		}		for (j=jline+width,k=width; k<widthpad; ++j,++k)		{		       if(byte_perpixel==1)                        ((unsigned char *)data)[j] =((unsigned char *)data)[jline+width-1];                        if(byte_perpixel==2)			  {			 ((unsigned char *)data)[j*2+0] =((unsigned char *)data)[(jline+width-1)*2+0];                        ((unsigned char *)data)[j*2+1] =((unsigned char *)data)[(jline+width-1)*2+1];                        /*((unsigned short *)data)[j] =((unsigned short *)data)[jline+width-1];*/			  }                        if(byte_perpixel==3){                        ((unsigned char *)data)[j*3+0] =((unsigned char *)data)[(jline+width-1)*3+0];                        ((unsigned char *)data)[j*3+1] =((unsigned char *)data)[(jline+width-1)*3+1];                        ((unsigned char *)data)[j*3+2] =((unsigned char *)data)[(jline+width-1)*3+2];			}                        if(byte_perpixel==4)			{                       ((unsigned char *)data)[j*4+0] =((unsigned char *)data)[(jline+width-1)*4+0];                        ((unsigned char *)data)[j*4+1] =((unsigned char *)data)[(jline+width-1)*4+1];                        ((unsigned char *)data)[j*4+2] =((unsigned char *)data)[(jline+width-1)*4+2];                        ((unsigned char *)data)[j*4+3] =((unsigned char *)data)[(jline+width-1)*4+3];                            /*((unsigned long *)data)[j] =((unsigned long *)data)[jline+width-1];*/			}		}	}		/* create and return image structure */	free1(pixels);	return xim;}/*****************************************************************************Bill Wingle's routine to handle key presses.*****************************************************************************/void key_pressed (Widget w, ClientData *cd, XKeyEvent *event){	char           buffer[2];	int            bufsize = 2;	KeySym         key;	XComposeStatus compose;	XLookupString (event, buffer, bufsize, &key, &compose);	if (key==XK_q || key==XK_Q)  {		exit(0);	}	else if (key==XK_s || key==XK_S) {		XtRemoveWorkProc(cd->wpid);		displayMode = DM_STEP;		return;	}	if (key==XK_c || key==XK_C)		displayMode = DM_CONT;	else if (key==XK_b || key==XK_B || key==XK_Left)		cd->forward = 0;	else if (key==XK_f || key==XK_F || key==XK_n || key==XK_N || key==XK_Right)		cd->forward = 1;	else		return;	cd->wpid = XtAppAddWorkProc(cd->ac, (XtWorkProc) readFrame,cd);}void intn2b (int nxin, float dxin, float fxin,	     int nyin, float dyin, float fyin, unsigned char *zin,	     int nxout, float dxout, float fxout,	     int nyout, float dyout, float fyout, unsigned char *zout)/*****************************************************************************nearest neighbor interpolation of a 2-D array of bytes******************************************************************************Input:nxin		number of x samples input (fast dimension of zin)dxin		x sampling interval inputfxin		first x sample inputnyin		number of y samples input (slow dimension of zin)dyin		y sampling interval inputfyin		first y sample inputzin		array[nyin][nxin] of input samples (see notes)nxout		number of x samples output (fast dimension of zout)dxout		x sampling interval outputfxout		first x sample outputnyout		number of y samples output (slow dimension of zout)dyout		y sampling interval outputfyout		first y sample outputOutput:zout		array[nyout][nxout] of output samples (see notes)******************************************************************************Notes:The arrays zin and zout must passed as pointers to the first element ofa two-dimensional contiguous array of unsigned char values.Constant extrapolation of zin is used to compute zout foroutput x and y outside the range of input x and y.******************************************************************************Author:  Craig Artley, Fairfield Industries, 08/31/98*****************************************************************************/{    float xout, yout, xi, yi;    int ixout, iyout, ix, iyin, *ixin;    ixin = ealloc1int(nxout);    for (ixout=0, xout=fxout; ixout<nxout; ++ixout, xout+=dxout) {	xi = (xout-fxin)/dxin;	ix = NINT(xi);	ix = MAX(0,ix);	ix = MIN(ix,nxin-1);	ixin[ixout] = ix;    }    for (iyout=0, yout=fyout; iyout<nyout; ++iyout, yout+=dyout) {	yi = (yout-fyin)/dyin;	iyin = NINT(yi);	iyin = MAX(0,iyin);	iyin = MIN(iyin,nyin-1);	for (ixout=0; ixout<nxout; ++ixout) {	    *zout++ = zin[iyin*nxin+ixin[ixout]];	}    }    free1int(ixin);}

⌨️ 快捷键说明

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