Пример #1
0
int X11_SetupImage(_THIS, SDL_Surface *screen)
{
#ifndef NO_SHARED_MEMORY
	try_mitshm(this, screen);
	if(use_mitshm) {
		SDL_Ximage = XShmCreateImage(SDL_Display, SDL_Visual,
					     this->hidden->depth, ZPixmap,
					     shminfo.shmaddr, &shminfo, 
					     screen->w, screen->h);
		if(!SDL_Ximage) {
			XShmDetach(SDL_Display, &shminfo);
			XSync(SDL_Display, False);
			shmdt(shminfo.shmaddr);
			screen->pixels = NULL;
			goto error;
		}
		this->UpdateRects = X11_MITSHMUpdate;
	}
	if(!use_mitshm)
#endif /* not NO_SHARED_MEMORY */
	{
		int bpp;
		screen->pixels = SDL_malloc(screen->h*screen->pitch);
		if ( screen->pixels == NULL ) {
			SDL_OutOfMemory();
			return -1;
		}
 	        bpp = screen->format->BytesPerPixel;
		SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual,
					  this->hidden->depth, ZPixmap, 0,
					  (char *)screen->pixels, 
					  screen->w, screen->h,
					  32, 0);
		if ( SDL_Ximage == NULL )
			goto error;
		/* XPutImage will convert byte sex automatically */
		SDL_Ximage->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN)
			                 ? MSBFirst : LSBFirst;
		this->UpdateRects = X11_NormalUpdate;
	}
	screen->pitch = SDL_Ximage->bytes_per_line;
	return(0);

error:
	SDL_SetError("Couldn't create XImage");
	return 1;
}
Пример #2
0
static Pixmap xf_mono_bitmap_new(xfContext* xfc, int width, int height,
                                 const BYTE* data)
{
	int scanline;
	XImage* image;
	Pixmap bitmap;
	scanline = (width + 7) / 8;
	bitmap = XCreatePixmap(xfc->display, xfc->drawable, width, height, 1);
	image = XCreateImage(xfc->display, xfc->visual, 1,
	                     ZPixmap, 0, (char*) data, width, height, 8, scanline);
	image->byte_order = LSBFirst;
	image->bitmap_bit_order = LSBFirst;
	XPutImage(xfc->display, bitmap, xfc->gc_mono, image, 0, 0, 0, 0, width, height);
	image->data = NULL;
	XDestroyImage(image);
	return bitmap;
}
Пример #3
0
static Bool
XCreateDrawable(struct drisw_drawable * pdp,
                Display * dpy, XID drawable, int visualid)
{
   XGCValues gcvalues;
   long visMask;
   XVisualInfo visTemp;
   int num_visuals;

   /* create GC's */
   pdp->gc = XCreateGC(dpy, drawable, 0, NULL);
   pdp->swapgc = XCreateGC(dpy, drawable, 0, NULL);

   gcvalues.function = GXcopy;
   gcvalues.graphics_exposures = False;
   XChangeGC(dpy, pdp->gc, GCFunction, &gcvalues);
   XChangeGC(dpy, pdp->swapgc, GCFunction, &gcvalues);
   XChangeGC(dpy, pdp->swapgc, GCGraphicsExposures, &gcvalues);

   /* visual */
   visTemp.visualid = visualid;
   visMask = VisualIDMask;
   pdp->visinfo = XGetVisualInfo(dpy, visMask, &visTemp, &num_visuals);

   if (!pdp->visinfo || num_visuals == 0)
      return False;

   /* create XImage */
   pdp->ximage = XCreateImage(dpy,
                              pdp->visinfo->visual,
                              pdp->visinfo->depth,
                              ZPixmap, 0,             /* format, offset */
                              NULL,                   /* data */
                              0, 0,                   /* width, height */
                              32,                     /* bitmap_pad */
                              0);                     /* bytes_per_line */

  /**
   * swrast does not handle 24-bit depth with 24 bpp, so let X do the
   * the conversion for us.
   */
  if (pdp->ximage->bits_per_pixel == 24)
     pdp->ximage->bits_per_pixel = 32;

   return True;
}
Пример #4
0
void DrawImage(char *data, int x, int y, int width, int height)
{
  XImage *xi;

  if (lsx_curwin->toplevel == NULL || data == NULL)
    return;

  xi = XCreateImage(display, DefaultVisual(display, DefaultScreen(display)),
                    8, ZPixmap, 0, data, width, height,
                    XBitmapPad(display),  width);
  if (xi == NULL)
    return;

  XPutImage(display, window, drawgc, xi, 0,0, x,y,  xi->width,xi->height);

  XFree((char *)xi);
}
Пример #5
0
Pixmap xf_glyph_new(xfInfo* xfi, int width, int height, uint8* data)
{
	int scanline;
	Pixmap bitmap;
	XImage* image;

	scanline = (width + 7) / 8;
	bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, 1);
	image = XCreateImage(xfi->display, xfi->visual, 1,
			ZPixmap, 0, (char*) data, width, height, 8, scanline);
	image->byte_order = MSBFirst;
	image->bitmap_bit_order = MSBFirst;
	XInitImage(image);
	XPutImage(xfi->display, bitmap, xfi->gc_mono, image, 0, 0, 0, 0, width, height);
	XFree(image);
	return bitmap;
}
Пример #6
0
void XWindow::CreateXImage(int width, int height)
{
#ifdef HAVE_SHM
    if (_useShm) {
      if (_isInitialized && _XShmInfo.shmaddr) {
        XShmDetach (_display, &_XShmInfo);
        shmdt (_XShmInfo.shmaddr);
      }
    } else
#endif
    {
      if (_XImage) {
        _XImage->data = _imageDataOrig;
      }
    }

  if (_XImage)
    XDestroyImage(_XImage);

  _imageDataOrig = NULL;

#ifdef HAVE_SHM
   if (XShmQueryExtension (_display)) {
     _useShm = true;
     PTRACE(1, "X11\tXQueryShmExtension success");
   }
   else {
     _useShm = false;
     PTRACE(1, "X11\tXQueryShmExtension failed");
   }

  if (_useShm)
     ShmAttach(width, height);

  if (_useShm) {
     PTRACE(4, "X11\tUsing shm extension");
  }
  else
#endif
  {
        _XImage = XCreateImage(_display, _XVInfo.visual, _depth, ZPixmap, 0, NULL,  width, height, 8, 0);
         _imageDataOrig = (char*)malloc(width  * height * 4 + 32);
         _XImage->data = _imageDataOrig + 16 - ((long)_imageDataOrig & 15);
         memset(_XImage->data, 0, width * 4 * height);
  }
}
Пример #7
0
void Xvars::gen_pix_from_trans(int dpyNum,Drawable dest,Drawable src,
                               const Size& srcSize,TransformType transform,
                               int depth) {
  // Get source image into client memory.
  XImage* srcImage = 
    XGetImage(dpy[dpyNum],src,0,0,srcSize.width,srcSize.height,
              AllPlanes,ZPixmap);
  if (!srcImage) {
    std::cerr << "Could not get image in Xvars::gen_pix_from_trans." << std::endl;
    return;
  }

  // Size of destination image.
  Size destSize = Transform2D::apply(transform,srcSize);

  // Allocate memory for the image.
  char* destData = new_bytes_for_image(destSize,depth,srcImage->bitmap_pad);

  // Create XImage for the transformed data.
  XImage* destImage =
    XCreateImage(dpy[dpyNum],visual[dpyNum],depth,ZPixmap,0,
                 destData,destSize.width,destSize.height,
                 srcImage->bitmap_pad,0);
  assert(destImage);
  assert(destData == destImage->data);
  

  // Traverse coordinates of src, compute corresponding position on 
  // dest and copy the pixel.
  Pos srcPos; 
  for (srcPos.y = 0; srcPos.y < srcSize.height; srcPos.y++) {
    for (srcPos.x = 0; srcPos.x < srcSize.width; srcPos.x++) {
      Pos destPos = Transform2D::apply(transform,srcPos,srcSize);
      unsigned long pix = XGetPixel(srcImage,srcPos.x,srcPos.y);
      XPutPixel(destImage,destPos.x,destPos.y,pix);
    }
  }

  put_image(dpyNum,dest,destImage,destSize);

  // Make sure to use new/delete for freeing the memory we allocated.
  destroy_image(destImage);

  XDestroyImage(srcImage);
}
Пример #8
0
XImage *create_image_from_buffer (Display *dis, int screen, int *width, int *height) {
	int magiclength = strlen(artnavsegda);
	char magic[sizeof(artnavsegda)];
	fgets(magic,magiclength+1,stdin);
	if (strcmp(artnavsegda,magic)!=0)
	{
		printf("incorrect format\n");
		exit(1);
	}
	*width = fgetc(stdin);
	*height = fgetc(stdin);
	XImage *img = NULL;
	Visual *vis;
	double rRatio;
	double gRatio;
	double bRatio;
	int outIndex = 0;	
	int i;
	int numBufBytes = (3 * (*width * *height));
	vis = DefaultVisual (dis, screen);
	rRatio = vis->red_mask / 255.0;
	gRatio = vis->green_mask / 255.0;
	bRatio = vis->blue_mask / 255.0;
	size_t numNewBufBytes = (4 * (*width * *height));
	u_int32_t *newBuf = malloc (numNewBufBytes);
	for (i = 0; i < numBufBytes; ++i)
	{
		unsigned int r, g, b;
		r = (fgetc(stdin) * rRatio);
		++i;
		g = (fgetc(stdin) * gRatio);
		++i;
		b = (fgetc(stdin) * bRatio);
		//r &= vis->red_mask;
		//g &= vis->green_mask;
		//b &= vis->blue_mask;
		newBuf[outIndex] = r | g | b;
		++outIndex;
	}		
	img = XCreateImage (dis,CopyFromParent, 24,ZPixmap, 0,(char *) newBuf,*width, *height,32, 0);
	XInitImage (img);
	img->byte_order = LSBFirst;
	img->bitmap_bit_order = MSBFirst;
	return img;
}		
Пример #9
0
Pixmap xf_mono_bitmap_new(xfInfo* xfi, int width, int height, BYTE* data)
{
	int scanline;
	XImage* image;
	Pixmap bitmap;

	scanline = (width + 7) / 8;

	bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, 1);

	image = XCreateImage(xfi->display, xfi->visual, 1,
			ZPixmap, 0, (char*) data, width, height, 8, scanline);

	XPutImage(xfi->display, bitmap, xfi->gc_mono, image, 0, 0, 0, 0, width, height);
	XFree(image);

	return bitmap;
}
Пример #10
0
static XImage *MakeXImage(Display *dpy, int w, int h)
{
  XImage *I;
  char *data;
  
  /* reserve memory for image */
  data=(char *)calloc((unsigned)(((w-1)/8+1)*h), 1);
  if(data==NULL)
    return NULL;
  
  /* create the XImage */
  I=XCreateImage(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), 1, XYBitmap, 0, data, w, h, 8, 0);
  if(I==NULL)
    return NULL;
  
  I->byte_order=I->bitmap_bit_order=MSBFirst;
  return I;
}
Пример #11
0
void MGLAPI XWIN8_putImage(MGLDC *dc,int left,int top,int right,
	int bottom,int dstLeft,int dstTop,int op,void *surface,
	int bytesPerLine,MGLDC *src)
/****************************************************************************
*
* Function:		XWIN8_putImage
* Parameters:	dc		- Device context
*
* Description:	Blt's a system memory buffer DC of the same pixel depth
*				as the display device context to the display DC.
*
****************************************************************************/
{
	MGL_HDC	gc = dc->wm.xwindc.gc;
	Window wnd = dc->wm.xwindc.wnd;
	Display *dpy = dc->wm.xwindc.dpy;
	xwindc_vars *v = &dc->wm.xwindc;
	
	//	XImage	*im = src->wm.memdc.img;
	XImage *im; // = dc->wm.xwindc.img;
	int func;

	switch(op){
	case MGL_REPLACE_MODE:
		func = GXcopy;
		break;
	case MGL_AND_MODE:
		func = GXand;
		break;
	case MGL_OR_MODE:
		func = GXor;
		break;
	case MGL_XOR_MODE:
		func = GXxor;
		break;
	}
	XSetFunction(dpy,gc,func);
	//	memcpy(im->data, surface, (src->mi.xRes+1) * (src->mi.yRes+1));
	//	memcpy(im->data, surface, (right-left+1) * (bottom-top+1));
	im = XCreateImage(dpy, DefaultVisualOfScreen(v->scr), 8, ZPixmap, 0, surface, right-left, bottom-top, 8, 0);
	XInitImage(im);
	XPutImage(dpy, wnd, gc, im, 0,0, dstLeft, dstTop, right-left,bottom-top);
	XDestroyImage(im);
}
Пример #12
0
void
wrbitmap(Bitmap *b, int miny, int maxy, unsigned char *data)
{
    XImage *im;
    int w, h, inld, outld, l, offset, px;
    GC g;
    char *tdata;

    w = Dx(b->r);
    h = maxy - miny;
    inld = b->ldepth;
    outld = (b->ldepth == 0) ? 0 : screen.ldepth;
    px = 1<<(3-outld);  /* pixels per byte */
    /* set l to number of bytes of data per scan line */
    if(b->r.min.x >= 0)
        offset = b->r.min.x % px;
    else
        offset = px - b->r.min.x % px;
    l = (-b->r.min.x+px-1)/px;
    if(b->r.max.x >= 0)
        l += (b->r.max.x+px-1)/px;
    else
        l -= b->r.max.x/px;
    l *= h;

    tdata = (char *)malloc(l);
    if (tdata == (char *) 0)
            berror("wrbitmap malloc");
    if (inld == outld)
        memcpy((void*)tdata, (void*)data, l);
    else
        _ldconvert((char*)data, inld, tdata, outld, w, h);

    im = XCreateImage(_dpy, 0, 1 << outld, ZPixmap, 0, tdata, w, h, 8, 0);

    /* Botched interface to XCreateImage doesn't let you set these: */
    im->bitmap_bit_order = MSBFirst;
    im->byte_order = MSBFirst;

    g = _getfillgc(S, b, ~0);
    XSetBackground(_dpy, g, b->flag&DP1 ? 0 : _bgpixel);
    XPutImage(_dpy, (Drawable)b->id, g, im, offset, 0, 0, miny - b->r.min.y, w-offset, h);
    XDestroyImage(im);
}
Пример #13
0
BC_XImage::BC_XImage(BC_Bitmap *bitmap, int index,
	int w, int h, int color_model)
 : BC_BitmapImage(bitmap, index)
{
	Display *display = top_level->display;
	Visual *visual = top_level->vis;
	int default_depth = bitmap->get_default_depth();
	ximage = XCreateImage(display, visual, default_depth, 
		default_depth == 1 ? XYBitmap : ZPixmap, 
		0, (char*)data, w, h, 8, 0);
 	bytesPerLine = ximage->bytes_per_line;
	bitsPerPixel = ximage->bits_per_pixel;
	dataSize = h * bytesPerLine;
	data = new unsigned char[dataSize + 8];
	ximage->data = (char*) data;
	row_data = new unsigned char*[h];
	for( int i=0; i<h; ++i )
		row_data[i] = &data[i*bytesPerLine];
}
Пример #14
0
int wsGetDepthOnScreen(void)
{
    int depth;
    XImage *mXImage;
    Visual *visual;

    if ((depth = vo_find_depth_from_visuals(wsDisplay, wsScreen, &visual)) > 0) {
        mXImage = XCreateImage(wsDisplay, visual, depth, ZPixmap, 0, NULL,
                               1, 1, 32, 0);
        wsDepthOnScreen = mXImage->bits_per_pixel;
        wsRedMask       = mXImage->red_mask;
        wsGreenMask     = mXImage->green_mask;
        wsBlueMask      = mXImage->blue_mask;
#if HAVE_BIGENDIAN
        wsNonNativeOrder = mXImage->byte_order == LSBFirst;
#else
        wsNonNativeOrder = mXImage->byte_order == MSBFirst;
#endif
        XDestroyImage(mXImage);
    } else {
        int bpp, ibpp;
        XWindowAttributes attribs;

        mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap);
        bpp     = mXImage->bits_per_pixel;

        XGetWindowAttributes(wsDisplay, wsRootWin, &attribs);
        ibpp    = attribs.depth;
        mXImage = XGetImage(wsDisplay, wsRootWin, 0, 0, 1, 1, AllPlanes, ZPixmap);
        bpp     = mXImage->bits_per_pixel;

        if ((ibpp + 7) / 8 != (bpp + 7) / 8)
            ibpp = bpp;

        wsDepthOnScreen = ibpp;
        wsRedMask       = mXImage->red_mask;
        wsGreenMask     = mXImage->green_mask;
        wsBlueMask      = mXImage->blue_mask;
        XDestroyImage(mXImage);
    }

    return wsDepthOnScreen;
}
Пример #15
0
int BC_Capture::init_window(char *display_path)
{
    int bits_per_pixel;
    if(display_path && display_path[0] == 0) display_path = NULL;
    if((display = XOpenDisplay(display_path)) == NULL)
    {
        printf(_("cannot connect to X server.\n"));
        if(getenv("DISPLAY") == NULL)
            printf(_("'DISPLAY' environment variable not set.\n"));
        exit(-1);
        return 1;
    }

    screen = DefaultScreen(display);
    rootwin = RootWindow(display, screen);
    vis = DefaultVisual(display, screen);
    default_depth = DefaultDepth(display, screen);
    client_byte_order = (*(u_int32_t*)"a   ") & 0x00000001;
    server_byte_order = (XImageByteOrder(display) == MSBFirst) ? 0 : 1;
    char *data = 0;
    XImage *ximage;
    ximage = XCreateImage(display,
                          vis,
                          default_depth,
                          ZPixmap,
                          0,
                          data,
                          16,
                          16,
                          8,
                          0);
    bits_per_pixel = ximage->bits_per_pixel;
    XDestroyImage(ximage);
    bitmap_color_model = BC_WindowBase::evaluate_color_model(client_byte_order, server_byte_order, bits_per_pixel);

// test shared memory
// This doesn't ensure the X Server is on the local host
    if(use_shm && !XShmQueryExtension(display))
    {
        use_shm = 0;
    }
    return 0;
}
Пример #16
0
XImage *create_image_from_buffer (Display *dis, int screen, u_char *buf, int width, int height) {
	XImage *img = NULL;
	Visual *vis;
	double rRatio;
	double gRatio;
	double bRatio;
	int outIndex = 0;	
	int i;
	int numBufBytes = (3 * (width * height));
		
	vis = DefaultVisual (dis, screen);

	rRatio = vis->red_mask / 255.0;
	gRatio = vis->green_mask / 255.0;
	bRatio = vis->blue_mask / 255.0;
		
	size_t numNewBufBytes = (4 * (width * height));
	u_int32_t *newBuf = malloc (numNewBufBytes);
	
	for (i = 0; i < numBufBytes; ++i)
	{
		unsigned int r, g, b;
		r = (buf[i] * rRatio);
		++i;
		g = (buf[i] * gRatio);
		++i;
		b = (buf[i] * bRatio);
		r &= vis->red_mask;
		g &= vis->green_mask;
		b &= vis->blue_mask;
		newBuf[outIndex] = r | g | b;
		++outIndex;
	}		
		
	img = XCreateImage (dis,CopyFromParent, 24,ZPixmap, 0,(char *) newBuf,width, height,32, 0);
	//img = XCreateImage (dis,CopyFromParent, 24,ZPixmap, 0,(char *) buf,width, height,32, 0);
	XInitImage (img);
	img->byte_order = LSBFirst;
	img->bitmap_bit_order = MSBFirst;

	return img;
}		
Пример #17
0
static int
X11_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
                      Uint32 format, const void * pixels, int pitch)
{
    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
    SDL_Window *window = renderer->window;
    SDL_VideoDisplay *display = window->display;
    Uint32 screen_format = display->current_mode.format;
    XImage *image;
    void *image_pixels;
    int image_pitch;

    image_pitch = rect->w * SDL_BYTESPERPIXEL(screen_format);
    image_pixels = SDL_malloc(rect->h * image_pitch);
    if (!image_pixels) {
        SDL_OutOfMemory();
        return -1;
    }

    image = XCreateImage(data->display, data->visual,
                         data->depth, ZPixmap, 0, image_pixels,
                         rect->w, rect->h,
                         SDL_BYTESPERPIXEL(screen_format) * 8,
                         image_pitch);
    if (!image) {
        SDL_SetError("XCreateImage() failed");
        return -1;
    }

    SDL_ConvertPixels(rect->w, rect->h,
                      format, pixels, pitch,
                      screen_format, image->data, image->bytes_per_line);

    XPutImage(data->display, data->drawable, data->gc,
              image, 0, 0, rect->x, rect->y, rect->w, rect->h);

    image->data = NULL;
    XDestroyImage(image);

    SDL_free(image_pixels);
    return 0;
}
Пример #18
0
void mainloop(StarfishRef tex)
{
  char *buf;
  int bpl;
  int n_pmf;
  int i;
  XPixmapFormatValues * pmf;   
     
  pmf = XListPixmapFormats (display, &n_pmf);
  if (pmf)
  {
    for (i = 0; i < n_pmf; i++)
    {
      if (pmf[i].depth == depth)
      {
        int pad, pad_bytes;
        bpp = pmf[i].bits_per_pixel;
	bpl = width * bpp / 8;
	pad = pmf[i].scanline_pad;
	pad_bytes = pad / 8;
	/* make bpl a whole multiple of pad/8 */
	bpl = (bpl + pad_bytes - 1) & ~(pad_bytes - 1);
        buf=malloc(height*bpl);
        image=XCreateImage(display,DefaultVisual(display,screen), depth,
       	                   ZPixmap,0,buf,width,height,pad,bpl);
        if(!image)
        {
          puts("starfish: XCreateImage failed");
          return;
        }
	break;
      }
    }
    XFree ((char *) pmf);
  }    

  if (! XInitImage(image))
    return;
  fillimage(tex);
  XSetWindowBackgroundImage(display, rootwin, image);
  XDestroyImage(image);
}
Пример #19
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);
}
Пример #20
0
/*-
 * initialise_image
 *
 * Initialise the image for drawing to
 *
 * -      swirl is the swirl data
 */
static Bool
initialise_image(Display * dpy, swirlstruct *sp)
{
	unsigned int pad;
	int         bytes_per_line;
	int         image_depth = sp->rdepth;
	int         data_depth = image_depth;
	unsigned char *image;	/* image data */

	/* On SGIs at least, using an XImage of depth 24 on a Visual of depth 24
	 *  requires the XImage data to use 32 bits per pixel.  I don't understand
	 *  how one is supposed to determine this -- maybe XListPixmapFormats?
	 *  But on systems that don't work this way, allocating 32 bpp instead of
	 *  24 will be wasteful but non-fatal.  -- jwz, 16-May-97.
	 */
	if (data_depth >= 24 && data_depth < 32)
		data_depth = 32;

	/* get the bitmap pad */
	pad = BitmapPad(dpy);
	/* destroy the old image (destroy XImage and data) */
	if (sp->ximage != NULL)
		(void) XDestroyImage(sp->ximage);

	/* how many bytes per line? (bits rounded up to pad) */
	bytes_per_line = ((sp->width * data_depth + pad - 1) / pad) * (pad / 8);

	/* allocate space for the image */
	if ((image = (unsigned char *) calloc(bytes_per_line *
			sp->height, 1)) == NULL) {
		return False;
	}

	/* create an ximage with this */
	if ((sp->ximage = XCreateImage(dpy, sp->visual, image_depth, ZPixmap,
				     0, (char *) image, sp->width,
				     sp->height, pad, bytes_per_line)) == None) {
		free(image);
		return False;
	}
	return True;
}
Пример #21
0
void xf_sw_desktop_resize(rdpContext *context)
{
	rdpSettings *settings;
	xfContext *xfc = (xfContext *) context;
	settings = xfc->instance->settings;
	xf_lock_x11(xfc, TRUE);
	if(!xfc->fullscreen)
	{
		rdpGdi *gdi = context->gdi;
		gdi_resize(gdi, xfc->width, xfc->height);
		if(xfc->image)
		{
			xfc->image->data = NULL;
			XDestroyImage(xfc->image);
			xfc->image = XCreateImage(xfc->display, xfc->visual, xfc->depth, ZPixmap, 0,
									  (char *) gdi->primary_buffer, gdi->width, gdi->height, xfc->scanline_pad, 0);
		}
	}
	xf_unlock_x11(xfc, TRUE);
}
Пример #22
0
static void
alloc_ximage(struct xlib_displaytarget *xlib_dt,
             struct xlib_drawable *xmb,
             unsigned width, unsigned height)
{
   /* try allocating a shared memory image first */
   if (xlib_dt->shm) {
      alloc_shm_ximage(xlib_dt, xmb, width, height);
      if (xlib_dt->tempImage)
         return; /* success */
   }

   /* try regular (non-shared memory) image */
   xlib_dt->tempImage = XCreateImage(xlib_dt->display,
                                   xmb->visual,
                                   xmb->depth,
                                   ZPixmap, 0,
                                   NULL, width, height,
                                   8, 0);
}
Пример #23
0
static BOOL xf_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
{
	XImage* image;
	int width, height;
	xfContext* xfc = (xfContext*) context;
	BOOL ret = TRUE;
	width = bitmap->right - bitmap->left + 1;
	height = bitmap->bottom - bitmap->top + 1;
	xf_lock_x11(xfc, FALSE);
	XSetFunction(xfc->display, xfc->gc, GXcopy);
	image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
	                     ZPixmap, 0, (char*) bitmap->data, bitmap->width, bitmap->height,
	                     xfc->scanline_pad, 0);
	XPutImage(xfc->display, xfc->primary, xfc->gc,
	          image, 0, 0, bitmap->left, bitmap->top, width, height);
	XFree(image);
	ret = gdi_InvalidateRegion(xfc->hdc, bitmap->left, bitmap->top, width, height);
	xf_unlock_x11(xfc, FALSE);
	return TRUE;
}
Пример #24
0
void xf_desktop_resize(rdpUpdate* update)
{
	GDI* gdi;
	xfInfo* xfi;
	boolean same;
	rdpSettings* settings;

	xfi = GET_XFI(update);
	gdi = GET_GDI(update);
	settings = xfi->instance->settings;

	if (!xfi->fullscreen)
	{
		xfi->width = settings->width;
		xfi->height = settings->height;

		if (xfi->window)
			xf_ResizeDesktopWindow(xfi, xfi->window, settings->width, settings->height);

		if (xfi->primary)
		{
			same = (xfi->primary == xfi->drawing ? True : False);
			XFreePixmap(xfi->display, xfi->primary);
			xfi->primary = XCreatePixmap(xfi->display, DefaultRootWindow(xfi->display),
				xfi->width, xfi->height, xfi->depth);
			if (same)
				xfi->drawing = xfi->primary;
		}

		if (gdi)
			gdi_resize(gdi, xfi->width, xfi->height);

		if (gdi && xfi->image)
		{
			xfi->image->data = NULL;
			XDestroyImage(xfi->image);
			xfi->image = XCreateImage(xfi->display, xfi->visual, xfi->depth, ZPixmap, 0,
					(char*) gdi->primary_buffer, gdi->width, gdi->height, xfi->scanline_pad, 0);
		}
	}
}
Пример #25
0
void xf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
{
	BYTE* data;
	Pixmap pixmap;
	XImage* image;
	xfContext* xfc = (xfContext*) context;

	xf_lock_x11(xfc, FALSE);

	XSetFunction(xfc->display, xfc->gc, GXcopy);
	pixmap = XCreatePixmap(xfc->display, xfc->drawable, bitmap->width, bitmap->height, xfc->depth);

	if (bitmap->data)
	{
		data = freerdp_image_convert(bitmap->data, NULL,
				bitmap->width, bitmap->height, context->settings->ColorDepth, xfc->bpp, xfc->clrconv);

		if (bitmap->ephemeral != TRUE)
		{
			image = XCreateImage(xfc->display, xfc->visual, xfc->depth,
				ZPixmap, 0, (char*) data, bitmap->width, bitmap->height, xfc->scanline_pad, 0);

			XPutImage(xfc->display, pixmap, xfc->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height);
			XFree(image);

			if (data != bitmap->data)
				_aligned_free(data);
		}
		else
		{
			if (data != bitmap->data)
				_aligned_free(bitmap->data);

			bitmap->data = data;
		}
	}

	((xfBitmap*) bitmap)->pixmap = pixmap;

	xf_unlock_x11(xfc, FALSE);
}
Пример #26
0
Pixmap xf_bitmap_new(xfInfo* xfi, int width, int height, int bpp, uint8* data)
{
	Pixmap bitmap;
	uint8* cdata;
	XImage* image;

	bitmap = XCreatePixmap(xfi->display, xfi->drawable, width, height, xfi->bpp);

	cdata = freerdp_image_convert(data, NULL, width, height, bpp, xfi->bpp, xfi->clrconv);

	image = XCreateImage(xfi->display, xfi->visual, xfi->depth,
			ZPixmap, 0, (char *) cdata, width, height, xfi->scanline_pad, 0);

	XPutImage(xfi->display, bitmap, xfi->gc, image, 0, 0, 0, 0, width, height);
	XFree(image);

	if (cdata != data)
		xfree(cdata);

	return bitmap;
}
int DisplayWindow(int width,int height, int positionX,int positionY){
  int ret =1;
  WindowProperties.width=width;
  WindowProperties.height=height;

  if ((WindowProperties.display = XOpenDisplay(NULL)) == NULL) ret = 0;
  else {  
    WindowProperties.screen = DefaultScreen(WindowProperties.display);
    WindowProperties.dplanes = DisplayPlanes(WindowProperties.display,WindowProperties.screen);   
    WindowProperties.visual = XDefaultVisual(WindowProperties.display,WindowProperties.screen);
    if (!(WindowProperties.window=XCreateSimpleWindow(WindowProperties.display,RootWindow(WindowProperties.display,WindowProperties.screen),positionX,positionY,width,height,1,BlackPixel(WindowProperties.display,WindowProperties.screen),WhitePixel(WindowProperties.display,WindowProperties.screen)))) ret = 0;
    else{
      XSelectInput(WindowProperties.display, WindowProperties.window, EventMask);
      WindowProperties.gc = XCreateGC(WindowProperties.display, WindowProperties.window, 0, &WindowProperties.values);
      XMapWindow(WindowProperties.display,WindowProperties.window);
      XSync(WindowProperties.display,False);
      WindowProperties.ximage = XCreateImage(WindowProperties.display,WindowProperties.visual,WindowProperties.dplanes,ZPixmap,0,malloc(width*height*sizeof(int)),width,height,8,0);
    }
    return ret;
  }
}
Пример #28
0
EGLBoolean eglSwapBuffers(EGLDisplay edisplay, EGLSurface egsurface) {
	 if (x11_enabled == 0) {
		return real_eglSwapBuffers(edisplay,egsurface);
	 }
	 unsigned int *buffer = (unsigned int *)malloc(height * width * 4);
         glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
	 static GC gc;
	 static int status =0;
	 static XImage *image =0;
         static Pixmap pixmap;
	 static XGCValues gcvalues;
	 if (status == 0 ) {	
	 	gc = XCreateGC(display, window,0,&gcvalues);
		image = XGetImage(display, window, 0, 0, width, height, AllPlanes, ZPixmap);
		status = 1;
	 }
	 XImage *img = XCreateImage(display,CopyFromParent,depth,ZPixmap,0,buffer,width, height, 32, 0);
	 XPutImage(display, window, gc, img, 0, 0, 0, 0, width, height);
	 free(buffer);
	 return EGL_TRUE;
}
Пример #29
0
static void
shadow_setup_part (Wm      *w, 
		   XImage **ximage, 
		   Picture *pic, 
		   Pixmap  *pxm,
		   int      width,
		   int      height)
{

   *ximage = XCreateImage (w->dpy, DefaultVisual(w->dpy,DefaultScreen(w->dpy)),
			   8, ZPixmap, 0, 0,
			   width, height, 8, width * sizeof (unsigned char));

   (*ximage)->data = malloc (width * height * sizeof (unsigned char)); 

   *pxm    = XCreatePixmap (w->dpy, w->root, width, height, 8); 
   *pic    = XRenderCreatePicture (w->dpy, *pxm,
				   XRenderFindStandardFormat (w->dpy, 
							      PictStandardA8),
				   0, 0);
}
Пример #30
0
void rf_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
{
#ifdef RF_BITMAP
	uint8* data;
	Pixmap pixmap;
	XImage* image;
	rfContext* rfi = (rfContext*) context;

	XSetFunction(rfi->display, rfi->gc, GXcopy);
	pixmap = XCreatePixmap(rfi->display, rfi->drawable, bitmap->width, bitmap->height, rfi->depth);

	if (bitmap->data != NULL)
	{
		data = freerdp_image_convert(bitmap->data, NULL,
				bitmap->width, bitmap->height, rfi->srcBpp, rfi->bpp, rfi->clrconv);

		if (bitmap->ephemeral != true)
		{
			image = XCreateImage(rfi->display, rfi->visual, rfi->depth,
				ZPixmap, 0, (char*) data, bitmap->width, bitmap->height, rfi->scanline_pad, 0);

			XPutImage(rfi->display, pixmap, rfi->gc, image, 0, 0, 0, 0, bitmap->width, bitmap->height);
			XFree(image);

			if (data != bitmap->data)
				xfree(data);
		}
		else
		{
			if (data != bitmap->data)
				xfree(bitmap->data);

			bitmap->data = data;
		}
	}

	((rfBitmap*) bitmap)->pixmap = pixmap;
#endif
}