bool ConfigDialog::createWindow () { // Create the dialog window mDialog = gtk_dialog_new_with_buttons ( "OGRE Engine Setup", NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); mOKButton = gtk_dialog_add_button (GTK_DIALOG (mDialog), GTK_STOCK_OK, GTK_RESPONSE_OK); gtk_window_set_position (GTK_WINDOW (mDialog), GTK_WIN_POS_CENTER); gtk_window_set_resizable (GTK_WINDOW (mDialog), FALSE); gtk_widget_show (GTK_DIALOG (mDialog)->vbox); GtkWidget *vbox = gtk_vbox_new (FALSE, 5); gtk_widget_show (vbox); gtk_box_pack_start (GTK_BOX (GTK_DIALOG (mDialog)->vbox), vbox, TRUE, TRUE, 0); // Unpack the image and create a GtkImage object from it try { static String imgType ("png"); Image img; MemoryDataStream *imgStream; DataStreamPtr imgStreamPtr; imgStream = new MemoryDataStream (GLX_backdrop_data, sizeof (GLX_backdrop_data), false); imgStreamPtr = DataStreamPtr (imgStream); img.load (imgStreamPtr, imgType); PixelBox src = img.getPixelBox (0, 0); size_t width = img.getWidth (); size_t height = img.getHeight (); // Convert and copy image -- must be allocated with malloc uint8 *data = (uint8 *)malloc (width * height * 4); // Keep in mind that PixelBox does not free the data - this is ok // as gtk takes pixel data ownership in gdk_pixbuf_new_from_data PixelBox dst (src, PF_A8B8G8R8, data); PixelUtil::bulkPixelConversion (src, dst); GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data ( (const guchar *)dst.data, GDK_COLORSPACE_RGB, true, 8, width, height, width * 4, backdrop_destructor, NULL); GtkWidget *ogre_logo = gtk_image_new_from_pixbuf (pixbuf); gdk_pixbuf_unref (pixbuf); gtk_widget_show (ogre_logo); gtk_box_pack_start (GTK_BOX (vbox), ogre_logo, FALSE, FALSE, 0); } catch (Exception &e) { // Could not decode image; never mind LogManager::getSingleton().logMessage("WARNING: Failed to decode Ogre logo image"); } GtkWidget *rs_hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), rs_hbox, FALSE, TRUE, 0); GtkWidget *rs_label = gtk_label_new ("Rendering subsystem:"); gtk_widget_show (rs_label); gtk_box_pack_start (GTK_BOX (rs_hbox), rs_label, TRUE, TRUE, 5); gtk_label_set_justify (GTK_LABEL (rs_label), GTK_JUSTIFY_RIGHT); gtk_misc_set_alignment (GTK_MISC (rs_label), 1, 0.5); GtkWidget *rs_cb = gtk_combo_box_new_text (); gtk_widget_show (rs_cb); gtk_box_pack_start (GTK_BOX (rs_hbox), rs_cb, TRUE, TRUE, 5); g_signal_connect (G_OBJECT (rs_cb), "changed", G_CALLBACK (rendererChanged), this); // Add all available renderers to the combo box const RenderSystemList &renderers = Root::getSingleton ().getAvailableRenderers (); uint idx = 0, sel_renderer_idx = 0; for (RenderSystemList::const_iterator r = renderers.begin(); r != renderers.end (); r++, idx++) { gtk_combo_box_append_text (GTK_COMBO_BOX (rs_cb), (*r)->getName ().c_str ()); if (mSelectedRenderSystem == *r) sel_renderer_idx = idx; } // Don't show the renderer choice combobox if there's just one renderer if (idx > 1) gtk_widget_show (rs_hbox); GtkWidget *ro_frame = gtk_frame_new (NULL); gtk_widget_show (ro_frame); gtk_box_pack_start (GTK_BOX (vbox), ro_frame, TRUE, TRUE, 0); GtkWidget *ro_label = gtk_label_new ("Renderer options:"); gtk_widget_show (ro_label); gtk_frame_set_label_widget (GTK_FRAME (ro_frame), ro_label); gtk_label_set_use_markup (GTK_LABEL (ro_label), TRUE); mParamTable = gtk_table_new (0, 0, FALSE); gtk_widget_show (mParamTable); gtk_container_add (GTK_CONTAINER (ro_frame), mParamTable); gtk_combo_box_set_active (GTK_COMBO_BOX (rs_cb), sel_renderer_idx); return true; }
static GdkPixbuf* tvtj_exif_extract_thumbnail (const guchar *data, guint length, gint size) { TvtjExif exif; guint offset; /* make sure we have enough data */ if (G_UNLIKELY (length < 6 + 8)) return NULL; /* validate Exif header */ if (memcmp (data, "Exif\0\0", 6) != 0) return NULL; /* advance to TIFF header */ data += 6; length -= 6; /* setup Exif data struct */ memset (&exif, 0, sizeof (exif)); exif.data_ptr = data; exif.data_len = length; /* determine byte order */ if (memcmp (data, "II", 2) == 0) exif.big_endian = FALSE; else if (memcmp (data, "MM", 2) == 0) exif.big_endian = TRUE; else return NULL; /* validate the TIFF header */ if (tvtj_exif_get_ushort (&exif, data + 2) != 0x2a) return NULL; /* determine the first IFD offset */ offset = tvtj_exif_get_ulong (&exif, data + 4); /* validate the offset */ if (G_LIKELY (offset < length)) { /* parse the first IFD (recursively parses the remaining...) */ tvtj_exif_parse_ifd (&exif, data + offset, length - offset, NULL); /* check thumbnail compression type */ if (G_LIKELY (exif.thumb_compression == 6)) /* JPEG */ { /* check if we have a valid thumbnail JPEG */ if (exif.thumb.thumb_jpeg.offset > 0 && exif.thumb.thumb_jpeg.length > 0 && exif.thumb.thumb_jpeg.offset + exif.thumb.thumb_jpeg.length <= length) { /* try to load the embedded thumbnail JPEG */ return tvtj_jpeg_load (data + exif.thumb.thumb_jpeg.offset, exif.thumb.thumb_jpeg.length, size); } } else if (exif.thumb_compression == 1) /* Uncompressed */ { /* check if we have a valid thumbnail (current only RGB interpretations) */ if (G_LIKELY (exif.thumb.thumb_tiff.interp == 2) && exif.thumb.thumb_tiff.offset > 0 && exif.thumb.thumb_tiff.length > 0 && exif.thumb.thumb_tiff.offset + exif.thumb.thumb_tiff.length <= length && exif.thumb.thumb_tiff.height * exif.thumb.thumb_tiff.width == exif.thumb.thumb_tiff.length) { /* plain RGB data, just what we need for a GdkPixbuf */ return gdk_pixbuf_new_from_data (g_memdup (data + exif.thumb.thumb_tiff.offset, exif.thumb.thumb_tiff.length), GDK_COLORSPACE_RGB, FALSE, 8, exif.thumb.thumb_tiff.width, exif.thumb.thumb_tiff.height, exif.thumb.thumb_tiff.width, (GdkPixbufDestroyNotify) g_free, NULL); } } } return NULL; }
void S9xGTKDisplayDriver::output (void *src, int src_pitch, int x, int y, int width, int height, int dst_width, int dst_height) { if (width != gdk_buffer_width || height != gdk_buffer_height) { gdk_buffer_width = width; gdk_buffer_height = height; gdk_pixbuf_unref (pixbuf); padded_buffer[2] = realloc (padded_buffer[2], gdk_buffer_width * gdk_buffer_height * 3); pixbuf = gdk_pixbuf_new_from_data ((guchar *) padded_buffer[2], GDK_COLORSPACE_RGB, FALSE, 8, gdk_buffer_width, gdk_buffer_height, gdk_buffer_width * 3, NULL, NULL); } if (last_known_width != dst_width || last_known_height != dst_height) { clear (); last_known_width = dst_width; last_known_height = dst_height; } S9xConvert (src, padded_buffer[2], src_pitch, gdk_buffer_width * 3, width, height, 24); cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (drawing_area)); gdk_cairo_set_source_pixbuf (cr, pixbuf, x, y); if (width != dst_width || height != dst_height) { cairo_matrix_t matrix; cairo_pattern_t *pattern = cairo_get_source (cr);; cairo_matrix_init_identity (&matrix); cairo_matrix_scale (&matrix, (double) width / (double) dst_width, (double) height / (double) dst_height); cairo_matrix_translate (&matrix, -x, -y); cairo_pattern_set_matrix (pattern, &matrix); cairo_pattern_set_filter (pattern, config->bilinear_filter ? CAIRO_FILTER_BILINEAR : CAIRO_FILTER_NEAREST); } cairo_rectangle (cr, x, y, dst_width, dst_height); cairo_fill (cr); cairo_destroy (cr); window->set_mouseable_area (x, y, width, height); return; }
gboolean _gst_playbin_get_current_frame (GstElement *playbin, int video_fps_n, int video_fps_d, FrameReadyCallback cb, gpointer user_data) { ScreenshotData *data; GstCaps *to_caps; GstSample *sample; GstCaps *sample_caps; GstStructure *s; int outwidth; int outheight; data = g_new0 (ScreenshotData, 1); data->cb = cb; data->user_data = user_data; /* our desired output format (RGB24) */ to_caps = gst_caps_new_simple ("video/x-raw", "format", G_TYPE_STRING, "RGB", /* Note: we don't ask for a specific width/height here, so that * videoscale can adjust dimensions from a non-1/1 pixel aspect * ratio to a 1/1 pixel-aspect-ratio. We also don't ask for a * specific framerate, because the input framerate won't * necessarily match the output framerate if there's a deinterlacer * in the pipeline. */ "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL); /* get frame */ sample = NULL; g_signal_emit_by_name (playbin, "convert-sample", to_caps, &sample); gst_caps_unref (to_caps); if (sample == NULL) { g_warning ("Could not take screenshot: %s", "failed to retrieve or convert video frame"); screenshot_data_finalize (data); return FALSE; } sample_caps = gst_sample_get_caps (sample); if (sample_caps == NULL) { g_warning ("Could not take screenshot: %s", "no caps on output buffer"); return FALSE; } s = gst_caps_get_structure (sample_caps, 0); gst_structure_get_int (s, "width", &outwidth); gst_structure_get_int (s, "height", &outheight); if ((outwidth > 0) && (outheight > 0)) { GstMemory *memory; GstMapInfo info; memory = gst_buffer_get_memory (gst_sample_get_buffer (sample), 0); gst_memory_map (memory, &info, GST_MAP_READ); data->pixbuf = gdk_pixbuf_new_from_data (info.data, GDK_COLORSPACE_RGB, FALSE, 8, outwidth, outheight, GST_ROUND_UP_4 (outwidth * 3), destroy_pixbuf, sample); gst_memory_unmap (memory, &info); } if (data->pixbuf == NULL) g_warning ("Could not take screenshot: %s", "could not create pixbuf"); screenshot_data_finalize (data); return TRUE; }
int loadImage( struct pixel * rgbImage) { GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data((unsigned char*)rgbImage, GDK_COLORSPACE_RGB, FALSE, 8, CAMERA_WIDTH, CAMERA_HEIGHT, CAMERA_WIDTH * 3, NULL, NULL); gtk_image_set_from_pixbuf((GtkImage*) image, pixbuf); //gtk_widget_queue_draw(image); }
int main (int argc, char **argv) { int i; int found_valid = FALSE; GdkPixbuf *pixbuf; GdkPixbufLoader *pixbuf_loader; gtk_init (&argc, &argv); gdk_rgb_set_verbose (TRUE); gdk_rgb_init (); gtk_widget_set_default_colormap (gdk_rgb_get_cmap ()); gtk_widget_set_default_visual (gdk_rgb_get_visual ()); { char *tbf_readlen = getenv("TBF_READLEN"); if(tbf_readlen) readlen = atoi(tbf_readlen); } { char *tbf_bps = getenv("TBF_KBPS"); guint bps; if (tbf_bps) { bps = atoi(tbf_bps); g_print ("Simulating %d kBytes/sec\n", bps); readlen = (bps*1024)/10; } } i = 1; if (argc == 1) { const gchar*** xpmp; pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3, NULL, NULL); new_testrgb_window (pixbuf, NULL); xpmp = xpms; while (*xpmp) { pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp); new_testrgb_window (pixbuf, NULL); ++xpmp; } found_valid = TRUE; } else { for (i = 1; i < argc; i++) { pixbuf = gdk_pixbuf_new_from_file (argv[i]); #if 0 pixbuf = gdk_pixbuf_rotate(pixbuf, 10.0); #endif if (pixbuf) { new_testrgb_window (pixbuf, "File"); found_valid = TRUE; } } #if 1 { GtkWidget* rgb_window = NULL; ProgressFileStatus status; pixbuf_loader = gdk_pixbuf_loader_new (); status.loader = pixbuf_loader; status.rgbwin = &rgb_window; status.buf = g_malloc (readlen); gtk_signal_connect(GTK_OBJECT(pixbuf_loader), "area_prepared", GTK_SIGNAL_FUNC(progressive_prepared_callback), &rgb_window); gtk_signal_connect(GTK_OBJECT(pixbuf_loader), "area_updated", GTK_SIGNAL_FUNC(progressive_updated_callback), &rgb_window); status.imagefile = fopen (argv[1], "r"); g_assert (status.imagefile != NULL); status.readlen = readlen; status.timeout = gtk_timeout_add(100, update_timeout, &status); } #endif } if (found_valid) gtk_main (); return 0; }
static GdkPixbuf * tiff_image_parse (TIFF *tiff, TiffContext *context, GError **error) { guchar *pixels = NULL; gint width, height, rowstride, bytes; GdkPixbuf *pixbuf; uint16 orientation = 0; uint16 transform = 0; uint16 codec; gchar *icc_profile_base64; const gchar *icc_profile; guint icc_profile_size; gint retval; /* We're called with the lock held. */ g_return_val_if_fail (global_error == NULL, NULL); if (!TIFFGetField (tiff, TIFFTAG_IMAGEWIDTH, &width) || global_error) { tiff_set_error (error, GDK_PIXBUF_ERROR_FAILED, _("Could not get image width (bad TIFF file)")); return NULL; } if (!TIFFGetField (tiff, TIFFTAG_IMAGELENGTH, &height) || global_error) { tiff_set_error (error, GDK_PIXBUF_ERROR_FAILED, _("Could not get image height (bad TIFF file)")); return NULL; } if (width <= 0 || height <= 0) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Width or height of TIFF image is zero")); return NULL; } rowstride = width * 4; if (rowstride / 4 != width) { /* overflow */ g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Dimensions of TIFF image too large")); return NULL; } bytes = height * rowstride; if (bytes / rowstride != height) { /* overflow */ g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Dimensions of TIFF image too large")); return NULL; } if (context && context->size_func) { gint w = width; gint h = height; (* context->size_func) (&w, &h, context->user_data); /* This is a signal that this function is being called to support gdk_pixbuf_get_file_info, so we can stop parsing the tiff file at this point. It is not an error condition. */ if (w == 0 || h == 0) return NULL; } pixels = g_try_malloc (bytes); if (!pixels) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, _("Insufficient memory to open TIFF file")); return NULL; } pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, width, height, rowstride, free_buffer, NULL); if (!pixbuf) { g_free (pixels); g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, _("Insufficient memory to open TIFF file")); return NULL; } /* Set the "orientation" key associated with this image. libtiff orientation handling is odd, so further processing is required by higher-level functions based on this tag. If the embedded orientation tag is 1-4, libtiff flips/mirrors the image as required, and no client processing is required - so we report no orientation. Orientations 5-8 require rotations which would swap the width and height of the image. libtiff does not do this. Instead it interprets orientations 5-8 the same as 1-4. See http://bugzilla.remotesensing.org/show_bug.cgi?id=1548. To correct for this, the client must apply the transform normally used for orientation 5 to both orientations 5 and 7, and apply the transform normally used for orientation 7 for both orientations 6 and 8. Then everythings works out OK! */ TIFFGetField (tiff, TIFFTAG_ORIENTATION, &orientation); switch (orientation) { case 5: case 7: transform = 5; break; case 6: case 8: transform = 7; break; default: transform = 0; break; } if (transform > 0 ) { gchar str[5]; g_snprintf (str, sizeof (str), "%d", transform); gdk_pixbuf_set_option (pixbuf, "orientation", str); } TIFFGetField (tiff, TIFFTAG_COMPRESSION, &codec); if (codec > 0) { gchar str[5]; g_snprintf (str, sizeof (str), "%d", codec); gdk_pixbuf_set_option (pixbuf, "compression", str); } /* Extract embedded ICC profile */ retval = TIFFGetField (tiff, TIFFTAG_ICCPROFILE, &icc_profile_size, &icc_profile); if (retval == 1) { icc_profile_base64 = g_base64_encode ((const guchar *) icc_profile, icc_profile_size); gdk_pixbuf_set_option (pixbuf, "icc-profile", icc_profile_base64); g_free (icc_profile_base64); } if (context && context->prepare_func) (* context->prepare_func) (pixbuf, NULL, context->user_data); if (!TIFFReadRGBAImageOriented (tiff, width, height, (uint32 *)pixels, ORIENTATION_TOPLEFT, 1) || global_error) { tiff_set_error (error, GDK_PIXBUF_ERROR_FAILED, _("Failed to load RGB data from TIFF file")); g_object_unref (pixbuf); return NULL; } #if G_BYTE_ORDER == G_BIG_ENDIAN /* Turns out that the packing used by TIFFRGBAImage depends on * the host byte order... */ while (pixels < pixbuf->pixels + bytes) { uint32 pixel = *(uint32 *)pixels; int r = TIFFGetR(pixel); int g = TIFFGetG(pixel); int b = TIFFGetB(pixel); int a = TIFFGetA(pixel); *pixels++ = r; *pixels++ = g; *pixels++ = b; *pixels++ = a; } #endif if (context && context->update_func) (* context->update_func) (pixbuf, 0, 0, width, height, context->user_data); return pixbuf; }
/** * gdk_pixbuf_from_pixdata: * @pixdata: a #GdkPixdata to convert into a #GdkPixbuf. * @copy_pixels: whether to copy raw pixel data; run-length encoded * pixel data is always copied. * @error: location to store possible errors. * * Converts a #GdkPixdata to a #GdkPixbuf. If @copy_pixels is %TRUE or * if the pixel data is run-length-encoded, the pixel data is copied into * newly-allocated memory; otherwise it is reused. * * Returns: (transfer full): a new #GdkPixbuf. * Deprecated: 2.32: Use #GResource instead. **/ GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, gboolean copy_pixels, GError **error) { guint encoding, bpp; guint8 *data = NULL; g_return_val_if_fail (pixdata != NULL, NULL); g_return_val_if_fail (pixdata->width > 0, NULL); g_return_val_if_fail (pixdata->height > 0, NULL); g_return_val_if_fail (pixdata->rowstride >= pixdata->width, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB || (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_SAMPLE_WIDTH_MASK) == GDK_PIXDATA_SAMPLE_WIDTH_8, NULL); g_return_val_if_fail ((pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RAW || (pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK) == GDK_PIXDATA_ENCODING_RLE, NULL); g_return_val_if_fail (pixdata->pixel_data != NULL, NULL); bpp = (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGB ? 3 : 4; encoding = pixdata->pixdata_type & GDK_PIXDATA_ENCODING_MASK; g_debug ("gdk_pixbuf_from_pixdata() called on:"); g_debug ("\tEncoding %s", encoding == GDK_PIXDATA_ENCODING_RAW ? "raw" : "rle"); g_debug ("\tDimensions: %d x %d", pixdata->width, pixdata->height); g_debug ("\tRowstride: %d, Length: %d", pixdata->rowstride, pixdata->length); g_debug ("\tCopy pixels == %s", copy_pixels ? "true" : "false"); if (encoding == GDK_PIXDATA_ENCODING_RLE) copy_pixels = TRUE; /* Sanity check the length and dimensions */ if (SIZE_OVERFLOWS (pixdata->height, pixdata->rowstride)) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } if (encoding == GDK_PIXDATA_ENCODING_RAW && pixdata->length >= 1 && pixdata->length < pixdata->height * pixdata->rowstride - GDK_PIXDATA_HEADER_LENGTH) { g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } if (copy_pixels) { data = g_try_malloc_n (pixdata->height, pixdata->rowstride); if (!data) { g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, g_dngettext(GETTEXT_PACKAGE, "failed to allocate image buffer of %u byte", "failed to allocate image buffer of %u bytes", pixdata->rowstride * pixdata->height), pixdata->rowstride * pixdata->height); return NULL; } } if (encoding == GDK_PIXDATA_ENCODING_RLE) { const guint8 *rle_buffer = pixdata->pixel_data; guint8 *rle_buffer_limit = NULL; guint8 *image_buffer = data; guint8 *image_limit = data + pixdata->rowstride * pixdata->height; gboolean check_overrun = FALSE; if (pixdata->length >= 1) rle_buffer_limit = pixdata->pixel_data + pixdata->length - GDK_PIXDATA_HEADER_LENGTH; while (image_buffer < image_limit && (rle_buffer_limit != NULL || rle_buffer > rle_buffer_limit)) { guint length; if (RLE_OVERRUN(1)) { check_overrun = TRUE; break; } length = *(rle_buffer++); if (length & 128) { length = length - 128; check_overrun = image_buffer + length * bpp > image_limit; if (check_overrun) length = (image_limit - image_buffer) / bpp; if (RLE_OVERRUN(bpp < 4 ? 3 : 4)) { check_overrun = TRUE; break; } if (bpp < 4) /* RGB */ do { memcpy (image_buffer, rle_buffer, 3); image_buffer += 3; } while (--length); else /* RGBA */ do { memcpy (image_buffer, rle_buffer, 4); image_buffer += 4; } while (--length); if (RLE_OVERRUN(bpp)) { check_overrun = TRUE; break; } rle_buffer += bpp; } else { length *= bpp; check_overrun = image_buffer + length > image_limit; if (check_overrun) length = image_limit - image_buffer; if (RLE_OVERRUN(length)) { check_overrun = TRUE; break; } memcpy (image_buffer, rle_buffer, length); image_buffer += length; rle_buffer += length; } } if (check_overrun) { g_free (data); g_set_error_literal (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_CORRUPT_IMAGE, _("Image pixel data corrupt")); return NULL; } } else if (copy_pixels) memcpy (data, pixdata->pixel_data, pixdata->rowstride * pixdata->height); else data = pixdata->pixel_data; return gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, (pixdata->pixdata_type & GDK_PIXDATA_COLOR_TYPE_MASK) == GDK_PIXDATA_COLOR_TYPE_RGBA, 8, pixdata->width, pixdata->height, pixdata->rowstride, copy_pixels ? (GdkPixbufDestroyNotify) g_free : NULL, data); }
static void _view_map_changed_callback(OsmGpsMap *map, dt_view_t *self) { dt_map_t *lib = (dt_map_t *)self->data; const int ts = 64; OsmGpsMapPoint bb[2]; /* get bounding box coords */ osm_gps_map_get_bbox(map, &bb[0], &bb[1]); float bb_0_lat = 0.0, bb_0_lon = 0.0, bb_1_lat = 0.0, bb_1_lon = 0.0; osm_gps_map_point_get_degrees(&bb[0], &bb_0_lat, &bb_0_lon); osm_gps_map_point_get_degrees(&bb[1], &bb_1_lat, &bb_1_lon); /* make the bounding box a little bigger to the west and south */ float lat0 = 0.0, lon0 = 0.0, lat1 = 0.0, lon1 = 0.0; OsmGpsMapPoint *pt0 = osm_gps_map_point_new_degrees(0.0, 0.0), *pt1 = osm_gps_map_point_new_degrees(0.0, 0.0); osm_gps_map_convert_screen_to_geographic(map, 0, 0, pt0); osm_gps_map_convert_screen_to_geographic(map, 1.5*ts, 1.5*ts, pt1); osm_gps_map_point_get_degrees(pt0, &lat0, &lon0); osm_gps_map_point_get_degrees(pt1, &lat1, &lon1); osm_gps_map_point_free(pt0); osm_gps_map_point_free(pt1); double south_border = lat0 - lat1, west_border = lon1 - lon0; /* get map view state and store */ int zoom; float center_lat, center_lon; g_object_get(G_OBJECT(map), "zoom", &zoom, "latitude", ¢er_lat, "longitude", ¢er_lon, NULL); dt_conf_set_float("plugins/map/longitude", center_lon); dt_conf_set_float("plugins/map/latitude", center_lat); dt_conf_set_int("plugins/map/zoom", zoom); /* let's reset and reuse the main_query statement */ DT_DEBUG_SQLITE3_CLEAR_BINDINGS(lib->statements.main_query); DT_DEBUG_SQLITE3_RESET(lib->statements.main_query); /* bind bounding box coords for the main query */ DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 1, bb_0_lon - west_border); DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 2, bb_1_lon); DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 3, bb_0_lat); DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 4, bb_1_lat - south_border); DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 5, center_lat); DT_DEBUG_SQLITE3_BIND_DOUBLE(lib->statements.main_query, 6, center_lon); /* remove the old images */ osm_gps_map_image_remove_all(map); if(lib->images) { g_slist_foreach(lib->images, (GFunc) g_free, NULL); g_slist_free(lib->images); lib->images = NULL; } /* add all images to the map */ gboolean needs_redraw = FALSE; dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, ts, ts); while(sqlite3_step(lib->statements.main_query) == SQLITE_ROW) { int imgid = sqlite3_column_int(lib->statements.main_query, 0); dt_mipmap_buffer_t buf; dt_mipmap_cache_read_get(darktable.mipmap_cache, &buf, imgid, mip, DT_MIPMAP_BEST_EFFORT); if(buf.buf) { uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache); uint8_t *buf_decompressed = dt_mipmap_cache_decompress(&buf, scratchmem); uint8_t *rgbbuf = g_malloc((buf.width+2)*(buf.height+2)*3); memset(rgbbuf, 64, (buf.width+2)*(buf.height+2)*3); for(int i=1; i<=buf.height; i++) for(int j=1; j<=buf.width; j++) for(int k=0; k<3; k++) rgbbuf[(i*(buf.width+2)+j)*3+k] = buf_decompressed[((i-1)*buf.width+j-1)*4+2-k]; int w=ts, h=ts; if(buf.width < buf.height) w = (buf.width*ts)/buf.height; // portrait else h = (buf.height*ts)/buf.width; // landscape GdkPixbuf *source = gdk_pixbuf_new_from_data(rgbbuf, GDK_COLORSPACE_RGB, FALSE, 8, (buf.width+2), (buf.height+2), (buf.width+2)*3, NULL, NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source, w, h, GDK_INTERP_HYPER); //TODO: add back the arrow on the left lower corner of the image, pointing to the location const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, imgid); dt_map_image_t *entry = (dt_map_image_t*)g_malloc(sizeof(dt_map_image_t)); entry->imgid = imgid; entry->image = osm_gps_map_image_add_with_alignment(map, cimg->latitude, cimg->longitude, scaled, 0, 1); entry->width = w; entry->height = h; lib->images = g_slist_prepend(lib->images, entry); dt_image_cache_read_release(darktable.image_cache, cimg); if(source) g_object_unref(source); if(scaled) g_object_unref(scaled); g_free(rgbbuf); } else needs_redraw = TRUE; dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); } // not exactly thread safe, but should be good enough for updating the display static int timeout_event_source = 0; if(needs_redraw && timeout_event_source == 0) timeout_event_source = g_timeout_add_seconds(1, _view_map_redraw, self); // try again in a second, maybe some pictures have loaded by then else timeout_event_source = 0; }
static void rc_prepare_post_process_lut(RendererClutter *rc) { PixbufRenderer *pr = rc->pr; static guchar clut[CLUT_SIZE * CLUT_SIZE * CLUT_SIZE * 3]; guint r, g, b; GdkPixbuf *tmp_pixbuf; CoglHandle material; CoglHandle tex3d; DEBUG_3("%s clut start", get_exec_time()); for (r = 0; r < CLUT_SIZE; r++) { for (g = 0; g < CLUT_SIZE; g++) { for (b = 0; b < CLUT_SIZE; b++) { guchar *ptr = clut + ((b * CLUT_SIZE + g) * CLUT_SIZE + r) * 3; ptr[0] = floor ((double) r / (CLUT_SIZE - 1) * 255.0 + 0.5); ptr[1] = floor ((double) g / (CLUT_SIZE - 1) * 255.0 + 0.5); ptr[2] = floor ((double) b / (CLUT_SIZE - 1) * 255.0 + 0.5); } } } tmp_pixbuf = gdk_pixbuf_new_from_data(clut, GDK_COLORSPACE_RGB, FALSE, 8, CLUT_SIZE * CLUT_SIZE, CLUT_SIZE, CLUT_SIZE * CLUT_SIZE * 3, NULL, NULL); if (pr->func_post_process) { pr->func_post_process(pr, &tmp_pixbuf, 0, 0, CLUT_SIZE * CLUT_SIZE, CLUT_SIZE, pr->post_process_user_data); } g_object_unref(tmp_pixbuf); DEBUG_3("%s clut upload start", get_exec_time()); #if COGL_VERSION_CHECK(1,18,2) { CoglContext *ctx = clutter_backend_get_cogl_context(clutter_get_default_backend ()); tex3d = cogl_texture_3d_new_from_data(ctx, CLUT_SIZE, CLUT_SIZE, CLUT_SIZE, COGL_PIXEL_FORMAT_RGB_888, CLUT_SIZE * 3, CLUT_SIZE * CLUT_SIZE * 3, clut, NULL); } #elif COGL_VERSION_CHECK(1,10,4) { CoglContext *ctx = clutter_backend_get_cogl_context(clutter_get_default_backend ()); tex3d = cogl_texture_3d_new_from_data(ctx, CLUT_SIZE, CLUT_SIZE, CLUT_SIZE, COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888, CLUT_SIZE * 3, CLUT_SIZE * CLUT_SIZE * 3, clut, NULL); } #else tex3d = cogl_texture_3d_new_from_data(CLUT_SIZE, CLUT_SIZE, CLUT_SIZE, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888, CLUT_SIZE * 3, CLUT_SIZE * CLUT_SIZE * 3, clut, NULL); #endif material = clutter_texture_get_cogl_material(CLUTTER_TEXTURE(rc->texture)); cogl_material_set_layer(material, 1, tex3d); cogl_handle_unref(tex3d); DEBUG_3("%s clut end", get_exec_time()); rc->clut_updated = TRUE; }
/** * gdk_pixdata_from_pixbuf: (skip) * @pixdata: a #GdkPixdata to fill. * @pixbuf: the data to fill @pixdata with. * @use_rle: whether to use run-length encoding for the pixel data. * * Converts a #GdkPixbuf to a #GdkPixdata. If @use_rle is %TRUE, the * pixel data is run-length encoded into newly-allocated memory and a * pointer to that memory is returned. * * Returns: (nullable): If @use_rle is %TRUE, a pointer to the * newly-allocated memory for the run-length encoded pixel data, * otherwise %NULL. * * Deprecated: 2.32: Use #GResource instead. **/ gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata, const GdkPixbuf *pixbuf, gboolean use_rle) { gpointer free_me = NULL; guint height, rowstride, encoding, bpp, length; guint8 *img_buffer; g_return_val_if_fail (pixdata != NULL, NULL); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); g_return_val_if_fail (pixbuf->bits_per_sample == 8, NULL); g_return_val_if_fail ((pixbuf->n_channels == 3 && !pixbuf->has_alpha) || (pixbuf->n_channels == 4 && pixbuf->has_alpha), NULL); g_return_val_if_fail (pixbuf->rowstride >= pixbuf->width, NULL); height = pixbuf->height; rowstride = pixbuf->rowstride; bpp = pixbuf->has_alpha ? 4 : 3; encoding = use_rle && ((rowstride / bpp | height) > 1) ? GDK_PIXDATA_ENCODING_RLE : GDK_PIXDATA_ENCODING_RAW; if (encoding == GDK_PIXDATA_ENCODING_RLE) { guint pad, n_bytes = rowstride * height; guint8 *img_buffer_end, *data; GdkPixbuf *buf = NULL; if (n_bytes % bpp != 0) { rowstride = pixbuf->width * bpp; n_bytes = rowstride * height; data = g_malloc (n_bytes); buf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, pixbuf->has_alpha, 8, pixbuf->width, pixbuf->height, rowstride, free_buffer, NULL); gdk_pixbuf_copy_area (pixbuf, 0, 0, pixbuf->width, pixbuf->height, buf, 0, 0); } else buf = (GdkPixbuf *)pixbuf; pad = rowstride; pad = MAX (pad, 130 + n_bytes / 127); data = g_new (guint8, pad + n_bytes); free_me = data; img_buffer = data; img_buffer_end = rl_encode_rgbx (img_buffer, buf->pixels, buf->pixels + n_bytes, bpp); length = img_buffer_end - img_buffer; if (buf != pixbuf) g_object_unref (buf); } else { img_buffer = pixbuf->pixels; length = rowstride * height; } pixdata->magic = GDK_PIXBUF_MAGIC_NUMBER; pixdata->length = GDK_PIXDATA_HEADER_LENGTH + length; pixdata->pixdata_type = pixbuf->has_alpha ? GDK_PIXDATA_COLOR_TYPE_RGBA : GDK_PIXDATA_COLOR_TYPE_RGB; pixdata->pixdata_type |= GDK_PIXDATA_SAMPLE_WIDTH_8; pixdata->pixdata_type |= encoding; pixdata->rowstride = rowstride; pixdata->width = pixbuf->width; pixdata->height = height; pixdata->pixel_data = img_buffer; return free_me; }
int main (int argc, char *argv[]) { ClutterActor *video; GdkPixbuf *shot = NULL; gint duration; CoglHandle tex_id; CoglPixelFormat format; gint size; gint width; gint height; gint rowstride; guchar *data = NULL; #ifdef USE_HELIX clutter_helix_init (&argc, &argv); #else gst_init (&argc, &argv); #endif clutter_init (&argc, &argv); if (argc < 3) { g_print ("Usage: %s <path to movie file> <output png>\n", argv[0]); exit(-1); } totem_resources_monitor_start (argv[1], 60 * G_USEC_PER_SEC); #ifdef USE_HELIX video = clutter_helix_video_texture_new (); #else video = clutter_gst_video_texture_new (); #endif if (argv[1][0] == '/') clutter_media_set_filename(CLUTTER_MEDIA(video), argv[1]); else clutter_media_set_uri(CLUTTER_MEDIA(video), argv[1]); clutter_media_set_volume (CLUTTER_MEDIA(video), 0); clutter_media_set_playing (CLUTTER_MEDIA(video), TRUE); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); duration = clutter_media_get_duration (CLUTTER_MEDIA(video)); } while (duration == 0); clutter_actor_realize (video); clutter_media_set_position (CLUTTER_MEDIA(video), duration/3); do { while (g_main_context_pending (NULL)) g_main_context_iteration (NULL, FALSE); } while (clutter_media_get_position (CLUTTER_MEDIA(video)) <= duration/3); tex_id = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (video)); if (tex_id) { format = cogl_texture_get_format (tex_id); size = cogl_texture_get_data (tex_id, format, 0, NULL); width = cogl_texture_get_width (tex_id); height = cogl_texture_get_height (tex_id); rowstride = cogl_texture_get_rowstride (tex_id); data = (guchar*) g_malloc (sizeof(guchar) * size); if (!data) g_error ("malloc");; cogl_texture_get_data (tex_id, format, rowstride, data); shot = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, rowstride, NULL, NULL); } totem_resources_monitor_stop (); if (shot) { GdkPixbuf *thumb, *pic; gint x, y, nw, nh, w, h, size; size = 128; /* FIXME swap RGB pixels */ w = clutter_actor_get_width (video); h = clutter_actor_get_height (video); nh = ( h * size) / w; if (nh <= size) { nw = size; x = 0; y = (size - nh) / 2; } else { nw = ( w * size ) / h; nh = size; x = (size - nw) / 2; y = 0; } thumb = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, size, size); gdk_pixbuf_fill (thumb, 0x000000FF); pic = gdk_pixbuf_scale_simple (shot, nw, nh, GDK_INTERP_BILINEAR); gdk_pixbuf_copy_area (pic, 0, 0, nw, nh, thumb, x, y); if (!gdk_pixbuf_save (thumb, argv[2], "png", NULL, NULL)) { g_error ("%s: Pixbuf save failed\n", argv[0]); exit(-1); } g_object_unref (shot); g_object_unref (thumb); g_object_unref (pic); exit(0); } exit (-1); }
/* [gtk thread] */ static GtkWidget *build_menu_item(ALLEGRO_MENU_ITEM *aitem) { GtkWidget *gitem; if (!aitem->caption) { gitem = gtk_separator_menu_item_new(); } else { ALLEGRO_USTR *caption = al_ustr_dup(aitem->caption); /* convert & to _ using unprintable chars as placeholders */ al_ustr_find_replace_cstr(caption, 0, "_", "\x01\x02"); al_ustr_find_replace_cstr(caption, 0, "&", "_"); al_ustr_find_replace_cstr(caption, 0, "\x01\x02", "__"); if (aitem->flags & ALLEGRO_MENU_ITEM_CHECKBOX) { gitem = gtk_check_menu_item_new_with_mnemonic(al_cstr(caption)); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gitem), aitem->flags & ALLEGRO_MENU_ITEM_CHECKED); g_signal_connect_swapped (gitem, "toggled", G_CALLBACK(checkbox_on_toggle), (gpointer) aitem); } else { /* always create an image menu item, in case the user ever sets an icon */ gitem = gtk_image_menu_item_new_with_mnemonic(al_cstr(caption)); if (aitem->icon) { const int w = al_get_bitmap_width(aitem->icon), h = al_get_bitmap_height(aitem->icon); const int stride = w * 4; int x, y, i; GdkPixbuf *pixbuf; uint8_t *data = al_malloc(stride * h); if (data) { for (y = 0, i = 0; y < h; ++y) { for (x = 0; x < w; ++x, i += 4) { al_unmap_rgba(al_get_pixel(aitem->icon, x, y), &data[i], &data[i + 1], &data[i + 2], &data[i + 3] ); } } pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE, 8, w, h, stride, destroy_pixbuf, NULL); aitem->extra2 = gtk_image_new_from_pixbuf(pixbuf); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(gitem), aitem->extra2); /* Subtract the main reference. the image still holds a reference, so the * pixbuf won't be destroyed until the image itself is. */ g_object_unref(pixbuf); } } } al_ustr_free(caption); gtk_widget_set_sensitive(gitem, !(aitem->flags & ALLEGRO_MENU_ITEM_DISABLED)); aitem->extra1 = gitem; if (aitem->popup) { GtkWidget *gsubmenu = gtk_menu_new(); build_menu(gsubmenu, aitem->popup); aitem->popup->extra1 = gsubmenu; gtk_widget_show(gsubmenu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(gitem), gsubmenu); } else if (aitem->id) { g_signal_connect_swapped (gitem, "activate", G_CALLBACK(menuitem_response), (gpointer) aitem); } } gtk_widget_show(gitem); return gitem; }
int main (int argc, char **argv) { int i; int found_valid = FALSE; GdkPixbuf *pixbuf; GdkPixbufLoader *pixbuf_loader; pixbuf_init (); gtk_init (&argc, &argv); /* gdk_rgb_set_verbose (TRUE);*/ gtk_widget_set_default_colormap (gdk_rgb_get_colormap ()); { char *tbf_readlen = getenv ("TBF_READLEN"); if (tbf_readlen) readlen = atoi (tbf_readlen); } { char *tbf_bps = getenv ("TBF_KBPS"); guint bps; if (tbf_bps) { bps = atoi (tbf_bps); g_print ("Simulating %d kBytes/sec\n", bps); readlen = (bps*1024)/10; } } i = 1; if (argc == 1) { const gchar*** xpmp; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8, DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3, NULL, NULL); new_testrgb_window (pixbuf, NULL); xpmp = xpms; while (*xpmp) { pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp); new_testrgb_window (pixbuf, NULL); ++xpmp; } /* Test loading from inline data. */ pixbuf = gdk_pixbuf_new_from_inline (-1, apple_red, FALSE, &error); if (!pixbuf) { fprintf (stderr, "failed to construct \"red apple\" pixbuf: %s\n", error->message); g_error_free (error); } else new_testrgb_window (pixbuf, "Red apple from inlined RLE data"); pixbuf = gdk_pixbuf_new_from_inline (sizeof (gnome_foot), gnome_foot, TRUE, NULL); new_testrgb_window (pixbuf, "GNOME Foot from inlined RLE data"); found_valid = TRUE; } else { for (i = 1; i < argc; i++) { GError *error; error = NULL; pixbuf = gdk_pixbuf_new_from_file (argv[i], &error); if (pixbuf == NULL) { g_warning ("Error loading image: %s", error->message); g_error_free (error); } #if 0 pixbuf = gdk_pixbuf_rotate (pixbuf, 10.0); #endif if (pixbuf) { new_testrgb_window (pixbuf, "File"); found_valid = TRUE; } } #if 1 { GtkWidget* rgb_window = NULL; ProgressFileStatus status; pixbuf_loader = gdk_pixbuf_loader_new (); status.loader = pixbuf_loader; status.rgbwin = &rgb_window; status.buf = g_malloc (readlen); #if 0 g_signal_connect (pixbuf_loader, "size_prepared", G_CALLBACK (size_func), NULL); #endif g_signal_connect (pixbuf_loader, "area_prepared", G_CALLBACK (progressive_prepared_callback), &rgb_window); g_signal_connect (pixbuf_loader, "area_updated", G_CALLBACK (progressive_updated_callback), &rgb_window); status.imagefile = fopen (argv[1], "r"); g_assert (status.imagefile != NULL); status.readlen = readlen; status.timeout = gdk_threads_add_timeout (100, update_timeout, &status); } #endif } if (found_valid) gtk_main (); return 0; }
static void ocvThread(void){ //if(cvDefined==FALSE){ ttModels theModels; ttInit(&theModels); static GdkPixbuf *pixbuf; IplImage *theFrame, *segmented; static char theStr[12]; thePixel=cvPoint(0,0); //globalFrame=cvCreateImage(size,IPL_DEPTH_8U,3); //char theChar; #if use_webcam==1 CvCapture* theCamera; CvSize size=cvSize(justWidth,justHeight); theCamera=cvCaptureFromCAM(-1); cvSetCaptureProperty( theCamera,CV_CAP_PROP_FRAME_WIDTH,justWidth ); cvSetCaptureProperty( theCamera,CV_CAP_PROP_FRAME_HEIGHT,justHeight ); theFrame=cvCreateImage(size,IPL_DEPTH_8U,3); #else theFrame=cvLoadImage("images/image02.jpg",1); assert(theFrame!=NULL); justWidth=theFrame->width; justHeight=theFrame->height; CvSize size=cvSize(justWidth,justHeight); cvConvertImage(theFrame,theFrame,CV_CVTIMG_SWAP_RB); #endif segmented=cvCreateImage(size,IPL_DEPTH_8U,3); while (1){ #if use_webcam==1 theFrame=cvQueryFrame(theCamera); assert(theFrame!=NULL); cvConvertImage(theFrame,theFrame,CV_CVTIMG_SWAP_RB); #endif if(changeFlag==1){ theRanger.hue=-1; theH=ttCalibration(theFrame,&thePixel,&theRanger,NULL); theRanger.hue=theH; changeFlag=0; //getIndex(); //printf("%d\n",theIndex); //updateLimits(); } ttCalibration(theFrame,&thePixel,&theRanger,segmented); sprintf(theStr,"Hue=%d",theH); getIndex(); //cvShowImage("window",theImage); //theFrame=theImage; //cvWaitKey(5000); gdk_threads_enter(); pixbuf = gdk_pixbuf_new_from_data ((guchar*) theFrame->imageData, GDK_COLORSPACE_RGB, FALSE, theFrame->depth, theFrame->width, theFrame->height, (theFrame->widthStep), NULL, NULL); //printf("\n\nchingadamadre!\n");CV_CVTIMG_SWAP_RB gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); pixbuf = gdk_pixbuf_new_from_data ((guchar*) segmented->imageData, GDK_COLORSPACE_RGB, FALSE, theFrame->depth, theFrame->width, theFrame->height, (theFrame->widthStep), NULL, NULL); gtk_image_set_from_pixbuf(GTK_IMAGE(gseg), pixbuf); gtk_label_set_text((GtkLabel *)hval,theStr); gdk_threads_leave(); //cvWaitKey(); #if use_webcam==0 g_usleep(50000); #endif } }
int32_t dt_control_indexer_job_run(dt_job_t *job) { // if no indexing was requested, bail out: if(!dt_conf_get_bool("run_similarity_indexer")) return 0; /* * First pass run thru ALL images and collect the ones who needs to update * \TODO in the future lets have a indexer table with ids filed with images * thats need some kind of reindexing.. all mark dirty functions adds image * to this table-- */ // temp memory for uncompressed images: uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache); GList *images=NULL; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select images.id,film_rolls.folder||'/'||images.filename,images.histogram,images.lightmap from images,film_rolls where film_rolls.id = images.film_id", -1, &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { _control_indexer_img_t *idximg=g_malloc(sizeof( _control_indexer_img_t)); memset(idximg,0,sizeof(_control_indexer_img_t)); idximg->id = sqlite3_column_int(stmt,0); /* first check if image file exists on disk */ const char *filename = (const char *)sqlite3_column_text(stmt, 1); if (filename && !g_file_test(filename, G_FILE_TEST_IS_REGULAR)) idximg->flags |= _INDEXER_IMAGE_FILE_REMOVED; /* check if histogram should be updated */ if (sqlite3_column_bytes(stmt, 2) != sizeof(dt_similarity_histogram_t)) idximg->flags |= _INDEXER_UPDATE_HISTOGRAM; /* check if lightmap should be updated */ if (sqlite3_column_bytes(stmt, 3) != sizeof(dt_similarity_lightmap_t)) idximg->flags |= _INDEXER_UPDATE_LIGHTMAP; /* if image is flagged add to collection */ if (idximg->flags != 0) images = g_list_append(images, idximg); else g_free(idximg); } sqlite3_finalize(stmt); /* * Second pass, run thru collected images thats * need reindexing... */ GList *imgitem = g_list_first(images); if(imgitem) { char message[512]= {0}; double fraction=0; int total = g_list_length(images); guint *jid = NULL; /* background job plate only if more then one image is reindexed */ if (total > 1) { snprintf(message, 512, ngettext ("re-indexing %d image", "re-indexing %d images", total), total ); jid = (guint *)dt_control_backgroundjobs_create(darktable.control, 0, message); } do { // bail out if we're shutting down: if(!dt_control_running()) break; // if indexer was switched off during runtime, respect that as soon as we can: if(!dt_conf_get_bool("run_similarity_indexer")) break; /* get the _control_indexer_img_t pointer */ _control_indexer_img_t *idximg = imgitem->data; /* * Check if image has been delete from disk */ if ((idximg->flags&_INDEXER_IMAGE_FILE_REMOVED)) { /* file does not exist on disk lets delete image reference from database */ //char query[512]={0}; // \TODO dont delete move to an temp table and let user to revalidate /*sprintf(query,"delete from history where imgid=%d",idximg->id); DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL); sprintf(query,"delete from tagged_images where imgid=%d",idximg->id); DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL); sprintf(query,"delete from images where id=%d",idximg->id); DT_DEBUG_SQLITE3_EXEC(darktable.db, query, NULL, NULL, NULL);*/ /* no need to additional work */ continue; } /* * Check if image histogram or lightmap should be updated. * those indexing that involves a image pipe should fall into this */ if ( (idximg->flags&_INDEXER_UPDATE_HISTOGRAM) || (idximg->flags&_INDEXER_UPDATE_LIGHTMAP) ) { /* get a mipmap of image to analyse */ dt_mipmap_buffer_t buf; dt_mipmap_cache_read_get(darktable.mipmap_cache, &buf, idximg->id, DT_MIPMAP_2, DT_MIPMAP_BLOCKING); // pointer owned by the cache or == scratchmem, no need to free this one: uint8_t *buf_decompressed = dt_mipmap_cache_decompress(&buf, scratchmem); if (!(buf.width * buf.height)) continue; /* * Generate similarity histogram data if requested */ if ( (idximg->flags&_INDEXER_UPDATE_HISTOGRAM) ) { dt_similarity_histogram_t histogram; float bucketscale = (float)DT_SIMILARITY_HISTOGRAM_BUCKETS/(float)0xff; for(int j=0; j<(4*buf.width*buf.height); j+=4) { /* swap rgb and scale to bucket index */ uint8_t rgb[3]; for(int k=0; k<3; k++) rgb[k] = (int)((buf_decompressed[j+2-k]/(float)0xff) * bucketscale); /* distribute rgb into buckets */ for(int k=0; k<3; k++) histogram.rgbl[rgb[k]][k]++; /* distribute lum into buckets */ uint8_t lum = MAX(MAX(rgb[0], rgb[1]), rgb[2]); histogram.rgbl[lum][3]++; } for(int k=0; k<DT_SIMILARITY_HISTOGRAM_BUCKETS; k++) for (int j=0; j<4; j++) histogram.rgbl[k][j] /= (buf.width*buf.height); /* store the histogram data */ dt_similarity_histogram_store(idximg->id, &histogram); } /* * Generate scaledowned similarity lightness map if requested */ if ( (idximg->flags&_INDEXER_UPDATE_LIGHTMAP) ) { dt_similarity_lightmap_t lightmap; memset(&lightmap,0,sizeof(dt_similarity_lightmap_t)); /* * create a pixbuf out of the image for downscaling */ /* first of setup a standard rgb buffer, swap bgr in same routine */ uint8_t *rgbbuf = g_malloc(buf.width*buf.height*3); for(int j=0; j<(buf.width*buf.height); j++) for(int k=0; k<3; k++) rgbbuf[3*j+k] = buf_decompressed[4*j+2-k]; /* then create pixbuf and scale down to lightmap size */ GdkPixbuf *source = gdk_pixbuf_new_from_data(rgbbuf,GDK_COLORSPACE_RGB,FALSE,8,buf.width,buf.height,(buf.width*3),NULL,NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source,DT_SIMILARITY_LIGHTMAP_SIZE,DT_SIMILARITY_LIGHTMAP_SIZE,GDK_INTERP_HYPER); /* copy scaled data into lightmap */ uint8_t min=0xff,max=0; uint8_t *spixels = gdk_pixbuf_get_pixels(scaled); for(int j=0; j<(DT_SIMILARITY_LIGHTMAP_SIZE*DT_SIMILARITY_LIGHTMAP_SIZE); j++) { /* copy rgb */ for(int k=0; k<3; k++) lightmap.pixels[4*j+k] = spixels[3*j+k]; /* average intensity into 4th channel */ lightmap.pixels[4*j+3] = (lightmap.pixels[4*j+0]+ lightmap.pixels[4*j+1]+ lightmap.pixels[4*j+2])/3.0; min = MIN(min, lightmap.pixels[4*j+3]); max = MAX(max, lightmap.pixels[4*j+3]); } /* contrast stretch each channel in lightmap * TODO: do we want this... */ float scale=0; int range = max-min; if(range==0) scale = 1.0; else scale = 0xff/range; for(int j=0; j<(DT_SIMILARITY_LIGHTMAP_SIZE*DT_SIMILARITY_LIGHTMAP_SIZE); j++) { for(int k=0; k<4; k++) lightmap.pixels[4*j+k] = (lightmap.pixels[4*j+k]-min)*scale; } /* free some resources */ g_object_unref(scaled); g_object_unref(source); g_free(rgbbuf); /* store the lightmap */ dt_similarity_lightmap_store(idximg->id, &lightmap); } /* no use for buffer anymore release the mipmap */ dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); } /* update background progress */ if (jid) { fraction+=1.0/total; dt_control_backgroundjobs_progress(darktable.control, jid, fraction); } } while ((imgitem=g_list_next(imgitem)) && dt_control_job_get_state(job) != DT_JOB_STATE_CANCELLED); /* cleanup */ if (jid) dt_control_backgroundjobs_destroy(darktable.control, jid); } free(scratchmem); /* * Indexing opertions finished, lets reschedule the indexer * unless control is shutting down... */ if(dt_control_running()) dt_control_start_indexer(); return 0; }
static GdkPixbuf * load_icon (unsigned size, IN gpointer data, gsize datalen) { guchar *icon = NULL; guchar *mask = NULL; gsize isize = 0, msize = 0, i; guchar *image = NULL; if (!load_resources (size, data, datalen, &icon, &isize, &mask, &msize)) return NULL; /* 256x256 icons don't use RLE or uncompressed data, * They're usually JPEG 2000 images */ if (size == 256) { GdkPixbufLoader *loader; GdkPixbuf *pixbuf; loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, icon, isize, NULL) || !gdk_pixbuf_loader_close (loader, NULL)) { g_object_unref (loader); return NULL; } pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); g_object_ref (pixbuf); g_object_unref (loader); return pixbuf; } g_assert (mask); if (msize != size * size) /* wrong mask size */ return NULL; image = (guchar *) g_try_malloc0 (size * size * 4); /* 4 bytes/pixel = RGBA */ if (!image) return NULL; if (isize == size * size * 4) /* icon data is uncompressed */ for (i = 0; i < size * size; i++) /* 4 bytes/pixel = ARGB (A: ignored) */ { image[i * 4] = icon[4 * i + 1]; /* R */ image[i * 4 + 1] = icon[4 * i + 2]; /* G */ image[i * 4 + 2] = icon[4 * i + 3]; /* B */ } else { guchar *data = icon; gsize remaining = 0; /* R */ if (!uncompress (size, &data, image, &remaining)) goto bail; /* G */ if (!uncompress (size, &data, image + 1, &remaining)) goto bail; /* B */ if (!uncompress (size, &data, image + 2, &remaining)) goto bail; } for (i = 0; i < size * size; i++) /* copy mask to alpha channel */ image[i * 4 + 3] = mask[i]; return gdk_pixbuf_new_from_data ((guchar *) image, GDK_COLORSPACE_RGB, /* RGB image */ TRUE, /* with alpha channel */ 8, /* 8 bits per sample */ size, /* width */ size, /* height */ size * 4, /* no gap between rows */ (GdkPixbufDestroyNotify)g_free, /* free() function */ NULL); /* param to free() function */ bail: g_free (image); return NULL; }
GdkPixbuf * convert_buffer_to_pixbuf (GstBuffer *buffer, GCancellable *cancellable) { GstCaps *pb_caps; GstElement *pipeline; GstBuffer *out_buffer = NULL; GstElement *src, *sink, *colorspace, *scale, *filter; GstBus *bus; GstMessage *msg; GstStateChangeReturn state G_GNUC_UNUSED; gboolean ret; int dw, dh, i; GstStructure *s; s = gst_caps_get_structure (GST_BUFFER_CAPS (buffer), 0); gst_structure_get_int (s, "width", &dw); gst_structure_get_int (s, "height", &dh); pb_caps = gst_caps_new_simple ("video/x-raw-rgb", "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24, "width", G_TYPE_INT, dw, "height", G_TYPE_INT, dh, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL); pipeline = gst_pipeline_new ("pipeline"); src = gst_element_factory_make ("fakesrc", "src"); colorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace"); scale = gst_element_factory_make ("videoscale", "scale"); filter = gst_element_factory_make ("capsfilter", "filter"); sink = gst_element_factory_make ("fakesink", "sink"); gst_bin_add_many (GST_BIN (pipeline), src, colorspace, scale, filter, sink, NULL); g_object_set (filter, "caps", pb_caps, NULL); g_object_set (src, "num-buffers", 1, "sizetype", 2, "sizemax", GST_BUFFER_SIZE (buffer), "signal-handoffs", TRUE, NULL); g_signal_connect (src, "handoff", G_CALLBACK (push_buffer), buffer); g_object_set (sink, "signal-handoffs", TRUE, "preroll-queue-len", 1, NULL); g_signal_connect (sink, "handoff", G_CALLBACK (pull_buffer), &out_buffer); ret = gst_element_link (src, colorspace); if (ret == FALSE) { g_warning ("Failed to link src->colorspace"); return NULL; } ret = gst_element_link (colorspace, scale); if (ret == FALSE) { g_warning ("Failed to link colorspace->scale"); return NULL; } ret = gst_element_link (scale, filter); if (ret == FALSE) { g_warning ("Failed to link scale->filter"); return NULL; } ret = gst_element_link (filter, sink); if (ret == FALSE) { g_warning ("Failed to link filter->sink"); return NULL; } bus = gst_element_get_bus (GST_ELEMENT (pipeline)); state = gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); i = 0; msg = NULL; while (msg == NULL && i < 5) { msg = gst_bus_timed_pop_filtered (bus, GST_SECOND, GST_MESSAGE_ERROR | GST_MESSAGE_EOS); i++; } /* FIXME: Notify about error? */ gst_message_unref (msg); gst_caps_unref (pb_caps); if (out_buffer) { GdkPixbuf *pixbuf; char *data; data = g_memdup (GST_BUFFER_DATA (out_buffer), GST_BUFFER_SIZE (out_buffer)); pixbuf = gdk_pixbuf_new_from_data ((guchar *) data, GDK_COLORSPACE_RGB, FALSE, 8, dw, dh, GST_ROUND_UP_4 (dw * 3), (GdkPixbufDestroyNotify) g_free, NULL); gst_buffer_unref (buffer); return pixbuf; } /* FIXME: Check what buffers need freed */ return NULL; }
GtkWidget *CreateImageButton( const char* image_file_path, const gchar* label, const char* font_file ) { #define DISPLAY_FONT_HEIGHT 8.5 // 貼り付けるイメージ cairo_surface_t *image = cairo_image_surface_create_from_png(image_file_path); // 文字描画用 cairo_t *cairo_p = cairo_create(image); // 画像のフォーマット cairo_format_t format = cairo_image_surface_get_format(image); // 画像の幅と高さ int32 width = cairo_image_surface_get_width(image); int32 height = cairo_image_surface_get_height(image); // 画像の一列分のバイト数 int32 stride = width * ((format == CAIRO_FORMAT_ARGB32) ? 4 : 3); // 文字表示のY座標 gdouble draw_y = 9.0; GtkWidget *image_widget; // ピクセルバッファ GdkPixbuf *pixbuf; // 返り値 GtkWidget *button; // 改行処理用のバッファ gchar* str = (label == NULL) ? NULL : MEM_STRDUP_FUNC(label); gchar* show_text = str; // 改行処理用 gchar *now, *next; // 文字列を描画 if(label != NULL && *label != '\0') { // フォントサイズセット cairo_select_font_face(cairo_p, font_file, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cairo_p, DISPLAY_FONT_HEIGHT); // 改行を処理しながら表示 now = show_text = str; next = g_utf8_next_char(show_text); while(*now != '\0' && *next != '\0') { if((uint8)*now == 0x5c && *next == 'n') { *now = '\0'; cairo_move_to(cairo_p, 0.0, draw_y); cairo_show_text(cairo_p, show_text); show_text = now = g_utf8_next_char(next); next = g_utf8_next_char(now); draw_y += DISPLAY_FONT_HEIGHT; } else if((next - now) >= 2 && (uint8)*now == 0xc2 && (uint8)(*(now+1)) == 0xa5 && (uint8)*next == 'n') { *now = '\0'; cairo_move_to(cairo_p, 0.0, draw_y); cairo_show_text(cairo_p, show_text); show_text = now = g_utf8_next_char(next); next = g_utf8_next_char(now); draw_y += DISPLAY_FONT_HEIGHT; } else { now = next; next = g_utf8_next_char(next); } } cairo_move_to(cairo_p, 0.0, draw_y); cairo_show_text(cairo_p, show_text); } // イメージからピクセルバッファを生成 pixbuf = gdk_pixbuf_new_from_data( cairo_image_surface_get_data(image), GDK_COLORSPACE_RGB, (format == CAIRO_FORMAT_ARGB32) ? TRUE : FALSE, 8, width, height, stride, NULL, NULL ); #if defined(USE_BGR_COLOR_SPACE) && USE_BGR_COLOR_SPACE != 0 { // WindowsならばBGR→RGBの変換を行う uint8* pix = cairo_image_surface_get_data(image); uint8 b; int32 channel = (format == CAIRO_FORMAT_ARGB32) ? 4 : 3; int32 i, j; for(i=0; i<height; i++) { for(j=0; j<width; j++) { b = pix[i*stride+j*channel]; pix[i*stride+j*channel] = pix[i*stride+j*channel+2]; pix[i*stride+j*channel+2] = b; } } } #endif // #if defined(DISPLAY_BGR) && DISPLAY_BGR != 0 image_widget = gtk_image_new_from_pixbuf(pixbuf); button = gtk_toggle_button_new(); // ボタンにイメージデータを載せる gtk_container_add(GTK_CONTAINER(button), image_widget); cairo_destroy(cairo_p); MEM_FREE_FUNC(str); return button; }
gpointer itdb_thumb_ipod_item_to_pixbuf (Itdb_Device *device, Itdb_Thumb_Ipod_Item *item) { /* pixbuf is already on the iPod -> read from there */ GdkPixbuf *pixbuf_full; GdkPixbuf *pixbuf_sub; GdkPixbuf *pixbuf; gint pad_x = item->horizontal_padding; gint pad_y = item->vertical_padding; gint width = item->width; gint height = item->height; guint rowstride; const Itdb_ArtworkFormat *img_info = item->format; guchar *pixels; /* printf ("hp%d vp%d w%d h%d\n", pad_x, pad_y, width, height);*/ if (item->format == NULL) { g_warning (_("Unable to retrieve thumbnail (appears to be on iPod, but no image info available): filename: '%s'\n"), item->filename); return NULL; } pixels = itdb_thumb_get_rgb_data (device, item); if (pixels == NULL) { return NULL; } /* FIXME: this is broken for non-16bpp image formats :-/ */ rowstride = get_aligned_width (img_info, sizeof(guint16))*3; pixbuf_full = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, FALSE, 8, img_info->width, img_info->height, rowstride, (GdkPixbufDestroyNotify)g_free, NULL); /* !! do not g_free(pixels) here: it will be freed when doing a * gdk_pixbuf_unref() on the GdkPixbuf !! */ /* Remove padding from the pixmap and/or cut the pixmap to the right size. */ /* Negative offsets indicate that part of the image was cut off at the left/top. thumb->width/height include that part of the image. Positive offsets indicate that part of the thumbnail are padded in black. thumb->width/height also include that part of the image -> reduce width and height by the absolute value of the padding */ width = width - abs (pad_x); height = height - abs (pad_y); /* And throw out "negative" padding */ if (pad_x < 0) pad_x = 0; if (pad_y < 0) pad_y = 0; /* Width/height might still be larger than img_info->width/height, indicating that part of the image was cut off at the right/bottom (similar to negative padding above). Adjust width/height accordingly. */ if (pad_x + width > img_info->width) width = img_info->width - pad_x; if (pad_y + height > img_info->height) height = img_info->height - pad_y; #if DEBUG_ARTWORK printf ("px=%2d py=%2d x=%3d y=%3d\n", pad_x, pad_y, width, height); #endif pixbuf_sub = gdk_pixbuf_new_subpixbuf (pixbuf_full, pad_x, pad_y, width, height); pixbuf = gdk_pixbuf_copy (pixbuf_sub); g_object_unref (pixbuf_full); g_object_unref (pixbuf_sub); return pixbuf; }
static void _lib_modulelist_populate_callback(gpointer instance, gpointer user_data) { dt_lib_module_t *self = (dt_lib_module_t *)user_data; if(!self || !(self->data)) return; GtkListStore *store; GtkTreeIter iter; GtkWidget *view = GTK_WIDGET(((dt_lib_modulelist_t *)self->data)->tree); GtkCellRenderer *pix_renderer, *fav_renderer, *text_renderer; GdkRGBA color; GtkStyleContext *context = gtk_widget_get_style_context(view); gboolean color_found = gtk_style_context_lookup_color (context, "selected_bg_color", &color); if(!color_found) { color.red = 1.0; color.green = 0.0; color.blue = 0.0; color.alpha = 1.0; } store = gtk_list_store_new(NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_POINTER); gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); g_object_unref(store); gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store), COL_MODULE, _lib_modulelist_gui_sort, NULL, NULL); gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), COL_MODULE, GTK_SORT_ASCENDING); pix_renderer = gtk_cell_renderer_pixbuf_new(); g_object_set(pix_renderer, "cell-background-rgba", &color, NULL); fav_renderer = gtk_cell_renderer_pixbuf_new(); cairo_surface_t *fav_cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ICON_SIZE, ICON_SIZE); cairo_t *fav_cr = cairo_create(fav_cst); cairo_set_source_rgb(fav_cr, 0.7, 0.7, 0.7); dtgtk_cairo_paint_modulegroup_favorites(fav_cr, 0, 0, ICON_SIZE, ICON_SIZE, 0); cairo_destroy(fav_cr); guchar *data = cairo_image_surface_get_data(fav_cst); dt_draw_cairo_to_gdk_pixbuf(data, ICON_SIZE, ICON_SIZE); ((dt_lib_modulelist_t *)self->data)->fav_pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, ICON_SIZE, ICON_SIZE, cairo_image_surface_get_stride(fav_cst), NULL, NULL); g_object_set(fav_renderer, "cell-background-rgba", &color, NULL); g_object_set(fav_renderer, "width", gdk_pixbuf_get_width(((dt_lib_modulelist_t *)self->data)->fav_pixbuf), NULL); text_renderer = gtk_cell_renderer_text_new(); g_object_set(text_renderer, "cell-background-rgba", &color, NULL); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE); gtk_tree_view_set_headers_clickable(GTK_TREE_VIEW(view), FALSE); GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); GtkTreeViewColumn *col; col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 0); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 0, "favorite", fav_renderer, favorite_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 1); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 1, "image", pix_renderer, image_renderer_function, NULL, NULL); col = gtk_tree_view_get_column(GTK_TREE_VIEW(view), 2); if(col) gtk_tree_view_remove_column(GTK_TREE_VIEW(view), col); gtk_tree_view_insert_column_with_data_func(GTK_TREE_VIEW(view), 2, "name", text_renderer, text_renderer_function, NULL, NULL); /* go thru list of iop modules and add them to the list */ GList *modules = g_list_last(darktable.iop); char datadir[PATH_MAX] = { 0 }; dt_loc_get_datadir(datadir, sizeof(datadir)); while(modules) { dt_iop_module_so_t *module = (dt_iop_module_so_t *)(modules->data); if(!dt_iop_so_is_hidden(module) && !(module->flags() & IOP_FLAGS_DEPRECATED)) { GdkPixbuf *pixbuf; char filename[PATH_MAX] = { 0 }; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.svg", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/%s.png", datadir, module->op); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.svg", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; snprintf(filename, sizeof(filename), "%s/pixmaps/plugins/darkroom/template.png", datadir); pixbuf = load_image(filename); if(pixbuf) goto end; // wow, we could neither load the SVG nor the PNG files. something is f****d up. pixbuf = gdk_pixbuf_new_from_data(fallback_pixel, GDK_COLORSPACE_RGB, TRUE, 8, 1, 1, 4, NULL, NULL); end: gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, COL_IMAGE, pixbuf, COL_MODULE, module, -1); g_object_unref(pixbuf); } modules = g_list_previous(modules); } }
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); if (!offset) return NULL; 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_message ("invalid pixel data type %u", type)); return NULL; } length = GET_UINT32 (cache->buffer, pixel_data_offset + 4); G_GNUC_BEGIN_IGNORE_DEPRECATIONS if (!gdk_pixdata_deserialize (&pixdata, length, (guchar *)(cache->buffer + pixel_data_offset + 8), &error)) { GTK_NOTE (ICONTHEME, g_message ("could not deserialize data: %s", error->message)); g_error_free (error); return NULL; } G_GNUC_END_IGNORE_DEPRECATIONS 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_message ("could not convert pixdata to pixbuf: %s", error->message)); g_error_free (error); return NULL; } gtk_icon_cache_ref (cache); return pixbuf; }
/* * The data that is passed to this function is either freed here or * owned by the returned pixbuf. */ static GdkPixbuf * gimp_pixbuf_from_data (guchar *data, gint width, gint height, gint bpp, GimpPixbufTransparency alpha) { GdkPixbuf *pixbuf; switch (bpp) { case 1: pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); { guchar *src = data; guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); gint rowstride = gdk_pixbuf_get_rowstride (pixbuf); gint y; for (y = 0; y < height; y++) { guchar *dest = pixels; gint x; for (x = 0; x < width; x++, src += 1, dest += 3) { dest[0] = dest[1] = dest[2] = src[0]; } pixels += rowstride; } g_free (data); } bpp = 3; break; case 2: pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height); { guchar *src = data; guchar *pixels = gdk_pixbuf_get_pixels (pixbuf); gint rowstride = gdk_pixbuf_get_rowstride (pixbuf); gint y; for (y = 0; y < height; y++) { guchar *dest = pixels; gint x; for (x = 0; x < width; x++, src += 2, dest += 4) { dest[0] = dest[1] = dest[2] = src[0]; dest[3] = src[1]; } pixels += rowstride; } g_free (data); } bpp = 4; break; case 3: pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, FALSE, 8, width, height, width * bpp, (GdkPixbufDestroyNotify) g_free, NULL); break; case 4: pixbuf = gdk_pixbuf_new_from_data (data, GDK_COLORSPACE_RGB, TRUE, 8, width, height, width * bpp, (GdkPixbufDestroyNotify) g_free, NULL); break; default: g_return_val_if_reached (NULL); return NULL; } if (bpp == 4) { GdkPixbuf *tmp; gint check_size = 0; switch (alpha) { case GIMP_PIXBUF_KEEP_ALPHA: return pixbuf; case GIMP_PIXBUF_SMALL_CHECKS: check_size = GIMP_CHECK_SIZE_SM; break; case GIMP_PIXBUF_LARGE_CHECKS: check_size = GIMP_CHECK_SIZE; break; } tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); gdk_pixbuf_composite_color (pixbuf, tmp, 0, 0, width, height, 0, 0, 1.0, 1.0, GDK_INTERP_NEAREST, 255, 0, 0, check_size, 0x66666666, 0x99999999); g_object_unref (pixbuf); pixbuf = tmp; } return pixbuf; }
GdkPixbuf * eventd_nd_pixbuf_from_data(GVariant *var, gint width, gint height) { GdkPixbuf *pixbuf = NULL; GError *error = NULL; const gchar *mime_type; GVariant *invar; g_variant_get(var, "(m&sm&sv)", &mime_type, NULL, &invar); if ( g_strcmp0(mime_type, "image/x.eventd.pixbuf") == 0 ) { gboolean a; gint b, w, h, s, n; GVariant *data; g_variant_get(invar, "(iiibii@ay)", &w, &h, &s, &a, &b, &n, &data); /* This is the only format gdk-pixbuf can read */ if ( ( b == 8 ) && ( n == ( a ? 4 : 3 ) ) && ( h * s == (gint) g_variant_get_size(data) ) ) return gdk_pixbuf_new_from_data(g_variant_get_data(data), GDK_COLORSPACE_RGB, a, b, w, h, s, _eventd_nd_pixbuf_free_data, data); g_variant_unref(data); goto end; } if ( ! g_variant_is_of_type(invar, G_VARIANT_TYPE_BYTESTRING) ) goto end; GdkPixbufLoader *loader; const guchar *data; gsize length; data = g_variant_get_data(invar); length = g_variant_get_size(invar); if ( mime_type != NULL ) { loader = gdk_pixbuf_loader_new_with_mime_type(mime_type, &error); if ( loader == NULL ) { g_warning("Couldn't create loader for MIME type '%s': %s", mime_type, error->message); goto end; } GdkPixbufFormat *format; if ( ( ( width > 0 ) || ( height > 0 ) ) && ( ( format = gdk_pixbuf_loader_get_format(loader) ) != NULL ) && gdk_pixbuf_format_is_scalable(format) ) gdk_pixbuf_loader_set_size(loader, width, height); } else loader = gdk_pixbuf_loader_new(); if ( ! gdk_pixbuf_loader_write(loader, data, length, &error) ) { g_warning("Couldn't write image data: %s", error->message); goto error; } if ( ! gdk_pixbuf_loader_close(loader, &error) ) { g_warning("Couldn't load image data: %s", error->message); goto error; } pixbuf = g_object_ref(gdk_pixbuf_loader_get_pixbuf(loader)); error: g_object_unref(loader); end: g_variant_unref(invar); g_variant_unref(var); g_clear_error(&error); return pixbuf; }
static GdkPixbuf* tvtj_jpeg_load (const JOCTET *content, gsize length, gint size) { struct jpeg_decompress_struct cinfo; struct jpeg_source_mgr source; TvtjErrorHandler handler; guchar *lines[1]; guchar *buffer = NULL; guchar *pixels = NULL; guchar *p; gint out_num_components; guint n; /* setup JPEG error handling */ cinfo.err = jpeg_std_error (&handler.mgr); handler.mgr.error_exit = fatal_error_handler; handler.mgr.output_message = (gpointer) tvtj_noop; if (setjmp (handler.setjmp_buffer)) goto error; /* setup the source */ source.bytes_in_buffer = length; source.next_input_byte = content; source.init_source = (gpointer) tvtj_noop; source.fill_input_buffer = tvtj_fill_input_buffer; source.skip_input_data = tvtj_skip_input_data; source.resync_to_restart = jpeg_resync_to_restart; source.term_source = (gpointer) tvtj_noop; /* setup the JPEG decompress struct */ jpeg_create_decompress (&cinfo); cinfo.src = &source; /* read the JPEG header from the file */ jpeg_read_header (&cinfo, TRUE); /* configure the JPEG decompress struct */ cinfo.scale_num = 1; cinfo.scale_denom = tvtj_denom (cinfo.image_width, cinfo.image_height, size); cinfo.dct_method = JDCT_FASTEST; cinfo.do_fancy_upsampling = FALSE; /* calculate the output dimensions */ jpeg_calc_output_dimensions (&cinfo); /* verify the JPEG color space */ if (cinfo.out_color_space != JCS_GRAYSCALE && cinfo.out_color_space != JCS_CMYK && cinfo.out_color_space != JCS_RGB) { /* we don't support this color space */ goto error; } /* start the decompression */ jpeg_start_decompress (&cinfo); /* allocate the pixel buffer and extra space for grayscale data */ if (G_LIKELY (cinfo.num_components != 1)) { pixels = g_malloc (cinfo.output_width * cinfo.output_height * cinfo.num_components); out_num_components = cinfo.num_components; lines[0] = pixels; } else { pixels = g_malloc (cinfo.output_width * cinfo.output_height * 3); buffer = g_malloc (cinfo.output_width); out_num_components = 3; lines[0] = buffer; } /* process the JPEG data */ for (p = pixels; cinfo.output_scanline < cinfo.output_height; ) { jpeg_read_scanlines (&cinfo, lines, 1); /* convert the data to RGB */ if (cinfo.num_components == 1) { for (n = 0; n < cinfo.output_width; ++n) { p[n * 3 + 0] = buffer[n]; p[n * 3 + 1] = buffer[n]; p[n * 3 + 2] = buffer[n]; } p += cinfo.output_width * 3; } else { if (cinfo.out_color_space == JCS_CMYK) tvtj_convert_cmyk_to_rgb (&cinfo, lines[0]); lines[0] += cinfo.output_width * cinfo.num_components; } } /* release the grayscale buffer */ g_free (buffer); buffer = NULL; /* finish the JPEG decompression */ jpeg_finish_decompress (&cinfo); jpeg_destroy_decompress (&cinfo); /* generate a pixbuf for the pixel data */ return gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, (cinfo.out_color_components == 4), 8, cinfo.output_width, cinfo.output_height, cinfo.output_width * out_num_components, (GdkPixbufDestroyNotify) g_free, NULL); error: jpeg_destroy_decompress (&cinfo); g_free (buffer); g_free (pixels); return NULL; }
static gboolean _frame_handler(GstElement *img, GstBuffer *buffer, gpointer data) { static gboolean inited = FALSE; static gboolean sended = FALSE; if (!inited) { g_timer_start(recognition_info.timer); inited = TRUE; } if (frame == NULL) frame = cvCreateImageHeader(cvSize(640, 480), IPL_DEPTH_8U, 3); switch (recognition_info.reco_state) { case NOT_START_RECOGNIZING: g_debug("[%s] not start recognizing", __func__); if (copy_buffer != NULL) gst_buffer_unref(copy_buffer); if (pure_buffer != NULL) gst_buffer_unref(pure_buffer); copy_buffer = gst_buffer_copy((buffer)); pure_buffer = gst_buffer_copy((buffer)); frame->imageData = (char*)GST_BUFFER_DATA(copy_buffer); if (recognition_info.detect_is_enabled) { detect(frame); } else { g_timer_start(recognition_info.timer); } recognition_info.source_data = (guchar*)(frame->imageData); recognition_info.length = GST_BUFFER_SIZE(copy_buffer); recognition_info.has_data = TRUE; break; case START_RECOGNIZING: g_debug("[%s] start recognizing", __func__); recognition_info.source_data = (guchar*)GST_BUFFER_DATA(pure_buffer); recognition_info.length = GST_BUFFER_SIZE(pure_buffer); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(recognition_info.source_data, GDK_COLORSPACE_RGB, // color space FALSE, // has alpha 8, // bits per sample CAMERA_WIDTH, // width CAMERA_HEIGHT, // height 3*CAMERA_WIDTH, // row stride NULL, // destroy function NULL // destroy function data ); GError* error = NULL; gdk_pixbuf_save(pixbuf, "/tmp/deepin_user_face.png", "png", &error, NULL); if (error != NULL) { g_debug("[%s] %s", __func__, error->message); g_error_free(error); } g_object_unref(pixbuf); recognition_info.has_data = TRUE; js_post_signal("start-animation"); recognition_info.reco_state = RECOGNIZING; sended = FALSE; reco(); break; case RECOGNIZED: g_debug("[%s] recognized", __func__); if (!sended) { g_timeout_add(ANIMATION_TIME, recognized_handler, NULL); sended = TRUE; } break; case NOT_RECOGNIZED: g_debug("[%s] not recognized", __func__); if (!sended) { g_timeout_add(ANIMATION_TIME, not_recognize_handler, NULL); sended = TRUE; } break; case RECOGNIZE_FINISH: g_debug("[%s] recognizing finish", __func__); if (copy_buffer != NULL) gst_buffer_unref(copy_buffer); copy_buffer = gst_buffer_copy((buffer)); recognition_info.source_data = (guchar*)GST_BUFFER_DATA(copy_buffer); recognition_info.length = GST_BUFFER_SIZE(pure_buffer); recognition_info.has_data = TRUE; } return TRUE; }
static void _lib_filmstrip_dnd_begin_callback(GtkWidget *widget, GdkDragContext *context, gpointer user_data) { const int ts = 64; dt_lib_module_t *self = (dt_lib_module_t *)user_data; dt_lib_filmstrip_t *strip = (dt_lib_filmstrip_t *)self->data; int imgid = strip->mouse_over_id; // imgid part of selection -> do nothing // otherwise -> select the current image strip->select = DT_LIB_FILMSTRIP_SELECT_NONE; sqlite3_stmt *stmt; DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select imgid from selected_images where imgid=?1", -1, &stmt, NULL); DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, imgid); if(sqlite3_step(stmt) != SQLITE_ROW) { dt_selection_select_single(darktable.selection, imgid); /* redraw filmstrip */ if(darktable.view_manager->proxy.filmstrip.module) gtk_widget_queue_draw(darktable.view_manager->proxy.filmstrip.module->widget); } sqlite3_finalize(stmt); // if we are dragging a single image -> use the thumbnail of that image // otherwise use the generic d&d icon // TODO: have something pretty in the 2nd case, too. if(dt_collection_get_selected_count(NULL) == 1) { dt_mipmap_buffer_t buf; dt_mipmap_size_t mip = dt_mipmap_cache_get_matching_size(darktable.mipmap_cache, ts, ts); dt_mipmap_cache_read_get(darktable.mipmap_cache, &buf, imgid, mip, DT_MIPMAP_BLOCKING); if(buf.buf) { uint8_t *scratchmem = dt_mipmap_cache_alloc_scratchmem(darktable.mipmap_cache); uint8_t *buf_decompressed = dt_mipmap_cache_decompress(&buf, scratchmem); uint8_t *rgbbuf = g_malloc((buf.width+2)*(buf.height+2)*3); memset(rgbbuf, 64, (buf.width+2)*(buf.height+2)*3); for(int i=1; i<=buf.height; i++) for(int j=1; j<=buf.width; j++) for(int k=0; k<3; k++) rgbbuf[(i*(buf.width+2)+j)*3+k] = buf_decompressed[((i-1)*buf.width+j-1)*4+2-k]; int w=ts, h=ts; if(buf.width < buf.height) w = (buf.width*ts)/buf.height; // portrait else h = (buf.height*ts)/buf.width; // landscape GdkPixbuf *source = gdk_pixbuf_new_from_data(rgbbuf, GDK_COLORSPACE_RGB, FALSE, 8, (buf.width+2), (buf.height+2), (buf.width+2)*3, NULL, NULL); GdkPixbuf *scaled = gdk_pixbuf_scale_simple(source, w, h, GDK_INTERP_HYPER); gtk_drag_set_icon_pixbuf(context, scaled, 0, 0); if(source) g_object_unref(source); if(scaled) g_object_unref(scaled); free(scratchmem); g_free(rgbbuf); } dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf); } }
void _draw(JSValueRef canvas, double dest_width, double dest_height) { static gboolean not_draw = FALSE; if (recognition_info.reco_state == RECOGNIZING) { /* g_debug("[%s] recognizing", __func__); */ return; } if (!recognition_info.has_data) { g_debug("[%s] get no data from camera", __func__); return; } if (JSValueIsNull(get_global_context(), canvas)) { g_debug("[%s] draw with null canvas!", __func__); return; } if (recognition_info.source_data == NULL) { g_debug("[%s] source_data is null", __func__); return; } g_debug("[%s]", __func__); cairo_t* cr = fetch_cairo_from_html_canvas(get_global_context(), canvas); g_assert(cr != NULL); cairo_save(cr); gulong len = recognition_info.length; guchar* data = g_slice_copy(len, recognition_info.source_data); GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, // color space FALSE, // has alpha 8, // bits per sample CAMERA_WIDTH, // width CAMERA_HEIGHT, // height 3*CAMERA_WIDTH, // row stride destroy_pixels, // destroy function GINT_TO_POINTER(len) // destroy function data ); double scale = 0; if (CAMERA_WIDTH > CAMERA_HEIGHT) { scale = dest_height/CAMERA_HEIGHT; cairo_scale(cr, scale, scale); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0.5 * (dest_width / scale - CAMERA_WIDTH), 0); } else { scale = dest_width/CAMERA_WIDTH; cairo_scale(cr, scale, scale); gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0.5 * (dest_height / scale - CAMERA_HEIGHT)); } cairo_paint(cr); cairo_restore(cr); canvas_custom_draw_did(cr, NULL); g_object_unref(pixbuf); recognition_info.has_data = FALSE; }
void create_map_image(playerc_map_t* map, const char* fname, const char* fmt) { GdkPixbuf* pixbuf; guchar* pixels; int i,j; g_type_init(); pixels = (guchar*)malloc(sizeof(unsigned char) * 3 * map->width * map->height); assert(pixels); for(j=0; j < map->height; j++) { for(i=0; i < map->width; i++) { if(map->cells[PLAYERC_MAP_INDEX(map,i,j)] == -1) { pixels[(map->width * (map->height - j-1) + i)*3] = 255; pixels[(map->width * (map->height - j-1) + i)*3+1] = 255; pixels[(map->width * (map->height - j-1) + i)*3+2] = 255; } else if(map->cells[PLAYERC_MAP_INDEX(map,i,j)] == 0) { pixels[(map->width * (map->height - j-1) + i)*3] = 100; pixels[(map->width * (map->height - j-1) + i)*3+1] = 100; pixels[(map->width * (map->height - j-1) + i)*3+2] = 100; } else { pixels[(map->width * (map->height - j-1) + i)*3] = 0; pixels[(map->width * (map->height - j-1) + i)*3+1] = 0; pixels[(map->width * (map->height - j-1) + i)*3+2] = 0; } } } // create the pixbuf g_assert((pixbuf = gdk_pixbuf_new_from_data(pixels, GDK_COLORSPACE_RGB, FALSE, 8, map->width, map->height, 3*map->width, NULL, NULL))); if(!gdk_pixbuf_save(pixbuf, fname, fmt, NULL, NULL)) puts("failed to save image file; sorry."); g_object_unref((GObject*)pixbuf); }
static GdkPixbuf * mouse_settings_themes_pixbuf_from_filename (const gchar *filename, guint size) { XcursorImage *image; GdkPixbuf *scaled, *pixbuf = NULL; gsize bsize; guchar *buffer, *p, tmp; gdouble wratio, hratio; gint dest_width, dest_height; /* load the image */ image = XcursorFilenameLoadImage (filename, size); if (G_LIKELY (image)) { /* buffer size */ bsize = image->width * image->height * 4; /* allocate buffer */ buffer = g_malloc (bsize); /* copy pixel data to buffer */ memcpy (buffer, image->pixels, bsize); /* swap bits */ for (p = buffer; p < buffer + bsize; p += 4) { tmp = p[0]; p[0] = p[2]; p[2] = tmp; } /* create pixbuf */ pixbuf = gdk_pixbuf_new_from_data (buffer, GDK_COLORSPACE_RGB, TRUE, 8, image->width, image->height, 4 * image->width, (GdkPixbufDestroyNotify) g_free, NULL); /* don't leak when creating the pixbuf failed */ if (G_UNLIKELY (pixbuf == NULL)) g_free (buffer); /* scale pixbuf if needed */ if (pixbuf && (image->height > size || image->width > size)) { /* calculate the ratio */ wratio = (gdouble) image->width / (gdouble) size; hratio = (gdouble) image->height / (gdouble) size; /* init */ dest_width = dest_height = size; /* set dest size */ /*if (hratio > wratio) dest_width = rint (image->width / hratio); else dest_height = rint (image->height / wratio);*/ dest_height = 16; dest_width = 16; /* scale pixbuf */ scaled = gdk_pixbuf_scale_simple (pixbuf, MAX (dest_width, 1), MAX (dest_height, 1), GDK_INTERP_BILINEAR); /* release and set scaled pixbuf */ g_object_unref (G_OBJECT (pixbuf)); pixbuf = scaled; } /* cleanup */ XcursorImageDestroy (image); } return pixbuf; }