]> Pileus Git - ~andy/gtk/blob - demos/testanimation.c
Most of this patch is based on a patch by Havoc Pennington (hp@redhat.com)
[~andy/gtk] / demos / testanimation.c
1
2 /* testpixbuf -- test program for gdk-pixbuf code
3  * Copyright (C) 1999 Mark Crichton, Larry Ewing
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <string.h>
26 #include <gtk/gtk.h>
27 #include "gdk-pixbuf.h"
28 #include "gdk-pixbuf-loader.h"
29
30 typedef struct {
31         FILE             *imagefile;
32         GdkPixbufLoader  *loader;
33         GtkWidget        **rgbwin;
34         guchar           *buf;
35         guint            timeout;
36         guint            readlen;
37
38 } ProgressFileStatus;
39
40
41 #define DEFAULT_WIDTH  24
42 #define DEFAULT_HEIGHT 24
43
44 static const unsigned char default_image[] = {
45         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
46         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
47         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
48         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
49         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
50         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
51         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
52         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
53         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
54         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
55         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
56         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
57         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
58         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
59         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
60         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
61         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
62         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
63         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
64         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
65         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
67         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
68         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
69         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
70         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
71         0x00, 0x00, 0x00, 0xae, 0xb3, 0xb3, 0xc6, 0xc9, 0xcd, 0xd7, 0xd4, 0xdf,
72         0xec, 0xde, 0xf3, 0xe7, 0xcb, 0xe9, 0xd9, 0xb5, 0xd3, 0x00, 0x00, 0x00,
73         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
74         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
75         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
76         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xb1, 0xb7, 0xa5,
77         0xb0, 0xb8, 0xad, 0xb3, 0xb9, 0xb6, 0xc1, 0xc6, 0xc8, 0xd5, 0xd3, 0xdc,
78         0xec, 0xde, 0xf3, 0xe5, 0xca, 0xe6, 0xe0, 0xbb, 0xd7, 0xe1, 0xad, 0xc2,
79         0xe3, 0xac, 0xa3, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
80         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
81         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
82         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xca, 0xc1, 0xa4, 0xc5, 0xc7, 0xac,
83         0xb7, 0xbe, 0xaf, 0xad, 0xb4, 0xaf, 0xbd, 0xc2, 0xc3, 0xd1, 0xd0, 0xd8,
84         0xec, 0xde, 0xf3, 0xe5, 0xc7, 0xe4, 0xe0, 0xb6, 0xd1, 0xe7, 0xa9, 0xb4,
85         0xed, 0xcd, 0xb6, 0xd6, 0xcf, 0xae, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
86         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
87         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
88         0x00, 0x00, 0x00, 0xdf, 0xa7, 0x9f, 0xdd, 0xbf, 0xaa, 0xcf, 0xc5, 0xa9,
89         0xc1, 0xc4, 0xac, 0xb2, 0xba, 0xaf, 0xb6, 0xbb, 0xbb, 0xcd, 0xce, 0xd4,
90         0xec, 0xde, 0xf3, 0xe4, 0xc4, 0xe1, 0xe0, 0xaf, 0xc7, 0xea, 0xbc, 0xae,
91         0xe1, 0xd6, 0xb6, 0xc7, 0xcc, 0xae, 0xa2, 0xab, 0x9a, 0x00, 0x00, 0x00,
92         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
93         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
94         0x00, 0x00, 0x00, 0xe3, 0xab, 0xc0, 0xe6, 0xa3, 0xa7, 0xdf, 0xba, 0xa8,
95         0xcf, 0xc5, 0xa9, 0xbd, 0xc2, 0xae, 0xad, 0xb4, 0xaf, 0xc6, 0xc9, 0xcd,
96         0xec, 0xde, 0xf3, 0xe2, 0xbf, 0xdc, 0xe7, 0xa9, 0xb4, 0xe7, 0xd6, 0xb8,
97         0xc7, 0xcc, 0xae, 0xac, 0xb6, 0xa6, 0x9d, 0xa8, 0x9f, 0x00, 0x00, 0x00,
98         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
99         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
100         0xd9, 0xaf, 0xcf, 0xe1, 0xb4, 0xd2, 0xe2, 0xb0, 0xcb, 0xe4, 0xa9, 0xbb,
101         0xe2, 0xb2, 0xa6, 0xcf, 0xc5, 0xa9, 0x6a, 0x6a, 0x6a, 0x0d, 0x0d, 0x0d,
102         0x0d, 0x0d, 0x0d, 0x6a, 0x6a, 0x6a, 0xed, 0xcd, 0xb6, 0xc7, 0xcc, 0xae,
103         0xa6, 0xb1, 0xa3, 0x98, 0xa2, 0x9c, 0x8f, 0x97, 0x96, 0x7e, 0x84, 0x85,
104         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
105         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
106         0xe8, 0xc6, 0xe7, 0xe5, 0xc2, 0xe3, 0xe3, 0xbd, 0xdd, 0xe1, 0xb6, 0xd5,
107         0xe2, 0xb0, 0xcb, 0x6a, 0x6a, 0x6a, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
108         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6a, 0x6a, 0x6a, 0x9d, 0xa8, 0x9f,
109         0x8f, 0x97, 0x96, 0x8b, 0x90, 0x92, 0x97, 0x9e, 0xa2, 0xa0, 0xa7, 0xae,
110         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
111         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
112         0xe7, 0xd3, 0xed, 0xe8, 0xd1, 0xed, 0xe8, 0xce, 0xec, 0xe9, 0xcc, 0xeb,
113         0xe8, 0xc6, 0xe7, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
114         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x0d, 0x0d, 0x0d, 0x97, 0x9e, 0xa2,
115         0xa7, 0xae, 0xb7, 0xb2, 0xb6, 0xc5, 0xba, 0xbc, 0xce, 0xbf, 0xbe, 0xd3,
116         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
117         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
118         0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0,
119         0xe9, 0xdf, 0xf0, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
120         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x0d, 0x0d, 0x0d, 0xe1, 0xd2, 0xf7,
121         0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7,
122         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
123         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
124         0xca, 0xc7, 0xd2, 0xc5, 0xc4, 0xcd, 0xbf, 0xbf, 0xc7, 0xb8, 0xb9, 0xc0,
125         0xae, 0xaf, 0xb6, 0x6a, 0x6a, 0x6a, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
126         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6a, 0x6a, 0x6a, 0xd5, 0xa8, 0xe1,
127         0xd8, 0xb2, 0xe9, 0xd9, 0xb8, 0xed, 0xdb, 0xbd, 0xf0, 0xdc, 0xbf, 0xf1,
128         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
129         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
130         0xa4, 0xa6, 0xac, 0xa8, 0xaa, 0xaf, 0xa0, 0xa6, 0xa8, 0x98, 0x9e, 0x9c,
131         0xa1, 0xa8, 0x9e, 0xb1, 0xb6, 0xa1, 0x6a, 0x6a, 0x6a, 0x0d, 0x0d, 0x0d,
132         0x0d, 0x0d, 0x0d, 0x6a, 0x6a, 0x6a, 0xc0, 0x8c, 0xad, 0xcc, 0x90, 0xb5,
133         0xd3, 0x94, 0xca, 0xd6, 0xa2, 0xdb, 0xd5, 0xa8, 0xe1, 0xcf, 0xa7, 0xdf,
134         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
135         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
136         0x00, 0x00, 0x00, 0x98, 0x9f, 0x9b, 0xa1, 0xa8, 0x9e, 0xac, 0xb3, 0xa0,
137         0xb9, 0xb9, 0xa4, 0xd0, 0xb8, 0xa8, 0xc5, 0xb5, 0xb8, 0xb6, 0xbb, 0xad,
138         0xe3, 0xd7, 0xb5, 0xdd, 0xb4, 0xa9, 0xcb, 0x89, 0xac, 0xc0, 0x8c, 0xad,
139         0xc8, 0x91, 0xb5, 0xd1, 0x8d, 0xb7, 0xd3, 0x94, 0xca, 0x00, 0x00, 0x00,
140         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
141         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
142         0x00, 0x00, 0x00, 0xa1, 0xa7, 0x98, 0xb1, 0xb6, 0xa1, 0xbd, 0xb9, 0xa5,
143         0xd0, 0xb8, 0xa8, 0xca, 0xb5, 0xb7, 0xb8, 0xb1, 0xb1, 0xc2, 0xc8, 0xb2,
144         0xe3, 0xd7, 0xb5, 0xe1, 0xbf, 0xaf, 0xdb, 0x92, 0x9a, 0xbe, 0x82, 0xa6,
145         0xc0, 0x8c, 0xad, 0xc8, 0x91, 0xb4, 0xc7, 0x8b, 0xb0, 0x00, 0x00, 0x00,
146         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
147         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
148         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xbc, 0xb6, 0xa1, 0xd0, 0xb8, 0xa8,
149         0xcd, 0xb6, 0xb7, 0xc0, 0xb4, 0xb5, 0xb1, 0xb1, 0xaa, 0xca, 0xd1, 0xb4,
150         0xe3, 0xd7, 0xb5, 0xe2, 0xc1, 0xb0, 0xdb, 0xa8, 0xa3, 0xd2, 0x8a, 0xa9,
151         0xb7, 0x7e, 0xa2, 0xbd, 0x89, 0xa9, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
152         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
153         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
154         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xc9, 0xaf, 0xaf,
155         0xc5, 0xb5, 0xb8, 0xb8, 0xb1, 0xb1, 0xb6, 0xbb, 0xad, 0xd0, 0xd6, 0xb5,
156         0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xaf, 0xdd, 0xb4, 0xa9, 0xdb, 0x92, 0x9a,
157         0xc6, 0x84, 0xa7, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
158         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
159         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
160         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
161         0x00, 0x00, 0x00, 0xac, 0xaa, 0xa6, 0xbd, 0xc3, 0xb0, 0xd2, 0xd7, 0xb5,
162         0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xae, 0xdb, 0xb6, 0xa8, 0x00, 0x00, 0x00,
163         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
164         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
165         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
166         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
167         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
169         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
170         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
171         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
172         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
173         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
174         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
175         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
176         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
177         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
178         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
179         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
180         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
181         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
182         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
183         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
184         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
185         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
186         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
187         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
188         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff
189 };
190
191 static void
192 quit_func (GtkWidget *widget, gpointer dummy)
193 {
194         gtk_main_quit ();
195 }
196
197 static void
198 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
199 {
200         GdkPixbuf *pixbuf;
201
202         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
203
204         if (gdk_pixbuf_get_has_alpha (pixbuf)) {
205                 gdk_draw_rgb_32_image (drawing_area->window,
206                                        drawing_area->style->black_gc,
207                                        event->area.x, event->area.y, 
208                                        event->area.width, 
209                                        event->area.height,
210                                        GDK_RGB_DITHER_MAX, 
211                                        gdk_pixbuf_get_pixels (pixbuf) 
212                                        + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf)) 
213                                        + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
214                                        gdk_pixbuf_get_rowstride (pixbuf));
215         } else {
216                 gdk_draw_rgb_image (drawing_area->window,
217                                     drawing_area->style->white_gc,
218                                     event->area.x, event->area.y, 
219                                     event->area.width, 
220                                     event->area.height,
221                                     GDK_RGB_DITHER_NORMAL,
222                                     gdk_pixbuf_get_pixels (pixbuf)
223                                     + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
224                                     + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
225                                     gdk_pixbuf_get_rowstride (pixbuf));
226         }
227 }
228
229 static void
230 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
231 {
232         GdkPixbuf *pixbuf;
233     
234         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
235
236 #if 0
237         if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
238             ((event->height) != gdk_pixbuf_get_height (pixbuf)))
239                 gdk_pixbuf_scale(pixbuf, event->width, event->height);
240 #endif
241 }
242
243 static GtkWidget*
244 new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
245 {
246         GtkWidget *window;
247         GtkWidget *vbox;
248         GtkWidget *temp_box;
249         GtkWidget *button;
250         GtkWidget *drawing_area;
251         gint w, h;
252  
253         w = gdk_pixbuf_get_width (pixbuf);
254         h = gdk_pixbuf_get_height (pixbuf);
255
256         window = gtk_widget_new (gtk_window_get_type (),
257                                  "GtkObject::user_data", NULL,
258                                  "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
259                                  "GtkWindow::title", "testrgb",
260                                  "GtkWindow::allow_shrink", TRUE,
261                                  NULL);
262         gtk_signal_connect (GTK_OBJECT (window), "destroy",
263                             (GtkSignalFunc) quit_func, NULL);
264
265         vbox = gtk_vbox_new (FALSE, 0);
266
267         if (title)
268                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
269                                     TRUE, TRUE, 0);
270
271         drawing_area = gtk_drawing_area_new ();
272
273         temp_box = gtk_hbox_new (FALSE, 0);
274         gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
275         gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
276         gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
277         
278
279         gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
280                             GTK_SIGNAL_FUNC(expose_func), NULL);
281         gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
282                             GTK_SIGNAL_FUNC (config_func), NULL);
283
284         gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
285
286         gtk_widget_show (drawing_area);
287
288         button = gtk_button_new_with_label ("Quit");
289         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
290         gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
291                                    (GtkSignalFunc) gtk_widget_destroy,
292                                    GTK_OBJECT (window));
293
294         gtk_widget_show (button);
295
296         gtk_container_add (GTK_CONTAINER (window), vbox);
297         gtk_widget_show_all (vbox);
298
299         gtk_widget_show (window);
300
301         return window;
302 }
303
304 #if 0
305
306 static gint
307 update_timeout(gpointer data)
308 {
309         ProgressFileStatus *status = data;
310         gboolean done;
311
312         done = TRUE;
313         if (!feof(status->imagefile)) {
314                 gint nbytes;
315
316                 nbytes = fread(status->buf, 1, status->readlen, 
317                                status->imagefile);
318
319                 done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
320                         
321         }
322
323         if (done) {
324                 gtk_widget_queue_draw(*status->rgbwin);
325                 gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader));
326                 gtk_object_destroy (GTK_OBJECT(status->loader));
327                 fclose (status->imagefile);
328                 g_free (status->buf);
329         }
330
331         return !done;
332 }
333
334
335 static void
336 progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
337 {
338         GtkWidget** retloc = data;
339         GdkPixbuf* pixbuf;
340
341         pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
342         g_assert(pixbuf != NULL);
343
344         gdk_pixbuf_ref(pixbuf); /* for the RGB window */
345
346         *retloc = new_testrgb_window(pixbuf, "Progressive");
347
348         return;
349 }
350
351
352 static void
353 progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
354 {
355         GtkWidget** window_loc = data;
356
357 /*      g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); */
358
359         if (*window_loc != NULL)
360                 gtk_widget_queue_draw_area(*window_loc,
361                                            x, y, width, height);
362
363         return;
364 }
365
366 #endif
367
368 static int readlen = 4096;
369
370 int
371 main (int argc, char **argv)
372 {
373         int i;
374         int found_valid = FALSE;
375
376         GdkPixbufAnimation *animation;
377
378         gtk_init (&argc, &argv);
379
380         gdk_rgb_set_verbose (TRUE);
381
382         gdk_rgb_init ();
383
384         gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
385         gtk_widget_set_default_visual (gdk_rgb_get_visual ());
386
387         {
388                 char *tbf_readlen = getenv("TBF_READLEN");
389                 if(tbf_readlen) readlen = atoi(tbf_readlen);
390         }
391
392         {
393                 char *tbf_bps = getenv("TBF_KBPS");
394                 guint bps;
395
396                 if (tbf_bps) {
397                         bps = atoi(tbf_bps);
398                         g_print ("Simulating %d kBytes/sec\n", bps);
399                         readlen = (bps*1024)/10;
400                 }
401         }
402
403         i = 1;
404         if (argc == 1) {
405                 g_print ("USAGE:  testanimation FILE1 ...\n");
406                 return 0;
407         } else {
408                 for (i = 1; i < argc; i++) {
409                         animation = gdk_pixbuf_animation_new_from_file (argv[i]);
410
411                         if (animation) {
412                                 gint i = 0;
413                                 GList *listptr;
414                                 for (listptr = gdk_pixbuf_animation_get_frames (animation);
415                                      listptr;
416                                      listptr = listptr->next) {
417                                         GdkPixbufFrame *frame;
418                                         GdkPixbuf *pixbuf;
419                                         gchar *title;
420
421                                         frame = listptr->data;
422                                         pixbuf = gdk_pixbuf_frame_get_pixbuf (frame);
423
424                                         title = g_strdup_printf ("Frame %d", i);
425                                         g_print ("Frame %d  x:%d y:%d width:%d height:%d\n",
426                                                  i,
427                                                  gdk_pixbuf_frame_get_x_offset (frame),
428                                                  gdk_pixbuf_frame_get_y_offset (frame),
429                                                  gdk_pixbuf_get_width (pixbuf),
430                                                  gdk_pixbuf_get_height (pixbuf));
431                                         new_testrgb_window (pixbuf, title);
432                                         g_free (title);
433                                         i++;
434                                 }
435                                 found_valid = TRUE;
436                         }
437                 }
438 #if 0
439                 {
440                         GtkWidget* rgb_window = NULL;
441                         ProgressFileStatus   status;
442                         GdkPixbufLoader *pixbuf_loader;
443
444                         pixbuf_loader = gdk_pixbuf_loader_new ();
445                         status.loader = pixbuf_loader;
446
447                         status.rgbwin = &rgb_window;
448
449                         status.buf = g_malloc (readlen);
450                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
451                                            "area_prepared",
452                                            GTK_SIGNAL_FUNC(progressive_prepared_callback),
453                                            &rgb_window);
454
455                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
456                                            "area_updated",
457                                            GTK_SIGNAL_FUNC(progressive_updated_callback),
458                                            &rgb_window);
459
460                         
461                         status.imagefile = fopen (argv[1], "r");
462                         g_assert (status.imagefile != NULL);
463
464                         status.readlen = readlen;
465
466                         status.timeout = gtk_timeout_add(100, update_timeout, &status);
467                 }
468 #endif
469         }
470
471         if (found_valid)
472                 gtk_main ();
473
474         return 0;
475 }