📄 pixops.c
字号:
has_alpha = gdk_pixbuf_get_has_alpha(src_pixbuf); w_src = gdk_pixbuf_get_width(src_pixbuf); h_src = gdk_pixbuf_get_height(src_pixbuf); if (w_dst == 0) w_dst = w_src; else if (w_dst < 0 && (w_dst = w_src * _GK.theme_scale / 100) <= 0) w_dst = 1; if (h_dst == 0) h_dst = h_src; else if (h_dst < 0 && (h_dst = h_src * _GK.theme_scale / 100) <= 0) h_dst = 1; *pixmap = gdk_pixmap_new(window, w_dst, h_dst, -1); if (mask && has_alpha) *mask = gdk_pixmap_new(window, w_dst, h_dst, 1); if (w_dst == w_src && h_dst == h_src) { _render_to_pixmap(src_pixbuf, pixmap, mask, 0, 0, 0, 0, w_dst, h_dst); return TRUE; } dst_pixbuf = gkrellm_scale_piximage_to_pixbuf(piximage, w_dst, h_dst); _render_to_pixmap(dst_pixbuf, pixmap, mask, 0, 0, 0, 0, w_dst, h_dst); g_object_unref(G_OBJECT(dst_pixbuf)); return TRUE; }voidgkrellm_paste_piximage(GkrellmPiximage *src_piximage, GdkDrawable *drawable, gint x_dst, gint y_dst, gint w_dst, gint h_dst) { GdkPixbuf *dst_pixbuf; gint w_src, h_src; if (!src_piximage || !drawable) return; w_src = gdk_pixbuf_get_width(src_piximage->pixbuf); h_src = gdk_pixbuf_get_height(src_piximage->pixbuf); if (w_dst == 0) w_dst = w_src; else if (w_dst < 0 && (w_dst = w_src * _GK.theme_scale / 100) <= 0) w_dst = 1; if (h_dst == 0) h_dst = h_src; else if (h_dst < 0 && (h_dst = h_src * _GK.theme_scale / 100) <= 0) h_dst = 1; dst_pixbuf = gkrellm_scale_piximage_to_pixbuf(src_piximage, w_dst, h_dst); gdk_pixbuf_render_to_drawable(dst_pixbuf, drawable, _GK.draw1_GC, 0, 0, x_dst, y_dst, w_dst, h_dst, GDK_RGB_DITHER_NORMAL, 0, 0); g_object_unref(G_OBJECT(dst_pixbuf)); }voidgkrellm_paste_pixbuf(GdkPixbuf *src_pixbuf, GdkDrawable *drawable, gint x_dst, gint y_dst, gint w_dst, gint h_dst) { GdkPixbuf *dst_pixbuf; GdkInterpType interp_type; gint w_src, h_src; if (!src_pixbuf || !drawable) return; w_src = gdk_pixbuf_get_width(src_pixbuf); h_src = gdk_pixbuf_get_height(src_pixbuf); if (w_dst > w_src && h_dst > h_src) interp_type = GDK_INTERP_NEAREST; else interp_type = GDK_INTERP_BILINEAR; dst_pixbuf = gdk_pixbuf_scale_simple(src_pixbuf, w_dst, h_dst,interp_type); gdk_pixbuf_render_to_drawable(dst_pixbuf, drawable, _GK.draw1_GC, 0, 0, x_dst, y_dst, w_dst, h_dst, GDK_RGB_DITHER_NORMAL, 0, 0); g_object_unref(G_OBJECT(dst_pixbuf)); }gbooleangkrellm_scale_theme_background(GkrellmPiximage *piximage, GdkPixmap **pixmap, GdkBitmap **mask, gint w_dst, gint h_dst) { GdkWindow *window = gkrellm_get_top_window()->window; GdkPixbuf *src_pixbuf, *sub_pixbuf, *pixbuf; GdkInterpType interp_type; GkrellmBorder bdr; gint w_src, h_src, l, r, t, b; gint hs, hd, ws, wd; gboolean has_alpha; if (_GK.theme_scale == 100) return gkrellm_scale_piximage_to_pixmap(piximage, pixmap, mask, w_dst, h_dst); /* I want the pixmap freed even if there is no image to render back | in. Eg. theme switch to one with no data_in/out_piximage. */ gkrellm_free_pixmap(pixmap); gkrellm_free_bitmap(mask); if (!piximage || !piximage->pixbuf || !pixmap) return FALSE; src_pixbuf = piximage->pixbuf; has_alpha = gdk_pixbuf_get_has_alpha(src_pixbuf); w_src = gdk_pixbuf_get_width(src_pixbuf); h_src = gdk_pixbuf_get_height(src_pixbuf); if (w_dst == 0) w_dst = w_src; if (h_dst == 0) h_dst = h_src; *pixmap = gdk_pixmap_new(window, w_dst, h_dst, -1); if (mask && has_alpha) *mask = gdk_pixmap_new(window, w_dst, h_dst, 1); bdr = piximage->border; if (bdr.left + bdr.right >= w_src) fix_border_overlap(&bdr.left, &bdr.right, w_src); if (bdr.top + bdr.bottom >= h_src) fix_border_overlap(&bdr.top, &bdr.bottom, h_src); l = bdr.left * _GK.theme_scale / 100; r = bdr.right * _GK.theme_scale / 100; t = bdr.top * _GK.theme_scale / 100; b = bdr.bottom * _GK.theme_scale / 100; if (l + r >= w_dst) fix_border_overlap(&l, &r, w_dst); if (t + b >= h_dst) fix_border_overlap(&t, &b, h_dst); interp_type = GDK_INTERP_BILINEAR; if (l > 0 && t > 0) /* top left corner */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, 0, 0, bdr.left, bdr.top); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, l, t, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, 0, 0, l, t); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (l > 0 && b > 0) /* bottom left corner */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, 0, h_src - bdr.bottom, bdr.left, bdr.bottom); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, l, b, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, 0, h_dst - b, l, b); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (r > 0 && t > 0) /* top right corner */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, w_src - bdr.right, 0, bdr.right, bdr.top); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, r, t, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, w_dst - r, 0, r, t); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (r > 0 && b > 0) /* bottom right corner */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, w_src - bdr.right, h_src - bdr.bottom, bdr.right, bdr.bottom); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, r, b, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, w_dst - r, h_dst - b, r, b); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } hs = h_src - bdr.top - bdr.bottom; hd = h_dst - t - b; if (l > 0 && hs > 0 && hd > 0) /* left edge */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, 0, bdr.top, bdr.left, hs); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, l, hd, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, 0, t, l, hd); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (r > 0 && hs > 0 && hd > 0) /* right edge */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, w_src - bdr.right, bdr.top, bdr.right, hs); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, r, hd, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, w_dst - r, t, r, hd); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } ws = w_src - bdr.left - bdr.right; wd = w_dst - l - r; if (t > 0 && ws > 0 && wd > 0) /* top edge */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, bdr.left, 0, ws, bdr.top); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, wd, t, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, l, 0, wd, t); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (b > 0 && ws > 0 && wd > 0) /* bottom edge */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, bdr.left, h_src - bdr.bottom, ws, bdr.bottom); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, wd, b, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, l, h_dst - b, wd, b); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } if (ws > 0 && wd > 0 && hs > 0 && hd > 0) /* center area */ { sub_pixbuf = gdk_pixbuf_new_subpixbuf(src_pixbuf, bdr.left, bdr.top, ws, hs); pixbuf = gdk_pixbuf_scale_simple(sub_pixbuf, wd, hd, interp_type); _render_to_pixmap(pixbuf, pixmap, mask, 0, 0, l, t, wd, hd); g_object_unref(G_OBJECT(sub_pixbuf)); g_object_unref(G_OBJECT(pixbuf)); } return TRUE; }voidgkrellm_destroy_piximage(GkrellmPiximage *piximage) { if (!piximage || !piximage->pixbuf) return; g_object_unref(G_OBJECT(piximage->pixbuf)); g_free(piximage); }voidgkrellm_set_piximage_border(GkrellmPiximage *piximage, GkrellmBorder *border) { GkrellmBorder *b; if (!piximage || !piximage->pixbuf) return; b = &piximage->border; *b = *border; if (b->left < 0) b->left = 0; if (b->right < 0) b->right = 0; if (b->top < 0) b->top = 0; if (b->bottom < 0) b->bottom = 0; }voidgkrellm_border_adjust(GkrellmBorder *border, gint l, gint r, gint t, gint b) { border->left += l; border->right += r; border->top += t; border->bottom += b; if (border->left < 0) border->left = 0; if (border->right < 0) border->right = 0; if (border->top < 0) border->top = 0; if (border->bottom < 0) border->bottom = 0; }GkrellmPiximage *gkrellm_clone_piximage(GkrellmPiximage *src_piximage) { GkrellmPiximage *piximage; if (!src_piximage) return NULL; piximage = g_new0(GkrellmPiximage, 1); piximage->border = src_piximage->border; piximage->pixbuf = gdk_pixbuf_copy(src_piximage->pixbuf); return piximage; }GkrellmPiximage *gkrellm_piximage_new_from_xpm_data(gchar **data) { GkrellmPiximage *piximage; GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) data); if (!pixbuf) return NULL; piximage = g_new0(GkrellmPiximage, 1); piximage->pixbuf = pixbuf; return piximage; }GkrellmPiximage *gkrellm_piximage_new_from_file(gchar *fname) { GkrellmPiximage *piximage; GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_file(fname, NULL); if (!pixbuf) return NULL; piximage = g_new0(GkrellmPiximage, 1); piximage->pixbuf = pixbuf; return piximage; }GkrellmPiximage *gkrellm_piximage_new_from_inline(const guint8 *data, gboolean copy_pixels) { GkrellmPiximage *piximage; GdkPixbuf *pixbuf; pixbuf = gdk_pixbuf_new_from_inline(-1, data, copy_pixels, NULL); if (!pixbuf) return NULL; piximage = g_new0(GkrellmPiximage, 1); piximage->pixbuf = pixbuf; return piximage; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -