Example #1
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);
}
Example #2
0
void iupdrvImageGetData(void* handle, unsigned char* imgdata)
{
  Pixmap pixmap = (Pixmap)handle;
  int w, h, y, x, bpp;
  XImage *xi;

  if (!iupdrvImageGetInfo(handle, &w, &h, &bpp))
    return;

  if (bpp == 8)
    return;

  xi = XGetImage(iupmot_display, pixmap, 0, 0, w, h, ULONG_MAX, ZPixmap);
  if (xi)
  {
    /* planes are packed and top-bottom in this imgdata */
    int planesize = w*h;
    unsigned char *line_data;

    for (y = 0; y<h; y++)
    {
      line_data = imgdata + y * planesize;
      for (x = 0; x<w; x++)
      {
        iupmotColorGetRGB(XGetPixel(xi, x, y), line_data + x, line_data + x + 1, line_data + x + 2);
      }
    }

    XDestroyImage(xi);
  }
}
Example #3
0
static int compare_color2(x11window_t * x11win, uint32_t w, uint32_t h, bool isRed, bool isGreen, bool isBlue)
{
   XImage * ximg = 0;
   size_t   pixels;
   uint32_t x, y;

   Window root = RootWindow(x11win->display->sys_display, screen_x11window(x11win));
   Window windummy;
   int32_t x2, y2;
   XTranslateCoordinates(x11win->display->sys_display, x11win->sys_drawable, root, 0, 0, &x2, &y2, &windummy);
   ximg = XGetImage(x11win->display->sys_display, root, x2, y2, w, h, (unsigned long)-1, ZPixmap);

   for (pixels = 0, y = 0; y < h; ++y) {
      for (x = 0; x < w; ++x) {
         unsigned long rgbcolor = XGetPixel(ximg, (int)x, (int)y);
         if (isRed == (0 != (rgbcolor & ximg->red_mask))
             && isGreen == (0 != (rgbcolor & ximg->green_mask))
             && isBlue  == (0 != (rgbcolor & ximg->blue_mask))) {
            ++ pixels;
         }
      }
   }

   XDestroyImage(ximg);

   return (pixels > ((uint64_t)x*y/2)) ? 0 : EINVAL;
}
Example #4
0
void save(){
  unsigned char   **image;         // image[HEIGHT][WIDTH]の形式です

  int             i, j, pixeldata;
  XImage *ximage;
  
  image = (unsigned char**)malloc(height * sizeof(unsigned char*)); // 以下3行は2次元配列を確保します
  for (j = 0; j < height; j++)
    image[j] = (unsigned char*)malloc(width * sizeof(unsigned char) * 3);

  for (j = 0; j < height; j++) {
    ximage = XGetImage(dis,history_pix[(next+MAX_HISTORY-1)%MAX_HISTORY],0,j,width,1,AllPlanes,ZPixmap);
  
    for(i=0;i<width;i++){
      pixeldata = XGetPixel(ximage,i,0);
      image[j][3*i] = pixeldata>>16&0xff;
      image[j][3*i+1] = pixeldata>>8&0xff;
      image[j][3*i+2] = pixeldata&0xff;
    }
    //XPutImage(dis,canvas,hcopy_gc,ximage,0,j,0,j,width,1);
  }
  write_png("test2.png", image, width, height);                           // PNGファイルを作成します
  for (j = 0; j < height; j++) free(image[j]);            // 以下2行は2次元配列を解放します
  free(image);
  
}
Example #5
0
int
egl_probe_front_pixel_rgb(struct egl_state *state,
			  int x, int y, const float *expected)
{
	XImage *ximage = XGetImage(state->dpy, state->win,
				   x, state->height - y - 1, 1, 1, AllPlanes, ZPixmap);
	unsigned long pixel = XGetPixel(ximage, 0, 0);
	uint8_t *probe = (uint8_t *)&pixel;
	int pass = 1;
	int i;

	XDestroyImage(ximage);

	/* NB: XGetPixel returns a normalized BGRA, byte per
	 * component, pixel format */
	for(i = 0; i < 3; ++i) {
		if (fabs(probe[2 - i]/255.0 - expected[i]) > piglit_tolerance[i]) {
			pass = 0;
		}
	}

	if (pass)
		return 1;

	printf("Front Buffer Probe at (%i,%i)\n", x, y);
	printf("  Expected: %f %f %f %f\n", expected[0], expected[1], expected[2], expected[3]);
	printf("  Observed: %f %f %f %f\n", probe[0]/255.0, probe[1]/255.0, probe[2]/255.0, probe[3]/255.0);

	return 0;
}
Example #6
0
int EZX_GetPixel (EZXW_p W, int x, int y)
{
    XImage *xi;

    xi = XGetImage (theDisplay,W->w,x,y,1,1,AllPlanes,XYPixmap);
    return (XGetPixel ( xi,x,y ));
}
Example #7
0
static int
mygetpixel (XImage * image, int pos, int y)
{
  int width = image->width;
  int i;
  int sum = font_error;
  int start = (pos * width + 4) / 8;
  int end = ((pos + 1) * width + 4) / 8;
  if (start == end)
    {
      if (start == image->width - 1)
	start--;
      else
	end++;
    }
  for (i = start; i < end; i++)
    sum += XGetPixel (image, i, y) != 0;
  if (sum <= (end - start) / 2)
    {
      font_error = sum;
      return 0;
    }
  else
    font_error = -(end - start - sum);
  return 1;
}
Example #8
0
void updateColor(int sq, Display *disp, Window wind, int x, int y, int dx, int dy)
//sq :: 1 - 64. 
{
	XImage *i =
	XGetImage(disp, wind, x, y, dx, dy, AllPlanes, XYPixmap);
	
	int j;
	int k;

	unsigned long findColor();
	unsigned long px;
	unsigned long cl;

	for (j = 0; j < 26; j++){
		for(k = 0; k < 26; k++){	
	
			px = XGetPixel(i, 10 + 2*j, 10 + 2*k);
			cl = findColor(px);
			
			if(cl != 0){
				colArr[sq] = cl;
				XDestroyImage(i);
				return;
			}
		}
	}

	XDestroyImage(i);

	colArr[sq] = UNK;
	return;
}
Example #9
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);
		}
}
Example #10
0
/*
 * Generate OpenGL-compatible bitmap.
 */
static void
fill_bitmap(Display * dpy, Window win, GC gc,
	    unsigned int width, unsigned int height,
	    int x0, int y0, unsigned int c, GLubyte * bitmap)
{
   XImage *image;
   unsigned int x, y;
   Pixmap pixmap;
   XChar2b char2b;

   pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1);
   XSetForeground(dpy, gc, 0);
   XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height);
   XSetForeground(dpy, gc, 1);

   char2b.byte1 = (c >> 8) & 0xff;
   char2b.byte2 = (c & 0xff);

   XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1);

   image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap);
   if (image) {
      /* Fill the bitmap (X11 and OpenGL are upside down wrt each other).  */
      for (y = 0; y < height; y++)
	 for (x = 0; x < 8 * width; x++)
	    if (XGetPixel(image, x, y))
	       bitmap[width * (height - y - 1) + x / 8] |=
		  (1 << (7 - (x % 8)));
      XDestroyImage(image);
   }

   XFreePixmap(dpy, pixmap);
}
Example #11
0
void iupdrvImageGetRawData(void* handle, unsigned char* imgdata)
{
  Pixmap pixmap = (Pixmap)handle;
  int w, h, y, x, bpp;
  XImage *xi;

  if (!iupdrvImageGetInfo(handle, &w, &h, &bpp))
    return;

  if (bpp==8)
    return;

  xi = XGetImage(iupmot_display, pixmap, 0, 0, w, h, ULONG_MAX, ZPixmap);
  if (xi)
  {
    /* planes are separated in imgdata */
    int planesize = w*h;
    unsigned char *r = imgdata,
                  *g = imgdata+planesize,
                  *b = imgdata+2*planesize;
    for (y=0; y<h; y++)
    {
      int lineoffset = (h-1 - y)*w;  /* imgdata is bottom up */
      for (x=0; x<w; x++)
      {
        iupmotColorGetRGB(XGetPixel(xi, x, y), r + lineoffset+x, g + lineoffset+x, b + lineoffset+x);
      }
    }
    
    XDestroyImage(xi);
  }
}
Example #12
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
		{
Example #13
0
File: filters.c Project: 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);

}
Example #14
0
// Get pixel color at coordinates x,y
void pixel_color (Display *display, int x, int y, XColor *color)
{
	XImage *image;
	image = XGetImage (display, DefaultRootWindow (display), x, y, 1, 1, AllPlanes, XYPixmap);
	color->pixel = XGetPixel (image, 0, 0);
	XFree (image);
	XQueryColor (display, DefaultColormap(display, DefaultScreen (display)), color);
}
Example #15
0
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);
}
Example #16
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);
}
Example #17
0
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);
    }
  }
}
Example #18
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);
}
Example #19
0
void gui_Draw_Image(winlist_t *win, int x, int y, char **xpm_data)
{
    XImage *image, *mask;
    XpmAttributes attr;
    Window w = win->window;
    GC pgc = XCreateGC(gui->display, w, 0, NULL);
    unsigned int px, py;
    unsigned long mask_val, img_val;

    bzero(&attr, sizeof(attr));
    XpmCreateImageFromData(gui->display, xpm_data, &image, &mask, &attr);
    if (mask)
    {
	for (py=0 ; py < attr.height ; py++)
	{
	    for (px=0 ; px < attr.width ; px++)
	    {
		mask_val = XGetPixel(mask, px, py);
		/* 要顯示的點 */
		if (mask_val)
		{
		    img_val = XGetPixel(image, px, py);
        	    XSetForeground(gui->display, pgc, img_val);
		    XDrawPoint(gui->display, w, pgc, px+x, py+y);
		}
	    }
	}
    }
    else
    {
	XPutImage(gui->display, w, DefaultGC(gui->display, gui->screen),
                image, 0, 0, x, y, attr.width, attr.height);
    }
    XDestroyImage(image);

    if (mask)
    {
	XDestroyImage(mask);
    }
    XpmFreeAttributes(&attr);
    XFreeGC(gui->display, pgc);
}
Example #20
0
QColor ColorPickerWidget::grabColor(const QPoint &p, bool destroyImage)
{
#ifdef Q_WS_X11
    /*
     we use the X11 API directly in this case as we are not getting back a valid
     return from QPixmap::grabWindow in the case where the application is using
     an argb visual
    */
    if( !qApp->desktop()->geometry().contains( p ))
        return QColor();
    unsigned long xpixel;
    if (m_image == NULL) {
        Window root = RootWindow(QX11Info::display(), QX11Info::appScreen());
        m_image = XGetImage(QX11Info::display(), root, p.x(), p.y(), 1, 1, -1, ZPixmap);
        xpixel = XGetPixel(m_image, 0, 0);
    } else {
        xpixel = XGetPixel(m_image, p.x(), p.y());
    }
    if (destroyImage) {
        XDestroyImage(m_image);
        m_image = 0;
    }
    XColor xcol;
    xcol.pixel = xpixel;
    xcol.flags = DoRed | DoGreen | DoBlue;
    XQueryColor(QX11Info::display(),
                DefaultColormap(QX11Info::display(), QX11Info::appScreen()),
                &xcol);
    return QColor::fromRgbF(xcol.red / 65535.0, xcol.green / 65535.0, xcol.blue / 65535.0);
#else
    Q_UNUSED(destroyImage)

    if (m_image.isNull()) {
        QWidget *desktop = QApplication::desktop();
        QPixmap pm = QPixmap::grabWindow(desktop->winId(), p.x(), p.y(), 1, 1);
        QImage i = pm.toImage();
        return i.pixel(0, 0);
    } else {
        return m_image.pixel(p.x(), p.y());
    }
#endif
}
Example #21
0
void logofill() {
	XImage *img = XGetImage(dpy, win, 0, 0, screen_width, screen_height, -1,
							ZPixmap );
	floodfill( img, xgr_pen.xpos, xgr_pen.ypos,
			   XGetPixel( img, xgr_pen.xpos, xgr_pen.ypos ),
			   color[(xgr_pen.color)+2].pixel );
	
	XPutImage( dpy, win, draw_gc, img, 0, 0, 0, 0, screen_width,
			   screen_height );
  XDestroyImage( img );
}
Example #22
0
	LLDSPEC	color_t gdisp_lld_get_pixel_color(GDisplay *g) {
		xPriv *	priv = (xPriv *)g->priv;
		XColor	color;
		XImage *img;

		img = XGetImage (dis, priv->pix, g->p.x, g->p.y, 1, 1, AllPlanes, XYPixmap);
		color.pixel = XGetPixel (img, 0, 0);
		XFree(img);
		XQueryColor(dis, cmap, &color);
		return RGB2COLOR(color.red>>8, color.green>>8, color.blue>>8);
	}
Example #23
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));
}
Example #24
0
color
x_picture_rep::internal_get_pixel (int x, int y) {
  if (im == NULL)
    im= XGetImage (the_gui->dpy, pm, 0, 0, w, h, AllPlanes, XYPixmap);
  if (im != NULL) {
    unsigned long c= XGetPixel (im, x, h-1-y);
    int r= (c >> 16) & 0xff;
    int g= (c >> 8 ) & 0xff;
    int b= (c      ) & 0xff;
    if (r == 0x64 && g == 0x65 && b == 0x66) return 0x00ffffff;
    return rgb_color (r, g, b, 255);
  }
Example #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);
}
Example #26
0
PetscErrorCode PetscDrawGetImage_X(PetscDraw draw,unsigned char palette[PETSC_DRAW_MAXCOLOR][3],unsigned int *out_w,unsigned int *out_h,unsigned char *out_pixels[])
{
  PetscDraw_X      *Xwin = (PetscDraw_X*)draw->data;
  PetscMPIInt      rank;
  PetscErrorCode   ierr;

  PetscFunctionBegin;
  if (out_w)      *out_w      = 0;
  if (out_h)      *out_h      = 0;
  if (out_pixels) *out_pixels = NULL;
  ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)draw),&rank);CHKERRQ(ierr);

  /* make sure the X server processed requests from all processes */
  ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
  XSync(Xwin->disp,True);
  ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
  ierr = MPI_Barrier(PetscObjectComm((PetscObject)draw));CHKERRQ(ierr);

  /* only the first process return image data */
  ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
  if (!rank) {
    Window        root;
    XImage        *ximage;
    int           pmap[PETSC_DRAW_MAXCOLOR];
    unsigned char *pixels = NULL;
    unsigned int  w,h,dummy;
    int           x,y,p;
    /* copy colormap palette to the caller */
    ierr = PetscMemcpy(palette,Xwin->cpalette,sizeof(Xwin->cpalette));CHKERRQ(ierr);
    /* get image out of the drawable */
    XGetGeometry(Xwin->disp,PetscDrawXiDrawable(Xwin),&root,&x,&y,&w,&h,&dummy,&dummy);
    ximage = XGetImage(Xwin->disp,PetscDrawXiDrawable(Xwin),0,0,w,h,AllPlanes,ZPixmap);
    if (!ximage) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Cannot XGetImage()");
    /* build indirect sort permutation (a.k.a argsort) of the color -> pixel mapping */
    for (p=0; p<PETSC_DRAW_MAXCOLOR; p++) pmap[p] = p; /* identity permutation */
    ierr = PetscArgSortPixVal(Xwin->cmapping,pmap,255);CHKERRQ(ierr);
    /* extract pixel values out of the image and map them to color indices */
    ierr = PetscMalloc1(w*h,&pixels);CHKERRQ(ierr);
    for (p=0,y=0; y<(int)h; y++)
      for (x=0; x<(int)w; x++) {
        PetscDrawXiPixVal pix = XGetPixel(ximage,x,y);
        pixels[p++] = (unsigned char)PetscDrawXiPixelToColor(Xwin,pmap,pix);
      }
    XDestroyImage(ximage);
    *out_w      = w;
    *out_h      = h;
    *out_pixels = pixels;
  }
  ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
Example #27
0
void mouse_track_2(Widget w, XtPointer client_data, XEvent *event)
{
   int mouse_x, mouse_y;

   if (file_not_loaded) return;

   /* Get actual co-ordinates of the mouse */
   mouse_x = event->xmotion.x;
   mouse_y = event->xmotion.y;

   /* Refresh the actual co-ordinates of the mouse on the screen */
   refresh_coord(mouse_x, mouse_y,
                 (int) XGetPixel(theXImage_2, mouse_x, mouse_y)); 
}
Example #28
0
void get_pixel_color(Display *d, int x, int y, struct rgb_color *c, int radius) {
#if USE_XQUERYCOLOR
	/* Cache color lookups */
#define CACHE_SIZE 16384
	static unsigned long pixels[CACHE_SIZE] = {0};
	static XColor colors[CACHE_SIZE] = {0};
	static uint8_t cached[CACHE_SIZE] = {0};

	XColor xc;
#else
	/* we blindly assume that we have an array of rgb structs */
	struct rgb_color *pic = (struct rgb_color *)img->data;
#endif
	/* calculate average color */
	long ix, iy;
	unsigned long r = 0;
	unsigned long g = 0;
	unsigned long b = 0;
	int n_pixels = 0;
	for (ix=0; ix < img->width; ix++) {
		if (ix+img_offset.x < x-radius || ix+img_offset.x > x+radius) continue;
		for (iy=0; iy < img->height; iy++) {
			if (iy+img_offset.y < y-radius || iy+img_offset.y > y+radius) continue;
#if USE_XQUERYCOLOR
			unsigned long p = XGetPixel(img, ix, iy);
			if (cached[p%CACHE_SIZE] && pixels[p%CACHE_SIZE] == p) {
				xc = colors[p%CACHE_SIZE];
			} else {
				xc.pixel = p;
				XQueryColor(d, DefaultColormap(d, DefaultScreen(d)), &xc);
				pixels[p%CACHE_SIZE] = p;
				colors[p%CACHE_SIZE] = xc;
				cached[p%CACHE_SIZE] = 1;
			}
			r += xc.red>>8;
			g += xc.green>>8;
			b += xc.blue>>8;
#else
			struct rgb_color *pixel = &pic[ix+iy*img->width];
			r += pixel->red;
			g += pixel->green;
			b += pixel->blue;
#endif
			n_pixels++;
		}
	}
	c->red = (r/n_pixels);
	c->green = (g/n_pixels);
	c->blue = (b/n_pixels);
}
Example #29
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));
}
Example #30
-1
value caml_gr_dump_image(value image)
{
  int width, height, i, j;
  XImage * idata, * imask;
  value m = Val_unit;

  Begin_roots2(image, m);
    caml_gr_check_open();
    width = Width_im(image);
    height = Height_im(image);
    m = alloc(height, 0);
    for (i = 0; i < height; i++) {
      value v = alloc(width, 0);
      modify(&Field(m, i), v);
    }

    idata =
      XGetImage(caml_gr_display, Data_im(image), 0, 0, width, height, (-1), ZPixmap);
    for (i = 0; i < height; i++)
      for (j = 0; j < width; j++)
        Field(Field(m, i), j) = Val_int(caml_gr_rgb_pixel(XGetPixel(idata, j, i)));
    XDestroyImage(idata);

    if (Mask_im(image) != None) {
      imask =
        XGetImage(caml_gr_display, Mask_im(image), 0, 0, width, height, 1, ZPixmap);
      for (i = 0; i < height; i++)
        for (j = 0; j < width; j++)
          if (XGetPixel(imask, j, i) == 0)
            Field(Field(m, i), j) = Val_int(Transparent);
      XDestroyImage(imask);
    }
  End_roots();
  return m;
}