示例#1
0
void MarkPix (ImageDisplay *IDdata, int iX, int iY, int iInner, int iOuter)
/*  Routine to mark cross on pixarray, iX, iY are 0-rel. */
/*  iX = 0-rel x pixel coordinate */
/*  iY = 0-rel y pixel coordinate */
/*  iInner = number of pixels from center on each arm of cross not to mark */
/*  iOuter = half width of cross in pixels */
{
    int iiY, iNx, iNy, i, j, i1, i2, i3, i4, j1, j2, j3, j4;

    iNx = image[CurImag].iImageNx;
    iNy = image[CurImag].iImageNy;
    iiY = iNy - iY - 1; /* image "upside down" */
/*  horizional */
    i1 = iX - iOuter; i1 = max (0, i1);
    i2 = iX - iInner; i2 = max (0, i2);
    i3 = iX + iInner; i3 = min (iNx-1, i3);
    i4 = iX + iOuter; i4 = min (iNx-1, i4);
    for (i=i1; i<=i2; i++)  /* first end */
      XPutPixel (image[CurImag].pixarray, i, iiY, IDdata->colut[MAXCOLOR-1]);
    for (i=i3; i<=i4; i++)  /* far end */
      XPutPixel (image[CurImag].pixarray, i, iiY, IDdata->colut[MAXCOLOR-1]);

/*  vertical */
    j1 = iiY - iOuter; j1 = max (0, j1);
    j2 = iiY - iInner; j2 = max (0, j2);
    j3 = iiY + iInner; j3 = min (iNy-1, j3);
    j4 = iiY + iOuter; j4 = min (iNy-1, j4);
    for (j=j1; j<=j2; j++)  /* top */
      XPutPixel (image[CurImag].pixarray, iX, j, IDdata->colut[MAXCOLOR-1]);
    for (j=j3; j<=j4; j++)  /* bottom */
      XPutPixel (image[CurImag].pixarray, iX, j, IDdata->colut[MAXCOLOR-1]);
}  /* End of MarkPix */
示例#2
0
static void RedrawCanvasImage(Canvas *C,
                              int FromX,
                              int ToX,
                              int FromY,
                              int ToY) {

    CanvasExtension *CE=CExt(C);

    int SwapRedAndBlue = CE->Image->red_mask != ONLY_RED;

    for (int Y=FromY; Y<=ToY; Y++)
        for (int X=FromX; X<=ToX; X++)
            if (TestImage)
                XPutPixel(CE->Image,X,Y,X%(1<<BitPlanes));
            else if (BitPlanes==24) {
                if(SwapRedAndBlue) {
                    unsigned p = (CE->Mask)&PIXEL(C,X,Y);
                    unsigned p1 = (GET_RED(p) << 16) | (GET_GREEN(p) << 8) | GET_BLUE(p);
                    XPutPixel(CE->Image,X,Y,p1);
                } else {
                    XPutPixel(CE->Image,X,Y,(CE->Mask)&PIXEL(C,X,Y));
                }
            } else if (BitPlanes==16) {
                unsigned p = (CE->Mask)&PIXEL(C,X,Y);
                unsigned p_r = GET_RED(p) >> 3;
                unsigned p_g = GET_GREEN(p) >> 2;
                unsigned p_b = GET_BLUE(p) >> 3;
                unsigned short p1 = (p_r << 11) | (p_g << 5) | (p_b);
                XPutPixel(CE->Image,X,Y,p1);
            } else if (BitPlanes==15) {
示例#3
0
void
JXImage::SetImageData
	(
	const JSize			colorCount,
	const JColorIndex*	colorTable,
	unsigned short**	imageData,
	const JBoolean		hasMask,
	const unsigned long	maskColor
	)
{
	const JCoordinate w = GetWidth();
	const JCoordinate h = GetHeight();

	PrepareForImageData();

	// convert color table to X pixel values

	unsigned long* xColorTable = new unsigned long [ colorCount ];
	assert( xColorTable != NULL );

	for (JIndex i=0; i<colorCount; i++)
		{
		if (!hasMask || i != maskColor)
			{
			xColorTable[i] = colorTable[i];
			}
		}

	// put data into image

	for (JCoordinate x=0; x<w; x++)
		{
		for (JCoordinate y=0; y<h; y++)
			{
			const unsigned short color = imageData[x][y];

			if (hasMask && color == maskColor)
				{
				if (itsMask == NULL)
					{
					itsMask = new JXImageMask(itsDisplay, w,h, kJTrue);
					assert( itsMask != NULL );
					}
				itsMask->RemovePixel(x,y);
				XPutPixel(itsImage, x,y, 0);
				}
			else
				{
				XPutPixel(itsImage, x,y, xColorTable[color]);
				}
			}
		}

	// clean up

	delete [] xColorTable;

	ImageDataFinished();
}
示例#4
0
文件: filters.c 项目: yhsesq/yhs
void dgauy_gaux_filter(float sigma){
  int i,j,k,length_gaussian,length_deriv;
  float gaussian[SIZE1],deriv_gaussian[SIZE1];
  matrix dgauy, dgauy_gaux, total_resul, m; 
  float rmin,rmax,rng;

  /* Fill in the image with background color */
  for(i=0; i<IMAGE_WIDTH; i++)
	for(j=0; j<IMAGE_HEIGHT; j++)
	    XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);
  
  get_gaussian(sigma,gaussian,&length_gaussian);

  get_derigaussian(sigma,deriv_gaussian,&length_deriv);
 
  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  /* Calculates convolution of the image with the derivative of a */
  convo_vectory(m,deriv_gaussian,length_deriv,&rmax,&rmin,dgauy);


  /*Calculate the smoothing of a Gaussian(y) in x direction */
  convo_vectorx(dgauy,gaussian,length_gaussian,&rmax,&rmin,
		dgauy_gaux);

  rng=(rmax-rmin);

  for(i=0;i<IMAGE_WIDTH;i++)
	for(j=0;j<IMAGE_HEIGHT;j++)
		total_resul[i][j]=sqrt(pow(dgauy_gaux[i][j],2));		

  for(i=0;i<IMAGE_WIDTH;i++)
	for(j=0;j<IMAGE_HEIGHT;j++)
        XPutPixel(theXImage_2,i,j,(unsigned long)
		 (((float)(total_resul[i][j]-rmin)/rng)*255.0));
  
  /* Copy image into pixmap */
  XPutImage(XtDisplay(draw_2), thePixmap_2,image_gc_2, theXImage_2,
		 0, 0, 0, 0, theXImage_2->width, theXImage_2->height);
  
  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);

}
示例#5
0
/*
 * Copy the the sub-image (src_x, src_y, w, h) to the screen at 
 * (x0 + x1, y0 + y1).
 * `src' is a pointer to the array of pixels.
 * `bpl' is the width of that array.
 * No clipping performed.
 */
void
Fgl_putbox_low (Drawable dst, int x0, int y0, int x1, int y1,
		int w, int h, unsigned char *src, int bpl,
		int src_x, int src_y)
{
    XImage *im;
    int x, y;

#ifdef ALLOW_PIX_DOUBLING
    const int pmult = pix_double ? 2 : 1;
#else
    const int pmult = 1;
#endif

    im = XCreateImage (display.dpy, 0,	/* display and visual */
		       DefaultDepth (display.dpy, display.screen),	/* depth */
		       ZPixmap,	/* format */
		       0,		/* offset */
		       0,		/* data */
		       pmult * w, pmult * h,	/* width and height */
		       32, 0);	/* bitmap_pad and bytes_per_line */
    /* XXX: assert is not the right way to check for errors - wck */
    assert (im != 0);
    im->data = (char *) malloc (im->bytes_per_line * pmult * h);
    assert (im->data != 0);

    src += src_x + src_y * bpl;

    if (pmult == 1) {
	for (y = 0; y < h; y++)
	    for (x = 0; x < w; x++)
		XPutPixel (im, x, y, colour_table[src[x + y * bpl]]);
    } else {
	for (y = 0; y < h; y++)
	    for (x = 0; x < w; x++)
	    {
		unsigned long c = colour_table[src[x + y * bpl]];

		XPutPixel (im, 2 * x + 0, 2 * y + 0, c);
		XPutPixel (im, 2 * x + 0, 2 * y + 1, c);
		XPutPixel (im, 2 * x + 1, 2 * y + 0, c);
		XPutPixel (im, 2 * x + 1, 2 * y + 1, c);
	    }
    }

    if (dst == display.win) {
	pixmap_putbox (src, 0, 0, bpl, x1, y1, w, h);
    }

    XPutImage (display.dpy, dst, display.pixcolour_gc[0], im, 0, 0,
	       x0 + pmult * x1, y0 + pmult * y1, pmult * w, pmult * h);

    XDestroyImage (im);
}
示例#6
0
/**
 * Part of the floodfill ??
 */
static int fill_line(XImage *image, int x, int y, int width, unsigned int area_color, unsigned int fill_color, int minx, int maxx, dir_type direction)
{
  register int left, right, i;

  XPutPixel(image, x, y, fill_color);
  for( left=x-1; (XGetPixel(image, left, y) == area_color) && (left >= 0);left--)
  {
    XPutPixel(image, left, y, fill_color);
  }
  left++;

  for (right = x+1; (XGetPixel(image, right, y) == area_color) && (right < width); right++)
  {
    XPutPixel(image, right, y, fill_color);
  }

  XDrawLine(dpy, drawable, fill_gc, left, y, right-1, y);

  for (i = left; i < right; i++)
  {
    if (XGetPixel(image, i, y+direction) == area_color)
    {
      /* Last one because we know there is one other pixel */
      i += fill_line(image, i, y+direction, width, area_color, fill_color, left, right, direction) + 1;
    }
  }

  if (left < minx-1) /* Fill other dir */
  {
    for (i = left; i < minx-1; i++)
    {
	    if (XGetPixel(image, i, y-direction) == area_color)
      {
        /* Last one because we know there is one other pixel */
	      i += fill_line(image, i, y-direction, width, area_color, fill_color, left, right, (direction==dir_down?dir_up:dir_down)) + 1;
      }
    }
  }

  if (right > maxx) /* Fill other dir */
  {
    for (i = maxx+1; i < right; i++)
    {
	    if (XGetPixel(image, i, y-direction) == area_color)
      {
        /* Last one because we know there is one other pixel */
	      i += fill_line(image, i, y-direction, width, area_color, fill_color, left, right, (direction==dir_down?dir_up:dir_down)) + 1;
      }
    }
  }
  return(right-x);
}
示例#7
0
static void
draw_ripple(struct state *st, short *src)
{
  int across, down;
  char *dirty = st->dirty_buffer;

  for (down = 0; down < st->height - 1; down++, src += 1, dirty += 1)
    for (across = 0; across < st->width - 1; across++, src++, dirty++) {
      int v1, v2, v3, v4;
      v1 = (int)*src;
      v2 = (int)*(src + 1);
      v3 = (int)*(src + st->width);
      v4 = (int)*(src + st->width + 1);
      if ((v1 == 0 && v2 == 0 && v3 == 0 && v4 == 0)) {
        if (*dirty > 0)
          (*dirty)--;
      } else
        *dirty = DIRTY;

      if (*dirty > 0) {
        int dx;
        if (st->light > 0) {
          dx = ((v3 - v1) + (v4 - v2)) << st->light; /* light from top */
        } else
          dx = 0;
        XPutPixel(st->buffer_map,(across<<1),  (down<<1),  map_color(st, dx + v1));
        XPutPixel(st->buffer_map,(across<<1)+1,(down<<1),  map_color(st, dx + ((v1 + v2) >> 1)));
        XPutPixel(st->buffer_map,(across<<1),  (down<<1)+1,map_color(st, dx + ((v1 + v3) >> 1)));
        XPutPixel(st->buffer_map,(across<<1)+1,(down<<1)+1,map_color(st, dx + ((v1 + v4) >> 1)));
      }
    }
示例#8
0
void
JXImage::Receive
	(
	JBroadcaster*	sender,
	const Message&	message
	)
{
	if (sender == itsColormap && message.Is(JXColormap::kNewColormap) &&
		itsDepth > 1 && (itsPixmap != None || itsImage != NULL))
		{
		const JXColormap::NewColormap* info =
			dynamic_cast(const JXColormap::NewColormap*, &message);
		assert( info != NULL );

		ConvertToImage();

		const JCoordinate width  = GetWidth();
		const JCoordinate height = GetHeight();
		for (JCoordinate y=0; y<height; y++)
			{
			for (JCoordinate x=0; x<width; x++)
				{
				const unsigned long xPixel = XGetPixel(itsImage, x,y);
				XPutPixel(itsImage, x,y, info->ConvertPixel(xPixel));
				}
			}

		ConvertToDefaultState();
		}

	else
		{
示例#9
0
void
xrender_surf_populate(Display *disp, Xrender_Surf *rs,
		      int w, int h, int stride, int channels,
		      guchar *img_data)
{
   GC gc;
   XGCValues gcv;
   XImage *xim;
   int x, y;
   
   /* yes this isn't optimal - i know.. i just want some data for now */
   gc = XCreateGC(disp, rs->draw, 0, &gcv);
   xim = XCreateImage(disp, rs->vis, rs->depth, ZPixmap, 0, NULL, w, h, 32, 0);
   xim->data = malloc(xim->bytes_per_line * xim->height);

   for (y = 0; y < h; y++)
     {
	for (x = 0; x < w; x++)
	  {
	     int pixel;
	     int a, r, g, b;
	     guchar * p = img_data + y * stride + x * channels;
	     r = p[0];
	     g = p[1];
	     b = p[2];
	     a = p[3];
	     XPutPixel(xim, x, y, (a << 24) | (r << 16) | (g << 8) | b);
	  }
     }
   XPutImage(disp, rs->draw, gc, xim, 0, 0, 0, 0, w, h);
   free(xim->data);
   xim->data = NULL;
   XDestroyImage(xim);
   XFreeGC(disp, gc);
}
示例#10
0
int uicolor_alloc_color(unsigned int red, unsigned int green, unsigned int blue, unsigned long *color_pixel, BYTE *pixel_return)
{
    XColor color;
    XImage *im;
    BYTE *data = (BYTE *)malloc(4); /* XDestroyImage will free data.  */
    Display *display = x11ui_get_display_ptr();

    /* This is a kludge to map pixels to zimage values. Is there a better
       way to do this? //tvr */
    im = XCreateImage(display, visual, x11ui_get_display_depth(), ZPixmap, 0, (char *)data, 1, 1, 8, 0);
    if (!im) {
        log_error(LOG_DEFAULT, "XCreateImage failed.");
        free(data);
        return -1;
    }

    color.flags = DoRed | DoGreen | DoBlue;
    color.red =  red << 8;
    color.green =  green << 8;
    color.blue = blue << 8;

    if (!XAllocColor(display, colormap, &color)) {
        log_error(LOG_DEFAULT, "Cannot allocate color \"#%04X%04X%04X\".", color.red, color.green, color.blue);
        XDestroyImage(im);
        return -1;
    }
    XPutPixel(im, 0, 0, color.pixel);

    *pixel_return = *data;
    *color_pixel = color.pixel;

    XDestroyImage(im);

    return 0;
}
示例#11
0
Global void
ConvertImage(XImage		*image,
	     unsigned int	width,
	     unsigned int	height,
	     ColormapPtr	src_cmap,
	     ColormapPtr	dst_cmap)
{
	int x, y;
	card32 pixel;

	if (image->depth == 1)
		return;

	if (src_cmap == NULL && dst_cmap == NULL)
		return;

	if (src_cmap == NULL) {
		MoveImage(image, image, width, height, dst_cmap, Request);
		return;
	}

	if (dst_cmap == NULL) {
		MoveImage(image, image, width, height, src_cmap, Reply);
		return;
	}

	for (x = 0; x < width; x++)
		for (y = 0; y < height; y++) {
			pixel = XGetPixel(image, x, y);
			pixel = MapColorCell(pixel, src_cmap, Reply);
			pixel = MapColorCell(pixel, dst_cmap, Request);
			XPutPixel(image, x, y, pixel);
		}
}
示例#12
0
void fillimage(StarfishRef tex)
{
  int x,y;
  unsigned long value;
  int redshift,greenshift,blueshift;
  pixel pixel;
     
  x=image->red_mask; redshift=-8;
  while(x) { x/=2; redshift++; }
  x=image->green_mask; greenshift=-8;
  while(x) { x/=2; greenshift++; }
  x=image->blue_mask; blueshift=-8;
  while(x) { x/=2; blueshift++; }
     
  for (y=0; y<height; y++)
  {
    for (x=0; x<width; x++)
    {
      GetStarfishPixel(x, y, tex, &pixel);
      value  = compose(pixel.red,redshift) & image->red_mask;
      value += compose(pixel.green,greenshift) & image->green_mask;
      value += compose(pixel.blue,blueshift) & image->blue_mask;
      XPutPixel(image,x,y,value);
    }
  }
}
示例#13
0
/* service function to convert an array of bytes to an array of dDepth
   depth pixels. 
*/
static void ConvertLine(unsigned char *line, int line_len, XImage * dest)
{
  int i, value, mult=0;
  switch (dDepth)
    {
    case 32:
      mult = 0x01010101;
      break;
    case 24:
      mult = 0x000f0704;
      break;
    case 16:
      mult = 0x00000101;
      break;
    case 8:
      mult = 1;
      break;
    }
  for (i=0;i<line_len;i++)
    {
      value = line[i] * mult;
      XPutPixel(dest, i, 0, value); 
    }
  return;
}
示例#14
0
文件: tcltk.c 项目: ricbit/Oldies
void tcltk_blit (short *buffer) {
    int i,j;

    for (j=0; j<RESY; j++)
        for (i=0; i<RESX; i++) {
            XPutPixel (ximage,i,j,(*buffer++)%16);
        }
}
示例#15
0
文件: filters.c 项目: yhsesq/yhs
/* Taking differences between the values of horizontally adjacent pixels */
void differencex_filter(){
  float mask[2]={1,-1};
  float rmax, rmin, rng;
  int i,j;
  matrix m,dx;

  /* Fill in the image with background color */
  for(i=0; i<IMAGE_WIDTH; i++)
    for(j=0; j<IMAGE_HEIGHT; j++)
      XPutPixel(theXImage_2,i,j,bg);

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

  /* Associate the watch cursor with the main window */ 
  XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

  /* Flush the request buffer and wait for all events */
  /* and errors to be processed by the server.        */
  XSync(XtDisplay(draw_1), False);

  for(i=0;i<IMAGE_WIDTH;i++)
    for(j=0;j<IMAGE_HEIGHT;j++)
       m[i][j]= XGetPixel(theXImage_1,i,j);

  convo_vectorx(m, mask, 1, &rmax, &rmin, dx);

  rng = (rmax-rmin);

  for(i=0;i<512;i++)
    for(j=0;j<511;j++){
	XPutPixel(theXImage_2,i,j,(unsigned long)
		(((float)(dx[i][j]-rmin)/rng)*255.0));
  }

  /* Copy image into pixmap */
  XPutImage(XtDisplay(draw_2), thePixmap_2, image_gc_2, theXImage_2,
		 0, 0, 0, 0, theXImage_2->width, theXImage_2->height);

  /* Disassociate the watch cursor from the main window */
  XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

  /* Clear the drawing window so the image is displayed again */
  XClearArea(XtDisplay(draw_2),XtWindow(draw_2),0,0,0,0,True);

}
示例#16
0
void fill(XEvent ev,Window *layer_expose,Window *layer,Window *mask,int num){

  int i,j;
  int x,y;
  unsigned long pixel;
  //unsigned long pixelmap[CANV_WIDTH][CANV_HEIGHT];
  XImage *ximage[CANV_HEIGHT];
  XImage *xmaskimage;

  XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, None, ShapeSet);//いったんマスクを解除
  XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, None, ShapeSet);
  
  x=ev.xbutton.x;
  y=ev.xbutton.y;

  XCopyArea( dis, layer_expose[num], copy_pix[0], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 );
  
  for (j = 0; j < CANV_HEIGHT; j++) {
    ximage[j] = XGetImage(dis,copy_pix[0],0,j,CANV_WIDTH,1,AllPlanes,ZPixmap);
  }
  xmaskimage = XGetImage(dis,mask[num],0,0,CANV_WIDTH,CANV_HEIGHT,AllPlanes,ZPixmap);

  pixel=XGetPixel(ximage[y],x,0);
  if(pixel==current_color){
    XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet);
    XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet);
    return;
  }
  XPutPixel(ximage[y],x,0,current_color);
  XPutPixel(xmaskimage,x,y,1);
  fillCheck(x,y,pixel,ximage,xmaskimage);
  for (j = 0; j < CANV_HEIGHT; j++) {
    XPutImage(dis,copy_pix[0],gc,ximage[j],0,0,0,j,CANV_WIDTH,1);
  }
  XPutImage(dis,mask[num],mask_gc,xmaskimage,0,0,0,0,CANV_WIDTH,CANV_HEIGHT);

  XCopyArea( dis, copy_pix[0], layer[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 );
  XCopyArea( dis, copy_pix[0], layer_expose[num], gc, 0, 0, CANV_WIDTH, CANV_HEIGHT, 0, 0 );
  

  XShapeCombineMask( dis, layer[num], ShapeBounding, 0, 0, mask[num], ShapeSet);
  XShapeCombineMask( dis, layer[num], ShapeClip, 0, 0, mask[num], ShapeSet);
  addHistory(layer_expose,mask,num);//履歴に追加

}
示例#17
0
文件: split_merge.c 项目: yhsesq/yhs
void start_merge(Widget w, XtPointer client_data,
			XmSelectionBoxCallbackStruct *call_data)
{
    short i,j,condition;
    char *cond;

    /* Get threshold value from user's selection */
    XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &cond);

    condition = atoi(cond);
    if (!(condition>=0 && condition<=512) ) {
	XBell(XtDisplay(w),100);
	return;
    }

    /* Clear the drawing window so the image is displayed again */
    XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);

    /* Associate the watch cursor with the main window */
    XDefineCursor(XtDisplay(draw_1), XtWindow(main_window), theCursor);

    /* Flush the request buffer and wait for all events */
    /* and errors to be processed by the server.        */
    XSync(XtDisplay(draw_1), False);

    /* Free the memory used for giving room to the structure */
    /* that represents the merged regions if any */
    if (merged_region_list!=NULL) free_merge(&merged_region_list);

    num_reg_after=0;

    /* Compute merge procedure */
    merged_region_list = merge(root,condition);

    fprintf (stderr,"\n    ------------- MERGE ------------\n");
    fprintf (stderr,"        Standard deviation  %i\n", condition);
    fprintf (stderr,"        Number of regions   %i\n", num_reg_after);

    /* Fill in the image with background color */
    for(i=0; i<IMAGE_WIDTH; i++)
	for(j=0; j<IMAGE_HEIGHT; j++)
	    XPutPixel(theXImage_2,i,j,XGetPixel(theXImage_1,i,j));

    display_contour(merged_region_list);

    /* Clear the drawing window so the image is displayed again */
    XClearArea(XtDisplay(draw_1),XtWindow(draw_1),0,0,0,0,True);

    /* Disassociate the watch cursor from the main window */
    XUndefineCursor(XtDisplay(draw_1), XtWindow(main_window));

    /* Copy image into pixmap */
    XPutImage(XtDisplay(draw_2), thePixmap_2, image_gc_2, theXImage_2, 
		0, 0, 0, 0, theXImage_2->width, theXImage_2->height);
    /* Clear the drawing window so the image is displayed again */
    XClearArea(XtDisplay(draw_1),XtWindow(draw_2),0,0,0,0,True);
}
示例#18
0
/*******************************************************************
   KF 6/14/90
   write_pixmap_file(display, filename, pm, width, height)
        and
   write_pixmap_file_xy(display, filename, pm, x, y, width, height)
   has been merged into one function.

   INPUT: display dsp, screen s, file name fn to write the file in,
          window id wid where pixmap is,
          upper left corner x, y of original pixmap,
          width and height of pixmap
   OUTPUT: binary file with data
   PURPOSE: write_pixmap_file gets the image structure of the input
          pixmap, convert the image data with the permutation color
          vector, writes the image structure out to filename.

   Note that writing out a Z pixmap is 8x faster than XY pixmap.
   This is because XY writes out each pixel value per plane, thus
   number of bits; Z writes out each pixel, or 8 bits at a time.

   The XY format may have been chosen for a reason -- I don't know.

********************************************************************/
void
write_pixmap_file(Display *dsp, int scr, char  *fn, 
                  Window wid, int x, int y, int width,int height)
{
    XImage *xi;
    FILE *file;
    int *permVector;
    int num;
    int num_colors;

    /* get color map and permutation vector */
    if ((num_colors = makePermVector(dsp, scr,(unsigned long **)&permVector)) < 0) {
        printf("num_colors < 0!!\n");
        exit(-1);
    }

    /* reads image structure in ZPixmap format */
    xi = XGetImage(dsp, wid, x, y, width, height, AllPlanes, ZPixmap);
    file = fopen(fn, "wb");
    if (file == NULL) {
        perror("opening pixmap file for write");
        exit(-1);
    }

#define PUTW(a,b) putw(htonl(a),b)


    PUTW(xi->width, file);
    PUTW(xi->height, file);
    PUTW(xi->xoffset, file);
    PUTW(xi->format, file);
    PUTW(xi->byte_order, file);
    PUTW(xi->bitmap_unit, file);
    PUTW(xi->bitmap_bit_order, file);
    PUTW(xi->bitmap_pad, file);
    PUTW(xi->depth, file);
    PUTW(xi->bytes_per_line, file);
    PUTW(xi->bits_per_pixel, file);
    PUTW(xi->red_mask, file);
    PUTW(xi->green_mask, file);
    PUTW(xi->blue_mask, file);

    num = xi->bytes_per_line * height;  /* total number of pixels in pixmap */

    /* store value from permutation */
    {
        int ii, jj;

        for (ii = 0; ii < width; ii++)
            for (jj = 0; jj < height; jj++) {
                XPutPixel(xi, ii, jj, permVector[(int) XGetPixel(xi, ii, jj)]);
            }
    }
    fwrite(xi->data, 1, num, file);
    fclose(file);
}
示例#19
0
文件: xdata.cpp 项目: toppk/xevil
static void Xvars_unstretch_subsample(XImage* dest,XImage* src) {
  // Real simple, sample every other pixel in ever other row.
  Pos destPos;
  for (destPos.y = 0; destPos.y < dest->height; destPos.y++) {
    for (destPos.x = 0; destPos.x < dest->width; destPos.x++) {
      unsigned long pix = XGetPixel(src,destPos.x * 2,destPos.y * 2);
      XPutPixel(dest,destPos.x,destPos.y,pix);
    }
  }
}
示例#20
0
/*-
 * draw_block
 *
 * Draw a square block of points with the same value.
 *
 * -      ximage is the XImage to draw on.
 * -      x, y is the top left corner
 * -      s is the length of each side
 * -      v is the value
 */
static void
draw_block(XImage * ximage, int x, int y, int s, unsigned long v)
{
	int         a, b;

	for (a = 0; a < s; a++)
		for (b = 0; b < s; b++) {
			XPutPixel(ximage, x + b, y + a, v);
		}
}
示例#21
0
/* generate an XImage from the reflect algoritm submitted by
 * Randy Zack <*****@*****.**>
 * draw really got too big and ugly so I split it up
 * it should be possible to use the from[][] to speed it up
 * (once I figure out the algorithm used :)
 */
static void reflect_draw(struct state *st, int k)
{
	int i, j;
	int	cx, cy;
	int	ly, lysq, lx, ny, dist, rsq = st->radius * st->radius;

	cx = cy = st->radius;
	if (st->xy_coo[k].ymove > 0)
		cy += st->speed;
	if (st->xy_coo[k].xmove > 0)
		cx += st->speed;

	for(i = 0 ; i < 2*st->radius+st->speed+2; i++) {
		ly = i - cy;
		lysq = ly * ly;
		ny = st->xy_coo[k].y + i;
		if (ny >= st->orig_map->height) ny = st->orig_map->height-1;
		for(j = 0 ; j < 2*st->radius+st->speed+2 ; j++) {
			lx = j - cx;
			dist = lx * lx + lysq;
			if (dist > rsq ||
				ly < -st->radius || ly > st->radius ||
				lx < -st->radius || lx > st->radius)
				XPutPixel( st->buffer_map, j, i,
						   XGetPixel( st->orig_map, st->xy_coo[k].x + j, ny ));
			else if (dist == 0)
				XPutPixel( st->buffer_map, j, i, st->black_pixel );
			else {
				int	x = st->xy_coo[k].x + cx + (lx * rsq / dist);
				int	y = st->xy_coo[k].y + cy + (ly * rsq / dist);
				if (x < 0 || x >= st->xgwa.width ||
					y < 0 || y >= st->xgwa.height)
					XPutPixel( st->buffer_map, j, i, st->black_pixel );
				else
					XPutPixel( st->buffer_map, j, i,
							   XGetPixel( st->orig_map, x, y ));
			}
		}
	}

	XPutImage(st->dpy, st->window, st->gc, st->buffer_map, 0, 0, st->xy_coo[k].x, st->xy_coo[k].y,
			2*st->radius+st->speed+2, 2*st->radius+st->speed+2);
}
示例#22
0
static void
floyd_steinberg (struct state *st)
{
  int x, y, err;

  /* Instead of repeatedly calling XPutPixel(), we make an Image and then
     send its bits over all at once.  This consumes much less network
     bandwidth.  The image we create is Wx1 intead of WxH, so that we
     don't use enormous amounts of memory.
   */
  XImage *image =
    XCreateImage (st->dpy, st->xgwa.visual,
		  1, XYBitmap, 0,		/* depth, format, offset */
		  (char *) calloc ((st->xmax + 8) / 8, 1),	/* data */
		  st->xmax, 1, 8, 0);		/* w, h, pad, bpl */

  XSetForeground (st->dpy, st->gc, st->colors[0].pixel);
  XSetBackground (st->dpy, st->gc, st->colors[1].pixel);

  for (y = 0; y < st->ymax - 1; y++)
    {
      for (x = 0; x < st->xmax - 1; x++)
	{
	  if (CELL(x, y) < 0)
	    {
	      err = CELL (x, y);
	      XPutPixel (image, x, 0, 1);
	    }
	  else
	    {
	      err = CELL (x, y) - 1;
	      XPutPixel (image, x, 0, 0);
	    }
	  /* distribute error */
	  CELL (x,   y+1) += (int) (((float) err) * 3.0/8.0);
	  CELL (x+1, y)   += (int) (((float) err) * 3.0/8.0);
	  CELL (x+1, y+1) += (int) (((float) err) * 1.0/4.0);
	}
      XPutImage (st->dpy, st->window, st->gc, image, 0, 0, 0, y, st->xmax, 1);
    }
  XDestroyImage (image);
}
static void
writeRow ( Image* img, GifPixelType* rowBuf, GifColorType* cm, int row )
{
  int             idx, col;
  jint            rgb;
  unsigned long   pix;

  for ( col=0; col < img->width; col++ ) {
	idx = rowBuf[col];
	if ( img->xMask && (idx == img->trans) ) {
	  pix = 0;
	  XPutPixel( img->xMask, col, row, 0);
	}
	else {
	  rgb = (cm[idx].Red << 16) | (cm[idx].Green << 8) | (cm[idx].Blue);
	  pix = pixelValue( X, rgb);
	}
	XPutPixel( img->xImg, col, row, pix);
  }
}
示例#24
0
Global void
CopyImage(XImage      *image,
	  XImage      *new_image,
	  unsigned int width,
	  unsigned int height)
{
	int x,y;
     
	for (x=0; x < width; x++)
		for (y=0; y < height; y++)
			XPutPixel(new_image, x, y, XGetPixel(image, x, y));
}
示例#25
0
int
Block_Rotate(
        XImage *src_image,
        XImage *dst_image,
        int rtype )
{
  int i, j, width, height;
  unsigned long n;

#ifdef DEBUG
  if (debug)
    stat_out("Entering Block_Rotate\n");
#endif

  width  = src_image->width;
  height = src_image->height;

  switch (rtype) {
    case ROTATE_L   : for (i=0; i<width; i++)
			for (j=0; j<height; j++) {
			  n = XGetPixel(src_image, i, j);
			  XPutPixel(dst_image, j, (width-1)-i, n);
			 }
		      break;
    case ROTATE_R   : for (i=0; i<width; i++)
			for (j=0; j<height; j++) {
			  n = XGetPixel(src_image, i, j);
			  XPutPixel(dst_image, (height-1)-j, i, n);
			 }
		      break;
   } /* switch */
  XFlush(dpy);

#ifdef DEBUG
  if (debug)
    stat_out("Leaving Block_Rotate\n");
#endif

  return (True);
}
示例#26
0
文件: brush.c 项目: klickverbot/wine
/***********************************************************************
 *           BRUSH_DitherColor
 */
static Pixmap BRUSH_DitherColor( COLORREF color, int depth)
{
    /* X image for building dithered pixmap */
    static XImage *ditherImage = NULL;
    static COLORREF prevColor = 0xffffffff;
    unsigned int x, y;
    Pixmap pixmap;
    GC gc = get_bitmap_gc(depth);

    wine_tsx11_lock();
    if (!ditherImage)
    {
        ditherImage = XCreateImage( gdi_display, visual, depth, ZPixmap, 0,
                                    NULL, MATRIX_SIZE, MATRIX_SIZE, 32, 0 );
        if (!ditherImage)
        {
            wine_tsx11_unlock();
            ERR("Could not create dither image\n");
            return 0;
        }
        ditherImage->data = HeapAlloc( GetProcessHeap(), 0,
                                       ditherImage->height * ditherImage->bytes_per_line );
    }

    if (color != prevColor)
    {
	int r = GetRValue( color ) * DITHER_LEVELS;
	int g = GetGValue( color ) * DITHER_LEVELS;
	int b = GetBValue( color ) * DITHER_LEVELS;
	const int *pmatrix = dither_matrix;

	for (y = 0; y < MATRIX_SIZE; y++)
	{
	    for (x = 0; x < MATRIX_SIZE; x++)
	    {
		int d  = *pmatrix++ * 256;
		int dr = ((r + d) / MATRIX_SIZE_2) / 256;
		int dg = ((g + d) / MATRIX_SIZE_2) / 256;
		int db = ((b + d) / MATRIX_SIZE_2) / 256;
		XPutPixel( ditherImage, x, y, PIXEL_VALUE(dr,dg,db) );
	    }
	}
	prevColor = color;
    }

    pixmap = XCreatePixmap( gdi_display, root_window, MATRIX_SIZE, MATRIX_SIZE, depth );
    XPutImage( gdi_display, pixmap, gc, ditherImage, 0, 0,
    	       0, 0, MATRIX_SIZE, MATRIX_SIZE );
    wine_tsx11_unlock();

    return pixmap;
}
示例#27
0
static void generic_draw(struct state *st, XImage *src, XImage *dest, int x, int y, int *distort_matrix)
{
	int i, j;
	for (i = 0; i < dest->width; i++)
		for (j = 0; j < dest->height; j++)
			if (st->from[i][j][0] + x >= 0 &&
					st->from[i][j][0] + x < src->width &&
					st->from[i][j][1] + y >= 0 &&
					st->from[i][j][1] + y < src->height)
				XPutPixel(dest, i, j,
						XGetPixel(src,
							st->from[i][j][0] + x,
							st->from[i][j][1] + y));
}
示例#28
0
int camera_shoot(struct IplImage *img, XImage *ximg, GC theGC, Window theWindow, int x1, int y1)
{
	int x, y;
	
	for (y = 0; y < img->height; y++)
		for (x = 0; x < img->width; x++) {
			unsigned char r, g, b;
			r = img->data[img->nchans * (y * img->width + x) + 0];
			g = img->data[img->nchans * (y * img->width + x) + 1];
			b = img->data[img->nchans * (y * img->width + x) + 2];
			XPutPixel(ximg, x, y, ((r << 16) | (g << 8) | b));
		}
	XPutImage(theDisplay, theWindow, theGC, ximg, 0, 0, x1, y1, 640, 480);

	return 0;	
}
示例#29
0
static unsigned long
shadebobs_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;

  if( st->draw_i++ >= st->cycles )
    {
      XWindowAttributes XWinAttribs;
      XGetWindowAttributes( st->dpy, st->window, &XWinAttribs );

      st->draw_i = 0;
#if 0
      memset( st->pImage->data, 0, st->pImage->bytes_per_line * st->pImage->height );
#else
      {
        /* fill the image with the actual value of the black pixel, not 0. */
        unsigned long black = BlackPixelOfScreen (XWinAttribs.screen);
        int x, y;
        for (y = 0; y < XWinAttribs.height; y++)
          for (x = 0; x < XWinAttribs.width; x++)
            XPutPixel (st->pImage, x, y, black);
      }
#endif

      for( st->iShadeBob=0; st->iShadeBob<st->nShadeBobCount; st->iShadeBob++ )
        ResetShadeBob( st, &st->aShadeBobs[ st->iShadeBob ] );
      XFreeColors( st->dpy, XWinAttribs.colormap, st->aiColorVals, st->iColorCount, 0 );
      free( st->aiColorVals );
      st->aiColorVals = SetPalette( st );
      XClearWindow( st->dpy, st->window );
    }

  for( st->iShadeBob=0; st->iShadeBob<st->nShadeBobCount; st->iShadeBob++ )
    Execute( st, &st->aShadeBobs[ st->iShadeBob ] );

#ifdef VERBOSE
  iFrame++;
  if( nTime - time( NULL ) )
    {
      printf( "%s: %d FPS\n", progname, iFrame );
      nTime = time( NULL );
      iFrame = 0;
    }
#endif  /*  VERBOSE */

  return st->delay;
}
示例#30
0
/******************************************************************************
 *
 * Function copy_pixels
 *
 * This routine loops through a scanline of decompressed, quantized
 * JPEG data and uses XPutPixel to copy the pixel values into the 
 * XImage associated with the destination manager.
 *
 *****************************************************************************/
static void copy_pixels(
    j_decompress_ptr cinfo, 
    djpeg_dest_ptr   dinfo,
    JDIMENSION       rows_supplied)
{
    register int pixval;
    register JSAMPROW ptr;
    register JDIMENSION col;
    ximg_dest_ptr dest = (ximg_dest_ptr) dinfo;

    ptr = dest->pub.buffer[0];
    for (col=0; col < cinfo->output_width; col++) 
    {
        pixval = GETJSAMPLE(*ptr++);
        XPutPixel(dest->ximage,col,cinfo->output_scanline-1, pixval);
    }
}