]> Pileus Git - ~andy/gtk/blob - demos/testpixbuf.c
More fixes. See ChangeLog
[~andy/gtk] / demos / testpixbuf.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.  See the ChangeLog
23  * files for a list of changes.  These files are distributed with
24  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
25  */
26
27
28 /* Note: these #includes differ slightly from the testrgb.c file included
29    in the GdkRgb release. */
30
31 /* For gettimeofday */
32 #include <stdlib.h>
33 #include <unistd.h>
34 #include <string.h>
35
36 #include <gtk/gtk.h>
37 #include "gdk-pixbuf.h"
38
39 static void
40 quit_func (GtkWidget *widget, gpointer dummy)
41 {
42   gtk_main_quit ();
43 }
44
45 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
46 {
47   GdkPixBuf *pixbuf = (GdkPixBuf *)data;
48   gint x1, y1, x2, y2;
49
50   if (pixbuf->art_pixbuf->has_alpha){
51     gdk_draw_rgb_32_image (drawing_area->window,
52                            drawing_area->style->black_gc,
53                            event->area.x, event->area.y, 
54                            event->area.width, 
55                            event->area.height,
56                            GDK_RGB_DITHER_MAX, 
57                            pixbuf->art_pixbuf->pixels 
58                            + (event->area.y * pixbuf->art_pixbuf->rowstride) 
59                            + (event->area.x * pixbuf->art_pixbuf->n_channels),
60                            pixbuf->art_pixbuf->rowstride);
61   }else{
62     gdk_draw_rgb_image (drawing_area->window,
63                         drawing_area->style->white_gc,
64                         event->area.x, event->area.y, 
65                         event->area.width, 
66                         event->area.height,
67                         GDK_RGB_DITHER_NORMAL,
68                         pixbuf->art_pixbuf->pixels 
69                         + (event->area.y * pixbuf->art_pixbuf->rowstride) 
70                         + (event->area.x * pixbuf->art_pixbuf->n_channels),
71                         pixbuf->art_pixbuf->rowstride);
72   }
73 }  
74
75 void
76 new_testrgb_window (GdkPixBuf *pixbuf)
77 {
78   GtkWidget *window;
79   GtkWidget *vbox;
80   GtkWidget *button;
81   GtkWidget *drawing_area;
82   gint w, h;
83  
84   w = pixbuf->art_pixbuf->width;
85   h = pixbuf->art_pixbuf->height;
86
87   window = gtk_widget_new (gtk_window_get_type (),
88                            "GtkObject::user_data", NULL,
89                            "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
90                            "GtkWindow::title", "testrgb",
91                            "GtkWindow::allow_shrink", FALSE,
92                            NULL);
93   gtk_signal_connect (GTK_OBJECT (window), "destroy",
94                       (GtkSignalFunc) quit_func, NULL);
95
96   vbox = gtk_vbox_new (FALSE, 0);
97
98   drawing_area = gtk_drawing_area_new ();
99
100   gtk_widget_set_usize (drawing_area, w, h);
101   gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
102
103   gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
104                       GTK_SIGNAL_FUNC (expose_func), pixbuf);
105
106   gtk_widget_show (drawing_area);
107
108   button = gtk_button_new_with_label ("Quit");
109   gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
110   gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
111                              (GtkSignalFunc) gtk_widget_destroy,
112                              GTK_OBJECT (window));
113
114   gtk_widget_show (button);
115
116   gtk_container_add (GTK_CONTAINER (window), vbox);
117   gtk_widget_show (vbox);
118
119   gtk_widget_show (window);
120 }
121
122 int
123 main (int argc, char **argv)
124 {
125   GdkPixBuf *pixbuf;
126
127   gtk_init (&argc, &argv);
128
129   gdk_rgb_set_verbose (TRUE);
130
131   gdk_rgb_init ();
132
133   gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
134   gtk_widget_set_default_visual (gdk_rgb_get_visual ());
135   pixbuf = gdk_pixbuf_load_image ("test.gif");
136
137   new_testrgb_window (pixbuf);
138
139   gtk_main ();
140
141   return 0;
142 }