[gthumb: 3/23] renamed some functions in pixbuf-utils.c
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb: 3/23] renamed some functions in pixbuf-utils.c
- Date: Sun, 26 Dec 2010 19:19:58 +0000 (UTC)
commit 03dff0eb1eae4399791131bbd56f04eb1e213340
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Dec 23 23:45:31 2010 +0100
renamed some functions in pixbuf-utils.c
.../data/contact_sheet_themes/default.cst | 28 +++
gthumb/gth-cell-renderer-thumbnail.c | 83 +------
gthumb/gth-icon-cache.c | 2 +-
gthumb/pixbuf-utils.c | 253 +++++++++++++++-----
gthumb/pixbuf-utils.h | 78 +++---
5 files changed, 259 insertions(+), 185 deletions(-)
---
diff --git a/extensions/contact_sheet/data/contact_sheet_themes/default.cst b/extensions/contact_sheet/data/contact_sheet_themes/default.cst
new file mode 100644
index 0000000..5ce9227
--- /dev/null
+++ b/extensions/contact_sheet/data/contact_sheet_themes/default.cst
@@ -0,0 +1,28 @@
+[Theme]
+Name=Default
+Authors=gthumb development team
+Copyright=Copyright © 2010 The Free Software Foundation, Inc.
+Version=1.0
+
+[Background]
+Type=full
+Color1=#e0d3c0
+Color2=#b1c3ad
+Color3=#e8e8ea
+Color4=#bad8d8
+
+[Frame]
+Style=slide
+Color=#f43421
+
+[Header]
+Font=Arial 22
+Color=#D5504A
+
+[Footer]
+Font=Arial Bold Italic 12
+Color=#394083
+
+[Caption]
+Font=Arial 10
+Color=#414141
diff --git a/gthumb/gth-cell-renderer-thumbnail.c b/gthumb/gth-cell-renderer-thumbnail.c
index 44a2635..db5f1c9 100644
--- a/gthumb/gth-cell-renderer-thumbnail.c
+++ b/gthumb/gth-cell-renderer-thumbnail.c
@@ -20,11 +20,11 @@
*/
#include <config.h>
-#include <math.h>
+#include "cairo-utils.h"
#include "gth-file-data.h"
#include "glib-utils.h"
#include "gth-cell-renderer-thumbnail.h"
-
+#include "pixbuf-utils.h"
#define DEFAULT_THUMBNAIL_SIZE 128
#define MAX_THUMBNAIL_SIZE 320
@@ -224,83 +224,6 @@ gth_cell_renderer_thumbnail_get_size (GtkCellRenderer *cell,
}
-/* From gtkcellrendererpixbuf.c
- * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb redhat com>
- *
- * modified for gthumb */
-static GdkPixbuf *
-create_colorized_pixbuf (GdkPixbuf *src,
- GdkColor *new_color,
- gdouble alpha)
-{
- gint i, j;
- gint width, height, has_alpha, src_row_stride, dst_row_stride;
- gint red_value, green_value, blue_value;
- guchar *target_pixels;
- guchar *original_pixels;
- guchar *pixsrc;
- guchar *pixdest;
- GdkPixbuf *dest;
-
- red_value = new_color->red / 255.0;
- green_value = new_color->green / 255.0;
- blue_value = new_color->blue / 255.0;
-
- dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
- TRUE /*gdk_pixbuf_get_has_alpha (src)*/,
- gdk_pixbuf_get_bits_per_sample (src),
- gdk_pixbuf_get_width (src),
- gdk_pixbuf_get_height (src));
-
- has_alpha = gdk_pixbuf_get_has_alpha (src);
- width = gdk_pixbuf_get_width (src);
- height = gdk_pixbuf_get_height (src);
- src_row_stride = gdk_pixbuf_get_rowstride (src);
- dst_row_stride = gdk_pixbuf_get_rowstride (dest);
- target_pixels = gdk_pixbuf_get_pixels (dest);
- original_pixels = gdk_pixbuf_get_pixels (src);
-
- for (i = 0; i < height; i++) {
- pixdest = target_pixels + i*dst_row_stride;
- pixsrc = original_pixels + i*src_row_stride;
- for (j = 0; j < width; j++) {
- *pixdest++ = (*pixsrc++ * red_value) >> 8;
- *pixdest++ = (*pixsrc++ * green_value) >> 8;
- *pixdest++ = (*pixsrc++ * blue_value) >> 8;
- if (has_alpha)
- *pixdest++ = (*pixsrc++ * alpha);
- else
- *pixdest++ = (255 * alpha);
- }
- }
-
- return dest;
-}
-
-
-static void
-_cairo_draw_rounded_box (cairo_t *cr,
- double x,
- double y,
- double w,
- double h,
- double r)
-{
- cairo_move_to (cr, x, y + r);
- if (r > 0)
- cairo_arc (cr, x + r, y + r, r, 1.0 * M_PI, 1.5 * M_PI);
- cairo_rel_line_to (cr, w - (r * 2), 0);
- if (r > 0)
- cairo_arc (cr, x + w - r, y + r, r, 1.5 * M_PI, 2.0 * M_PI);
- cairo_rel_line_to (cr, 0, h - (r * 2));
- if (r > 0)
- cairo_arc (cr, x + w - r, y + h - r, r, 0.0 * M_PI, 0.5 * M_PI);
- cairo_rel_line_to (cr, - (w - (r * 2)), 0);
- if (r > 0)
- cairo_arc (cr, x + r, y + h - r, r, 0.5 * M_PI, 1.0 * M_PI);
-}
-
-
static void
gth_cell_renderer_thumbnail_render (GtkCellRenderer *cell,
GdkWindow *window,
@@ -433,7 +356,7 @@ gth_cell_renderer_thumbnail_render (GtkCellRenderer *cell,
}
if (! self->priv->checked || ((flags & (GTK_CELL_RENDERER_SELECTED | GTK_CELL_RENDERER_PRELIT)) != 0)) {
- colorized = create_colorized_pixbuf (pixbuf, &style->base[state], self->priv->checked ? 1.0 : 0.33);
+ colorized = _gdk_pixbuf_colorize (pixbuf, &style->base[state], self->priv->checked ? 1.0 : 0.33);
pixbuf = colorized;
}
diff --git a/gthumb/gth-icon-cache.c b/gthumb/gth-icon-cache.c
index 1d117cd..58262d2 100644
--- a/gthumb/gth-icon-cache.c
+++ b/gthumb/gth-icon-cache.c
@@ -49,7 +49,7 @@ gth_icon_cache_new (GtkIconTheme *icon_theme,
icon_cache->icon_size = icon_size;
icon_cache->cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
- g_hash_table_insert (icon_cache->cache, VOID_PIXBUF_KEY, create_void_pixbuf (icon_cache->icon_size, icon_cache->icon_size));
+ g_hash_table_insert (icon_cache->cache, VOID_PIXBUF_KEY, _gdk_pixbuf_new_void (icon_cache->icon_size, icon_cache->icon_size));
return icon_cache;
}
diff --git a/gthumb/pixbuf-utils.c b/gthumb/pixbuf-utils.c
index 3679e21..c856115 100644
--- a/gthumb/pixbuf-utils.c
+++ b/gthumb/pixbuf-utils.c
@@ -27,6 +27,144 @@
#include "pixbuf-utils.h"
+GdkPixbuf*
+_gdk_pixbuf_new_void (int width,
+ int height)
+{
+ GdkPixbuf *p;
+
+ p = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+ TRUE,
+ 8,
+ width,
+ height);
+ gdk_pixbuf_fill (p, 0xFFFFFF00);
+
+ return p;
+}
+
+
+/* Taken from http://www.gtkforums.com/about5204.html
+ * Author: tadeboro */
+GdkPixbuf *
+_gdk_pixbuf_new_from_cairo_surface (cairo_t *cr)
+{
+ cairo_surface_t *surface;
+ int width;
+ int height;
+ int s_stride;
+ unsigned char *s_pixels;
+ GdkPixbuf *pixbuf;
+ int p_stride;
+ guchar *p_pixels;
+ int p_n_channels;
+
+ surface = cairo_get_target (cr);
+ if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
+ return NULL;
+
+ width = cairo_image_surface_get_width (surface);
+ height = cairo_image_surface_get_height (surface);
+ s_stride = cairo_image_surface_get_stride (surface);
+ s_pixels = cairo_image_surface_get_data (surface);
+
+ pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+ p_stride = gdk_pixbuf_get_rowstride (pixbuf);
+ p_pixels = gdk_pixbuf_get_pixels (pixbuf);
+ p_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+
+ while (height--) {
+ guchar *s_iter = s_pixels;
+ guchar *p_iter = p_pixels;
+ int i;
+
+ for (i = 0; i < width; i++) {
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+ /* Pixbuf: RGB(A)
+ * Surface: BGRA */
+ gdouble alpha_factor = (gdouble)0xff / s_iter[3];
+
+ p_iter[0] = (guchar) (s_iter[2] * alpha_factor + .5);
+ p_iter[1] = (guchar) (s_iter[1] * alpha_factor + .5);
+ p_iter[2] = (guchar) (s_iter[0] * alpha_factor + .5);
+ if (p_n_channels == 4)
+ p_iter[3] = s_iter[3];
+#elif G_BYTE_ORDER == G_BIG_ENDIAN
+ /* Pixbuf: RGB(A)
+ * Surface: ARGB */
+ gdouble alpha_factor = (gdouble)0xff / s_iter[0];
+
+ p_iter[0] = (guchar) (s_iter[1] * alpha_factor + .5);
+ p_iter[1] = (guchar) (s_iter[2] * alpha_factor + .5);
+ p_iter[2] = (guchar) (s_iter[3] * alpha_factor + .5);
+ if (p_n_channels == 4)
+ p_iter[3] = s_iter[0];
+#else /* PDP endianness */
+ /* Pixbuf: RGB(A)
+ * Surface: RABG */
+ gdouble alpha_factor = (gdouble)0xff / s_iter[1];
+
+ p_iter[0] = (guchar) (s_iter[0] * alpha_factor + .5);
+ p_iter[1] = (guchar) (s_iter[3] * alpha_factor + .5);
+ p_iter[2] = (guchar) (s_iter[2] * alpha_factor + .5);
+ if (p_n_channels == 4)
+ p_iter[3] = s_iter[1];
+#endif
+
+ s_iter += 4;
+ p_iter += p_n_channels;
+ }
+
+ s_pixels += s_stride;
+ p_pixels += p_stride;
+ }
+
+ return pixbuf;
+}
+
+
+/* The gdk_pixbuf scaling routines do not handle large-ratio downscaling
+ very well. Memory usage explodes and the application may freeze or crash.
+ For scale-down ratios in excess of 100, do the scale in two steps.
+ It is faster and safer that way. See bug 80925 for background info. */
+GdkPixbuf*
+_gdk_pixbuf_scale_simple_safe (const GdkPixbuf *src,
+ int dest_width,
+ int dest_height,
+ GdkInterpType interp_type)
+{
+ GdkPixbuf* temp_pixbuf1;
+ GdkPixbuf* temp_pixbuf2;
+ int x_ratio, y_ratio;
+ int temp_width = dest_width, temp_height = dest_height;
+
+ g_assert (dest_width >= 1);
+ g_assert (dest_height >= 1);
+
+ x_ratio = gdk_pixbuf_get_width (src) / dest_width;
+ y_ratio = gdk_pixbuf_get_height (src) / dest_height;
+
+
+
+ if (x_ratio > 100)
+ /* Scale down to 10x the requested size first. */
+ temp_width = 10 * dest_width;
+
+ if (y_ratio > 100)
+ /* Scale down to 10x the requested size first. */
+ temp_height = 10 * dest_height;
+
+ if ( (temp_width != dest_width) || (temp_height != dest_height)) {
+ temp_pixbuf1 = gdk_pixbuf_scale_simple (src, temp_width, temp_height, interp_type);
+ temp_pixbuf2 = gdk_pixbuf_scale_simple (temp_pixbuf1, dest_width, dest_height, interp_type);
+ g_object_unref (temp_pixbuf1);
+ } else
+ temp_pixbuf2 = gdk_pixbuf_scale_simple (src, dest_width, dest_height, interp_type);
+
+ return temp_pixbuf2;
+}
+
+
/*
* Returns a transformed image.
*/
@@ -122,16 +260,57 @@ _gdk_pixbuf_colorshift (GdkPixbuf *dest,
}
-void
-pixmap_from_xpm (const char **data,
- GdkPixmap **pixmap,
- GdkBitmap **mask)
+/* From gtkcellrendererpixbuf.c
+ * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb redhat com>
+ *
+ * modified for gthumb */
+GdkPixbuf *
+_gdk_pixbuf_colorize (GdkPixbuf *src,
+ GdkColor *new_color,
+ gdouble alpha)
{
- GdkPixbuf *pixbuf;
+ gint i, j;
+ gint width, height, has_alpha, src_row_stride, dst_row_stride;
+ gint red_value, green_value, blue_value;
+ guchar *target_pixels;
+ guchar *original_pixels;
+ guchar *pixsrc;
+ guchar *pixdest;
+ GdkPixbuf *dest;
+
+ red_value = new_color->red / 255.0;
+ green_value = new_color->green / 255.0;
+ blue_value = new_color->blue / 255.0;
+
+ dest = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (src),
+ TRUE /*gdk_pixbuf_get_has_alpha (src)*/,
+ gdk_pixbuf_get_bits_per_sample (src),
+ gdk_pixbuf_get_width (src),
+ gdk_pixbuf_get_height (src));
+
+ has_alpha = gdk_pixbuf_get_has_alpha (src);
+ width = gdk_pixbuf_get_width (src);
+ height = gdk_pixbuf_get_height (src);
+ src_row_stride = gdk_pixbuf_get_rowstride (src);
+ dst_row_stride = gdk_pixbuf_get_rowstride (dest);
+ target_pixels = gdk_pixbuf_get_pixels (dest);
+ original_pixels = gdk_pixbuf_get_pixels (src);
- pixbuf = gdk_pixbuf_new_from_xpm_data (data);
- gdk_pixbuf_render_pixmap_and_mask (pixbuf, pixmap, mask, 127);
- g_object_unref (pixbuf);
+ for (i = 0; i < height; i++) {
+ pixdest = target_pixels + i*dst_row_stride;
+ pixsrc = original_pixels + i*src_row_stride;
+ for (j = 0; j < width; j++) {
+ *pixdest++ = (*pixsrc++ * red_value) >> 8;
+ *pixdest++ = (*pixsrc++ * green_value) >> 8;
+ *pixdest++ = (*pixsrc++ * blue_value) >> 8;
+ if (has_alpha)
+ *pixdest++ = (*pixsrc++ * alpha);
+ else
+ *pixdest++ = (255 * alpha);
+ }
+ }
+
+ return dest;
}
@@ -417,47 +596,6 @@ _gdk_pixbuf_hv_gradient (GdkPixbuf *pixbuf,
}
-GdkPixbuf*
-_gdk_pixbuf_scale_simple_safe (const GdkPixbuf *src,
- int dest_width,
- int dest_height,
- GdkInterpType interp_type)
-{
- GdkPixbuf* temp_pixbuf1;
- GdkPixbuf* temp_pixbuf2;
- int x_ratio, y_ratio;
- int temp_width = dest_width, temp_height = dest_height;
-
- g_assert (dest_width >= 1);
- g_assert (dest_height >= 1);
-
- x_ratio = gdk_pixbuf_get_width (src) / dest_width;
- y_ratio = gdk_pixbuf_get_height (src) / dest_height;
-
- /* The gdk_pixbuf scaling routines do not handle large-ratio downscaling
- very well. Memory usage explodes and the application may freeze or crash.
- For scale-down ratios in excess of 100, do the scale in two steps.
- It is faster and safer that way. See bug 80925 for background info. */
-
- if (x_ratio > 100)
- /* Scale down to 10x the requested size first. */
- temp_width = 10 * dest_width;
-
- if (y_ratio > 100)
- /* Scale down to 10x the requested size first. */
- temp_height = 10 * dest_height;
-
- if ( (temp_width != dest_width) || (temp_height != dest_height)) {
- temp_pixbuf1 = gdk_pixbuf_scale_simple (src, temp_width, temp_height, interp_type);
- temp_pixbuf2 = gdk_pixbuf_scale_simple (temp_pixbuf1, dest_width, dest_height, interp_type);
- g_object_unref (temp_pixbuf1);
- } else
- temp_pixbuf2 = gdk_pixbuf_scale_simple (src, dest_width, dest_height, interp_type);
-
- return temp_pixbuf2;
-}
-
-
gboolean
scale_keeping_ratio_min (int *width,
int *height,
@@ -513,23 +651,6 @@ scale_keeping_ratio (int *width,
}
-GdkPixbuf*
-create_void_pixbuf (int width,
- int height)
-{
- GdkPixbuf *p;
-
- p = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
- TRUE,
- 8,
- width,
- height);
- gdk_pixbuf_fill (p, 0xFFFFFF00);
-
- return p;
-}
-
-
gboolean
_g_mime_type_is_writable (const char *mime_type)
{
diff --git a/gthumb/pixbuf-utils.h b/gthumb/pixbuf-utils.h
index d737255..1752581 100644
--- a/gthumb/pixbuf-utils.h
+++ b/gthumb/pixbuf-utils.h
@@ -25,48 +25,50 @@
#include <glib.h>
#include <gdk/gdk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <cairo.h>
#include "typedefs.h"
G_BEGIN_DECLS
-void pixmap_from_xpm (const char **data,
- GdkPixmap **pixmap,
- GdkBitmap **mask);
-void _gdk_pixbuf_vertical_gradient (GdkPixbuf *pixbuf,
- guint32 color1,
- guint32 color2);
-void _gdk_pixbuf_horizontal_gradient (GdkPixbuf *pixbuf,
- guint32 color1,
- guint32 color2);
-void _gdk_pixbuf_hv_gradient (GdkPixbuf *pixbuf,
- guint32 hcolor1,
- guint32 hcolor2,
- guint32 vcolor1,
- guint32 vcolor2);
-GdkPixbuf * _gdk_pixbuf_transform (GdkPixbuf *src,
- GthTransform transform);
-void _gdk_pixbuf_colorshift (GdkPixbuf *dest,
- GdkPixbuf *src,
- int shift);
-gboolean scale_keeping_ratio_min (int *width,
- int *height,
- int min_width,
- int min_height,
- int max_width,
- int max_height,
- gboolean allow_upscaling);
-gboolean scale_keeping_ratio (int *width,
- int *height,
- int max_width,
- int max_height,
- gboolean allow_upscaling);
-GdkPixbuf * create_void_pixbuf (int width,
- int height);
-GdkPixbuf * _gdk_pixbuf_scale_simple_safe (const GdkPixbuf *src,
- int dest_width,
- int dest_height,
- GdkInterpType interp_type);
-gboolean _g_mime_type_is_writable (const char *mime_type);
+GdkPixbuf * _gdk_pixbuf_new_void (int width,
+ int height);
+GdkPixbuf * _gdk_pixbuf_new_from_cairo_surface (cairo_t *cr);
+GdkPixbuf * _gdk_pixbuf_scale_simple_safe (const GdkPixbuf *src,
+ int dest_width,
+ int dest_height,
+ GdkInterpType interp_type);
+GdkPixbuf * _gdk_pixbuf_transform (GdkPixbuf *src,
+ GthTransform transform);
+void _gdk_pixbuf_colorshift (GdkPixbuf *dest,
+ GdkPixbuf *src,
+ int shift);
+GdkPixbuf * _gdk_pixbuf_colorize (GdkPixbuf *src,
+ GdkColor *new_color,
+ gdouble alpha);
+void _gdk_pixbuf_vertical_gradient (GdkPixbuf *pixbuf,
+ guint32 color1,
+ guint32 color2);
+void _gdk_pixbuf_horizontal_gradient (GdkPixbuf *pixbuf,
+ guint32 color1,
+ guint32 color2);
+void _gdk_pixbuf_hv_gradient (GdkPixbuf *pixbuf,
+ guint32 hcolor1,
+ guint32 hcolor2,
+ guint32 vcolor1,
+ guint32 vcolor2);
+gboolean scale_keeping_ratio_min (int *width,
+ int *height,
+ int min_width,
+ int min_height,
+ int max_width,
+ int max_height,
+ gboolean allow_upscaling);
+gboolean scale_keeping_ratio (int *width,
+ int *height,
+ int max_width,
+ int max_height,
+ gboolean allow_upscaling);
+gboolean _g_mime_type_is_writable (const char *mime_type);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]