Mercurial > audlegacy
annotate Plugins/Visualization/blur_scope/blur_scope.c @ 713:cf7b5a288564 trunk
[svn] rule for installing data
| author | nenolod |
|---|---|
| date | Sun, 26 Feb 2006 20:14:08 -0800 |
| parents | d539e5c5f730 |
| children | c8cf439179b8 |
| rev | line source |
|---|---|
| 61 | 1 /* BMP - Cross-platform multimedia player |
| 2 * Copyright (C) 2003-2004 BMP development team. | |
| 3 * | |
| 4 * Based on XMMS: | |
| 5 * Copyright (C) 1998-2003 XMMS development team. | |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * w | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 21 */ | |
| 22 | |
| 23 #ifdef HAVE_CONFIG_H | |
| 24 # include "config.h" | |
| 25 #endif | |
| 26 | |
| 27 #include <glib.h> | |
| 28 #include <glib/gi18n.h> | |
| 29 #include <gtk/gtk.h> | |
| 30 #include <string.h> | |
| 31 #include "audacious/plugin.h" | |
| 32 #include "libaudacious/util.h" | |
| 33 #include "libaudacious/configdb.h" | |
| 34 #include "blur_scope.h" | |
| 35 #include "bscope_logo.xpm" | |
| 36 | |
| 37 static GtkWidget *window = NULL, *area; | |
| 38 static GdkPixmap *bg_pixmap = NULL; | |
| 39 static gboolean config_read = FALSE; | |
| 40 | |
| 41 static void bscope_init(void); | |
| 42 static void bscope_cleanup(void); | |
| 43 static void bscope_playback_stop(void); | |
| 44 static void bscope_render_pcm(gint16 data[2][512]); | |
| 45 | |
| 46 BlurScopeConfig bscope_cfg; | |
| 47 | |
| 48 GtkItemFactory *blurscope_popup; | |
| 49 | |
| 50 enum { SCOPE_TOGGLE, SCOPE_CLOSE }; | |
| 51 | |
| 52 void blurscope_callback(gpointer data, guint action, GtkWidget * widget); | |
| 53 gboolean blurscope_popup_menu(GtkWidget * widget, | |
| 54 GdkEventButton * event, gpointer user_data); | |
| 55 | |
| 56 GtkItemFactoryEntry blurscope_menu_entries[] = { | |
| 57 {N_("/Toggle Decorations"), NULL, blurscope_callback, SCOPE_TOGGLE, | |
|
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
482
diff
changeset
|
58 "<Item>", 0}, |
|
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
482
diff
changeset
|
59 {N_("/-"), NULL, NULL, 0, "<Separator>", 0}, |
| 61 | 60 {N_("/Close"), NULL, blurscope_callback, SCOPE_CLOSE, "<StockItem>", |
| 61 GTK_STOCK_CLOSE}, | |
| 62 }; | |
| 63 | |
| 64 static const int blurscope_menu_entries_num = | |
| 65 sizeof(blurscope_menu_entries) / sizeof(blurscope_menu_entries[0]); | |
| 66 | |
| 67 | |
| 68 VisPlugin bscope_vp = { | |
| 69 NULL, | |
| 70 NULL, | |
| 71 0, /* XMMS Session ID, filled in by XMMS */ | |
| 72 NULL, /* description */ | |
| 73 1, /* Number of PCM channels wanted */ | |
| 74 0, /* Number of freq channels wanted */ | |
| 75 bscope_init, /* init */ | |
| 76 bscope_cleanup, /* cleanup */ | |
| 77 NULL, /* about */ | |
| 78 bscope_configure, /* configure */ | |
| 79 NULL, /* disable_plugin */ | |
| 80 NULL, /* playback_start */ | |
| 81 bscope_playback_stop, /* playback_stop */ | |
| 82 bscope_render_pcm, /* render_pcm */ | |
| 83 NULL /* render_freq */ | |
| 84 }; | |
| 85 | |
| 86 VisPlugin * | |
| 87 get_vplugin_info(void) | |
| 88 { | |
| 89 bscope_vp.description = g_strdup("Blur Scope"); | |
| 90 return &bscope_vp; | |
| 91 } | |
| 92 | |
| 93 #define WIDTH 256 | |
| 94 #define HEIGHT 128 | |
| 95 #define min(x,y) ((x)<(y)?(x):(y)) | |
| 96 #define BPL ((WIDTH + 2)) | |
| 97 | |
| 98 static guchar rgb_buf[(WIDTH + 2) * (HEIGHT + 2)]; | |
| 99 static GdkRgbCmap *cmap = NULL; | |
| 100 | |
|
701
d539e5c5f730
[svn] Fixes of the remaining GCC 4.1 warnings from external contributor Diego "Flameeyes" Petteno (Gentoo).
chainsaw
parents:
482
diff
changeset
|
101 inline static void |
| 61 | 102 draw_pixel_8(guchar * buffer, gint x, gint y, guchar c) |
| 103 { | |
| 104 buffer[((y + 1) * BPL) + (x + 1)] = c; | |
| 105 } | |
| 106 | |
| 107 | |
| 108 void | |
| 109 bscope_read_config(void) | |
| 110 { | |
| 111 ConfigDb *db; | |
| 112 | |
| 113 if (!config_read) { | |
| 114 bscope_cfg.color = 0xFF3F7F; | |
| 115 db = bmp_cfg_db_open(); | |
| 116 | |
| 117 if (db) { | |
| 118 bmp_cfg_db_get_int(db, "BlurScope", "color", | |
| 119 (int *) &bscope_cfg.color); | |
| 120 bmp_cfg_db_close(db); | |
| 121 } | |
| 122 config_read = TRUE; | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 | |
| 127 void | |
| 128 bscope_blur_8(guchar * ptr, gint w, gint h, gint bpl) | |
| 129 { | |
| 130 register guint i, sum; | |
| 131 register guchar *iptr; | |
| 132 | |
| 133 iptr = ptr + bpl + 1; | |
| 134 i = bpl * h; | |
| 135 while (i--) { | |
| 136 sum = (iptr[-bpl] + iptr[-1] + iptr[1] + iptr[bpl]) >> 2; | |
| 137 if (sum > 2) | |
| 138 sum -= 2; | |
| 139 *(iptr++) = sum; | |
| 140 } | |
| 141 | |
| 142 | |
| 143 } | |
| 144 | |
| 145 void | |
| 146 generate_cmap(void) | |
| 147 { | |
| 148 guint32 colors[256], i, red, blue, green; | |
| 149 if (window) { | |
| 150 red = (guint32) (bscope_cfg.color / 0x10000); | |
| 151 green = (guint32) ((bscope_cfg.color % 0x10000) / 0x100); | |
| 152 blue = (guint32) (bscope_cfg.color % 0x100); | |
| 153 for (i = 255; i > 0; i--) { | |
| 154 colors[i] = | |
| 155 (((guint32) (i * red / 256) << 16) | | |
| 156 ((guint32) (i * green / 256) << 8) | | |
| 157 ((guint32) (i * blue / 256))); | |
| 158 } | |
| 159 colors[0] = 0; | |
| 160 if (cmap) { | |
| 161 gdk_rgb_cmap_free(cmap); | |
| 162 } | |
| 163 cmap = gdk_rgb_cmap_new(colors, 256); | |
| 164 } | |
| 165 } | |
| 166 | |
| 167 static void | |
| 168 bscope_destroy_cb(GtkWidget * w, gpointer data) | |
| 169 { | |
| 170 bscope_vp.disable_plugin(&bscope_vp); | |
| 171 } | |
| 172 | |
| 173 static void | |
| 174 bscope_init(void) | |
| 175 { | |
| 176 if (window) | |
| 177 return; | |
| 178 bscope_read_config(); | |
| 179 | |
| 180 window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
| 181 gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG); | |
| 182 | |
| 183 blurscope_popup = gtk_item_factory_new(GTK_TYPE_MENU, "<Main>", NULL); | |
| 184 | |
| 185 gtk_item_factory_create_items(GTK_ITEM_FACTORY(blurscope_popup), | |
| 186 blurscope_menu_entries_num, | |
| 187 blurscope_menu_entries, NULL); | |
| 188 | |
| 189 gtk_widget_set_events(window, | |
| 190 GDK_FOCUS_CHANGE_MASK | GDK_BUTTON_MOTION_MASK | | |
| 191 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | | |
| 192 GDK_SCROLL_MASK | GDK_VISIBILITY_NOTIFY_MASK); | |
| 193 | |
| 194 gtk_window_set_title(GTK_WINDOW(window), _("Blur scope")); | |
| 195 gtk_window_set_resizable(GTK_WINDOW(window), FALSE); | |
| 196 gtk_widget_realize(window); | |
| 197 bg_pixmap = | |
| 198 gdk_pixmap_create_from_xpm_d(window->window, NULL, NULL, bscope_logo); | |
| 199 // gdk_window_set_back_pixmap(window->window,bg_pixmap,0); | |
| 200 | |
| 201 g_signal_connect(G_OBJECT(window), "destroy", | |
| 202 G_CALLBACK(bscope_destroy_cb), NULL); | |
| 203 g_signal_connect(G_OBJECT(window), "destroy", | |
| 204 G_CALLBACK(gtk_widget_destroyed), &window); | |
| 205 g_signal_connect(G_OBJECT(window), "button-press-event", | |
| 206 G_CALLBACK(blurscope_popup_menu), NULL); | |
| 207 | |
| 208 gtk_widget_set_size_request(window, WIDTH, HEIGHT); | |
| 209 area = gtk_drawing_area_new(); | |
| 210 gtk_container_add(GTK_CONTAINER(window), area); | |
| 211 gtk_widget_realize(area); | |
| 212 gdk_window_set_back_pixmap(area->window, bg_pixmap, 0); | |
| 213 generate_cmap(); | |
| 214 memset(rgb_buf, 0, (WIDTH + 2) * (HEIGHT + 2)); | |
| 215 | |
| 216 | |
| 217 | |
| 218 gtk_widget_show(area); | |
| 219 gtk_widget_show(window); | |
| 220 gdk_window_clear(window->window); | |
| 221 gdk_window_clear(area->window); | |
| 222 | |
| 223 | |
| 224 } | |
| 225 | |
| 226 static void | |
| 227 bscope_cleanup(void) | |
| 228 { | |
| 229 if (window) | |
| 230 gtk_widget_destroy(window); | |
| 231 if (bg_pixmap) { | |
| 232 g_object_unref(bg_pixmap); | |
| 233 bg_pixmap = NULL; | |
| 234 } | |
| 235 if (cmap) { | |
| 236 gdk_rgb_cmap_free(cmap); | |
| 237 cmap = NULL; | |
| 238 } | |
| 239 } | |
| 240 | |
| 241 static void | |
| 242 bscope_playback_stop(void) | |
| 243 { | |
| 244 if (GTK_WIDGET_REALIZED(area)) | |
| 245 gdk_window_clear(area->window); | |
| 246 } | |
| 247 | |
| 248 static inline void | |
| 249 draw_vert_line(guchar * buffer, gint x, gint y1, gint y2) | |
| 250 { | |
| 251 int y; | |
| 252 if (y1 < y2) { | |
| 253 for (y = y1; y <= y2; y++) | |
| 254 draw_pixel_8(buffer, x, y, 0xFF); | |
| 255 } | |
| 256 else if (y2 < y1) { | |
| 257 for (y = y2; y <= y1; y++) | |
| 258 draw_pixel_8(buffer, x, y, 0xFF); | |
| 259 } | |
| 260 else | |
| 261 draw_pixel_8(buffer, x, y1, 0xFF); | |
| 262 } | |
| 263 | |
| 264 static void | |
| 265 bscope_render_pcm(gint16 data[2][512]) | |
| 266 { | |
| 267 gint i, y, prev_y; | |
| 268 | |
| 269 if (!window) | |
| 270 return; | |
| 271 bscope_blur_8(rgb_buf, WIDTH, HEIGHT, BPL); | |
| 272 prev_y = y = (HEIGHT / 2) + (data[0][0] >> 9); | |
| 273 for (i = 0; i < WIDTH; i++) { | |
| 274 y = (HEIGHT / 2) + (data[0][i >> 1] >> 9); | |
| 275 if (y < 0) | |
| 276 y = 0; | |
| 277 if (y >= HEIGHT) | |
| 278 y = HEIGHT - 1; | |
| 279 draw_vert_line(rgb_buf, i, prev_y, y); | |
| 280 prev_y = y; | |
| 281 } | |
| 282 | |
| 283 GDK_THREADS_ENTER(); | |
| 284 gdk_draw_indexed_image(area->window, area->style->white_gc, 0, 0, | |
| 285 WIDTH, HEIGHT, GDK_RGB_DITHER_NONE, | |
| 286 rgb_buf + BPL + 1, (WIDTH + 2), cmap); | |
| 287 GDK_THREADS_LEAVE(); | |
| 288 return; | |
| 289 } | |
| 290 | |
| 291 gboolean | |
| 292 blurscope_popup_menu(GtkWidget * widget, | |
| 293 GdkEventButton * event, gpointer user_data) | |
| 294 { | |
| 295 | |
| 296 if (event->button == 3) { | |
| 297 gtk_item_factory_popup(blurscope_popup, | |
| 298 event->x_root, | |
| 299 event->y_root, event->button, event->time); | |
| 300 return TRUE; | |
| 301 } | |
| 302 | |
| 303 return FALSE; | |
| 304 } | |
| 305 | |
| 306 void | |
| 307 blurscope_callback(gpointer data, guint action, GtkWidget * widget) | |
| 308 { | |
| 309 | |
| 310 switch (action) { | |
| 311 case SCOPE_TOGGLE: | |
| 312 gtk_window_set_decorated(GTK_WINDOW(window), | |
| 313 !gtk_window_get_decorated(GTK_WINDOW | |
| 314 (window))); | |
| 315 break; | |
| 316 case SCOPE_CLOSE: | |
| 317 gtk_widget_destroy(window); | |
| 318 break; | |
| 319 default: | |
| 320 break; | |
| 321 } | |
| 322 return; | |
| 323 } |
