static void init_X() { int screen; unsigned long foreground, background; XSizeHints hints; char **argv = NULL; XGCValues gcValues; Colormap colormap; XColor rgb_color, hw_color; Font font; //char *FNAME = "hanzigb24st"; char *FNAME = "-misc-fixed-medium-r-normal--0-0-100-100-c-0-iso10646-1"; display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "Can't open dsplay\n"); exit(1); } screen = DefaultScreen(display); foreground = BlackPixel(display, screen); background = WhitePixel(display, screen); window = XCreateSimpleWindow(display, DefaultRootWindow(display), 0, 0, WIDTH, HEIGHT, 10, foreground, background); hints.x = 0; hints.y = 0; hints.width = WIDTH; hints.height = HEIGHT; hints.flags = PPosition | PSize; XSetStandardProperties(display, window, "X", "X", None, argv, 0, &hints); XMapWindow(display, window); set_font(); surface = cairo_xlib_surface_create(display, window, DefaultVisual(display, 0), WIDTH, HEIGHT); cairo_xlib_surface_set_size(surface, WIDTH, HEIGHT); paint_background(); /* cr = cairo_create(surface); draw_text(g_array_index(lyric_lines.lines, GString *, 0)->str, 0.0, 0.0, 1.0, height_lyric_pixbufs[0]); draw_text(g_array_index(lyric_lines.lines, GString*, 1)->str, 0.0, 0.0, 1.0, height_lyric_pixbufs[0]); cairo_destroy(cr); */ XFlush(display); }
static cairo_surface_t* cd_clock_create_bg_surface (CairoDockModuleInstance *myApplet, cairo_t* pSourceContext, int iWidth, int iHeight, SurfaceKind kind) { //g_print ("%s (%dx%d)\n", __func__, iWidth, iHeight); cairo_surface_t* pNewSurface =_cairo_dock_create_blank_surface (pSourceContext, iWidth, iHeight); g_return_val_if_fail (cairo_surface_status (pNewSurface) == CAIRO_STATUS_SUCCESS, NULL); cairo_t* pDrawingContext = cairo_create (pNewSurface); g_return_val_if_fail (cairo_status (pDrawingContext) == CAIRO_STATUS_SUCCESS, NULL); cairo_set_operator (pDrawingContext, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba (pDrawingContext, 1.0f, 1.0f, 1.0f, 0.0f); cairo_paint (pDrawingContext); cairo_set_operator (pDrawingContext, CAIRO_OPERATOR_OVER); cairo_scale (pDrawingContext, (double) iWidth / (double) myData.DimensionData.width, (double) iHeight / (double) myData.DimensionData.height); switch (kind) { case KIND_BACKGROUND : paint_background (myApplet, pDrawingContext); break; case KIND_FOREGROUND : paint_foreground (myApplet, pDrawingContext); break; default : return NULL; } cairo_destroy (pDrawingContext); return pNewSurface; }
void spectrum_extension::refresh(const audio_chunk * p_chunk) { ui_extension::visualisation_host::painter_ptr ps; p_host->create_painter(ps); HDC dc = ps->get_device_context(); const RECT * rc_client = ps->get_area(); { paint_background(dc, rc_client); if (g_is_stream_active(this) && p_chunk) { if (!br_foreground) br_foreground = CreateSolidBrush(cr_fore); if (mode == MODE_BARS) { unsigned totalbars = rc_client->right / m_bar_width; if (totalbars) { const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<totalbars;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, totalbars, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { double sample_val = 0; t_size k; for (k=0; k<channel_count; k++) sample_val += p_data[j*channel_count + k]; sample_val *= 1.0 / channel_count; val = max(val, sample_val); } } RECT r; r.left = 1 + i*m_bar_width; r.right = r.left + m_bar_width - m_bar_gap; r.bottom = rc_client->bottom ? rc_client->bottom-1 : 0; r.top = rc_client->bottom - g_scale_value_single(val, (rc_client->bottom + 1)/2 , m_vertical_scale == scale_logarithmic)*2; if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } int j; for (j=rc_client->bottom; j>rc_client->top; j-=2) { RECT rc = {0, j-1, rc_client->right, j}; FillRect(dc,&rc,br_background); } } } else { const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<(t_size)rc_client->right;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, rc_client->right, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { double sample_val = 0; t_size k; for (k = 0; k<channel_count; k++) sample_val += p_data[j*channel_count + k]; sample_val *= 1.0 / channel_count; val = max(val, sample_val); } } RECT r; r.left = i; r.right = i+1; r.bottom = rc_client->bottom; r.top = rc_client->bottom - g_scale_value_single (val, rc_client->bottom, m_vertical_scale == scale_logarithmic); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } } } } ps.release(); }
/* Paints a rectangle of the dirty region */ static void paint_rectangle (ImageView *view, ArtIRect *rect, GdkInterpType interp_type) { ImageViewPrivate *priv; int scaled_width, scaled_height; int width, height; int xofs, yofs; ArtIRect r, d; GdkPixbuf *tmp; int check_size; guint32 check_1, check_2; priv = view->priv; compute_scaled_size (view, priv->zoomx, priv->zoomy, &scaled_width, &scaled_height); width = GTK_WIDGET (view)->allocation.width; height = GTK_WIDGET (view)->allocation.height; /* Compute image offsets with respect to the window */ if (scaled_width < width) xofs = (width - scaled_width) / 2; else xofs = -priv->xofs; if (scaled_height < height) yofs = (height - scaled_height) / 2; else yofs = -priv->yofs; /* Draw background if necessary, in four steps */ /* Top */ if (yofs > 0) { r.x0 = 0; r.y0 = 0; r.x1 = width; r.y1 = yofs; paint_background (view, &r, rect); } /* Left */ if (xofs > 0) { r.x0 = 0; r.y0 = yofs; r.x1 = xofs; r.y1 = yofs + scaled_height; paint_background (view, &r, rect); } /* Right */ if (xofs >= 0) { r.x0 = xofs + scaled_width; r.y0 = yofs; r.x1 = width; r.y1 = yofs + scaled_height; if (r.x0 < r.x1) paint_background (view, &r, rect); } /* Bottom */ if (yofs >= 0) { r.x0 = 0; r.y0 = yofs + scaled_height; r.x1 = width; r.y1 = height; if (r.y0 < r.y1) paint_background (view, &r, rect); } /* Draw the scaled image * * FIXME: this is not using the color correction tables! */ if (!priv->pixbuf) return; r.x0 = xofs; r.y0 = yofs; r.x1 = xofs + scaled_width; r.y1 = yofs + scaled_height; art_irect_intersect (&d, &r, rect); if (art_irect_empty (&d)) return; /* Short-circuit the fast case to avoid a memcpy() */ if (unity_zoom (priv) && gdk_pixbuf_get_colorspace (priv->pixbuf) == GDK_COLORSPACE_RGB && !gdk_pixbuf_get_has_alpha (priv->pixbuf) && gdk_pixbuf_get_bits_per_sample (priv->pixbuf) == 8) { guchar *pixels; int rowstride; rowstride = gdk_pixbuf_get_rowstride (priv->pixbuf); pixels = (gdk_pixbuf_get_pixels (priv->pixbuf) + (d.y0 - yofs) * rowstride + 3 * (d.x0 - xofs)); gdk_draw_rgb_image_dithalign (GTK_WIDGET (view)->window, GTK_WIDGET (view)->style->black_gc, d.x0, d.y0, d.x1 - d.x0, d.y1 - d.y0, priv->dither, pixels, rowstride, d.x0 - xofs, d.y0 - yofs); return; } /* For all other cases, create a temporary pixbuf */ #ifdef PACK_RGBA tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, d.x1 - d.x0, d.y1 - d.y0); #else tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, d.x1 - d.x0, d.y1 - d.y0); #endif if (!tmp) { g_message ("paint_rectangle(): Could not allocate temporary pixbuf of " "size (%d, %d); skipping", d.x1 - d.x0, d.y1 - d.y0); return; } /* Compute check parameters */ switch (priv->check_type) { case CHECK_TYPE_DARK: check_1 = CHECK_BLACK; check_2 = CHECK_DARK; break; case CHECK_TYPE_MIDTONE: check_1 = CHECK_DARK; check_2 = CHECK_LIGHT; break; case CHECK_TYPE_LIGHT: check_1 = CHECK_LIGHT; check_2 = CHECK_WHITE; break; case CHECK_TYPE_BLACK: check_1 = check_2 = CHECK_BLACK; break; case CHECK_TYPE_GRAY: check_1 = check_2 = CHECK_GRAY; break; case CHECK_TYPE_WHITE: check_1 = check_2 = CHECK_WHITE; break; default: g_assert_not_reached (); return; } switch (priv->check_size) { case CHECK_SIZE_SMALL: check_size = CHECK_SMALL; break; case CHECK_SIZE_MEDIUM: check_size = CHECK_MEDIUM; break; case CHECK_SIZE_LARGE: check_size = CHECK_LARGE; break; default: g_assert_not_reached (); return; } /* Draw! */ gdk_pixbuf_composite_color (priv->pixbuf, tmp, 0, 0, d.x1 - d.x0, d.y1 - d.y0, -(d.x0 - xofs), -(d.y0 - yofs), priv->zoomx, priv->zoomy, unity_zoom (priv) ? GDK_INTERP_NEAREST : interp_type, 255, d.x0 - xofs, d.y0 - yofs, check_size, check_1, check_2); #ifdef PACK_RGBA pack_pixbuf (tmp); #endif gdk_draw_rgb_image_dithalign (GTK_WIDGET (view)->window, GTK_WIDGET (view)->style->black_gc, d.x0, d.y0, d.x1 - d.x0, d.y1 - d.y0, priv->dither, gdk_pixbuf_get_pixels (tmp), gdk_pixbuf_get_rowstride (tmp), d.x0 - xofs, d.y0 - yofs); g_object_unref (tmp); #if 0 gdk_draw_line (GTK_WIDGET (view)->window, GTK_WIDGET (view)->style->black_gc, d.x0, d.y0, d.x1 - 1, d.y1 - 1); gdk_draw_line (GTK_WIDGET (view)->window, GTK_WIDGET (view)->style->black_gc, d.x1 - 1, d.y0, d.x0, d.y1 - 1); #endif }
void spectrum_extension::refresh(const audio_chunk * p_chunk) { ui_extension::visualisation_host::painter_ptr ps; p_host->create_painter(ps); HDC dc = ps->get_device_context(); const RECT * rc_client = ps->get_area(); { /* if (!br_background) br_background = CreateSolidBrush(cr_back); FillRect(dc,&rc_client,br_background);*/ paint_background(dc, rc_client); //HPEN pn = CreatePen(PS_SOLID, 1, cr_fore); //HPEN pn_old = SelectPen(dc, pn); if (g_is_stream_active(this) && p_chunk) { if (!br_foreground) br_foreground = CreateSolidBrush(cr_fore); if (mode == MODE_BARS) { unsigned totalbars = rc_client->right / m_bar_width; if (totalbars) { #if 1 const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<totalbars;i++) { double val = 0; t_size starti, endi, j; g_scale_value(sample_count, i, totalbars, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { t_size k; for (k=0; k<channel_count; k++) val += p_data[j*channel_count + k]; } } val *= 1.0/( (endi-starti+1)*channel_count); val *= 0.80; if (val>1.0) val = 1.0; RECT r; r.left = 1 + i*m_bar_width; r.right = r.left + m_bar_width - m_bar_gap; r.bottom = rc_client->bottom ? rc_client->bottom-1 : 0; r.top = g_scale_value_single(1.0-val, rc_client->bottom, m_vertical_scale == scale_logarithmic); //pfc::rint32((1.0 - val) * (rc_client->bottom)); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); } #else int spread = MulDiv(1, p_chunk->get_sample_count(), totalbars); if (spread < 1) spread = 1; double div = 1.0 / (double) p_chunk->get_channels(); unsigned left = 1; for(i=0;i<totalbars;i++) { unsigned right = left+MulDiv(1, rc_client->right-left-totalbars+i, totalbars-i); RECT r; r.left = left; r.right = right; double val = 0; unsigned start=MulDiv(i, p_chunk->get_sample_count()-spread, totalbars),co = 0; for (n=start;n<(start+spread);n++) { if (n<p_chunk->get_sample_count()) { co++; unsigned c; for(c=0;c<p_chunk->get_channels();c++) { val += ((p_chunk->get_data()[n*p_chunk->get_channels() + c])); } } } val *= div; if (co) val *= (1.0/(double)co); //val = log((val/2.0) + 1.0)*2.0; val *= 0.80; if (val>1.0) val = 1.0; r.bottom = rc_client->bottom > 0 ? rc_client->bottom-1 : 0; int top = (int)( (val) * (double(r.bottom)) + 0.5); top= r.bottom - top; // if (top==0) top++; /* for (;r.bottom-1>top; r.bottom-=2) { r.top = r.bottom-1; //FillRect(dc,&r,br_foreground);//LineToEx ? MoveToEx(dc, r.left, r.top, NULL); LineTo(dc, r.right, r.bottom); }*/ { RECT rc = {left, top, right, rc_client->bottom > 0 ? rc_client->bottom-1 : 0}; FillRect(dc,&rc,br_foreground); } left=right+1; } #endif int j; for (j=rc_client->bottom; j>rc_client->top; j-=2) { RECT rc = {0, j-1, rc_client->right, j}; FillRect(dc,&rc,br_background); } } } else { #if 1 //gdi_object_t<HPEN>::ptr_t pn = CreatePen(PS_SOLID, 1, cr_fore); //HPEN pn_old = SelectPen(dc, pn.get()); const audio_sample * p_data = p_chunk->get_data(); t_size sample_count = p_chunk->get_sample_count(); t_size channel_count = p_chunk->get_channels(); t_size i; for(i=0;i<(t_size)rc_client->right;i++) { double val = 0; //t_size starti = pfc::rint32(start), endi = pfc::rint32(end), j; t_size starti, endi, j; g_scale_value(sample_count, i, rc_client->right, starti, endi, m_scale == scale_logarithmic); for (j=starti;j<=endi; j++) { if (j < sample_count) { t_size k; for (k=0; k<channel_count; k++) val += p_data[j*channel_count + k]; } } val *= 1.0/( (endi-starti+1)*channel_count); val *= 0.80; if (val>1.0) val = 1.0; RECT r; r.left = i; r.right = i+1; r.bottom = rc_client->bottom; r.top = g_scale_value_single (1.0-val, rc_client->bottom, m_vertical_scale == scale_logarithmic);//pfc::rint32((1.0 - val) * (rc_client->bottom)); if (r.bottom>r.top) FillRect(dc,&r,br_foreground); //MoveToEx(dc, r.left, r.bottom, NULL); //LineTo(dc, r.left, r.top); } //SelectPen(dc, pn_old); #else int spread = MulDiv(1, p_chunk->get_sample_count(), rc_client->right); if (spread < 1) spread = 1; double div = 1.0 / (double) p_chunk->get_channels(); assert(rc_client->right>=0); for(i=0;i<(unsigned)rc_client->right;i++) { RECT r; r.left = i;//MulDiv(rc_client->right,n,data->spectrum_size+1); r.right = i+1;//MulDiv(rc_client->right,n+1,data->spectrum_size+1); // if (r.left < r.right) double val = 0; unsigned start=MulDiv(i, p_chunk->get_sample_count()-spread, rc_client->right),co = 0; for (n=start;n<(start+spread);n++) { if (n<p_chunk->get_sample_count()) { co++; unsigned c; for(c=0;c<p_chunk->get_channels();c++) { val += p_chunk->get_data()[n*p_chunk->get_channels() + c]; } } } val *= div; if (co) val *= (1.0/(double)co); //val = log((val/2.0) + 1.0) * 2.0; //close to a str8 line val *= 0.80; if (val>1.0) val = 1.0; r.bottom = rc_client->bottom; r.top = (int)((1.0 - val) * (rc_client->bottom)); /*double rt = sqrt(val); HBRUSH br_test = CreateSolidBrush(pfc::rint32((1.0-rt)*0xff + rt*(0x55))); FillRect(dc,&r,br_test); DeleteBrush(br_test);*/ FillRect(dc,&r,br_foreground); } #endif } } } ps.release(); }