changeset 4214:41655c090c53

converted ui_skinned_equalizer_graph to GdkPixbuf
author Cristi Magherusan <majeru@atheme.org>
date Wed, 23 Jan 2008 01:12:08 +0200
parents 56e189ecb477
children 6028b7fff0bd
files src/audacious/skin.c src/audacious/ui_skinned_equalizer_graph.c src/audacious/util.c src/audacious/util.h
diffstat 4 files changed, 24 insertions(+), 57 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/skin.c	Tue Jan 22 22:41:42 2008 +0100
+++ b/src/audacious/skin.c	Wed Jan 23 01:12:08 2008 +0200
@@ -1852,8 +1852,9 @@
     {
         p = pixels + rowstride * (i + 294) + 115 * n_channels;
         colors[i] = (p[0] << 16) | (p[1] << 8) | p[2]; 
-        if(n_channels == 4)       /* should we really treat the Alpha channel? */
-            colors[i]= (colors[i] << 8) | p[3];
+        /* should we really treat the Alpha channel? */
+        /*if (n_channels == 4)
+            colors[i] = (colors[i] << 8) | p[3];*/
     }
 }
 
--- a/src/audacious/ui_skinned_equalizer_graph.c	Tue Jan 22 22:41:42 2008 +0100
+++ b/src/audacious/ui_skinned_equalizer_graph.c	Wed Jan 23 01:12:08 2008 +0200
@@ -228,19 +228,15 @@
     UiSkinnedEqualizerGraph *equalizer_graph = UI_SKINNED_EQUALIZER_GRAPH (widget);
     g_return_val_if_fail (equalizer_graph->width > 0 && equalizer_graph->height > 0, FALSE);
 
-    GdkPixmap *obj = NULL;
-    GdkPixbuf *pix = NULL;
-    GdkGC *gc;
+    GdkPixbuf *obj = NULL;
 
-    pix = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, equalizer_graph->width, equalizer_graph->height);
-    obj = gdk_pixmap_new(NULL, equalizer_graph->width, equalizer_graph->height, gdk_rgb_get_visual()->depth);
-    gc = gdk_gc_new(obj);
+    obj = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, equalizer_graph->width, equalizer_graph->height);
 
-    GdkColor col;
-    guint32 cols[19];
+    guint32 cols[19], rowstride;
     gint i, y, ymin, ymax, py = 0;
     gfloat x[] = { 0, 11, 23, 35, 47, 59, 71, 83, 97, 109 }, yf[10];
-
+    guchar* pixels, *p;
+    gint n_channels;
     /*
      * This avoids the init_spline() function to be inlined.
      * Inlining the function caused troubles when compiling with
@@ -248,17 +244,12 @@
      */
     void (*__init_spline) (gfloat *, gfloat *, gint, gfloat *) = init_spline;
 
-    skin_draw_pixbuf(widget, bmp_active_skin, pix, equalizer_graph->skin_index, 0, 294, 0, 0,
+    skin_draw_pixbuf(widget, bmp_active_skin, obj, equalizer_graph->skin_index, 0, 294, 0, 0,
                      equalizer_graph->width, equalizer_graph->height);
-    skin_draw_pixbuf(widget, bmp_active_skin, pix, equalizer_graph->skin_index, 0, 314,
+    skin_draw_pixbuf(widget, bmp_active_skin, obj, equalizer_graph->skin_index, 0, 314,
                      0, 9 + ((cfg.equalizer_preamp * 9) / 20),
                      equalizer_graph->width, 1);
 
-    /* we shouldn't do it this way... we should paint equalizer-line pixels on pixbuf */
-    gdk_draw_pixbuf(obj, gc, pix, 0, 0, 0, 0, equalizer_graph->width, equalizer_graph->height,
-                    GDK_RGB_DITHER_NONE, 0, 0);
-    g_object_unref(pix);
-
     skin_get_eq_spline_colors(bmp_active_skin, cols);
 
     __init_spline(x, cfg.equalizer_bands, 10, yf);
@@ -282,31 +273,26 @@
         }
         py = y;
 
-        /* this should operate directly on GdkPixbuf */
-        for (y = ymin; y <= ymax; y++) {
-            col.pixel = cols[y];
-            gdk_gc_set_foreground(gc, &col);
-            gdk_draw_point(obj, gc, i + 2, y);
+        pixels = gdk_pixbuf_get_pixels(obj);
+        rowstride = gdk_pixbuf_get_rowstride(obj);
+        n_channels = gdk_pixbuf_get_n_channels(obj); 
+
+        for (y = ymin; y <= ymax; y++) 
+        {
+            p = pixels + (y * rowstride) + (( i + 2) * n_channels); 
+            p[0] = (cols[y] & 0xff0000) >> 16;
+            p[1] = (cols[y] & 0x00ff00) >> 8;
+            p[2] = (cols[y] & 0x0000ff);
+            /* do we really need to treat the alpha channel? */
+            /*if (n_channels == 4)
+                  p[3] = cols[y] >> 24;*/
         }
     }
 
-    gc = gdk_gc_new(obj);
-    GdkPixmap *image = NULL;
-
-    if (equalizer_graph->double_size) {
-        image = create_dblsize_pixmap(obj);
-    } else {
-        image = gdk_pixmap_new(NULL, equalizer_graph->width, equalizer_graph->height, gdk_rgb_get_visual()->depth);
-        gdk_draw_drawable (image, gc, obj, 0, 0, 0, 0, equalizer_graph->width, equalizer_graph->height);
-    }
+    ui_skinned_widget_draw(widget, obj, equalizer_graph->width, equalizer_graph->height, equalizer_graph->double_size);
 
     g_object_unref(obj);
 
-    gdk_draw_drawable (widget->window, gc, image, 0, 0, 0, 0,
-                       equalizer_graph->width*(1+equalizer_graph->double_size), equalizer_graph->height*(1+equalizer_graph->double_size));
-    g_object_unref(gc);
-    g_object_unref(image);
-
     return FALSE;
 }
 
--- a/src/audacious/util.c	Tue Jan 22 22:41:42 2008 +0100
+++ b/src/audacious/util.c	Wed Jan 23 01:12:08 2008 +0200
@@ -889,25 +889,6 @@
     return out;
 }
 
-GdkPixmap *create_dblsize_pixmap(GdkPixmap *pix) {
-    int w, h;
-    gdk_drawable_get_size(pix, &w, &h);
-    GdkGC* gc = gdk_gc_new(pix);
-    GdkPixbuf *img, *img2x;
-    GdkColormap *colormap = gdk_colormap_get_system();
-    img = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, w, h);
-    gdk_pixbuf_get_from_drawable(img, pix, colormap, 0, 0, 0, 0, w, h);
-    img2x = gdk_pixbuf_scale_simple(img, w*2, h*2, GDK_INTERP_NEAREST);
-
-    GdkPixmap *image;
-    image = gdk_pixmap_new(NULL, w*2, h*2, gdk_rgb_get_visual()->depth);
-    gdk_draw_pixbuf(image, gc, img2x, 0, 0, 0, 0, w*2, h*2, GDK_RGB_DITHER_NONE, 0, 0);
-    g_object_unref(img);
-    g_object_unref(img2x);
-    g_object_unref(gc);
-    return image;
-}
-
 void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale) {
     g_return_if_fail(widget != NULL);
     g_return_if_fail(obj != NULL);
--- a/src/audacious/util.h	Tue Jan 22 22:41:42 2008 +0100
+++ b/src/audacious/util.h	Wed Jan 23 01:12:08 2008 +0200
@@ -96,7 +96,6 @@
                             GCallback button_action,
                             gpointer action_data);
 
-GdkPixmap *create_dblsize_pixmap(GdkPixmap *pix);
 void ui_skinned_widget_draw(GtkWidget *widget, GdkPixbuf *obj, gint width, gint height, gboolean scale);
 
 GdkPixbuf *audacious_create_colorized_pixbuf(GdkPixbuf *src, gint red, gint green, gint blue);