static void* draw_framebuffer_data(GtkWidget *widget) { char *pixels; struct fb_fix_screeninfo fix; struct fb_var_screeninfo var; get_screen_info(&var, &fix); gtk_widget_set_size_request(widget, var.xres, var.yres); pixels = mmap(NULL, fix.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb0, 0); switch (var.bits_per_pixel) { case 24: gdk_draw_rgb_image(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], var.xoffset, var.yoffset, var.xres, var.yres, GDK_RGB_DITHER_NONE, pixels, fix.line_length); case 32: gdk_draw_rgb_32_image(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], var.xoffset, var.yoffset, var.xres, var.yres, GDK_RGB_DITHER_NONE, pixels, fix.line_length); break; } munmap(pixels, fix.smem_len); }
/*! Display a selection of the color image \e I in RGBa format (32bits). \warning Display has to be initialized. \warning Suppress the overlay drawing in the region of interest. \param I : Image to display. \param iP : Top left corner of the region of interest \param w : Width of the region of interest \param h : Height of the region of interest \sa init(), closeDisplay() */ void vpDisplayGTK::displayImageROI ( const vpImage<vpRGBa> &I,const vpImagePoint &iP, const unsigned int w, const unsigned int h ) { if (displayHasBeenInitialized) { vpImage<vpRGBa> Itemp; vpImageTools::crop(I,(unsigned int)iP.get_i(), (unsigned int)iP.get_j(), h, w, Itemp); /* Copie de l'image dans le pixmap fond */ gdk_draw_rgb_32_image(background, gc, (gint)iP.get_u(), (gint)iP.get_v(), (gint)w, (gint)h, GDK_RGB_DITHER_NONE, (unsigned char *)Itemp.bitmap, (gint)(4*w)); /* Permet de fermer la fenetre si besoin (cas des sequences d'images) */ //while (g_main_iteration(FALSE)); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //flushDisplay() ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
static void expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data) { GdkPixbuf *pixbuf; pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf"); if (gdk_pixbuf_get_has_alpha (pixbuf)) { gdk_draw_rgb_32_image (drawing_area->window, drawing_area->style->black_gc, event->area.x, event->area.y, event->area.width, event->area.height, GDK_RGB_DITHER_MAX, gdk_pixbuf_get_pixels (pixbuf) + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf)) + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)), gdk_pixbuf_get_rowstride (pixbuf)); } else { gdk_draw_rgb_image (drawing_area->window, drawing_area->style->white_gc, event->area.x, event->area.y, event->area.width, event->area.height, GDK_RGB_DITHER_NORMAL, gdk_pixbuf_get_pixels (pixbuf) + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf)) + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)), gdk_pixbuf_get_rowstride (pixbuf)); } }
Py::Object agg_to_gtk_drawable(const Py::Tuple &args) { args.verify_length(2); PyGObject *py_drawable = (PyGObject *)(args[0].ptr()); RendererAgg* aggRenderer = static_cast<RendererAgg*>(args[1].ptr()); GdkDrawable *drawable = GDK_DRAWABLE(py_drawable->obj); GdkGC* gc = gdk_gc_new(drawable); unsigned int width = aggRenderer->get_width(); unsigned int height = aggRenderer->get_height(); gdk_draw_rgb_32_image(drawable, gc, 0, 0, width, height, GDK_RGB_DITHER_NORMAL, aggRenderer->pixBuffer, width*4); return Py::Object(); }
/*! Display the color image \e I in RGBa format (32bits). \warning Display has to be initialized. \warning Suppress the overlay drawing. \param I : Image to display. \sa init(), closeDisplay() */ void vpDisplayGTK::displayImage(const vpImage<vpRGBa> &I) { if (displayHasBeenInitialized) { /* Copie de l'image dans le pixmap fond */ gdk_draw_rgb_32_image(background, gc, 0, 0, (gint)width, (gint)height, GDK_RGB_DITHER_NONE, (unsigned char *)I.bitmap, (gint)(4*width)); /* Permet de fermer la fenetre si besoin (cas des sequences d'images) */ //while (g_main_iteration(FALSE)); /* Le pixmap background devient le fond de la zone de dessin */ gdk_window_set_back_pixmap(widget->window, background, FALSE); /* Affichage */ //gdk_window_clear(GTK_WINDOW(widget)); //flushDisplay() ; } else { vpERROR_TRACE("GTK not initialized " ) ; throw(vpDisplayException(vpDisplayException::notInitializedError, "GTK not initialized")) ; } }
/** * gdk_pixbuf_render_pixmap_and_mask_for_colormap: * @pixbuf: A pixbuf. * @colormap: A #GdkColormap * @pixmap_return: Location to store a pointer to the created pixmap, * or %NULL if the pixmap is not needed. * @mask_return: Location to store a pointer to the created mask, * or %NULL if the mask is not needed. * @alpha_threshold: Threshold value for opacity values. * * Creates a pixmap and a mask bitmap which are returned in the @pixmap_return * and @mask_return arguments, respectively, and renders a pixbuf and its * corresponding tresholded alpha mask to them. This is merely a convenience * function; applications that need to render pixbufs with dither offsets or to * given drawables should use gdk_draw_pixbuf(), and gdk_pixbuf_render_threshold_alpha(). * * The pixmap that is created uses the #GdkColormap specified by @colormap. * This colormap must match the colormap of the window where the pixmap * will eventually be used or an error will result. * * If the pixbuf does not have an alpha channel, then *@mask_return will be set * to %NULL. **/ void gdk_pixbuf_render_pixmap_and_mask_for_colormap (GdkPixbuf *pixbuf, GdkColormap *colormap, GdkPixmap **pixmap_return, GdkBitmap **mask_return, int alpha_threshold) { GdkScreen *screen; g_return_if_fail (GDK_IS_PIXBUF (pixbuf)); g_return_if_fail (GDK_IS_COLORMAP (colormap)); screen = gdk_colormap_get_screen (colormap); if (pixmap_return) { GdkGC *gc; *pixmap_return = gdk_pixmap_new (gdk_screen_get_root_window (screen), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), gdk_colormap_get_visual (colormap)->depth); gdk_drawable_set_colormap (GDK_DRAWABLE (*pixmap_return), colormap); gc = _gdk_drawable_get_scratch_gc (*pixmap_return, FALSE); /* If the pixbuf has an alpha channel, using gdk_pixbuf_draw would give * random pixel values in the area that are within the mask, but semi- * transparent. So we treat the pixbuf like a pixbuf without alpha channel; * see bug #487865. */ if (gdk_pixbuf_get_has_alpha (pixbuf)) gdk_draw_rgb_32_image (*pixmap_return, gc, 0, 0, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GDK_RGB_DITHER_NORMAL, gdk_pixbuf_get_pixels (pixbuf), gdk_pixbuf_get_rowstride (pixbuf)); else gdk_draw_pixbuf (*pixmap_return, gc, pixbuf, 0, 0, 0, 0, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), GDK_RGB_DITHER_NORMAL, 0, 0); } if (mask_return) { if (gdk_pixbuf_get_has_alpha (pixbuf)) { *mask_return = gdk_pixmap_new (gdk_screen_get_root_window (screen), gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), 1); gdk_pixbuf_render_threshold_alpha (pixbuf, *mask_return, 0, 0, 0, 0, gdk_pixbuf_get_width (pixbuf), gdk_pixbuf_get_height (pixbuf), alpha_threshold); } else *mask_return = NULL; } }
/* update_window: * Copy the backing image onto the window. */ void update_window() { if (backing_image) { GdkGC *gc; gc = gdk_gc_new(drawable); gdk_draw_rgb_32_image(drawable, gc, 0, 0, width, height, GDK_RGB_DITHER_NORMAL, (guchar*)backing_image->flat, sizeof(pel) * width); g_object_unref(gc); } }
static gboolean draw_frame(GtkWidget* widget, GdkEventExpose* event) { gdk_draw_rgb_32_image(main_canvas->window, main_canvas->style->fg_gc[GTK_WIDGET_STATE(main_canvas)], 0, 0, 240, 320, GDK_RGB_DITHER_NONE, frame_buffer, 240*4); return FALSE; }
void SetFrameBuffer(rect* inBoundary) { int x, y; int sx, sy; int ex, ey; // revised as pixel position concept by Joshua // initialization sx = 0; sy = 0; ex = DEVICE_WIDTH -1; ey = DEVICE_HEIGHT-1; if ( inBoundary ) { //printf(" partial: top:%d,left:%d,right:%d,bottom:%d",inBoundary->top,inBoundary->left,inBoundary->right,inBoundary->bottom); if ( inBoundary->left > sx ) sx = inBoundary->left; if ( inBoundary->right < ex ) ex = inBoundary->right; if ( inBoundary->top > sy ) sy = inBoundary->top; if ( inBoundary->bottom < ey ) ey = inBoundary->bottom; } //printf("\n"); gdk_threads_enter(); for( y = sy ; y <= ey ; y++ ) { for ( x = sx ; x <= ex ; x++ ) { int r, g, b, data; data = lcd_bmp_buffer[y][x]; r = (data&0xF800)>>8; g = (data&0x07E0)>>3; b = (data&0x001F)<<3; frame_buffer[y][x][0] = r; frame_buffer[y][x][1] = g; frame_buffer[y][x][2] = b; } } gdk_draw_rgb_32_image(main_canvas->window, main_canvas->style->fg_gc[GTK_WIDGET_STATE(main_canvas)], 0, 0, 240, 320, GDK_RGB_DITHER_NONE, frame_buffer, 240*4); gdk_threads_leave(); }
static void gtkdisplay_area(int x, int y, int width, int height) { #if !GTK_CHECK_VERSION( 3, 0, 0 ) gdk_draw_rgb_32_image( gtkui_drawing_area->window, gtkui_drawing_area->style->fg_gc[GTK_STATE_NORMAL], x, y, width, height, GDK_RGB_DITHER_NONE, &scaled_image[ y * scaled_pitch + 4 * x ], scaled_pitch ); #else display_updated = 1; gtk_widget_queue_draw_area( gtkui_drawing_area, x, y, width, height ); #endif /* #if !GTK_CHECK_VERSION( 3, 0, 0 ) */ }
void GUI_RGBDisplay(uint8_t * dis, uint32_t w, uint32_t h, void *widg) { GtkWidget *widget; widget = (GtkWidget *)widg; //return; gdk_draw_rgb_32_image(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, // X 0, // y w, //width h, //h*2, // heigth GDK_RGB_DITHER_NONE, //GDK_RGB_DITHER_MAX, // dithering (guchar *) dis, // buffer w * 4); }
/** \brief Display to widget in RGB32 */ void UI_rgbDraw(void *widg,uint32_t w, uint32_t h,uint8_t *ptr) { GtkWidget *widget; widget = (GtkWidget *)widg; if(lastW>w || lastH>h) { // This makes a lot of noise if you use the Crop filter... perhaps it should // be output only once? Or maybe there is a real bug - I'm not sure. [Chris MacGregor] // printf("[GTK] Warning window bigger than display %u x %u vs %u x %u\n",w,h,lastW,lastH); } gdk_draw_rgb_32_image(widget->window, widget->style->fg_gc[GTK_STATE_NORMAL], 0, // X 0, // y w, //width h, //h*2, // heigth GDK_RGB_DITHER_NONE, //GDK_RGB_DITHER_MAX, // dithering (guchar *) ptr, // buffer w * 4); }
void VideoRenderer::RedrawRenderArea() { gdk_threads_enter(); #ifdef GOCAST_PLUGIN pthread_mutex_lock(&pluginWinMutex); if(NULL != pThePluginWindow) { FB::PluginWindowX11* pThePluginWindowX11 = reinterpret_cast<FB::PluginWindowX11*>(pThePluginWindow); m_pRenderArea = pThePluginWindowX11->getWidget(); #endif gdk_draw_rgb_32_image( m_pRenderArea->window, m_pRenderArea->style->fg_gc[GTK_STATE_NORMAL], #ifdef GOCAST_PLUGIN (m_rendererIndex=(m_pNext?(m_pNext->RendererIndex()+1):m_rendererIndex))*m_width, #else 0, #endif 0, m_width, m_height, GDK_RGB_DITHER_MAX, m_spFrmBuf.get(), m_width*4 ); #ifdef GOCAST_PLUGIN } pthread_mutex_unlock(&pluginWinMutex); #endif gdk_threads_leave(); }
static PyObject *Py_agg_to_gtk_drawable(PyObject *self, PyObject *args, PyObject *kwds) { typedef agg::pixfmt_rgba32_plain pixfmt; typedef agg::renderer_base<pixfmt> renderer_base; PyGObject *py_drawable; numpy::array_view<agg::int8u, 3> buffer; agg::rect_d rect; // args are gc, renderer, bbox where bbox is a transforms BBox // (possibly None). If bbox is None, blit the entire agg buffer // to gtk. If bbox is not None, blit only the region defined by // the bbox if (!PyArg_ParseTuple(args, "OO&O&:agg_to_gtk_drawable", &py_drawable, &buffer.converter, &buffer, &convert_rect, &rect)) { return NULL; } if (buffer.dim(2) != 4) { PyErr_SetString(PyExc_ValueError, "Invalid image buffer. Must be NxMx4."); return NULL; } GdkDrawable *drawable = GDK_DRAWABLE(py_drawable->obj); GdkGC *gc = gdk_gc_new(drawable); int srcstride = buffer.dim(1) * 4; int srcwidth = buffer.dim(1); int srcheight = buffer.dim(0); // these three will be overridden below int destx = 0; int desty = 0; int destwidth = 1; int destheight = 1; int deststride = 1; std::vector<agg::int8u> destbuffer; agg::int8u *destbufferptr; if (rect.x1 == 0.0 && rect.x2 == 0.0 && rect.y1 == 0.0 && rect.y2 == 0.0) { // bbox is None; copy the entire image destbufferptr = (agg::int8u *)buffer.data(); destwidth = srcwidth; destheight = srcheight; deststride = srcstride; } else { destx = (int)rect.x1; desty = srcheight - (int)rect.y2; destwidth = (int)(rect.x2 - rect.x1); destheight = (int)(rect.y2 - rect.y1); deststride = destwidth * 4; destbuffer.reserve(destheight * deststride); destbufferptr = &destbuffer[0]; agg::rendering_buffer destrbuf; destrbuf.attach(destbufferptr, destwidth, destheight, deststride); pixfmt destpf(destrbuf); renderer_base destrb(destpf); agg::rendering_buffer srcrbuf; srcrbuf.attach((agg::int8u *)buffer.data(), buffer.dim(1), buffer.dim(0), buffer.dim(1) * 4); agg::rect_base<int> region(destx, desty, (int)rect.x2, srcheight - (int)rect.y1); destrb.copy_from(srcrbuf, ®ion, -destx, -desty); } gdk_draw_rgb_32_image(drawable, gc, destx, desty, destwidth, destheight, GDK_RGB_DITHER_NORMAL, destbufferptr, deststride); gdk_gc_destroy(gc); Py_RETURN_NONE; }
Py::Object agg_to_gtk_drawable(const Py::Tuple &args) { // args are gc, renderer, bbox where bbox is a transforms BBox // (possibly None). If bbox is None, blit the entire agg buffer // to gtk. If bbox is not None, blit only the region defined by // the bbox args.verify_length(3); PyGObject *py_drawable = (PyGObject *)(args[0].ptr()); RendererAgg* aggRenderer = static_cast<RendererAgg*>(args[1].ptr()); GdkDrawable *drawable = GDK_DRAWABLE(py_drawable->obj); GdkGC* gc = gdk_gc_new(drawable); int srcstride = aggRenderer->get_width() * 4; int srcwidth = (int)aggRenderer->get_width(); int srcheight = (int)aggRenderer->get_height(); // these three will be overridden below int destx = 0; int desty = 0; int destwidth = 1; int destheight = 1; int deststride = 1; bool needfree = false; agg::int8u *destbuffer = NULL; if (args[2].ptr() == Py_None) { //bbox is None; copy the entire image destbuffer = aggRenderer->pixBuffer; destwidth = srcwidth; destheight = srcheight; deststride = srcstride; } else { //bbox is not None; copy the image in the bbox PyObject* clipbox = args[2].ptr(); double l, b, r, t; if (!py_convert_bbox(clipbox, l, b, r, t)) { throw Py::TypeError ("Argument 3 to agg_to_gtk_drawable must be a Bbox object."); } destx = (int)l; desty = srcheight - (int)t; destwidth = (int)(r - l); destheight = (int)(t - b); deststride = destwidth * 4; needfree = true; destbuffer = new agg::int8u[deststride*destheight]; if (destbuffer == NULL) { throw Py::MemoryError("_gtkagg could not allocate memory for destbuffer"); } agg::rendering_buffer destrbuf; destrbuf.attach(destbuffer, destwidth, destheight, deststride); pixfmt destpf(destrbuf); renderer_base destrb(destpf); //destrb.clear(agg::rgba(1, 1, 1, 0)); agg::rect_base<int> region(destx, desty, (int)r, srcheight - (int)b); destrb.copy_from(aggRenderer->renderingBuffer, ®ion, -destx, -desty); } /*std::cout << desty << " " << destheight << " " << srcheight << std::endl;*/ //gdk_rgb_init(); gdk_draw_rgb_32_image(drawable, gc, destx, desty, destwidth, destheight, GDK_RGB_DITHER_NORMAL, destbuffer, deststride); if (needfree) { delete [] destbuffer; } return Py::Object(); }