]> Pileus Git - ~andy/gtk/blob - demos/testpixbuf.c
85dea5b7b78d7ba229ac0d49bf9b1c782cfd1ef8
[~andy/gtk] / demos / testpixbuf.c
1 /* testpixbuf -- test program for gdk-pixbuf code
2  * Copyright (C) 1999 Mark Crichton, Larry Ewing
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 #include <config.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <gtk/gtk.h>
26 #include <gtk/gdk-pixbuf-loader.h>
27
28 typedef struct {
29         FILE             *imagefile;
30         GdkPixbufLoader  *loader;
31         GtkWidget        **rgbwin;
32         guchar           *buf;
33         guint            timeout;
34         guint            readlen;
35 } ProgressFileStatus;
36
37
38 #define DEFAULT_WIDTH  24
39 #define DEFAULT_HEIGHT 24
40
41 static const unsigned char default_image[] = {
42         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
43         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
44         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
64         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
65         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
66         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
67         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
68         0x00, 0x00, 0x00, 0xae, 0xb3, 0xb3, 0xc6, 0xc9, 0xcd, 0xd7, 0xd4, 0xdf,
69         0xec, 0xde, 0xf3, 0xe7, 0xcb, 0xe9, 0xd9, 0xb5, 0xd3, 0x00, 0x00, 0x00,
70         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
71         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
72         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
73         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xb1, 0xb7, 0xa5,
74         0xb0, 0xb8, 0xad, 0xb3, 0xb9, 0xb6, 0xc1, 0xc6, 0xc8, 0xd5, 0xd3, 0xdc,
75         0xec, 0xde, 0xf3, 0xe5, 0xca, 0xe6, 0xe0, 0xbb, 0xd7, 0xe1, 0xad, 0xc2,
76         0xe3, 0xac, 0xa3, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
77         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
78         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
79         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xca, 0xc1, 0xa4, 0xc5, 0xc7, 0xac,
80         0xb7, 0xbe, 0xaf, 0xad, 0xb4, 0xaf, 0xbd, 0xc2, 0xc3, 0xd1, 0xd0, 0xd8,
81         0xec, 0xde, 0xf3, 0xe5, 0xc7, 0xe4, 0xe0, 0xb6, 0xd1, 0xe7, 0xa9, 0xb4,
82         0xed, 0xcd, 0xb6, 0xd6, 0xcf, 0xae, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
83         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
84         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
85         0x00, 0x00, 0x00, 0xdf, 0xa7, 0x9f, 0xdd, 0xbf, 0xaa, 0xcf, 0xc5, 0xa9,
86         0xc1, 0xc4, 0xac, 0xb2, 0xba, 0xaf, 0xb6, 0xbb, 0xbb, 0xcd, 0xce, 0xd4,
87         0xec, 0xde, 0xf3, 0xe4, 0xc4, 0xe1, 0xe0, 0xaf, 0xc7, 0xea, 0xbc, 0xae,
88         0xe1, 0xd6, 0xb6, 0xc7, 0xcc, 0xae, 0xa2, 0xab, 0x9a, 0x00, 0x00, 0x00,
89         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
90         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
91         0x00, 0x00, 0x00, 0xe3, 0xab, 0xc0, 0xe6, 0xa3, 0xa7, 0xdf, 0xba, 0xa8,
92         0xcf, 0xc5, 0xa9, 0xbd, 0xc2, 0xae, 0xad, 0xb4, 0xaf, 0xc6, 0xc9, 0xcd,
93         0xec, 0xde, 0xf3, 0xe2, 0xbf, 0xdc, 0xe7, 0xa9, 0xb4, 0xe7, 0xd6, 0xb8,
94         0xc7, 0xcc, 0xae, 0xac, 0xb6, 0xa6, 0x9d, 0xa8, 0x9f, 0x00, 0x00, 0x00,
95         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
96         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
97         0xd9, 0xaf, 0xcf, 0xe1, 0xb4, 0xd2, 0xe2, 0xb0, 0xcb, 0xe4, 0xa9, 0xbb,
98         0xe2, 0xb2, 0xa6, 0xcf, 0xc5, 0xa9, 0x6a, 0x6a, 0x6a, 0x0d, 0x0d, 0x0d,
99         0x0d, 0x0d, 0x0d, 0x6a, 0x6a, 0x6a, 0xed, 0xcd, 0xb6, 0xc7, 0xcc, 0xae,
100         0xa6, 0xb1, 0xa3, 0x98, 0xa2, 0x9c, 0x8f, 0x97, 0x96, 0x7e, 0x84, 0x85,
101         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
102         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
103         0xe8, 0xc6, 0xe7, 0xe5, 0xc2, 0xe3, 0xe3, 0xbd, 0xdd, 0xe1, 0xb6, 0xd5,
104         0xe2, 0xb0, 0xcb, 0x6a, 0x6a, 0x6a, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
105         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6a, 0x6a, 0x6a, 0x9d, 0xa8, 0x9f,
106         0x8f, 0x97, 0x96, 0x8b, 0x90, 0x92, 0x97, 0x9e, 0xa2, 0xa0, 0xa7, 0xae,
107         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
108         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
109         0xe7, 0xd3, 0xed, 0xe8, 0xd1, 0xed, 0xe8, 0xce, 0xec, 0xe9, 0xcc, 0xeb,
110         0xe8, 0xc6, 0xe7, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
111         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x0d, 0x0d, 0x0d, 0x97, 0x9e, 0xa2,
112         0xa7, 0xae, 0xb7, 0xb2, 0xb6, 0xc5, 0xba, 0xbc, 0xce, 0xbf, 0xbe, 0xd3,
113         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
114         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
115         0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0, 0xe9, 0xdf, 0xf0,
116         0xe9, 0xdf, 0xf0, 0x0d, 0x0d, 0x0d, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
117         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x0d, 0x0d, 0x0d, 0xe1, 0xd2, 0xf7,
118         0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7, 0xe1, 0xd2, 0xf7,
119         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
120         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
121         0xca, 0xc7, 0xd2, 0xc5, 0xc4, 0xcd, 0xbf, 0xbf, 0xc7, 0xb8, 0xb9, 0xc0,
122         0xae, 0xaf, 0xb6, 0x6a, 0x6a, 0x6a, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
123         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x6a, 0x6a, 0x6a, 0xd5, 0xa8, 0xe1,
124         0xd8, 0xb2, 0xe9, 0xd9, 0xb8, 0xed, 0xdb, 0xbd, 0xf0, 0xdc, 0xbf, 0xf1,
125         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
126         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
127         0xa4, 0xa6, 0xac, 0xa8, 0xaa, 0xaf, 0xa0, 0xa6, 0xa8, 0x98, 0x9e, 0x9c,
128         0xa1, 0xa8, 0x9e, 0xb1, 0xb6, 0xa1, 0x6a, 0x6a, 0x6a, 0x0d, 0x0d, 0x0d,
129         0x0d, 0x0d, 0x0d, 0x6a, 0x6a, 0x6a, 0xc0, 0x8c, 0xad, 0xcc, 0x90, 0xb5,
130         0xd3, 0x94, 0xca, 0xd6, 0xa2, 0xdb, 0xd5, 0xa8, 0xe1, 0xcf, 0xa7, 0xdf,
131         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
132         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
133         0x00, 0x00, 0x00, 0x98, 0x9f, 0x9b, 0xa1, 0xa8, 0x9e, 0xac, 0xb3, 0xa0,
134         0xb9, 0xb9, 0xa4, 0xd0, 0xb8, 0xa8, 0xc5, 0xb5, 0xb8, 0xb6, 0xbb, 0xad,
135         0xe3, 0xd7, 0xb5, 0xdd, 0xb4, 0xa9, 0xcb, 0x89, 0xac, 0xc0, 0x8c, 0xad,
136         0xc8, 0x91, 0xb5, 0xd1, 0x8d, 0xb7, 0xd3, 0x94, 0xca, 0x00, 0x00, 0x00,
137         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
138         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
139         0x00, 0x00, 0x00, 0xa1, 0xa7, 0x98, 0xb1, 0xb6, 0xa1, 0xbd, 0xb9, 0xa5,
140         0xd0, 0xb8, 0xa8, 0xca, 0xb5, 0xb7, 0xb8, 0xb1, 0xb1, 0xc2, 0xc8, 0xb2,
141         0xe3, 0xd7, 0xb5, 0xe1, 0xbf, 0xaf, 0xdb, 0x92, 0x9a, 0xbe, 0x82, 0xa6,
142         0xc0, 0x8c, 0xad, 0xc8, 0x91, 0xb4, 0xc7, 0x8b, 0xb0, 0x00, 0x00, 0x00,
143         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
144         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
145         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xbc, 0xb6, 0xa1, 0xd0, 0xb8, 0xa8,
146         0xcd, 0xb6, 0xb7, 0xc0, 0xb4, 0xb5, 0xb1, 0xb1, 0xaa, 0xca, 0xd1, 0xb4,
147         0xe3, 0xd7, 0xb5, 0xe2, 0xc1, 0xb0, 0xdb, 0xa8, 0xa3, 0xd2, 0x8a, 0xa9,
148         0xb7, 0x7e, 0xa2, 0xbd, 0x89, 0xa9, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
149         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
150         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
151         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xc9, 0xaf, 0xaf,
152         0xc5, 0xb5, 0xb8, 0xb8, 0xb1, 0xb1, 0xb6, 0xbb, 0xad, 0xd0, 0xd6, 0xb5,
153         0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xaf, 0xdd, 0xb4, 0xa9, 0xdb, 0x92, 0x9a,
154         0xc6, 0x84, 0xa7, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
155         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
156         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
157         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
158         0x00, 0x00, 0x00, 0xac, 0xaa, 0xa6, 0xbd, 0xc3, 0xb0, 0xd2, 0xd7, 0xb5,
159         0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xae, 0xdb, 0xb6, 0xa8, 0x00, 0x00, 0x00,
160         0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
161         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
162         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
163         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
164         0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
166         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
167         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
168         0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 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 };
187
188
189 static const char * book_open_xpm[] = {
190 "16 16 4 1",
191 "       c None s None",
192 ".      c black",
193 "X      c #808080",
194 "o      c white",
195 "                ",
196 "  ..            ",
197 " .Xo.    ...    ",
198 " .Xoo. ..oo.    ",
199 " .Xooo.Xooo...  ",
200 " .Xooo.oooo.X.  ",
201 " .Xooo.Xooo.X.  ",
202 " .Xooo.oooo.X.  ",
203 " .Xooo.Xooo.X.  ",
204 " .Xooo.oooo.X.  ",
205 "  .Xoo.Xoo..X.  ",
206 "   .Xo.o..ooX.  ",
207 "    .X..XXXXX.  ",
208 "    ..X.......  ",
209 "     ..         ",
210 "                "};
211
212 static const char * book_closed_xpm[] = {
213 "16 16 6 1",
214 "       c None s None",
215 ".      c black",
216 "X      c red",
217 "o      c yellow",
218 "O      c #808080",
219 "#      c white",
220 "                ",
221 "       ..       ",
222 "     ..XX.      ",
223 "   ..XXXXX.     ",
224 " ..XXXXXXXX.    ",
225 ".ooXXXXXXXXX.   ",
226 "..ooXXXXXXXXX.  ",
227 ".X.ooXXXXXXXXX. ",
228 ".XX.ooXXXXXX..  ",
229 " .XX.ooXXX..#O  ",
230 "  .XX.oo..##OO. ",
231 "   .XX..##OO..  ",
232 "    .X.#OO..    ",
233 "     ..O..      ",
234 "      ..        ",
235 "                "};
236
237 static const char * mini_page_xpm[] = {
238 "16 16 4 1",
239 "       c None s None",
240 ".      c black",
241 "X      c white",
242 "o      c #808080",
243 "                ",
244 "   .......      ",
245 "   .XXXXX..     ",
246 "   .XoooX.X.    ",
247 "   .XXXXX....   ",
248 "   .XooooXoo.o  ",
249 "   .XXXXXXXX.o  ",
250 "   .XooooooX.o  ",
251 "   .XXXXXXXX.o  ",
252 "   .XooooooX.o  ",
253 "   .XXXXXXXX.o  ",
254 "   .XooooooX.o  ",
255 "   .XXXXXXXX.o  ",
256 "   ..........o  ",
257 "    oooooooooo  ",
258 "                "};
259
260 static const char * gtk_mini_xpm[] = {
261 "15 20 17 1",
262 "       c None",
263 ".      c #14121F",
264 "+      c #278828",
265 "@      c #9B3334",
266 "#      c #284C72",
267 "$      c #24692A",
268 "%      c #69282E",
269 "&      c #37C539",
270 "*      c #1D2F4D",
271 "=      c #6D7076",
272 "-      c #7D8482",
273 ";      c #E24A49",
274 ">      c #515357",
275 ",      c #9B9C9B",
276 "'      c #2FA232",
277 ")      c #3CE23D",
278 "!      c #3B6CCB",
279 "               ",
280 "      ***>     ",
281 "    >.*!!!*    ",
282 "   ***....#*=  ",
283 "  *!*.!!!**!!# ",
284 " .!!#*!#*!!!!# ",
285 " @%#!.##.*!!$& ",
286 " @;%*!*.#!#')) ",
287 " @;;@%!!*$&)'' ",
288 " @%.%@%$'&)$+' ",
289 " @;...@$'*'*)+ ",
290 " @;%..@$+*.')$ ",
291 " @;%%;;$+..$)# ",
292 " @;%%;@$$$'.$# ",
293 " %;@@;;$$+))&* ",
294 "  %;;;@+$&)&*  ",
295 "   %;;@'))+>   ",
296 "    %;@'&#     ",
297 "     >%$$      ",
298 "      >=       "};
299
300 const gchar ** xpms[] = { 
301   book_open_xpm,
302   book_closed_xpm,
303   mini_page_xpm,
304   gtk_mini_xpm,
305   NULL
306 };
307
308 static void
309 quit_func (GtkWidget *widget, gpointer dummy)
310 {
311         gtk_main_quit ();
312 }
313
314 static void
315 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
316 {
317         GdkPixbuf *pixbuf;
318
319         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
320
321         if (gdk_pixbuf_get_has_alpha (pixbuf)) {
322                 gdk_draw_rgb_32_image (drawing_area->window,
323                                        drawing_area->style->black_gc,
324                                        event->area.x, event->area.y, 
325                                        event->area.width, 
326                                        event->area.height,
327                                        GDK_RGB_DITHER_MAX, 
328                                        gdk_pixbuf_get_pixels (pixbuf)
329                                        + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf)) 
330                                        + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
331                                        gdk_pixbuf_get_rowstride (pixbuf));
332         } else {
333                 gdk_draw_rgb_image (drawing_area->window,
334                                     drawing_area->style->white_gc,
335                                     event->area.x, event->area.y, 
336                                     event->area.width, 
337                                     event->area.height,
338                                     GDK_RGB_DITHER_NORMAL,
339                                     gdk_pixbuf_get_pixels (pixbuf)
340                                     + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
341                                     + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
342                                     gdk_pixbuf_get_rowstride (pixbuf));
343         }
344 }
345
346 static void
347 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
348 {
349         GdkPixbuf *pixbuf;
350     
351         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
352
353         g_print("X:%d Y:%d\n", event->width, event->height);
354
355 #if 0
356         if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
357             ((event->height) != gdk_pixbuf_get_height (pixbuf)))
358                 gdk_pixbuf_scale(pixbuf, event->width, event->height);
359 #endif
360 }
361
362 static GtkWidget*
363 new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
364 {
365         GtkWidget *window;
366         GtkWidget *vbox;
367         GtkWidget *temp_box;
368         GtkWidget *button;
369         GtkWidget *drawing_area;
370         gint w, h;
371  
372         w = gdk_pixbuf_get_width (pixbuf);
373         h = gdk_pixbuf_get_height (pixbuf);
374
375         window = gtk_widget_new (gtk_window_get_type (),
376                                  "GtkObject::user_data", NULL,
377                                  "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
378                                  "GtkWindow::title", "testrgb",
379                                  "GtkWindow::allow_shrink", TRUE,
380                                  NULL);
381         gtk_signal_connect (GTK_OBJECT (window), "destroy",
382                             (GtkSignalFunc) quit_func, NULL);
383
384         vbox = gtk_vbox_new (FALSE, 0);
385
386         if (title)
387                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
388                                     TRUE, TRUE, 0);
389
390         drawing_area = gtk_drawing_area_new ();
391
392         temp_box = gtk_hbox_new (FALSE, 0);
393         gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
394         gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
395         gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
396         
397
398         gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
399                             GTK_SIGNAL_FUNC(expose_func), NULL);
400         gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
401                             GTK_SIGNAL_FUNC (config_func), NULL);
402
403         gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
404
405         gtk_widget_show (drawing_area);
406
407         button = gtk_button_new_with_label ("Quit");
408         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
409         gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
410                                    (GtkSignalFunc) gtk_widget_destroy,
411                                    GTK_OBJECT (window));
412
413         gtk_widget_show (button);
414
415         gtk_container_add (GTK_CONTAINER (window), vbox);
416         gtk_widget_show_all (vbox);
417
418         gtk_widget_show (window);
419
420         return window;
421 }
422
423
424 static gint
425 update_timeout(gpointer data)
426 {
427         ProgressFileStatus *status = data;
428         gboolean done;
429
430         done = TRUE;
431         if (!feof(status->imagefile)) {
432                 gint nbytes;
433
434                 nbytes = fread(status->buf, 1, status->readlen, 
435                                status->imagefile);
436
437                 done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
438                         
439         }
440
441         if (done) {
442                 gtk_widget_queue_draw(*status->rgbwin);
443                 gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader));
444                 gtk_object_destroy (GTK_OBJECT(status->loader));
445                 fclose (status->imagefile);
446                 g_free (status->buf);
447         }
448
449         return !done;
450 }
451
452
453 static void
454 progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
455 {
456         GtkWidget** retloc = data;
457         GdkPixbuf* pixbuf;
458
459         pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
460         g_assert(pixbuf != NULL);
461
462         gdk_pixbuf_ref(pixbuf); /* for the RGB window */
463
464         *retloc = new_testrgb_window(pixbuf, "Progressive");
465
466         return;
467 }
468
469
470 static void
471 progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
472 {
473         GtkWidget** window_loc = data;
474
475 /*      g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); */
476
477         if (*window_loc != NULL)
478                 gtk_widget_queue_draw_area(*window_loc,
479                                            x, y, width, height);
480
481         return;
482 }
483
484 static int readlen = 4096;
485
486 extern void pixbuf_init();
487
488 int
489 main (int argc, char **argv)
490 {
491         int i;
492         int found_valid = FALSE;
493
494         GdkPixbuf *pixbuf;
495         GdkPixbufLoader *pixbuf_loader;
496
497         pixbuf_init ();
498
499         gtk_init (&argc, &argv);
500
501         gdk_rgb_set_verbose (TRUE);
502
503         gdk_rgb_init ();
504
505         gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
506         gtk_widget_set_default_visual (gdk_rgb_get_visual ());
507
508         {
509                 char *tbf_readlen = getenv("TBF_READLEN");
510                 if(tbf_readlen) readlen = atoi(tbf_readlen);
511         }
512
513         {
514                 char *tbf_bps = getenv("TBF_KBPS");
515                 guint bps;
516
517                 if (tbf_bps) {
518                         bps = atoi(tbf_bps);
519                         g_print ("Simulating %d kBytes/sec\n", bps);
520                         readlen = (bps*1024)/10;
521                 }
522         }
523
524         i = 1;
525         if (argc == 1) {
526                 const gchar*** xpmp;
527                 
528                 pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
529                                                    DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
530                                                    NULL, NULL);
531                 new_testrgb_window (pixbuf, NULL);
532
533                 xpmp = xpms;
534                 while (*xpmp) {
535                         pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
536                         new_testrgb_window (pixbuf, NULL);
537                         ++xpmp;
538                 }
539                 
540                 found_valid = TRUE;
541         } else {
542                 for (i = 1; i < argc; i++) {
543
544                         pixbuf = gdk_pixbuf_new_from_file (argv[i]);
545 #if 0
546                         pixbuf = gdk_pixbuf_rotate(pixbuf, 10.0);
547 #endif
548
549                         if (pixbuf) {
550                                 new_testrgb_window (pixbuf, "File");
551                                 found_valid = TRUE;
552                         }
553                 }
554 #if 1
555                 {
556                         GtkWidget* rgb_window = NULL;
557                         ProgressFileStatus   status;
558
559                         pixbuf_loader = gdk_pixbuf_loader_new ();
560                         status.loader = pixbuf_loader;
561
562                         status.rgbwin = &rgb_window;
563
564                         status.buf = g_malloc (readlen);
565                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
566                                            "area_prepared",
567                                            GTK_SIGNAL_FUNC(progressive_prepared_callback),
568                                            &rgb_window);
569
570                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
571                                            "area_updated",
572                                            GTK_SIGNAL_FUNC(progressive_updated_callback),
573                                            &rgb_window);
574
575                         
576                         status.imagefile = fopen (argv[1], "r");
577                         g_assert (status.imagefile != NULL);
578
579                         status.readlen = readlen;
580
581                         status.timeout = gtk_timeout_add(100, update_timeout, &status);
582                 }
583 #endif
584         }
585
586         if (found_valid)
587                 gtk_main ();
588
589         return 0;
590 }