void background_info_set_background_by_drawable(BackgroundInfo* info, guint32 drawable) { gint x, y; guint border,depth, width=0, height=0; Display* dpy = gdk_x11_get_default_xdisplay(); gdk_error_trap_push(); //TODO: //we shoul use xatom_name window to set events instead of root window //because the monitors changed signal will came before root window rect changed //so the Xroot window rect maybe keep old rect in update_bg function and in Display DBus signal "PrimaryChanged" Window root; XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border, &depth); g_debug("[%s] width: %d, height: %d, x: %d y: %d\n", __func__, width, height, x, y); if (gdk_error_trap_pop()) { g_warning("[%s] invalid drawable %d \n", __func__, drawable); return; } g_mutex_lock(&info->m); if (info->bg != NULL) { cairo_surface_destroy(info->bg); info->bg = NULL; } info->bg = cairo_xlib_surface_create(dpy, drawable, gdk_x11_visual_get_xvisual(gdk_visual_get_system()), width, height); g_mutex_unlock(&info->m); if (gtk_widget_get_realized(info->container)) { gdk_window_invalidate_rect(gtk_widget_get_window(info->container), NULL, TRUE); } }
GdkColormap* gdk_colormap_new (GdkVisual *visual, gboolean private_cmap) { GdkColormap *colormap; gint i; g_return_val_if_fail (visual != NULL, NULL); colormap = g_object_new (gdk_colormap_get_type (), NULL); colormap->visual = visual; colormap->size = visual->colormap_size; switch (visual->type) { case GDK_VISUAL_PSEUDO_COLOR: { GdkColormapPrivateDirectFB *private; DFBPaletteDescription dsc; colormap->colors = g_new0 (GdkColor, colormap->size); private = g_new0 (GdkColormapPrivateDirectFB, 1); private->info = g_new0 (GdkColorInfo, colormap->size); if (visual == gdk_visual_get_system()) { /* save the first (transparent) palette entry */ private->info[0].ref_count++; }
void image_to_pixmap(image *img, GdkPixmap *pm, int w, int h) { int realw, realh; int need_free; imlib_context_set_image(img->image); realw = imlib_image_get_width(); realh = imlib_image_get_height(); if (w != realw || h != realh) { Imlib_Image newimg; newimg = imlib_create_cropped_scaled_image(0, 0, realw, realh, w, h); imlib_context_set_image(newimg); need_free = TRUE; } else need_free = FALSE; imlib_context_set_display(GDK_WINDOW_XDISPLAY(pm)); imlib_context_set_visual(GDK_VISUAL_XVISUAL(gdk_visual_get_system())); imlib_context_set_colormap (GDK_COLORMAP_XCOLORMAP(gdk_colormap_get_system())); imlib_context_set_drawable(GDK_WINDOW_XWINDOW(pm)); imlib_context_set_blend(1); imlib_render_image_on_drawable(0, 0); if (need_free) imlib_free_image(); }
static GdkColormap * gdk_gl_config_setup_colormap (GdkScreen *screen, PIXELFORMATDESCRIPTOR *pfd, gboolean is_rgba) { GDK_GL_NOTE_FUNC_PRIVATE (); if (is_rgba) { /* * For RGBA mode. */ /* Default colormap. */ GDK_GL_NOTE (MISC, g_message (" -- Colormap: system default")); return g_object_ref (G_OBJECT (gdk_colormap_get_system ())); } else { /* * For color index mode. */ /* New private colormap. */ GDK_GL_NOTE (MISC, g_message (" -- Colormap: new allocated writable")); return gdk_colormap_new (gdk_visual_get_system (), TRUE); } /* not reached */ return NULL; }
static GdkPixmap * scale_pixmap (GdkWindow *window, GdkPixmap *pixmap, gdouble scale_x, gdouble scale_y) { GdkGC *gc; GdkColormap *colormap; GdkColorContext *cc; GdkVisual *visual; GdkImage *image; GdkPixmap *new_pixmap; gint x, y, width, height, new_width, new_height; if(!pixmap) return NULL; if(!window) return NULL; gc = gdk_gc_new(pixmap); colormap = gdk_colormap_get_system (); visual = gdk_visual_get_system (); cc = gdk_color_context_new(visual, colormap); gdk_window_get_size(pixmap, &width, &height); if(scale_x == 1.0 && scale_y == 1.0){ new_pixmap = gdk_pixmap_new(window, width, height, -1); gdk_draw_pixmap(new_pixmap, gc, pixmap, 0, 0, 0, 0, width, height); return new_pixmap; } new_width = roundint(width * scale_x); new_height = roundint(height * scale_y); new_pixmap = gdk_pixmap_new(window, new_width, new_height, -1); image = gdk_image_get(pixmap, 0, 0, width, height); for(x = 0; x < new_width; x++){ for(y = 0; y < new_height; y++){ GdkColor color; gint px, py; px = MIN(roundint(x / scale_x), width - 1); py = MIN(roundint(y / scale_y), height - 1); color.pixel = gdk_image_get_pixel(image, px, py); gdk_color_context_query_color(cc, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_point(new_pixmap, gc, x, y); } } gdk_image_destroy(image); gdk_color_context_free(cc); return new_pixmap; }
bool wxApp::OnInitGui() { if ( !wxAppBase::OnInitGui() ) return false; #ifndef __WXGTK3__ // if this is a wxGLApp (derived from wxApp), and we've already // chosen a specific visual, then derive the GdkVisual from that if ( GetXVisualInfo() ) { GdkVisual* vis = gtk_widget_get_default_visual(); GdkColormap *colormap = gdk_colormap_new( vis, FALSE ); gtk_widget_set_default_colormap( colormap ); } else { // On some machines, the default visual is just 256 colours, so // we make sure we get the best. This can sometimes be wasteful. if (m_useBestVisual) { if (m_forceTrueColour) { GdkVisual* visual = gdk_visual_get_best_with_both( 24, GDK_VISUAL_TRUE_COLOR ); if (!visual) { wxLogError(wxT("Unable to initialize TrueColor visual.")); return false; } GdkColormap *colormap = gdk_colormap_new( visual, FALSE ); gtk_widget_set_default_colormap( colormap ); } else { if (gdk_visual_get_best() != gdk_visual_get_system()) { GdkVisual* visual = gdk_visual_get_best(); GdkColormap *colormap = gdk_colormap_new( visual, FALSE ); gtk_widget_set_default_colormap( colormap ); } } } } #endif #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 if ( !GetHildonProgram() ) { wxLogError(_("Unable to initialize Hildon program")); return false; } #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 return true; }
int main (int argc, char *argv[]) { int i; GdkImage *image; rfbClientLog = GtkDefaultLog; rfbClientErr = GtkErrorLog; gtk_init (&argc, &argv); /* create a dummy image just to make use of its properties */ image = gdk_image_new (GDK_IMAGE_FASTEST, gdk_visual_get_system(), 200, 100); cl = rfbGetClient (image->depth / 3, 3, image->bpp); cl->format.redShift = image->visual->red_shift; cl->format.greenShift = image->visual->green_shift; cl->format.blueShift = image->visual->blue_shift; cl->format.redMax = (1 << image->visual->red_prec) - 1; cl->format.greenMax = (1 << image->visual->green_prec) - 1; cl->format.blueMax = (1 << image->visual->blue_prec) - 1; g_object_unref (image); cl->MallocFrameBuffer = resize; cl->canHandleNewFBSize = TRUE; cl->GotFrameBufferUpdate = update; cl->GotXCutText = got_cut_text; cl->HandleKeyboardLedState = kbd_leds; cl->HandleTextChat = text_chat; cl->GetPassword = get_password; cl->GetCredential = get_credential; show_connect_window (argc, argv); if (!rfbInitClient (cl, &argc, argv)) return 1; while (1) { while (gtk_events_pending ()) gtk_main_iteration (); i = WaitForMessage (cl, 500); if (i < 0) return 0; if (i && framebuffer_allocated == TRUE) if (!HandleRFBServerMessage(cl)) return 0; } gtk_main (); return 0; }
/** * Function that calculates a fractal and shows it in a GTK+ pixbuf * * @param[in] _oZmid Center coordinate for the Mandelbrot fractal * @param[in] _oZxy Size of the Mandelbrot window * @param[in] _rZoomFactor Zoom factor ( Deduces the size of the window) * @return Returns true success, otherwise false */ bool bCalc_Fractal( void ) { // Create fractal int iSizeX=800; int iSizeY=800; Fractal *poFractal= new Cmandelbrot( iSizeX, iSizeY); if(!poFractal) return false; bool bRet=poFractal->bCalc(oZmid,oZxy,rScale, 255); if (sFractal.pGDKimage2 == NULL ) { sFractal.pGDKvisual2 = gdk_visual_get_system(); sFractal.pGDKimage2= gdk_image_new( GDK_IMAGE_NORMAL, sFractal.pGDKvisual2, poFractal->iSizeX,poFractal->iSizeY); } if (sFractal.pGDKimage2 == NULL ) { fprintf( stderr, "Not able to create gdkimage object\n"); return FALSE; } if(sFractal.pWindow2== NULL) { sFractal.pWindow2= gtk_window_new(GTK_WINDOW_TOPLEVEL); } if(sFractal.pImage2==NULL) { sFractal.pImage2= gtk_image_new_from_image( sFractal.pGDKimage2, NULL ); } else { gtk_image_set_from_image(GTK_IMAGE(sFractal.pImage2), sFractal.pGDKimage2, NULL ); } for (int i=0; i<poFractal->iSizeX; i++) { for (int j=0; j<poFractal->iSizeY; j++) { unsigned int uiColor = poFractal->uiGetPixBufColor(i,j); gdk_image_put_pixel( sFractal.pGDKimage2, i, j,(int) uiColor); //65535*rAbsSqr/rMax); } } if(poFractal) delete poFractal; return bRet; }
void *pl_fbdev_set_mode(int w, int h, int bpp) { if (w <= 0 || h <= 0) return pl_fbdev_buf; if (image) gdk_image_destroy(image); image = gdk_image_new( GDK_IMAGE_FASTEST, gdk_visual_get_system(), w, h ); pl_fbdev_buf = (void *) image->mem; gtk_image_set_from_image (GTK_IMAGE(drawing), image, NULL); gtk_window_resize (GTK_WINDOW (actor), w, h); hildon_animation_actor_set_scale (actor, (gdouble)D_WIDTH / (gdouble)w, (gdouble)D_HEIGHT / (gdouble)h ); return pl_fbdev_buf; }
static void gtk_plot_gdk_init (GtkPlotGdk *pc) { GdkWindowAttr attributes; gint attributes_mask; attributes.window_type = GDK_WINDOW_CHILD; attributes.title = NULL; attributes.wclass = GDK_INPUT_OUTPUT; attributes.visual = gdk_visual_get_system (); attributes.colormap = gdk_colormap_get_system (); attributes.event_mask = 0; attributes_mask = GDK_WA_VISUAL | GDK_WA_COLORMAP; pc->gc = NULL; pc->drawable = NULL; pc->ref_count = 0; pc->window = gdk_window_new (NULL, &attributes, attributes_mask); }
void creat_notebook(t_init *init, t_menu *menu, t_launch_infos *infos) { infos->notebook->notebook = gtk_notebook_new(); gtk_box_pack_start(GTK_BOX(init->vbox), infos->notebook->notebook, TRUE, TRUE, 0); infos->notebook->text_view = gtk_text_view_new(); infos->notebook->text_buffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(infos->notebook->text_view)); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(infos->notebook->text_view), GTK_WRAP_WORD); creat_editor(menu, infos); infos->notebook->tablabel = gtk_label_new("SCENE"); infos->notebook->image = gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), 800, 600); infos->notebook->scene = gtk_image_new_from_image(infos->notebook->image, NULL); gtk_notebook_append_page(GTK_NOTEBOOK(infos->notebook->notebook), infos->notebook->scene, infos->notebook->tablabel); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(infos->notebook->notebook), GTK_POS_TOP); gtk_notebook_set_scrollable(GTK_NOTEBOOK(infos->notebook->notebook), TRUE); }
GdkColormap* gdk_colormap_new (GdkVisual *visual, gboolean private_cmap) { GdkColormap *colormap; gint i; g_return_val_if_fail (visual != NULL, NULL); colormap = g_object_new (gdk_colormap_get_type (), NULL); colormap->visual = visual; colormap->size = visual->colormap_size; switch (visual->type) { case GDK_VISUAL_PSEUDO_COLOR: { IDirectFB *dfb = _gdk_display->directfb; IDirectFBPalette *palette; GdkColormapPrivateDirectFB *private; DFBPaletteDescription dsc; dsc.flags = DPDESC_SIZE; dsc.size = colormap->size; if (!dfb->CreatePalette (dfb, &dsc, &palette)) return NULL; colormap->colors = g_new0 (GdkColor, colormap->size); private = g_new0 (GdkColormapPrivateDirectFB, 1); private->info = g_new0 (GdkColorInfo, colormap->size); if (visual == gdk_visual_get_system()) { /* save the first (transparent) palette entry */ private->info[0].ref_count++; }
static void setup_font_sample(GtkWidget* darea, Antialiasing antialiasing, Hinting hinting) { const char* string1 = "abcfgop AO "; const char* string2 = "abcfgop"; XftColor black, white; XRenderColor rendcolor; Display* xdisplay = gdk_x11_get_default_xdisplay(); #if GTK_CHECK_VERSION (3, 0, 0) Colormap xcolormap = DefaultColormap(xdisplay, 0); #else GdkColormap* colormap = gdk_rgb_get_colormap(); Colormap xcolormap = GDK_COLORMAP_XCOLORMAP(colormap); #endif #if GTK_CHECK_VERSION (3, 0, 0) GdkVisual* visual = gdk_visual_get_system (); #else GdkVisual* visual = gdk_colormap_get_visual(colormap); #endif Visual* xvisual = GDK_VISUAL_XVISUAL(visual); FcPattern* pattern; XftFont* font1; XftFont* font2; XGlyphInfo extents1 = { 0 }; XGlyphInfo extents2 = { 0 }; #if !GTK_CHECK_VERSION (3, 0, 0) GdkPixmap* pixmap; #endif XftDraw* draw; GdkPixbuf* tmp_pixbuf; GdkPixbuf* pixbuf; int width, height; int ascent, descent; pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "Serif", FC_SLANT, FcTypeInteger, FC_SLANT_ROMAN, FC_SIZE, FcTypeDouble, 18., NULL); font1 = open_pattern (pattern, antialiasing, hinting); FcPatternDestroy (pattern); pattern = FcPatternBuild (NULL, FC_FAMILY, FcTypeString, "Serif", FC_SLANT, FcTypeInteger, FC_SLANT_ITALIC, FC_SIZE, FcTypeDouble, 20., NULL); font2 = open_pattern (pattern, antialiasing, hinting); FcPatternDestroy (pattern); ascent = 0; descent = 0; if (font1) { XftTextExtentsUtf8 (xdisplay, font1, (unsigned char*) string1, strlen (string1), &extents1); ascent = MAX (ascent, font1->ascent); descent = MAX (descent, font1->descent); } if (font2) { XftTextExtentsUtf8 (xdisplay, font2, (unsigned char*) string2, strlen (string2), &extents2); ascent = MAX (ascent, font2->ascent); descent = MAX (descent, font2->descent); } width = extents1.xOff + extents2.xOff + 4; height = ascent + descent + 2; #if !GTK_CHECK_VERSION (3, 0, 0) pixmap = gdk_pixmap_new (NULL, width, height, visual->depth); #endif #if GTK_CHECK_VERSION (3, 0, 0) draw = XftDrawCreate (xdisplay, GDK_WINDOW_XID (gdk_screen_get_root_window (gdk_screen_get_default ())), xvisual, xcolormap); #else draw = XftDrawCreate (xdisplay, GDK_DRAWABLE_XID (pixmap), xvisual, xcolormap); #endif rendcolor.red = 0; rendcolor.green = 0; rendcolor.blue = 0; rendcolor.alpha = 0xffff; XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &black); rendcolor.red = 0xffff; rendcolor.green = 0xffff; rendcolor.blue = 0xffff; rendcolor.alpha = 0xffff; XftColorAllocValue(xdisplay, xvisual, xcolormap, &rendcolor, &white); XftDrawRect(draw, &white, 0, 0, width, height); if (font1) { XftDrawStringUtf8(draw, &black, font1, 2, 2 + ascent, (unsigned char*) string1, strlen(string1)); } if (font2) { XftDrawStringUtf8(draw, &black, font2, 2 + extents1.xOff, 2 + ascent, (unsigned char*) string2, strlen(string2)); } XftDrawDestroy(draw); if (font1) { XftFontClose(xdisplay, font1); } if (font2) { XftFontClose(xdisplay, font2); } #if GTK_CHECK_VERSION (3, 0, 0) tmp_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE,8, width, height); #else tmp_pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, colormap, 0, 0, 0, 0, width, height); #endif pixbuf = gdk_pixbuf_scale_simple(tmp_pixbuf, 1 * width, 1 * height, GDK_INTERP_TILES); #if !GTK_CHECK_VERSION (3, 0, 0) g_object_unref(pixmap); #endif g_object_unref(tmp_pixbuf); g_object_set_data_full(G_OBJECT(darea), "sample-pixbuf", pixbuf, (GDestroyNotify) g_object_unref); #if GTK_CHECK_VERSION (3, 0, 0) gtk_widget_set_size_request (GTK_WIDGET(darea), width + 2, height + 2); g_signal_connect(darea, "draw", G_CALLBACK(sample_draw), NULL); #else g_signal_connect(darea, "size_request", G_CALLBACK(sample_size_request), NULL); g_signal_connect(darea, "expose_event", G_CALLBACK(sample_expose), NULL); #endif }
GdkImage *gdkimage_from_pikeimage(struct object *img, int fast, GdkImage *i) { GdkColormap *col=gdk_colormap_get_system(); GdkVisual *vis=gdk_visual_get_system(); struct image *img_data; INT_TYPE x,y; TIMER_INIT("Getting extents"); img_data=(struct image*)get_storage(img, image_program); /* 1a: create the actual image... */ x = img_data->xsize; y = img_data->ysize; if (x==0 || y==0) Pike_error("Size of image must be > 0x0\n"); if (i) { if ((i->width!=x) || (i->height!=y)) { gdk_image_destroy((void *)i); i=NULL; } } if (!i) { PFTIME("Create"); i=(void *)gdk_image_new(fast,vis,x,y); } if (!i) Pike_error("Failed to create gdkimage\n"); /* 1b: do the work.. */ if (vis->type==GDK_VISUAL_TRUE_COLOR || vis->type==GDK_VISUAL_STATIC_GRAY) /* no colormap.. */ { int pad=0; int native_byteorder; PFTIME("Convert"); if (vis->type==GDK_VISUAL_STATIC_GRAY) pgtk2_encode_grey(img_data,i->mem,i->bpp,i->bpl); else { if (i->bpl!=(i->bpp*x)) switch(i->bpl & 3) { case 0: pad = 4; break; case 1: pad = 1; break; case 2: pad = 2; break; case 3: pad = 1; break; } else pad=0; pgtk2_encode_truecolor_masks(img_data,i->bpp*8,pad*8, (i->byte_order!=1),vis->red_mask, vis->green_mask,vis->blue_mask, i->mem, i->bpl*y); } } else { static int colors_allocated=0; static struct object *pike_cmap; /* I hate this... colormaps, here we come.. */ /* This is rather complicated, but: 1/ build an array of the colors in the colormap 2/ use that array to build a pike X-image colormap. 3/ call Image.X.encode_pseudocolor( img, bpp, lpad, depth, colormp ) 4/ copy the actual data to the image.. */ if (!colors_allocated) { #define COLORMAP_SIZE 256 char allocated[COLORMAP_SIZE]; int j,i,r,g,b; PFTIME("Creating colormap"); colors_allocated=1; MEMSET(allocated,0,sizeof(allocated)); for (r=0; r<3; r++) for (g=0; g<4; g++) for (b=0; b<3; b++) { GdkColor color; color.red = (guint16)(r * (65535/2.0)); color.green = (guint16)(g * (65535/3.0)); color.blue = (guint16)(b * (65535/2.0)); color.pixel = 0; if (gdk_color_alloc(col,&color)) if (color.pixel<COLORMAP_SIZE) allocated[color.pixel]=1; } for (r=0; r<6; r++) for (g=0; g<7; g++) for (b=0; b<6; b++) { GdkColor color; color.red=(guint16)(r*(65535/5.0)); color.green=(guint16)(g*(65535/6.0)); color.blue=(guint16)(b*(65535/5.0)); color.pixel=0; if (gdk_color_alloc(col,&color)) if (color.pixel<COLORMAP_SIZE) allocated[color.pixel]=1; } for (i=0; i<COLORMAP_SIZE; i++) { if (allocated[i]) { push_int(col->colors[i].red>>8); push_int(col->colors[i].green>>8); push_int(col->colors[i].blue>>8); f_aggregate(3); } else push_int(0); } f_aggregate(256); /* now on stack: the array with colors. */ pgtk2_get_image_module(); pgtk2_index_stack("colortable"); /* on stack: array function */ Pike_sp[0]=Pike_sp[-1]; Pike_sp[-1]=Pike_sp[-2]; Pike_sp[-2]=Pike_sp[0]; /* on stack: function array */ PFTIME("Creating colormap obj"); apply_svalue(Pike_sp-2,1); /* on stack: function cmap */ get_all_args("internal",1,"%o",&pike_cmap); pike_cmap->refs+=100; /* lets keep this one.. :-) */ push_int(8); push_int(8); push_int(8); apply(pike_cmap,"rigid",3); pop_stack(); apply(pike_cmap,"ordered",0); pop_stack(); pop_stack(); }
void resource_format_type_image(GtkImage * image, const gint * resources, gint max_width) { gint num_res, tot_res, idx, i, pos; GdkPixmap *p, *pdest; GdkBitmap *b, *bdest; gchar *data; gint size, step; gint width; cairo_t *cr; GdkRectangle r; num_res = tot_res = 0; for (idx = 0; idx < NO_RESOURCE; idx++) { if (resources[idx]) { num_res++; tot_res += resources[idx]; } } if (tot_res == 0) { tot_res = 1; /* Avoid division by zero */ } size = gui_get_resource_pixmap_res(); pos = 0; if (max_width <= 0 || tot_res == num_res || max_width >= size * tot_res) { step = size; width = size * num_res + step * (tot_res - num_res); if (width < max_width) width = max_width; } else { step = (max_width - num_res * size) / (tot_res - num_res); if (step <= 0) step = 1; width = max_width; } pdest = gdk_pixmap_new(NULL, width, size, gdk_visual_get_system()->depth); data = g_malloc0((((width + 7) >> 3) * size)); bdest = gdk_bitmap_create_from_data(NULL, data, size * num_res + step * (tot_res - num_res), size); g_free(data); r.x = 0; r.y = 0; r.width = width; r.height = width; for (idx = 0; idx < NO_RESOURCE; idx++) { if (!resources[idx]) continue; gui_get_resource_pixmap(idx, &p, &b); for (i = 0; i < resources[idx]; i++) { cr = gdk_cairo_create(pdest); gdk_cairo_set_source_pixmap(cr, p, pos, 0); gdk_cairo_rectangle(cr, &r); cairo_fill(cr); cairo_destroy(cr); cr = gdk_cairo_create(bdest); gdk_cairo_set_source_pixmap(cr, b, pos, 0); gdk_cairo_rectangle(cr, &r); cairo_fill(cr); cairo_destroy(cr); pos += step; } pos += size - step; } gtk_image_set_from_pixmap(image, pdest, bdest); g_object_unref(pdest); g_object_unref(bdest); }
GdkVisual *gdk_gl_choose_visual(int *attrlist) { return gdk_visual_get_system (); }
static VALUE rg_s_system(G_GNUC_UNUSED VALUE self) { return GOBJ2RVAL(gdk_visual_get_system()); }
static enum xshm_map_mode x_tile_set_map_mode(TileTab *t, NhGtkProgressWindow *w) { int i; enum xshm_map_mode mode; GdkPixbuf *copy; guchar *pixels; GdkGC *gc; if (!t->spread && !t->transparent) mode = XSHM_MAP_PIXMAP; else mode = getenv("HACKPIXBUF") ? XSHM_MAP_PIXBUF : XSHM_MAP_IMAGE; /* * Pixbufs use so much memory that it's not unexpected for us to * fail to generate the alpha channel correctly. This is not a * great problem since we carefully avoid using it ourselves * (preferring to use the transparent colour directly), but might * cause gdk_pixbuf_render_to_drawable() to get slightly confused * when it dithers the tile (the transparent colour may bleed into * the glyph). We therefore issue a warning. * * Note: It's not clear that gdk_pixbuf_render_to_drawable() * actually uses this information, but what more can we do? * There's little point using gdk_pixbuf_render_to_drawable_alpha() * since all that does is take care not to draw transparent pixels * (which we don't care about anyway; we'll never read them). */ if (mode == XSHM_MAP_PIXBUF && gdk_pixbuf_get_has_alpha(tile_pixbuf)) { /* We can't trust the XPM alpha channel & it will * overide if we don't get rid of it here */ copy = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(tile_pixbuf), FALSE, gdk_pixbuf_get_bits_per_sample(tile_pixbuf), t->tilemap_width, t->tilemap_height); nh_gtk_progress_window_stage_set_fraction(w, 0.25); if (copy) { gdk_pixbuf_copy_area(tile_pixbuf, 0, 0, t->tilemap_width, t->tilemap_height, copy, 0, 0); gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = copy; nh_gtk_progress_window_stage_set_fraction(w, 0.5); } else { pline("Warning: Not enough memory: Tiles may be degraded"); mode = XSHM_MAP_IMAGE; nh_gtk_progress_window_stage_set_fraction(w, 0.0); } } if (mode == XSHM_MAP_PIXBUF && !gdk_pixbuf_get_has_alpha(tile_pixbuf)) { pixels = gdk_pixbuf_get_pixels(tile_pixbuf); nh_gtk_progress_window_stage_set_fraction(w, 0.75); copy = gdk_pixbuf_add_alpha(tile_pixbuf, TRUE, pixels[0], pixels[1], pixels[2]); if (copy) { gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = copy; } else { pline("Warning: Not enough memory: Tiles may be degraded"); mode = XSHM_MAP_IMAGE; nh_gtk_progress_window_stage_set_fraction(w, 0.0); } } tmp_pixbuf = NULL; if (mode != XSHM_MAP_PIXBUF) { tile_pixmap = gdk_pixmap_new(main_window->window, t->tilemap_width, t->tilemap_height, -1); if (!tile_pixmap) panic("Not enough memory to load tiles!"); nh_gtk_progress_window_stage_set_fraction(w, mode == XSHM_MAP_IMAGE ? 0.025 : 0.3); gc = gdk_gc_new(tile_pixmap); gdk_pixbuf_render_to_drawable(tile_pixbuf, tile_pixmap, gc, 0, 0, 0, 0, t->tilemap_width, t->tilemap_height, GDK_RGB_DITHER_NORMAL, 0, 0); gdk_gc_unref(gc); if (mode == XSHM_MAP_IMAGE) { int step = total_tiles_used >= 100 ? total_tiles_used / 100 : 1; nh_gtk_progress_window_stage_set_fraction(w, 0.1); tile_transp = (struct tile_transp *) alloc(total_tiles_used * sizeof(*tile_transp)); for(i = 0; i < total_tiles_used; i++) { calc_tile_transp(t, tile_pixbuf, i); if (i % step == 0) nh_gtk_progress_window_stage_set_fraction(w, 0.1 + (i * 0.8) / total_tiles_used); } calc_tile_transp(t, tile_pixbuf, -1); nh_gtk_progress_window_stage_set_fraction(w, 0.9); /* TODO: Creating an image via a pixmap is very inefficient; * this should be done directly from pixbuf, even if GTK+ doesn't * provide any easy way to do this. */ tile_image = gdk_image_get((GdkWindow *)tile_pixmap, 0, 0, t->tilemap_width, t->tilemap_height); if (!tile_image) panic("Not enough memory to load tiles!"); gdk_pixmap_unref(tile_pixmap); tile_pixmap = NULL; nh_gtk_progress_window_stage_set_fraction(w, 0.975); tmp_img = gdk_image_new(GDK_IMAGE_NORMAL, gdk_visual_get_system(), t->unit_width, t->unit_height); if (!tmp_img) panic("Not enough memory to load tiles!"); #if GTK_CHECK_VERSION(1,3,3) tile_bits_per_pixel = tile_image->bits_per_pixel; #else /* * Technically, this could give an incorrect result. However, as * long as the bitmap_pad is no more than 32 bits (max. X11 allows); * the bytes/line is not larger than necessary; and the width is * at least 32 pixels, then it will be correct. */ tile_bits_per_pixel = tile_image->bpl * 8 / t->tilemap_width; #endif } else tmp_img = tile_image = NULL; gdk_pixbuf_unref(tile_pixbuf); tile_pixbuf = NULL; } nh_gtk_progress_window_stage_set_fraction(w, 1.0); return mode; }
static void file_info_box_build() { GtkWidget *hbox1, *vbox1; GtkWidget *info_exit, *info_mute; GtkWidget *info_unmute, *info_about; GtkWidget *scrw1; GtkWidget *expander; GdkVisual *visual; PangoFontDescription *desc; info_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_object_set_data(GTK_OBJECT(info_window), "info_window", info_window); gtk_window_set_title(GTK_WINDOW(info_window),"Extended Module Player"); gtk_window_set_policy(GTK_WINDOW(info_window), FALSE, FALSE, TRUE); gtk_signal_connect(GTK_OBJECT(info_window), "destroy", GTK_SIGNAL_FUNC(gtk_widget_destroyed), &info_window); gtk_container_border_width(GTK_CONTAINER(info_window), 0); gtk_widget_realize (info_window); vbox1 = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(info_window), vbox1); gtk_object_set_data(GTK_OBJECT(vbox1), "vbox1", vbox1); gtk_container_border_width(GTK_CONTAINER(vbox1), 4); visual = gdk_visual_get_system(); /* * Image */ frame1 = gtk_event_box_new(); gtk_object_set_data(GTK_OBJECT(frame1), "frame1", frame1); gtk_widget_set_size_request(frame1, 300, 128); gtk_box_pack_start(GTK_BOX(vbox1), frame1, FALSE, FALSE, 0); image = gdk_image_new(GDK_IMAGE_FASTEST, visual, 300, 128); ximage = GDK_IMAGE_XIMAGE(image); image1 = gtk_image_new_from_image(image, NULL); gtk_object_set_data(GTK_OBJECT(image1), "image1", image1); gtk_container_add (GTK_CONTAINER(frame1), image1); gtk_widget_set_events (frame1, GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK); gtk_signal_connect (GTK_OBJECT (frame1), "button_press_event", (GtkSignalFunc)image1_clicked, NULL); /* * Buttons */ hbox1 = gtk_hbox_new (TRUE, 0); gtk_object_set_data(GTK_OBJECT(hbox1), "hbox1", hbox1); gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, FALSE, 0); info_mute = gtk_button_new_with_label("Mute"); gtk_signal_connect (GTK_OBJECT (info_mute), "clicked", (GtkSignalFunc) button_mute, NULL); gtk_object_set_data(GTK_OBJECT(info_mute), "info_mute", info_mute); gtk_box_pack_start(GTK_BOX(hbox1), info_mute, TRUE, TRUE, 0); info_unmute = gtk_button_new_with_label("Unmute"); gtk_signal_connect (GTK_OBJECT (info_unmute), "clicked", (GtkSignalFunc) button_unmute, NULL); gtk_object_set_data(GTK_OBJECT(info_unmute), "info_unmute", info_unmute); gtk_box_pack_start(GTK_BOX(hbox1), info_unmute, TRUE, TRUE, 0); info_about = gtk_button_new_with_label("About"); gtk_signal_connect_object(GTK_OBJECT(info_about), "clicked", (GtkSignalFunc) aboutbox, NULL); gtk_object_set_data(GTK_OBJECT(info_about), "info_about", info_about); gtk_box_pack_start(GTK_BOX(hbox1), info_about, TRUE, TRUE, 0); info_exit = gtk_button_new_with_label("Close"); gtk_signal_connect_object(GTK_OBJECT(info_exit), "clicked", GTK_SIGNAL_FUNC(gtk_widget_hide), GTK_OBJECT(info_window)); gtk_object_set_data(GTK_OBJECT(info_exit), "info_exit", info_exit); gtk_box_pack_start(GTK_BOX(hbox1), info_exit, TRUE, TRUE, 0); /* * Info area */ expander = gtk_expander_new("Module information"); scrw1 = gtk_scrolled_window_new(NULL, NULL); gtk_object_set_data(GTK_OBJECT(scrw1), "scrw1", scrw1); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrw1), GTK_POLICY_ALWAYS, GTK_POLICY_AUTOMATIC); gtk_container_add(GTK_CONTAINER(expander), scrw1); gtk_box_pack_start(GTK_BOX(vbox1), expander, TRUE, TRUE, 0); gtk_widget_set_size_request(scrw1, 290, 200); text1b = gtk_text_buffer_new(NULL); text1 = gtk_text_view_new_with_buffer(text1b); desc = pango_font_description_new(); pango_font_description_set_family(desc, "Monospace"); gtk_widget_modify_font(text1, desc); pango_font_description_free(desc); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text1), GTK_WRAP_NONE); gtk_object_set_data(GTK_OBJECT(text1), "text1", text1); gtk_container_add(GTK_CONTAINER(scrw1), text1); gtk_widget_realize(text1); gtk_widget_realize(image1); display = GDK_WINDOW_XDISPLAY(info_window->window); window = GDK_WINDOW_XWINDOW(info_window->window); colormap = gdk_colormap_get_system(); gdk_color_black(colormap, color_black); gdk_color_white(colormap, color_white); init_visual(visual); set_palette(); clear_screen(); ii->wresult = 0; panel_setup(); gtk_timeout_add(50, (GtkFunction)panel_loop, NULL); }
int main(int argc, char *argv[]) { GtkWidget *window, *imagebox; GdkVisual *visual; GdkImage *image; FIBITMAP *dib; int y; // initialize the FreeImage library FreeImage_Initialise(); dib = FreeImage_Load(FIF_PNG, "freeimage.png", PNG_DEFAULT); gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_signal_connect(GTK_OBJECT(window), "destroy", GTK_SIGNAL_FUNC(destroy), NULL); visual = gdk_visual_get_system(); image = gdk_image_new(GDK_IMAGE_NORMAL,visual, FreeImage_GetWidth(dib),FreeImage_GetHeight(dib)); g_print("picture: %d bpp\n" "system: %d bpp byteorder: %d\n" " redbits: %d greenbits: %d bluebits: %d\n" "image: %d bpp %d bytes/pixel\n", FreeImage_GetBPP(dib), visual->depth,visual->byte_order, visual->red_prec,visual->green_prec,visual->blue_prec, image->depth,image->bpp ); if (FreeImage_GetBPP(dib) != (image->bpp << 3)) { FIBITMAP *ptr; switch (image->bpp) { case 1: ptr = FreeImage_ConvertTo8Bits(dib); break; case 2: if (image->depth == 15) { ptr = FreeImage_ConvertTo16Bits555(dib); } else { ptr = FreeImage_ConvertTo16Bits565(dib); } break; case 3: ptr = FreeImage_ConvertTo24Bits(dib); break; default: case 4: ptr = FreeImage_ConvertTo32Bits(dib); break; } FreeImage_Unload(dib); dib = ptr; } //makes it upside down :( // memcpy(image->mem, FreeImage_GetBits(dib), image->bpl * image->height); BYTE *ptr = FreeImage_GetBits(dib); for (y = 0; y < image->height; y++) { memcpy(image->mem + (y * image->bpl), ptr + ((image->height - y - 1) * image->bpl), image->bpl); } FreeImage_Unload(dib); imagebox = gtk_image_new(image, NULL); gtk_container_add(GTK_CONTAINER(window), imagebox); gtk_widget_show(imagebox); gtk_widget_show(window); gtk_main(); // release the FreeImage library FreeImage_DeInitialise(); return 0; }
int main(int argc, char *argv[]) { GtkWidget *window; GtkWidget *box; GdkColor color; XWMHints mywmhints; GtkWidget *main_button; GdkPixmap *main_button_pixmap; GdkBitmap *main_button_mask; GtkWidget *main_button_box; GtkWidget *color_menu; GtkWidget *item; GtkWidget *label; GtkWidget *color_box; GtkWidget *hbox; GdkColor gcolor; char *wmstickynotes_dir = NULL; gboolean use_default_dir = TRUE; int option_index = 0; int i = 0; struct option long_options[] = { {"directory", required_argument, 0, 'd'}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; for( i = getopt_long(argc, argv, "d:vh", long_options, &option_index); i >= 0; i = getopt_long(argc, argv, "d:vh", long_options, &option_index) ) { switch(i) { case 'd': wmstickynotes_dir = optarg; use_default_dir = FALSE; break; case 'v': printf("%s\n", PACKAGE_STRING); printf("Copyright (C) 2009 %s\n", PACKAGE_BUGREPORT); return 0; case 'h': usage(); return 0; default: usage(); return 1; } } umask(077); if(use_default_dir) { wmstickynotes_dir = calloc( strlen(default_wmstickynotes_dir) + strlen(getenv("HOME")) + 2, sizeof(char)); strcpy(wmstickynotes_dir, getenv("HOME")); strcat(wmstickynotes_dir, "/"); strcat(wmstickynotes_dir, default_wmstickynotes_dir); } if(chdir(wmstickynotes_dir)) { if(errno == ENOENT) { if(mkdir(wmstickynotes_dir, 0777)) { fprintf(stderr, "Couldn't make directory: %s\n", wmstickynotes_dir); exit(1); } if(chdir(wmstickynotes_dir)) { fprintf(stderr, "Couldn't change to directory: %s\n", wmstickynotes_dir); exit(1); } } else { fprintf(stderr, "Couldn't change to directory: %s\n", wmstickynotes_dir); exit(1); } } if(use_default_dir) free(wmstickynotes_dir); gtk_init(&argc, &argv); colormap = gdk_colormap_new(gdk_visual_get_system(), TRUE); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(window), 64, 64); box = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER (window), box); gdk_color_parse ("#fafafa", &color); gtk_widget_modify_bg(box, GTK_STATE_NORMAL, &color); main_button_pixmap = gdk_pixmap_colormap_create_from_xpm_d(NULL, colormap, &main_button_mask, NULL, wmstickynotes_xpm); main_button = gtk_image_new_from_pixmap(main_button_pixmap, main_button_mask); main_button_box = gtk_event_box_new(); gtk_container_add(GTK_CONTAINER(main_button_box), main_button); gtk_container_add(GTK_CONTAINER(box), main_button_box); color_menu = gtk_menu_new(); for(i=0; i < num_color_schemes; i++) { item = gtk_menu_item_new(); label = gtk_label_new(color_schemes[i].name); color_box = gtk_event_box_new(); gtk_widget_set_size_request(color_box, 15, -1); hbox = gtk_hbox_new(FALSE, 4); gdk_color_parse(color_schemes[i].top, &gcolor); gtk_widget_modify_bg(color_box, GTK_STATE_NORMAL, &gcolor); gtk_widget_modify_bg(color_box, GTK_STATE_PRELIGHT, &gcolor); gtk_container_add(GTK_CONTAINER(item), hbox); gtk_box_pack_start(GTK_BOX(hbox), color_box, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); gtk_menu_shell_append(GTK_MENU_SHELL(color_menu), item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(new_note_from_menu), &color_schemes[i]); } gtk_widget_show_all(GTK_WIDGET(color_menu)); gtk_widget_show_all(window); mywmhints.initial_state = WithdrawnState; mywmhints.icon_window = GDK_WINDOW_XWINDOW(box->window); mywmhints.icon_x = 0; mywmhints.icon_y = 0; mywmhints.window_group = GDK_WINDOW_XWINDOW(window->window); mywmhints.flags = StateHint | IconWindowHint | IconPositionHint | WindowGroupHint; XSetWMHints(GDK_DISPLAY(), GDK_WINDOW_XWINDOW(window->window), &mywmhints); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(G_OBJECT(main_button_box), "button-press-event", G_CALLBACK(main_button_pressed), color_menu); read_old_notes(); gtk_main(); return 0; }
static GdkVisual* gdk_directfb_get_visual (GdkDrawable *drawable) { return gdk_visual_get_system (); }
/* this makes a new screen: */ struct tme_gtk_screen * _tme_gtk_screen_new(struct tme_gtk_display *display) { struct tme_gtk_screen *screen, **_prev; GtkWidget *menu_bar; GtkWidget *menu; GtkWidget *submenu; GtkWidget *menu_item; tme_uint8_t *bitmap_data; unsigned int y; #define BLANK_SIDE (16 * 8) /* create the new screen and link it in: */ for (_prev = &display->tme_gtk_display_screens; (screen = *_prev) != NULL; _prev = &screen->tme_gtk_screen_next); screen = *_prev = tme_new0(struct tme_gtk_screen, 1); /* the backpointer to the display: */ screen->tme_gtk_screen_display = display; /* there is no framebuffer connection yet: */ screen->tme_gtk_screen_fb = NULL; /* the user hasn't specified a scaling yet: */ screen->tme_gtk_screen_fb_scale = -TME_FB_XLAT_SCALE_NONE; /* we have no colorset: */ screen->tme_gtk_screen_colorset = TME_FB_COLORSET_NONE; /* create the top-level window, and allow it to shrink, grow, and auto-shrink: */ screen->tme_gtk_screen_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_policy(GTK_WINDOW(screen->tme_gtk_screen_window), FALSE, FALSE, TRUE); /* create the outer vertical packing box: */ screen->tme_gtk_screen_vbox0 = gtk_vbox_new(FALSE, 0); /* add the outer vertical packing box to the window: */ gtk_container_add(GTK_CONTAINER(screen->tme_gtk_screen_window), screen->tme_gtk_screen_vbox0); /* create the menu bar and pack it into the outer vertical packing box: */ menu_bar = gtk_menu_bar_new (); gtk_box_pack_start(GTK_BOX(screen->tme_gtk_screen_vbox0), menu_bar, FALSE, FALSE, 0); gtk_widget_show(menu_bar); /* create the Screen menu: */ menu = gtk_menu_new(); /* create the Screen scaling submenu: */ submenu = _tme_gtk_display_menu_radio(screen, _tme_gtk_screen_submenu_scaling); /* create the Screen scaling submenu item: */ menu_item = gtk_menu_item_new_with_label(_("Scale")); gtk_widget_show(menu_item); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), submenu); gtk_menu_append(GTK_MENU(menu), menu_item); /* create the Screen menu bar item, attach the menu to it, and attach the menu bar item to the menu bar: */ menu_item = gtk_menu_item_new_with_label("Screen"); gtk_widget_show(menu_item); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item), menu); gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), menu_item); /* create an event box for the framebuffer area: */ screen->tme_gtk_screen_event_box = gtk_event_box_new(); /* pack the event box into the outer vertical packing box: */ gtk_box_pack_start(GTK_BOX(screen->tme_gtk_screen_vbox0), screen->tme_gtk_screen_event_box, FALSE, FALSE, 0); /* show the event box: */ gtk_widget_show(screen->tme_gtk_screen_event_box); /* create a GdkImage of an alternating-bits area. we must use malloc() here since this memory will end up as part of an XImage, and X will call free() on it: */ bitmap_data = (tme_uint8_t *) malloc((BLANK_SIDE * BLANK_SIDE) / 8); assert(bitmap_data != NULL); for (y = 0; y < BLANK_SIDE; y++) { memset(bitmap_data + (y * BLANK_SIDE / 8), (y & 1 ? 0x33 : 0xcc), (BLANK_SIDE / 8)); } screen->tme_gtk_screen_gdkimage = gdk_image_new_bitmap(gdk_visual_get_system(), bitmap_data, BLANK_SIDE, BLANK_SIDE); /* create the GtkImage for the framebuffer area: */ screen->tme_gtk_screen_gtkimage = gtk_image_new_from_image(screen->tme_gtk_screen_gdkimage, NULL); /* add the GtkImage to the event box: */ gtk_container_add(GTK_CONTAINER(screen->tme_gtk_screen_event_box), screen->tme_gtk_screen_gtkimage); /* show the GtkImage: */ gtk_widget_show(screen->tme_gtk_screen_gtkimage); /* show the outer vertical packing box: */ gtk_widget_show(screen->tme_gtk_screen_vbox0); /* show the top-level window: */ gtk_widget_show(screen->tme_gtk_screen_window); /* there is no translation function: */ screen->tme_gtk_screen_fb_xlat = NULL; /* attach the mouse to this screen: */ _tme_gtk_mouse_attach(screen); /* attach the keyboard to this screen: */ _tme_gtk_keyboard_attach(screen); return (screen); }
int appAllocateColors( AppDrawingData * add, AppColors * acSys ) { GdkVisual * vis= gdk_visual_get_system(); GdkColormap * cmap= gdk_colormap_get_system(); int count; ColorAllocator * ca= &(acSys->acAllocator); acSys->acColormap= cmap; acSys->acVisualClass= vis->type; ca->caSystemPrivate= acSys; ca->caDepth= vis->depth; switch( acSys->acVisualClass ) { case GDK_VISUAL_STATIC_GRAY: case GDK_VISUAL_GRAYSCALE: ca->caAllocationType= CA_INDEX_ALLOC; switch( ca->caDepth ) { case 1: case 2: case 4: case 8: break; default: LLDEB(acSys->acVisualClass,ca->caDepth); } break; case GDK_VISUAL_STATIC_COLOR: ca->caAllocationType= CA_INDEX_ALLOC; break; case GDK_VISUAL_PSEUDO_COLOR: ca->caAllocationType= CA_INDEX_ALLOC; break; case GDK_VISUAL_TRUE_COLOR: case GDK_VISUAL_DIRECT_COLOR: ca->caAllocationType= CA_CALCULATED; bmSetCalculatedShifts( ca, vis->red_mask, vis->green_mask, vis->blue_mask ); return 0; } switch( ca->caDepth ) { case 1: count= 2; ca->caSystemAllocator= appColorRgb111; bmSetCalculatedShifts( ca, 0x0004, 0x0002, 0x0001 ); break; case 2: count= 4; ca->caSystemAllocator= appColorRgb111; bmSetCalculatedShifts( ca, 0x0004, 0x0002, 0x0001 ); break; case 4: count= 16; ca->caSystemAllocator= appColorRgb222; bmSetCalculatedShifts( ca, 0x0030, 0x000c, 0x0003 ); break; case 8: count= 256; ca->caSystemAllocator= appColorRgb332; bmSetCalculatedShifts( ca, 0x00e0, 0x001c, 0x0003 ); break; case 16: count= 256* 256; ca->caSystemAllocator= appColorRgb555; bmSetCalculatedShifts( ca, 0x7c00, 0x03e0, 0x001f ); break; case 24: case 32: return 0; default: LDEB(vis->depth); return -1; } if ( bmAllocateAllocatorColors( ca, count ) ) { LDEB(count); return -1; } return 0; }
/* this is called for a mode change: */ int _tme_gtk_screen_mode_change(struct tme_fb_connection *conn_fb) { struct tme_gtk_display *display; struct tme_gtk_screen *screen; struct tme_fb_connection *conn_fb_other; struct tme_fb_xlat fb_xlat_q; const struct tme_fb_xlat *fb_xlat_a; int scale; unsigned long fb_area, avail_area, percentage; gint width, height; gint height_extra; const void *map_g_old; const void *map_r_old; const void *map_b_old; const tme_uint32_t *map_pixel_old; tme_uint32_t map_pixel_count_old; tme_uint32_t colorset; GdkImage *gdkimage; GdkVisual *visual; tme_uint32_t color_count, color_i; tme_uint32_t color_count_distinct; tme_uint32_t color_j; struct tme_fb_color *colors_tme; GdkColor *colors_gdk; gboolean *success; gboolean warned_color_alloc; /* recover our data structures: */ display = conn_fb->tme_fb_connection.tme_connection_element->tme_element_private; conn_fb_other = (struct tme_fb_connection *) conn_fb->tme_fb_connection.tme_connection_other; /* lock our mutex: */ tme_mutex_lock(&display->tme_gtk_display_mutex); /* find the screen that this framebuffer connection references: */ for (screen = display->tme_gtk_display_screens; (screen != NULL && screen->tme_gtk_screen_fb != conn_fb); screen = screen->tme_gtk_screen_next); assert (screen != NULL); /* if the user hasn't specified a scaling, pick one: */ scale = screen->tme_gtk_screen_fb_scale; if (scale < 0) { /* calulate the areas, in square pixels, of the emulated framebuffer and the host's screen: */ fb_area = (conn_fb_other->tme_fb_connection_width * conn_fb_other->tme_fb_connection_height); avail_area = (gdk_screen_width() * gdk_screen_height()); /* see what percentage of the host's screen would be taken up by an unscaled emulated framebuffer: */ percentage = (fb_area * 100) / avail_area; /* if this is at least 70%, halve the emulated framebuffer, else if this is 30% or less, double the emulated framebuffer: */ if (percentage >= 70) { scale = TME_FB_XLAT_SCALE_HALF; } else if (percentage <= 30) { scale = TME_FB_XLAT_SCALE_DOUBLE; } else { scale = TME_FB_XLAT_SCALE_NONE; } screen->tme_gtk_screen_fb_scale = -scale; } /* get the system's default visual: */ visual = gdk_visual_get_system(); /* get the required dimensions for the GdkImage: */ width = ((conn_fb_other->tme_fb_connection_width * scale) / TME_FB_XLAT_SCALE_NONE); height = ((conn_fb_other->tme_fb_connection_height * scale) / TME_FB_XLAT_SCALE_NONE); /* NB: we need to allocate an extra scanline's worth (or, if we're doubling, an extra two scanlines' worth) of image, because the framebuffer translation functions can sometimes overtranslate (see the explanation of TME_FB_XLAT_RUN in fb-xlat-auto.sh): */ height_extra = (scale == TME_FB_XLAT_SCALE_DOUBLE ? 2 : 1); /* if the previous gdkimage isn't the right size: */ gdkimage = screen->tme_gtk_screen_gdkimage; if (gdkimage->width != width || gdkimage->height != (height + height_extra)) { /* allocate a new gdkimage: */ gdkimage = gdk_image_new(GDK_IMAGE_FASTEST, visual, width, height + height_extra); /* set the new image on the image widget: */ gtk_image_set(GTK_IMAGE(screen->tme_gtk_screen_gtkimage), gdkimage, NULL); /* destroy the previous gdkimage and remember the new one: */ gdk_image_destroy(screen->tme_gtk_screen_gdkimage); screen->tme_gtk_screen_gdkimage = gdkimage; } /* remember all previously allocated maps and colors, but otherwise remove them from our framebuffer structure: */ map_g_old = conn_fb->tme_fb_connection_map_g; map_r_old = conn_fb->tme_fb_connection_map_r; map_b_old = conn_fb->tme_fb_connection_map_b; map_pixel_old = conn_fb->tme_fb_connection_map_pixel; map_pixel_count_old = conn_fb->tme_fb_connection_map_pixel_count; conn_fb->tme_fb_connection_map_g = NULL; conn_fb->tme_fb_connection_map_r = NULL; conn_fb->tme_fb_connection_map_b = NULL; conn_fb->tme_fb_connection_map_pixel = NULL; conn_fb->tme_fb_connection_map_pixel_count = 0; /* update our framebuffer connection: */ conn_fb->tme_fb_connection_width = width; conn_fb->tme_fb_connection_height = height; conn_fb->tme_fb_connection_depth = gdkimage->depth; conn_fb->tme_fb_connection_bits_per_pixel = _tme_gtk_gdkimage_bipp(gdkimage); conn_fb->tme_fb_connection_skipx = 0; conn_fb->tme_fb_connection_scanline_pad = _tme_gtk_gdkimage_scanline_pad(gdkimage); conn_fb->tme_fb_connection_order = (gdkimage->byte_order == GDK_LSB_FIRST ? TME_ENDIAN_LITTLE : TME_ENDIAN_BIG); conn_fb->tme_fb_connection_buffer = gdkimage->mem; switch (visual->type) { case GDK_VISUAL_STATIC_GRAY: case GDK_VISUAL_GRAYSCALE: conn_fb->tme_fb_connection_class = TME_FB_XLAT_CLASS_MONOCHROME; break; default: assert(FALSE); /* FALLTHROUGH */ case GDK_VISUAL_STATIC_COLOR: case GDK_VISUAL_PSEUDO_COLOR: case GDK_VISUAL_DIRECT_COLOR: case GDK_VISUAL_TRUE_COLOR: conn_fb->tme_fb_connection_class = TME_FB_XLAT_CLASS_COLOR; break; } switch (visual->type) { case GDK_VISUAL_DIRECT_COLOR: /* we set the primary maps to anything non-NULL, to indicate that primaries are index mapped: */ conn_fb->tme_fb_connection_map_g = conn_fb; conn_fb->tme_fb_connection_map_r = conn_fb; conn_fb->tme_fb_connection_map_b = conn_fb; /* FALLTHROUGH */ case GDK_VISUAL_TRUE_COLOR: conn_fb->tme_fb_connection_mask_g = visual->green_mask; conn_fb->tme_fb_connection_mask_r = visual->red_mask; conn_fb->tme_fb_connection_mask_b = visual->blue_mask; break; default: conn_fb->tme_fb_connection_mask_g = 0; conn_fb->tme_fb_connection_mask_r = 0; conn_fb->tme_fb_connection_mask_b = 0; break; } /* get the needed colors: */ colorset = tme_fb_xlat_colors_get(conn_fb_other, scale, conn_fb, &colors_tme); color_count = conn_fb->tme_fb_connection_map_pixel_count; /* if we need to allocate colors, but the colorset is not tied to the source framebuffer characteristics, and is identical to the currently allocated colorset, we can reuse the previously allocated maps and colors: */ if (color_count > 0 && colorset != TME_FB_COLORSET_NONE && colorset == screen->tme_gtk_screen_colorset) { /* free the requested color array: */ tme_free(colors_tme); /* restore the previously allocated maps and colors: */ conn_fb->tme_fb_connection_map_g = map_g_old; conn_fb->tme_fb_connection_map_r = map_r_old; conn_fb->tme_fb_connection_map_b = map_b_old; conn_fb->tme_fb_connection_map_pixel = map_pixel_old; conn_fb->tme_fb_connection_map_pixel_count = map_pixel_count_old; } /* otherwise, we may need to free and/or allocate colors: */ else { /* save the colorset signature: */ screen->tme_gtk_screen_colorset = colorset; /* free any previously allocated maps and colors: */ if (map_g_old != NULL) { tme_free((void *) map_g_old); } if (map_r_old != NULL) { tme_free((void *) map_r_old); } if (map_b_old != NULL) { tme_free((void *) map_b_old); } if (map_pixel_old != NULL) { /* recreate the array of GdkColor: */ colors_gdk = tme_new(GdkColor, map_pixel_count_old); color_i = 0; do { colors_gdk[color_i].pixel = map_pixel_old[color_i]; } while (++color_i < map_pixel_count_old); /* free the colors: */ gdk_colormap_free_colors(gdk_colormap_get_system(), colors_gdk, map_pixel_count_old); tme_free(colors_gdk); tme_free((void *) map_pixel_old); } /* if we need to allocate colors: */ if (color_count > 0) { /* make the GdkColor array, and count the number of distinct colors: */ colors_gdk = tme_new(GdkColor, color_count * 2); color_count_distinct = 0; for (color_i = 0; color_i < color_count; color_i++) { color_j = colors_tme[color_i].tme_fb_color_pixel; colors_gdk[color_j].green = colors_tme[color_i].tme_fb_color_value_g; colors_gdk[color_j].red = colors_tme[color_i].tme_fb_color_value_r; colors_gdk[color_j].blue = colors_tme[color_i].tme_fb_color_value_b; if (color_j >= color_count_distinct) { color_count_distinct = color_j + 1; } } success = tme_new(gboolean, color_count_distinct); /* allocate exact matches for as many colors as possible: */ gdk_colormap_alloc_colors(gdk_colormap_get_system(), colors_gdk, color_count_distinct, FALSE, FALSE, success); /* allocate read-only best matches for any colors we failed to allocate exactly: */ warned_color_alloc = FALSE; for (color_i = 0; color_i < color_count; color_i++) { color_j = colors_tme[color_i].tme_fb_color_pixel; if (!success[color_j]) { if (!gdk_colormap_alloc_color(gdk_colormap_get_system(), &colors_gdk[color_j], FALSE, TRUE)) { if (!warned_color_alloc) { warned_color_alloc = TRUE; tme_log(&display->tme_gtk_display_element->tme_element_log_handle, 0, ENOMEM, (&display->tme_gtk_display_element->tme_element_log_handle, _("could not allocate all colors"))); } } } colors_tme[color_i].tme_fb_color_pixel = colors_gdk[color_j].pixel; } /* free the arrays used with gdk_colormap_alloc_colors(): */ tme_free(success); tme_free(colors_gdk); /* set the needed colors: */ tme_fb_xlat_colors_set(conn_fb_other, scale, conn_fb, colors_tme); } } /* compose the framebuffer translation question: */ fb_xlat_q.tme_fb_xlat_width = conn_fb_other->tme_fb_connection_width; fb_xlat_q.tme_fb_xlat_height = conn_fb_other->tme_fb_connection_height; fb_xlat_q.tme_fb_xlat_scale = (unsigned int) scale; fb_xlat_q.tme_fb_xlat_src_depth = conn_fb_other->tme_fb_connection_depth; fb_xlat_q.tme_fb_xlat_src_bits_per_pixel = conn_fb_other->tme_fb_connection_bits_per_pixel; fb_xlat_q.tme_fb_xlat_src_skipx = conn_fb_other->tme_fb_connection_skipx; fb_xlat_q.tme_fb_xlat_src_scanline_pad = conn_fb_other->tme_fb_connection_scanline_pad; fb_xlat_q.tme_fb_xlat_src_order = conn_fb_other->tme_fb_connection_order; fb_xlat_q.tme_fb_xlat_src_class = conn_fb_other->tme_fb_connection_class; fb_xlat_q.tme_fb_xlat_src_map = (conn_fb_other->tme_fb_connection_map_g != NULL ? TME_FB_XLAT_MAP_INDEX : TME_FB_XLAT_MAP_LINEAR); fb_xlat_q.tme_fb_xlat_src_map_bits = conn_fb_other->tme_fb_connection_map_bits; fb_xlat_q.tme_fb_xlat_src_mask_g = conn_fb_other->tme_fb_connection_mask_g; fb_xlat_q.tme_fb_xlat_src_mask_r = conn_fb_other->tme_fb_connection_mask_r; fb_xlat_q.tme_fb_xlat_src_mask_b = conn_fb_other->tme_fb_connection_mask_b; fb_xlat_q.tme_fb_xlat_dst_depth = conn_fb->tme_fb_connection_depth; fb_xlat_q.tme_fb_xlat_dst_bits_per_pixel = conn_fb->tme_fb_connection_bits_per_pixel; fb_xlat_q.tme_fb_xlat_dst_skipx = conn_fb->tme_fb_connection_skipx; fb_xlat_q.tme_fb_xlat_dst_scanline_pad = conn_fb->tme_fb_connection_scanline_pad; fb_xlat_q.tme_fb_xlat_dst_order = conn_fb->tme_fb_connection_order; fb_xlat_q.tme_fb_xlat_dst_map = (conn_fb->tme_fb_connection_map_g != NULL ? TME_FB_XLAT_MAP_INDEX : TME_FB_XLAT_MAP_LINEAR); fb_xlat_q.tme_fb_xlat_dst_mask_g = conn_fb->tme_fb_connection_mask_g; fb_xlat_q.tme_fb_xlat_dst_mask_r = conn_fb->tme_fb_connection_mask_r; fb_xlat_q.tme_fb_xlat_dst_mask_b = conn_fb->tme_fb_connection_mask_b; /* ask the framebuffer translation question: */ fb_xlat_a = tme_fb_xlat_best(&fb_xlat_q); /* if this translation isn't optimal, log a note: */ if (!tme_fb_xlat_is_optimal(fb_xlat_a)) { tme_log(&display->tme_gtk_display_element->tme_element_log_handle, 0, TME_OK, (&display->tme_gtk_display_element->tme_element_log_handle, _("no optimal framebuffer translation function available"))); } /* save the translation function: */ screen->tme_gtk_screen_fb_xlat = fb_xlat_a->tme_fb_xlat_func; /* force the next translation to do a complete redraw: */ screen->tme_gtk_screen_full_redraw = TRUE; /* unlock our mutex: */ tme_mutex_unlock(&display->tme_gtk_display_mutex); /* done: */ return (TME_OK); }