GdkPixbuf * _gtk_icon_cache_get_icon (GtkIconCache *cache, const gchar *icon_name, gint directory_index) { guint32 offset, image_data_offset, pixel_data_offset; guint32 length, type; GdkPixbuf *pixbuf; GdkPixdata pixdata; GError *error = NULL; offset = find_image_offset (cache, icon_name, directory_index); image_data_offset = GET_UINT32 (cache->buffer, offset + 4); if (!image_data_offset) return NULL; pixel_data_offset = GET_UINT32 (cache->buffer, image_data_offset); type = GET_UINT32 (cache->buffer, pixel_data_offset); if (type != 0) { GTK_NOTE (ICONTHEME, g_print ("invalid pixel data type %u\n", type)); return NULL; } length = GET_UINT32 (cache->buffer, pixel_data_offset + 4); if (!gdk_pixdata_deserialize (&pixdata, length, (guchar *)(cache->buffer + pixel_data_offset + 8), &error)) { GTK_NOTE (ICONTHEME, g_print ("could not deserialize data: %s\n", error->message)); g_error_free (error); return NULL; } pixbuf = gdk_pixbuf_new_from_data (pixdata.pixel_data, GDK_COLORSPACE_RGB, (pixdata.pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, 8, pixdata.width, pixdata.height, pixdata.rowstride, (GdkPixbufDestroyNotify)pixbuf_destroy_cb, cache); if (!pixbuf) { GTK_NOTE (ICONTHEME, g_print ("could not convert pixdata to pixbuf: %s\n", error->message)); g_error_free (error); return NULL; } _gtk_icon_cache_ref (cache); return pixbuf; }
static gboolean try_load (struct pixdata_context *context, GError **error) { GdkPixbuf *pixbuf; G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (context->got_pixbuf) return TRUE; if (!gdk_pixdata_deserialize (&context->pixdata, context->data->len, (guchar *)context->data->str, error)) return FALSE; pixbuf = gdk_pixbuf_from_pixdata (&context->pixdata, TRUE, error); if (pixbuf == NULL) return FALSE; context->got_pixbuf = TRUE; if (context->prepared_func) (* context->prepared_func) (pixbuf, NULL, context->user_data); if (context->updated_func) (* context->updated_func) (pixbuf, 0, 0, pixbuf->width, pixbuf->height, context->user_data); return TRUE; G_GNUC_END_IGNORE_DEPRECATIONS }
GdkPixbuf * ma_deserialize_pixdata (const guint8 *bytes, gint size) { GdkPixdata pixdata; if (gdk_pixdata_deserialize (&pixdata, size, bytes, NULL)) { return gdk_pixbuf_from_pixdata (&pixdata, TRUE, NULL); } else { return NULL; } }
/** * Convertit une chaine codée en base 64 en pixbuf * * \param str_base64 * * return a new pixbuf * */ GdkPixbuf *gsb_select_icon_create_pixbuf_from_chaine_base64 ( gchar *str_base64 ) { guchar *data; gsize longueur; GdkPixdata pixdata; GdkPixbuf *pixbuf = NULL; data = g_base64_decode ( str_base64, &longueur ); gdk_pixdata_deserialize ( &pixdata, longueur, data, NULL ); pixbuf = gdk_pixbuf_from_pixdata ( &pixdata, TRUE, NULL ); g_free ( data ); return pixbuf; }
/** * gdk_pixbuf_new_from_inline: * @data_length: Length in bytes of the @data argument or -1 to * disable length checks * @data: (array length=data_length): Byte data containing a * serialized #GdkPixdata structure * @copy_pixels: Whether to copy the pixel data, or use direct pointers * @data for the resulting pixbuf * @error: #GError return location, may be %NULL to ignore errors * * Create a #GdkPixbuf from a flat representation that is suitable for * storing as inline data in a program. This is useful if you want to * ship a program with images, but don't want to depend on any * external files. * * gdk-pixbuf ships with a program called [gdk-pixbuf-csource][gdk-pixbuf-csource], * which allows for conversion of #GdkPixbufs into such a inline representation. * In almost all cases, you should pass the `--raw` option to * `gdk-pixbuf-csource`. A sample invocation would be: * * |[ * gdk-pixbuf-csource --raw --name=myimage_inline myimage.png * ]| * * For the typical case where the inline pixbuf is read-only static data, * you don't need to copy the pixel data unless you intend to write to * it, so you can pass %FALSE for @copy_pixels. (If you pass `--rle` to * `gdk-pixbuf-csource`, a copy will be made even if @copy_pixels is %FALSE, * so using this option is generally a bad idea.) * * If you create a pixbuf from const inline data compiled into your * program, it's probably safe to ignore errors and disable length checks, * since things will always succeed: * |[ * pixbuf = gdk_pixbuf_new_from_inline (-1, myimage_inline, FALSE, NULL); * ]| * * For non-const inline data, you could get out of memory. For untrusted * inline data located at runtime, you could have corrupt inline data in * addition. * * Return value: A newly-created #GdkPixbuf structure with a reference, * count of 1, or %NULL if an error occurred. * * Deprecated: 2.32: Use #GResource instead. **/ GdkPixbuf* gdk_pixbuf_new_from_inline (gint data_length, const guint8 *data, gboolean copy_pixels, GError **error) { GdkPixdata pixdata; if (data_length != -1) g_return_val_if_fail (data_length > GDK_PIXDATA_HEADER_LENGTH, NULL); g_return_val_if_fail (data != NULL, NULL); if (!gdk_pixdata_deserialize (&pixdata, data_length, data, error)) return NULL; return gdk_pixbuf_from_pixdata (&pixdata, copy_pixels, error); }
static gboolean pixdata_image_load_increment (gpointer data, const guchar *buf, guint size, GError **error) { struct pixdata_context *context = (struct pixdata_context *) data; G_GNUC_BEGIN_IGNORE_DEPRECATIONS g_string_append_len (context->data, (char *)buf, size); if (!context->got_header && context->data->len >= GDK_PIXDATA_HEADER_LENGTH) { /* This never reads past the header anyway, and we know we have at least the header size, so we pass it a really large size to avoid any error reporting due to missing data */ if (!gdk_pixdata_deserialize (&context->pixdata, G_MAXUINT, (guchar *)context->data->str, error)) return FALSE; context->got_header = TRUE; if (context->size_func) { gint w = context->pixdata.width; gint h = context->pixdata.height; (* context->size_func) (&w, &h, context->user_data); if (w == 0 || h == 0) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, _("Transformed pixbuf has zero width or height.")); return FALSE; } } } try_load (context, NULL); return TRUE; G_GNUC_END_IGNORE_DEPRECATIONS }
void mysql__add_row_to_model(MYSQL_ROW row, unsigned long* lengths) { GdkPixbuf* iconbuf = NULL; char length[64]; char keywords[256]; char name[256]; float samplerate; char samplerate_s[32]; unsigned channels, colour; gboolean online = FALSE; GtkTreeIter iter; //db__iter_to_result(result); //deserialise the pixbuf field: GdkPixdata pixdata; GdkPixbuf* pixbuf = NULL; if(row[MYSQL_PIXBUF]){ if(gdk_pixdata_deserialize(&pixdata, lengths[MYSQL_PIXBUF], (guint8*)row[MYSQL_PIXBUF], NULL)){ pixbuf = gdk_pixbuf_from_pixdata(&pixdata, TRUE, NULL); } } format_time(length, row[MYSQL_LENGTH]); if(row[MYSQL_KEYWORDS]) snprintf(keywords, 256, "%s", row[MYSQL_KEYWORDS]); else keywords[0] = 0; if(!row[MYSQL_SAMPLERATE]) samplerate = 0; else samplerate = atoi(row[MYSQL_SAMPLERATE]); samplerate_format(samplerate_s, samplerate); if(row[7]==NULL) channels = 0; else channels = atoi(row[7]); if(row[MYSQL_ONLINE]==NULL) online = 0; else online = atoi(row[MYSQL_ONLINE]); if(row[MYSQL_COLOUR]==NULL) colour = 0; else colour = atoi(row[MYSQL_COLOUR]); strncpy(name, row[MYSQL_NAME], 255); //TODO markup should be set in cellrenderer, not model! #if 0 if(GTK_WIDGET_REALIZED(app.view)){ //check colours dont clash: long c_num = strtol(app.config.colour[colour], NULL, 16); dbg(2, "rowcolour=%s", app.config.colour[colour]); GdkColor row_colour; color_rgba_to_gdk(&row_colour, c_num << 8); if(is_similar(&row_colour, &app.fg_colour, 0x60)){ snprintf(name, 255, "%s%s%s", "<span foreground=\"blue\">", row[MYSQL_NAME], "</span>"); } } #endif #ifdef USE_AYYI //is the file loaded in the current Ayyi song? if(ayyi.got_song){ gchar* fullpath = g_build_filename(row[MYSQL_DIR], name, NULL); if(pool__file_exists(fullpath)) dbg(0, "exists"); else dbg(0, "doesnt exist"); g_free(fullpath); } #endif //icon (only shown if the sound file is currently available): if(online){ MIME_type* mime_type = mime_type_lookup(row[MYSQL_MIMETYPE]); type_to_icon(mime_type); if ( ! mime_type->image ) dbg(0, "no icon."); iconbuf = mime_type->image->sm_pixbuf; } else iconbuf = NULL; #if 0 //strip the homedir from the dir string: char* path = strstr(row[MYSQL_DIR], g_get_home_dir()); path = path ? path + strlen(g_get_home_dir()) + 1 : row[MYSQL_DIR]; #endif gtk_list_store_append(app.store, &iter); gtk_list_store_set(app.store, &iter, COL_ICON, iconbuf, #ifdef USE_AYYI COL_AYYI_ICON, ayyi_icon, #endif COL_IDX, atoi(row[MYSQL_ID]), COL_NAME, name, COL_FNAME, row[MYSQL_DIR], COL_KEYWORDS, keywords, COL_OVERVIEW, pixbuf, COL_LENGTH, length, COL_SAMPLERATE, samplerate_s, COL_CHANNELS, channels, COL_MIMETYPE, row[MYSQL_MIMETYPE], COL_NOTES, row[MYSQL_NOTES], COL_COLOUR, colour, -1); if(pixbuf) g_object_unref(pixbuf); #if 0 if(app.no_gui){ printf(" %s\n", name); } #endif }
void doppelganger_set_image (Doppelganger *dg, GdkPixbuf *pixbuf) { GdkPixbuf *scaled = NULL; GdkPixdata black_arrow_data; GdkPixbuf *black_arrow; GdkPixbuf *cursor_image; gboolean preexisting = dg->cursor!=NULL; if (!gdk_pixdata_deserialize (&black_arrow_data, -1, black_cursor, NULL) || black_cursor == NULL) { /* This won't happen in practice, so it can be fatal */ g_error ("Failed to deseralise pointer."); } black_arrow = gdk_pixbuf_from_pixdata (&black_arrow_data, TRUE, NULL); if (pixbuf) { scaled = gdk_pixbuf_scale_simple (pixbuf, 64, 64, GDK_INTERP_BILINEAR); /* * Composite a black arrow onto the top left-hand * corner. */ gdk_pixbuf_composite (black_arrow, scaled, 0, 0, 13, 21, 0.0, 0.0, 1.0, 1.0, GDK_INTERP_NEAREST, 255); gdk_pixbuf_unref (black_arrow); cursor_image = scaled; } else { cursor_image = black_arrow; } if (preexisting) { gdk_cursor_unref (dg->cursor); } dg->cursor = gdk_cursor_new_from_pixbuf (gdk_display_get_default (), cursor_image, 1, 1); gdk_pixbuf_unref (cursor_image); #if 0 if (preexisting) { XIEventMask mask = { dg->mpx, 0, "" }; if (XIUngrabDevice (gdk_x11_get_default_xdisplay (), dg->mpx, CurrentTime) != GrabSuccess) { g_warning ("Ungrab failed."); } if (XIGrabDevice (gdk_x11_get_default_xdisplay (), dg->mpx, GDK_ROOT_WINDOW(), CurrentTime, gdk_x11_cursor_get_xcursor (dg->cursor), GrabModeAsync, GrabModeAsync, True, &mask) != GrabSuccess) { g_warning ("Grab failed."); } } #endif }