/*------------------------------------------------------------------*/ static void init_kugel(struct state *st) { #ifdef FASTDRAW int i; for(i=0; i<st->fastch; i++) { # ifdef FASTCOPY st->kugeln[i].r1=-((double) i)/2 -1; st->kugeln[i].x1=sum1ton(i); st->kugeln[i].y1=((double) i)/2 +1; fill_kugel(st,i,st->fastcircles,1); setink((1<<MIN(24,st->xgwa.depth))-1); fill_kugel(st,i,st->fastmask,0); # else st->kugeln[i].r1=-((double) i)/2 -1; st->kugeln[i].x1=st->kugeln[i].y1=((double) i)/2 +1; fill_kugel(i,st->buffer,1); st->fastcircles[i]=XGetImage(st->dpy,st->buffer,0,0,i+2,i+2,(1<<st->planes)-1,ZPixmap); setink((1<<MIN(24,st->xgwa.depth))-1); fill_kugel(i,st->buffer,0); st->fastmask[i]=XGetImage(st->dpy,st->buffer,0,0,i+2,i+2,(1<<st->planes)-1,ZPixmap); setink(0); XFillRectangle (st->dpy, st->buffer , st->gc, 0, 0, st->scrnWidth, st->scrnHeight); # endif } st->fastdraw=1; #endif }
void Process_Copy( XImage **img, XImage **img_mono ) { if (Selected) { *img = XGetImage(dpy, color_icon, select_box.x, select_box.y, select_box.width, select_box.height, AllPlanes, format); *img_mono = XGetImage(dpy, mono_icon, select_box.x, select_box.y, select_box.width, select_box.height, AllPlanes, format); XtSetSensitive( editMenu_paste_pb, True); } else DoErrorDialog( GETSTR(16,12, "No area has been selected") ); }
static int tc_x11source_acquire_image_plain(TCX11Source *handle, uint8_t *data, int maxdata) { int size = -1; /* but draw such areas if windows are opaque */ /* FIXME: switch to XCreateImage? */ handle->image = XGetImage(handle->dpy, handle->pix, 0, 0, handle->width, handle->height, AllPlanes, ZPixmap); if (handle->image == NULL || handle->image->data == NULL) { tc_log_error(__FILE__, "cannot get X image"); } else { size = (int)tc_video_frame_size(handle->image->width, handle->image->height, handle->out_fmt); if (size <= maxdata) { tcv_convert(handle->tcvhandle, handle->image->data, data, handle->image->width, handle->image->height, IMG_BGRA32, handle->conv_fmt); } else { size = 0; } XDestroyImage(handle->image); } return size; }
XImage* xf_snapshot(xfPeerContext* xfp, int x, int y, int width, int height) { XImage* image; xfInfo* xfi = xfp->info; if (xfi->use_xshm) { pthread_mutex_lock(&(xfp->mutex)); XCopyArea(xfi->display, xfi->root_window, xfi->fb_pixmap, xfi->xdamage_gc, x, y, width, height, x, y); XSync(xfi->display, False); image = xfi->fb_image; pthread_mutex_unlock(&(xfp->mutex)); } else { pthread_mutex_lock(&(xfp->mutex)); image = XGetImage(xfi->display, xfi->root_window, x, y, width, height, AllPlanes, ZPixmap); pthread_mutex_unlock(&(xfp->mutex)); } return image; }
void putimage_test(void) { int num_copies = 200; int i; long totaltime; char buf[80]; num_copies *= X.percent; XSetFillStyle(X.dpy,X.miscgc,FillTiled); XFillRectangle(X.dpy,X.win,X.miscgc,0,0,400,400); X.image = XGetImage(X.dpy,X.win,0,0,200,200,~0,XYPixmap); XSync(X.dpy,0); timer(StartTimer); for (i=0;i<num_copies;++i) XPutImage(X.dpy,X.win,X.gc,X.image,0,0,i,i,200,200); XSync(X.dpy,0); totaltime = timer(EndTimer); snprintf(buf,sizeof buf,"%.2f seconds.",(double)totaltime/1000000.); show_result(buf); }
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; }
FImage *FGetFImage( Display *dpy, Drawable d, Visual *visual, unsigned int depth, int x, int y, unsigned int width, unsigned int height, unsigned long plane_mask, int format) { FImage *fim; FShmInit(dpy); fim = mvwm_malloc(sizeof(FImage)); fim->im = NULL; fim->shminfo = NULL; if (XShmSupport && FShmImagesSupported) { FShmSafeCreateImage( dpy, fim, visual, depth, format, width, height); if (fim->im) { FShmGetImage( dpy, d, fim->im, x, y, plane_mask); } } if (!fim->im) { fim->im = XGetImage( dpy, d, x, y, width, height, plane_mask, format); } return fim; }
static PyObject* get_rgb_screen(PyObject *self, PyObject *args) { int x, y, dx, dy; int good_args = PyArg_ParseTuple(args, "IIII", &x, &y, &dx, &dy); if (!good_args) { return NULL; } Display *display = XOpenDisplay(NULL); Window window = RootWindow(display, DefaultScreen(display)); XImage *img = XGetImage(display, window, x, y, dx, dy, AllPlanes, ZPixmap); int w = img->width; int h = img->height; unsigned char *rgb_arr = (unsigned char*) malloc(4*w*h); if (rgb_arr == NULL) { PyErr_NoMemory(); return NULL; } npy_intp dims[] = {h, w, 4}; PyObject *np_arr = PyArray_SimpleNewFromData(3, dims, NPY_UINT8, img->data); return np_arr; }
void draw(Display *dis, Window win, GC gc) { //XDrawRectangle (dis, win, gc, 50, 50, 398, 398); if (image == NULL) { FILE *bitmap; size_t read_size; unsigned char *bin; /* Create image */ image = XGetImage(dis, win, 0, 0, image_width, image_height, AllPlanes, ZPixmap); image->data = malloc(image_width * image_height * 4); /* Fill with white pixels */ memset(image->data, 0xFF, image_width * image_height * 4); currentPtr = (uint32_t *)image->data; /* Open raw file */ bitmap = fopen(strFilename, "r"); if (bitmap) { /* Read up to 64000 bytes */ bin = malloc(64000); read_size = fread(bin, sizeof(char), 64000, bitmap); fclose(bitmap); /* transform to fit the bitmap format */ transform(bin, read_size, (uint32_t *)image->data, image_width * image_height); } } /* Display the new image */ XPutImage(dis, win, gc, image, 0, 0, 0, 0, image_width, image_height); //XSetForeground(dis, gc, 0xFF0000); //XFillRectangle(dis, win, gc, 1, 1, 10, 10); /* Force output now */ XFlush(dis); }
/* * This function is kind of gaggy in some respects because it * winds up requiring twice the amount of memory really needed. * It would be possible to return the XImage structure directly, * but that kind of defeats the whole purpose of libsx in addition * to the fact that X packs the data in ways that might not be * what the user wants. So we unpack the data and just put the * raw bytes of the image in the user's buffer. */ void GetImage(char *data, int x, int y, int width, int height) { XImage *xi; int i,j; char *xi_data; if (lsx_curwin->toplevel == NULL || data == NULL) return; xi = XGetImage(display, window, x,y, width,height, ~0, ZPixmap); xi_data = xi->data; for (i=0; i < height; i++) { char *line_start = xi_data; for (j=0; j < width; j++, xi_data++, data++) *data = *xi_data; while ((xi_data - line_start) < xi->bytes_per_line) xi_data++; } XFree((char *)xi); }
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 )); }
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; }
/* * Function for window capturing * Parameters: a window handler for window to capture * Returns a ponter to created dump(XImage struct)*/ XImage* windowCapture(Window handler){ Display *dpy; XImage *image; XWindowAttributes attr; int visibility=isVisible(handler); if(visibility==0){ fprintf(stderr,"Error: Window %d is not visible\n",(int)handler); return NULL; } if(visibility==-1){ fprintf(stderr,"Error: Failed fetching window visibility for %d\n", (int)handler); return NULL; } /*Connecting to X server*/ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr,"Error: Unable to connect to X server\n"); return NULL; } /*Getting window attributes*/ XGetWindowAttributes(dpy,handler,&attr); /*Doing a dump*/ image = XGetImage (dpy, handler, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); if (!image) { fprintf (stderr, "Error: Unable to get image from X server\n"); XCloseDisplay(dpy); return NULL; } /*Finishing*/ XCloseDisplay(dpy); return image; }
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); } }
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); } }
/** * capture image */ static NftResult _capture(LedFrame *frame, LedFrameCord x, LedFrameCord y) { if(!frame) NFT_LOG_NULL(NFT_FAILURE); /* get screen-portion from X server */ XImage *image = NULL; if(!(image = XGetImage(_c.display, RootWindow(_c.display, _c.screen), x, y, led_frame_get_width(frame), led_frame_get_height(frame), AllPlanes, ZPixmap))) { NFT_LOG(L_ERROR, "XGetImage() failed"); return NFT_FAILURE; } /* copy framebuffer */ memcpy(led_frame_get_buffer(frame), image->data, led_frame_get_buffersize(frame)); /* destroy images */ XDestroyImage(image); return NFT_SUCCESS; }
void tool_text_paint(tool_text_context_t *context, canvas_event_t event) { /* Create a pixmap on the server on which we draw the text */ Pixmap pixmap = XCreatePixmap(context->repaint_context->display, context->repaint_context->window, context->repaint_context->canvas->width, context->repaint_context->canvas->height, context->repaint_context->canvas->depth); XFillRectangle(context->repaint_context->display, pixmap, DefaultGC(context->repaint_context->display, context->repaint_context->screen), 0, 0, context->repaint_context->canvas->width, context->repaint_context->canvas->height); XGCValues values; values.foreground = TMP_COLOR; GC gc = XCreateGC(context->repaint_context->display, context->repaint_context->window, GCForeground, &values); XDrawString(context->repaint_context->display, pixmap, gc, event.x, event.y, context->repaint_context->input_string, strlen(context->repaint_context->input_string)); /* Now we create an image from the pixmap. */ XImage *image = XGetImage(context->repaint_context->display, pixmap, 0, 0, context->repaint_context->canvas->width, context->repaint_context->canvas->height, TMP_COLOR, /* Plane mask. Only copy the pixels set to the right color */ ZPixmap); process_image(context->repaint_context, image); XFreePixmap(context->repaint_context->display, pixmap); XDestroyImage(image); }
QImage QXlibScreen::grabWindow(Window window, int x, int y, int w, int h) { if (w == 0 || h ==0) return QImage(); //WinId 0 means the desktop widget if (!window) window = rootWindow(); XWindowAttributes window_attr; if (!XGetWindowAttributes(mDisplay->nativeDisplay(), window, &window_attr)) return QImage(); if (w < 0) w = window_attr.width - x; if (h < 0) h = window_attr.height - y; // Ideally, we should also limit ourselves to the screen area, but the Qt docs say // that it's "unsafe" to go outside the screen, so we can ignore that problem. //We're definitely not optimizing for speed... XImage *xi = XGetImage(mDisplay->nativeDisplay(), window, x, y, w, h, AllPlanes, ZPixmap); if (!xi) return QImage(); //taking a copy to make sure we have ownership -- not fast QImage result = QImage( (uchar*) xi->data, xi->width, xi->height, xi->bytes_per_line, QImage::Format_RGB32 ).copy(); XDestroyImage(xi); return result; }
static agsurface_t *get_drawn_glyph(const char *str, int w) { XImage *src; agsurface_t *dst; XSetForeground(x11_display, gc_pix_glyph, 0); XFillRectangle(x11_display, pix_glyph, gc_pix_glyph, 0, 0, GLYPH_PIXMAP_WIDTH, GLYPH_PIXMAP_HEIGHT); XSetForeground(x11_display, gc_pix_glyph, 1); XmbDrawString(x11_display, pix_glyph, fontset, gc_pix_glyph, 0, font_ascent, str, strlen(str)); src = XGetImage(x11_display, pix_glyph, 0, 0, w, font_ascent + font_descent, AllPlanes, ZPixmap); dst = g_new(agsurface_t, 1); dst->width = w; dst->height = font_ascent + font_descent; dst->bytes_per_line = src->bytes_per_line; dst->pixel = (BYTE *)src->data; dst->bytes_per_pixel = x11_workinfo->cimg.bytes_per_pixel; src->data = NULL; XDestroyImage(src); return dst; }
/***************************************************************** Capture a local screenshot of the desktop, saving to the file specified by filename. If type = 0, then write a bitmap file, else write a JPEG file. Return Value: 0 - fail 1 - success ******************************************************************/ int CaptureDesktop(char* filename) { Window desktop; Display* dsp; XImage* img; int screen_width; int screen_height; //dsp = XOpenDisplay(NULL); /* Connect to a local display */ dsp = XOpenDisplay(":0"); if(NULL==dsp) { return 0; } desktop = RootWindow(dsp,0);/* Refer to the root window */ if(0==desktop) { return 0; } /* Retrive the width and the height of the screen */ screen_width = DisplayWidth(dsp,0); screen_height = DisplayHeight(dsp,0); /* Get the Image of the root window */ img = XGetImage(dsp,desktop,0,0,screen_width,screen_height,~0,ZPixmap); JpegWriteFileFromImage(filename,img); XDestroyImage(img); XCloseDisplay(dsp); return 1; }
/*Function returns a pointer to a full-screen dump (XImage structure)*/ XImage* fullScreenCapture() { int screen_num; Display *dpy; XImage *image; /*Connecting to X server*/ dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "Error: Unable to establish connection to X server\n"); return NULL; } /*Getting default screen*/ screen_num = DefaultScreen(dpy); /*Doing a full-screen dump*/ image = XGetImage (dpy, RootWindow(dpy, screen_num), 0, 0, DisplayWidth(dpy,screen_num), DisplayHeight(dpy,screen_num), AllPlanes, ZPixmap); if (!image) { fprintf (stderr, "Error: Unable to get image from X server\n"); XCloseDisplay(dpy); return NULL; } /*Finishing*/ XCloseDisplay(dpy); return image; }
void EGLXTransportSurfaceClient::prepareTexture() { ::glBindTexture(GL_TEXTURE_2D, m_texture); if (m_eglImage) { m_eglImage->reBindTexImage(); return; } // Fallback to use XImage in case EGLImage and TextureToPixmap are not supported. m_image = XGetImage(NativeWrapper::nativeDisplay(), m_handle, 0, 0, m_size.width(), m_size.height(), AllPlanes, ZPixmap); #if USE(OPENGL_ES_2) if (m_format != GraphicsContext3D::BGRA) { for (unsigned i = 0; i < m_totalBytes; i += 4) std::swap(m_image->data[i], m_image->data[i + 2]); } #endif glTexImage2D(GL_TEXTURE_2D, 0, m_format, m_size.width(), m_size.height(), 0, m_format, GL_UNSIGNED_BYTE, m_image->data); if (m_image) { XDestroyImage(m_image); m_image = 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; }
/* * 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); }
void slop::GLSelectRectangle::generateMagnifyingGlass() { int x = xengine->m_mousex-m_glassPixels/2; int y = xengine->m_mousey-m_glassPixels/2; bool fx = xengine->m_mousex < m_x+m_width/2; bool fy = xengine->m_mousey < m_y+m_height/2; // Mouse behavior SUCKS if ( !fx && !fy ) { x += 1; y += 1; } else if ( fx && !fy ) { y += 1; } else if ( !fx && fy ) { x += 1; } int w = m_glassPixels; int h = m_glassPixels; constrainWithinMonitor( &x, &y, &w, &h ); XImage* image = XGetImage( xengine->m_display, xengine->m_root, x, y, w, h, 0xffffffff, ZPixmap ); glEnable(GL_TEXTURE_2D); glGenTextures(1, &m_texid); glBindTexture(GL_TEXTURE_2D, m_texid); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)(&(image->data[0]))); XDestroyImage( image ); glDisable(GL_TEXTURE_2D); }
bool Output::update() { if (!ImageNode::update()) return false; cv::Mat in = getImage("in"); if (in.empty()) return true; if (!ximage) return true; XWindowAttributes xwAttr; Status ret = XGetWindowAttributes( display, win, &xwAttr ); int screen_w = xwAttr.width; int screen_h = xwAttr.height; setSignal("disp_w", screen_w); setSignal("disp_h", screen_h); // TBD is this necessary or does X do it for me if the window is resized? cv::Size sz = cv::Size(screen_w, screen_h); cv::Mat scaled; cv::resize(in, scaled, sz, 0, 0, cv::INTER_NEAREST ); XDestroyImage(ximage); ximage = XGetImage(display, DefaultRootWindow(display), 0, 0, screen_w, screen_h, AllPlanes, ZPixmap); bm::matToXImage(scaled, ximage, win, *display, *screen); bool window_decorations_on = getSignal("decor"); setSignal("decor", window_decorations_on); bm::setWindowDecorations(display, win, window_decorations_on); }
bool Output::setup(const int width, const int height) { bm::setupX(display, win, width, height, opcode); gc = XCreateGC(display, win, 0, NULL); ximage = XGetImage(display, DefaultRootWindow(display), 0, 0, width, height, AllPlanes, ZPixmap); screen = DefaultScreenOfDisplay(display); }
void *XScreenSaverLayer::feed(double feed) { // notice("feed %i, %i", freej->screen->w, freej->screen->h); // XCopyArea(display, wmgen.pixmap, iconwin, NormalGC, 0,0, // wmgen.attributes.width, wmgen.attributes.height, 0, 0); // XCopyArea(dpy, back_win, *img, gc, 0,0, freej->screen->w, // freej->screen->h, 0, 0); // buffer=&img.data; // XCopyArea(dpy, back_win, *img->data, gc, 0,0, geo.w , geo.h, 0, 0); // img = XGetImage(dpy, back_win, 0, 0, freej->screen->w, freej->screen->h, // XDestroyImage(img); // Pixmap p=XCreatePixmap(dpy, back_win, 400,300,24); // XGetSubImage(dpy, back_win, 0,0, geo.w, geo.h, ~0L, ZPixmap, img, 0, 0); // XCopyArea(display, src, dest, gc, src_x, src_y, width, height, // dest_x, dest_y) // XCopyArea(dpy, back_win, p, gc, 0,0, geo.w , geo.h, 0, 0); // XCopyArea(dpy, back_win, (long unsigned int)img, gc, 0,0, geo.w, geo.h, // 0, 0); // XSync(dpy, true); // XFreePixmap(dpy, img); // img = XGetImage(dpy, back_win, 0, 0, geo.w, geo.h, 32, XYBitmap); img = XGetImage(dpy, back_win, 0, 0, geo.w, geo.h, ~0L, ZPixmap); // buffer=img->data; memcpy(output, img->data, geo.getByteSize()); // buffer=*(&img->data); XDestroyImage(img); // XSync(dpy, true); return output; }
RImage *RCreateImageFromDrawable(RContext * context, Drawable drawable, Pixmap mask) { RImage *image; XImage *pimg, *mimg; unsigned int w, h, bar; int foo; Window baz; assert(drawable != None); if (!XGetGeometry(context->dpy, drawable, &baz, &foo, &foo, &w, &h, &bar, &bar)) { printf("wrlib: invalid window or pixmap passed to RCreateImageFromDrawable\n"); return NULL; } pimg = XGetImage(context->dpy, drawable, 0, 0, w, h, AllPlanes, ZPixmap); if (!pimg) { RErrorCode = RERR_XERROR; return NULL; } mimg = NULL; if (mask) { if (XGetGeometry(context->dpy, mask, &baz, &foo, &foo, &w, &h, &bar, &bar)) { mimg = XGetImage(context->dpy, mask, 0, 0, w, h, AllPlanes, ZPixmap); } } image = RCreateImageFromXImage(context, pimg, mimg); XDestroyImage(pimg); if (mimg) XDestroyImage(mimg); return image; }
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; }