void XWindow::PutFrame (uint8_t* frame, uint16_t width, uint16_t height) { if (!_XImage) return; if (width != _imageWidth || height != _imageHeight) { PTRACE (1, "X11\tDynamic switching of resolution not supported\n"); return; } XLockDisplay (_display); if ((_state.curWidth != _XImage->width) || (_state.curHeight!=_XImage->height)) CreateXImage(_state.curWidth, _state.curHeight); _colorConverter->Convert((BYTE*)frame, (BYTE*)_frameBuffer.get ()); pixops_scale ((guchar*) _XImage->data, 0,0, _state.curWidth, _state.curHeight, _state.curWidth * _planes, //dest_rowstride _planes, //dest_channels, FALSE, //dest_has_alpha, (const guchar*) _frameBuffer.get (), width, height, width * _planes, //src_rowstride _planes, //src_channels, FALSE, //src_has_alpha, (double) _state.curWidth / width, (double) _state.curHeight / height, (PixopsInterpType) _scalingAlgorithm); _XImage->data += _outOffset; #ifdef HAVE_SHM if (_useShm) { XShmPutImage(_display, _XWindow, _gc, _XImage, 0, 0, _state.curX, _state.curY, _state.curWidth, _state.curHeight, false); } else #endif { XPutImage(_display, _XWindow, _gc, _XImage, 0, 0, _state.curX, _state.curY, _state.curWidth,_state.curHeight); } _XImage->data -= _outOffset; XUnlockDisplay (_display); }
void JXImage::ConvertToImage() const { if (itsImage == NULL) { assert( itsPixmap != None ); JXImage* me = const_cast<JXImage*>(this); me->itsImage = CreateXImage(); XFreePixmap(*itsDisplay, itsPixmap); me->itsPixmap = None; } }
int XWindow::Init (Display* dp, Window rootWindow, GC gc, int x, int y, int windowWidth, int windowHeight, int imageWidth, int imageHeight) { _display = dp; _rootWindow = rootWindow; _imageWidth = imageWidth; _imageHeight = imageHeight; PTRACE(4, "X11\tInitiasing new X11 window with " << windowWidth << "x" << windowHeight << " at " << x << "," << y); XLockDisplay (_display); #if PTRACING DumpVisuals(); #endif if (!CreateAtomsAndWindow(gc, x, y, windowWidth, windowHeight)) { XUnlockDisplay(_display); return 0; } CreateXImage(windowWidth, windowHeight); _isInitialized = true; XUnlockDisplay (_display); // check if that format is supported struct xFormatsentry* xFormat = xFormats; while (xFormat->name) { if (xFormat->depth == _XImage->bits_per_pixel && xFormat->byte_order == _XImage->byte_order && xFormat->red_mask == _XImage->red_mask && xFormat->green_mask == _XImage->green_mask && xFormat->blue_mask == _XImage->blue_mask) break; xFormat++; } PTRACE(4, "X11\tXImage created with format: " << _XImage->bits_per_pixel <<" BPP, " << "Byte order: " << (_XImage->byte_order ? "MSBFirst" : "LSBFirst") << " Native: " << (BO_NATIVE ? "MSBFirst" : "LSBFirst")); PTRACE(4, std::hex << "X11\tMask: Red: 0x" << _XImage->red_mask << " Green: 0x" << _XImage->green_mask << " Blue: 0x" << _XImage->blue_mask << std::dec); if (!xFormat->name) { PTRACE(1, "X11\tX server image format not supported, please contact the developers"); return 0; } snprintf (_colorFormat, sizeof(_colorFormat), "%s", xFormat->name); _outOffset = 0; _planes = xFormat->planes; #ifdef WORDS_BIGENDIAN if (g_strcmp0 (xFormat->name, "BGRA") == 0) { snprintf (_colorFormat, sizeof(_colorFormat), "RGB32"); _outOffset = 1; _planes = 4; } if (g_strcmp0 (xFormat->name, "RGBA") == 0) { snprintf (_colorFormat, sizeof(_colorFormat), "BGR32"); _outOffset = 1; _planes = 4; } #else if (g_strcmp0 (xFormat->name, "ABGR") == 0) { snprintf (_colorFormat, sizeof(_colorFormat), "BGR32"); _outOffset = -1; _planes = 4; } if (g_strcmp0 (xFormat->name, "ARGB") == 0) { snprintf (_colorFormat, sizeof(_colorFormat), "RGB32"); _outOffset = -1; _planes = 4; } #endif PTRACE(4, "X11\tUsing color format: " << _colorFormat); PTRACE(4, "X11\tPlanes: " << _planes); PVideoFrameInfo srcFrameInfo, dstFrameInfo; srcFrameInfo.SetFrameSize(_imageWidth,_imageHeight); dstFrameInfo.SetFrameSize(_imageWidth,_imageHeight); dstFrameInfo.SetColourFormat(_colorFormat); _colorConverter = PColourConverter::Create(srcFrameInfo, dstFrameInfo); if (!_colorConverter) return 0; _frameBuffer = boost::shared_ptr<void> (malloc (_imageWidth * _imageHeight * _planes), free); // detect the window manager type _wmType = GetWMType (); CalculateSize (windowWidth, windowHeight, true); return 1; }