2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2000-01-05 21:33:58 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2001-07-18 04:31:11 +00:00
|
|
|
#include <stdlib.h>
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2000-04-11 07:03:25 +00:00
|
|
|
GdkInterpType interp_type = GDK_INTERP_BILINEAR;
|
2000-01-05 21:33:58 +00:00
|
|
|
int overall_alpha = 255;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GtkWidget *darea;
|
|
|
|
|
|
|
|
void
|
2000-04-11 07:03:25 +00:00
|
|
|
set_interp_type (GtkWidget *widget, gpointer data)
|
2000-01-05 21:33:58 +00:00
|
|
|
{
|
2003-10-13 18:15:10 +00:00
|
|
|
guint types[] = { GDK_INTERP_NEAREST,
|
|
|
|
GDK_INTERP_BILINEAR,
|
|
|
|
GDK_INTERP_TILES,
|
|
|
|
GDK_INTERP_HYPER };
|
|
|
|
|
|
|
|
interp_type = types[gtk_combo_box_get_active (GTK_COMBO_BOX (widget))];
|
2000-01-05 21:33:58 +00:00
|
|
|
gtk_widget_queue_draw (darea);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
overall_changed_cb (GtkAdjustment *adjustment, gpointer data)
|
|
|
|
{
|
2011-01-05 21:14:32 +00:00
|
|
|
if (gtk_adjustment_get_value (adjustment) != overall_alpha)
|
2000-01-05 21:33:58 +00:00
|
|
|
{
|
2011-01-05 21:14:32 +00:00
|
|
|
overall_alpha = gtk_adjustment_get_value (adjustment);
|
2000-01-05 21:33:58 +00:00
|
|
|
gtk_widget_queue_draw (darea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 21:27:02 +00:00
|
|
|
static void
|
|
|
|
draw_func (GtkDrawingArea *darea,
|
|
|
|
cairo_t *cr,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gpointer data)
|
2000-01-05 21:33:58 +00:00
|
|
|
{
|
|
|
|
GdkPixbuf *dest;
|
2010-09-08 23:01:35 +00:00
|
|
|
|
|
|
|
dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2000-06-21 19:48:47 +00:00
|
|
|
gdk_pixbuf_composite_color (pixbuf, dest,
|
2010-09-08 23:01:35 +00:00
|
|
|
0, 0, width, height,
|
|
|
|
0, 0,
|
|
|
|
(double) width / gdk_pixbuf_get_width (pixbuf),
|
|
|
|
(double) height / gdk_pixbuf_get_height (pixbuf),
|
2000-06-21 19:48:47 +00:00
|
|
|
interp_type, overall_alpha,
|
2010-09-08 23:01:35 +00:00
|
|
|
0, 0, 16, 0xaaaaaa, 0x555555);
|
2010-07-12 14:48:53 +00:00
|
|
|
|
|
|
|
gdk_cairo_set_source_pixbuf (cr, dest, 0, 0);
|
2010-09-08 23:01:35 +00:00
|
|
|
cairo_paint (cr);
|
2010-07-12 14:48:53 +00:00
|
|
|
|
Remove assorted G_OBJECT casts where unnecessary.
2001-12-13 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gdk-pixbuf-animation.c, gdk-pixbuf-loader.c, gdk-pixpuf.c,
io-gif-animation.c, io-gif.c, io-tiff.c, test-loaders.c: Remove
assorted G_OBJECT casts where unnecessary.
* gdk-pixbuf-loader.c: Call g_object_ref and g_object_unref
instead of gdk_pixbuf_animation_ref and gdk_pixbuf_animation_unref
resp.
* gdk-pixbuf-csource.c, io-bmp.c, io-gif-animation.c, io-ico.c,
io-jpeg.c, io-png.c, io-pnm.c, io-ras.c, io-tga.c, io-wbmp.c,
io-xbm.c, io-xpm.c, test-gdk-pixbuf.c: Dito for gdk_pixbuf_ref and
gdk_pixbuf_unref.
* Makefile.am, pixops/Makefile.am: Compile everything with
-DG_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED
* gdk-pixdata.c: Use g_ascii_strup() instead of g_strup().
* io-xpm.c: Use g_ascii_strcasecmp() instead of g_strcasecmp().
* demos/testpixbuf-drawable.c, demos/testpixbuf-save.c,
demos/testpixbuf-scale.c, demos/testpixbuf.c: Call g_object_ref
and g_object_unref instead of gdk_pixbuf_ref and gdk_pixbuf_unref
resp.
2001-12-13 21:22:12 +00:00
|
|
|
g_object_unref (dest);
|
2000-01-05 21:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkWidget *window, *vbox;
|
2003-10-13 18:15:10 +00:00
|
|
|
GtkWidget *combo_box;
|
2000-01-05 21:33:58 +00:00
|
|
|
GtkWidget *hbox, *label, *hscale;
|
|
|
|
GtkAdjustment *adjustment;
|
|
|
|
GtkRequisition scratch_requisition;
|
2001-10-05 18:51:47 +00:00
|
|
|
const gchar *creator;
|
2000-10-18 18:42:54 +00:00
|
|
|
GError *error;
|
2000-06-21 20:47:22 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
fprintf (stderr, "Usage: testpixbuf-scale FILE\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2000-10-18 18:42:54 +00:00
|
|
|
error = NULL;
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
|
2000-01-05 21:33:58 +00:00
|
|
|
if (!pixbuf) {
|
2000-10-18 18:42:54 +00:00
|
|
|
fprintf (stderr, "Cannot load image: %s\n",
|
|
|
|
error->message);
|
|
|
|
g_error_free (error);
|
2000-01-05 21:33:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-10-05 18:51:47 +00:00
|
|
|
creator = gdk_pixbuf_get_option (pixbuf, "tEXt::Software");
|
|
|
|
if (creator)
|
|
|
|
g_print ("%s was created by '%s'\n", argv[1], creator);
|
|
|
|
|
2000-01-05 21:33:58 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_main_quit), NULL);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2000-01-05 21:33:58 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
combo_box = gtk_combo_box_text_new ();
|
2003-10-13 18:15:10 +00:00
|
|
|
|
2010-10-02 16:19:46 +00:00
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "NEAREST");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "BILINEAR");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "TILES");
|
|
|
|
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo_box), "HYPER");
|
2003-10-13 18:15:10 +00:00
|
|
|
|
|
|
|
gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 1);
|
|
|
|
|
|
|
|
g_signal_connect (combo_box, "changed",
|
|
|
|
G_CALLBACK (set_interp_type),
|
|
|
|
NULL);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2014-05-24 00:42:47 +00:00
|
|
|
gtk_widget_set_halign (combo_box, GTK_ALIGN_START);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), combo_box);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Overall Alpha:");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), label);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2010-09-27 13:10:12 +00:00
|
|
|
adjustment = gtk_adjustment_new (overall_alpha, 0, 255, 1, 10, 0);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (adjustment, "value_changed",
|
|
|
|
G_CALLBACK (overall_changed_cb), NULL);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2010-10-30 00:07:28 +00:00
|
|
|
hscale = gtk_scale_new (GTK_ORIENTATION_HORIZONTAL, adjustment);
|
2000-01-05 21:33:58 +00:00
|
|
|
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (hscale, TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), hscale);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
/* Compute the size without the drawing area, so we know how big to make the default size */
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size ( (vbox),
|
2010-09-15 01:13:58 +00:00
|
|
|
&scratch_requisition, NULL);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
darea = gtk_drawing_area_new ();
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_hexpand (darea, TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), darea);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2016-11-18 21:27:02 +00:00
|
|
|
gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), draw_func, NULL, NULL);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window),
|
2000-04-11 07:03:25 +00:00
|
|
|
gdk_pixbuf_get_width (pixbuf),
|
|
|
|
scratch_requisition.height + gdk_pixbuf_get_height (pixbuf));
|
2000-01-05 21:33:58 +00:00
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2000-01-05 21:33:58 +00:00
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|