]> Pileus Git - ~andy/gtk/blob - demos/testpixbuf.c
Remove now-unnecessary cast.
[~andy/gtk] / demos / testpixbuf.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 <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <gtk/gtk.h>
26 #include "gdk-pixbuf.h"
27 #include "gdk-pixbuf-io.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
192 static const char * book_open_xpm[] = {
193 "16 16 4 1",
194 "       c None s None",
195 ".      c black",
196 "X      c #808080",
197 "o      c white",
198 "                ",
199 "  ..            ",
200 " .Xo.    ...    ",
201 " .Xoo. ..oo.    ",
202 " .Xooo.Xooo...  ",
203 " .Xooo.oooo.X.  ",
204 " .Xooo.Xooo.X.  ",
205 " .Xooo.oooo.X.  ",
206 " .Xooo.Xooo.X.  ",
207 " .Xooo.oooo.X.  ",
208 "  .Xoo.Xoo..X.  ",
209 "   .Xo.o..ooX.  ",
210 "    .X..XXXXX.  ",
211 "    ..X.......  ",
212 "     ..         ",
213 "                "};
214
215 static const char * book_closed_xpm[] = {
216 "16 16 6 1",
217 "       c None s None",
218 ".      c black",
219 "X      c red",
220 "o      c yellow",
221 "O      c #808080",
222 "#      c white",
223 "                ",
224 "       ..       ",
225 "     ..XX.      ",
226 "   ..XXXXX.     ",
227 " ..XXXXXXXX.    ",
228 ".ooXXXXXXXXX.   ",
229 "..ooXXXXXXXXX.  ",
230 ".X.ooXXXXXXXXX. ",
231 ".XX.ooXXXXXX..  ",
232 " .XX.ooXXX..#O  ",
233 "  .XX.oo..##OO. ",
234 "   .XX..##OO..  ",
235 "    .X.#OO..    ",
236 "     ..O..      ",
237 "      ..        ",
238 "                "};
239
240 static const char * mini_page_xpm[] = {
241 "16 16 4 1",
242 "       c None s None",
243 ".      c black",
244 "X      c white",
245 "o      c #808080",
246 "                ",
247 "   .......      ",
248 "   .XXXXX..     ",
249 "   .XoooX.X.    ",
250 "   .XXXXX....   ",
251 "   .XooooXoo.o  ",
252 "   .XXXXXXXX.o  ",
253 "   .XooooooX.o  ",
254 "   .XXXXXXXX.o  ",
255 "   .XooooooX.o  ",
256 "   .XXXXXXXX.o  ",
257 "   .XooooooX.o  ",
258 "   .XXXXXXXX.o  ",
259 "   ..........o  ",
260 "    oooooooooo  ",
261 "                "};
262
263 static const char * gtk_mini_xpm[] = {
264 "15 20 17 1",
265 "       c None",
266 ".      c #14121F",
267 "+      c #278828",
268 "@      c #9B3334",
269 "#      c #284C72",
270 "$      c #24692A",
271 "%      c #69282E",
272 "&      c #37C539",
273 "*      c #1D2F4D",
274 "=      c #6D7076",
275 "-      c #7D8482",
276 ";      c #E24A49",
277 ">      c #515357",
278 ",      c #9B9C9B",
279 "'      c #2FA232",
280 ")      c #3CE23D",
281 "!      c #3B6CCB",
282 "               ",
283 "      ***>     ",
284 "    >.*!!!*    ",
285 "   ***....#*=  ",
286 "  *!*.!!!**!!# ",
287 " .!!#*!#*!!!!# ",
288 " @%#!.##.*!!$& ",
289 " @;%*!*.#!#')) ",
290 " @;;@%!!*$&)'' ",
291 " @%.%@%$'&)$+' ",
292 " @;...@$'*'*)+ ",
293 " @;%..@$+*.')$ ",
294 " @;%%;;$+..$)# ",
295 " @;%%;@$$$'.$# ",
296 " %;@@;;$$+))&* ",
297 "  %;;;@+$&)&*  ",
298 "   %;;@'))+>   ",
299 "    %;@'&#     ",
300 "     >%$$      ",
301 "      >=       "};
302
303 const gchar ** xpms[] = { 
304   book_open_xpm,
305   book_closed_xpm,
306   mini_page_xpm,
307   gtk_mini_xpm,
308   NULL
309 };
310
311 static void
312 quit_func (GtkWidget *widget, gpointer dummy)
313 {
314         gtk_main_quit ();
315 }
316
317 static void
318 expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
319 {
320         GdkPixbuf *pixbuf;
321
322         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
323
324         if (!pixbuf->art_pixbuf) {
325                 g_warning ("art_pixbuf is NULL in expose_func!!\n");
326                 return;
327         }
328
329         if (pixbuf->art_pixbuf->has_alpha) {
330                 gdk_draw_rgb_32_image (drawing_area->window,
331                                        drawing_area->style->black_gc,
332                                        event->area.x, event->area.y, 
333                                        event->area.width, 
334                                        event->area.height,
335                                        GDK_RGB_DITHER_MAX, 
336                                        pixbuf->art_pixbuf->pixels 
337                                        + (event->area.y * pixbuf->art_pixbuf->rowstride) 
338                                        + (event->area.x * pixbuf->art_pixbuf->n_channels),
339                                        pixbuf->art_pixbuf->rowstride);
340         } else {
341                 gdk_draw_rgb_image (drawing_area->window,
342                                     drawing_area->style->white_gc,
343                                     event->area.x, event->area.y, 
344                                     event->area.width, 
345                                     event->area.height,
346                                     GDK_RGB_DITHER_NORMAL,
347                                     pixbuf->art_pixbuf->pixels 
348                                     + (event->area.y * pixbuf->art_pixbuf->rowstride) 
349                                     + (event->area.x * pixbuf->art_pixbuf->n_channels),
350                                     pixbuf->art_pixbuf->rowstride);
351         }
352 }
353
354 static void
355 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
356 {
357         GdkPixbuf *pixbuf;
358     
359         pixbuf = (GdkPixbuf *)gtk_object_get_data(GTK_OBJECT(drawing_area), "pixbuf");
360
361         g_print("X:%d Y:%d\n", event->width, event->height);
362
363 #if 0
364         if (((event->width) != (pixbuf->art_pixbuf->width)) ||
365             ((event->height) != (pixbuf->art_pixbuf->height))) 
366                 gdk_pixbuf_scale(pixbuf, event->width, event->height);
367 #endif
368 }
369
370 static GtkWidget*
371 new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
372 {
373         GtkWidget *window;
374         GtkWidget *vbox;
375         GtkWidget *temp_box;
376         GtkWidget *button;
377         GtkWidget *drawing_area;
378         gint w, h;
379  
380         w = pixbuf->art_pixbuf->width;
381         h = pixbuf->art_pixbuf->height;
382
383         window = gtk_widget_new (gtk_window_get_type (),
384                                  "GtkObject::user_data", NULL,
385                                  "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
386                                  "GtkWindow::title", "testrgb",
387                                  "GtkWindow::allow_shrink", TRUE,
388                                  NULL);
389         gtk_signal_connect (GTK_OBJECT (window), "destroy",
390                             (GtkSignalFunc) quit_func, NULL);
391
392         vbox = gtk_vbox_new (FALSE, 0);
393
394         if (title)
395                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
396                                     TRUE, TRUE, 0);
397
398         drawing_area = gtk_drawing_area_new ();
399
400         temp_box = gtk_hbox_new (FALSE, 0);
401         gtk_drawing_area_size (GTK_DRAWING_AREA(drawing_area), w, h);
402         gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
403         gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
404         
405
406         gtk_signal_connect (GTK_OBJECT(drawing_area), "expose_event",
407                             GTK_SIGNAL_FUNC(expose_func), NULL);
408         gtk_signal_connect (GTK_OBJECT(drawing_area), "configure_event",
409                             GTK_SIGNAL_FUNC (config_func), NULL);
410
411         gtk_object_set_data (GTK_OBJECT(drawing_area), "pixbuf", pixbuf);
412
413         gtk_widget_show (drawing_area);
414
415         button = gtk_button_new_with_label ("Quit");
416         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
417         gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
418                                    (GtkSignalFunc) gtk_widget_destroy,
419                                    GTK_OBJECT (window));
420
421         gtk_widget_show (button);
422
423         gtk_container_add (GTK_CONTAINER (window), vbox);
424         gtk_widget_show_all (vbox);
425
426         gtk_widget_show (window);
427
428         return window;
429 }
430
431
432 static gint
433 update_timeout(gpointer data)
434 {
435         ProgressFileStatus *status = data;
436         gboolean done;
437
438         done = TRUE;
439         if (!feof(status->imagefile)) {
440                 gint nbytes;
441
442                 nbytes = fread(status->buf, 1, status->readlen, 
443                                status->imagefile);
444
445                 done = !gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes);
446                         
447         }
448
449         if (done) {
450                 gtk_widget_queue_draw(*status->rgbwin);
451                 gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader));
452                 gtk_object_destroy (GTK_OBJECT(status->loader));
453                 fclose (status->imagefile);
454                 g_free (status->buf);
455         }
456
457         return !done;
458 }
459
460
461 static void
462 progressive_prepared_callback(GdkPixbufLoader* loader, gpointer data)
463 {
464         GtkWidget** retloc = data;
465         GdkPixbuf* pixbuf;
466
467         pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
468         g_assert(pixbuf != NULL);
469
470         gdk_pixbuf_ref(pixbuf); /* for the RGB window */
471
472         *retloc = new_testrgb_window(pixbuf, "Progressive");
473
474         return;
475 }
476
477
478 static void
479 progressive_updated_callback(GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
480 {
481         GtkWidget** window_loc = data;
482
483 /*      g_print ("progressive_updated_callback:\n\t%d\t%d\t%d\t%d\n", x, y, width, height); */
484
485         if (*window_loc != NULL)
486                 gtk_widget_queue_draw_area(*window_loc,
487                                            x, y, width, height);
488
489         return;
490 }
491
492 static int readlen = 4096;
493
494 int
495 main (int argc, char **argv)
496 {
497         int i;
498         int found_valid = FALSE;
499
500         GdkPixbuf *pixbuf;
501         GdkPixbufLoader *pixbuf_loader;
502
503         gtk_init (&argc, &argv);
504
505         gdk_rgb_set_verbose (TRUE);
506
507         gdk_rgb_init ();
508
509         gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
510         gtk_widget_set_default_visual (gdk_rgb_get_visual ());
511
512         {
513                 char *tbf_readlen = getenv("TBF_READLEN");
514                 if(tbf_readlen) readlen = atoi(tbf_readlen);
515         }
516
517         {
518                 char *tbf_bps = getenv("TBF_KBPS");
519                 guint bps;
520
521                 if (tbf_bps) {
522                         bps = atoi(tbf_bps);
523                         g_print ("Simulating %d kBytes/sec\n", bps);
524                         readlen = (bps*1024)/10;
525                 }
526         }
527
528         i = 1;
529         if (argc == 1) {
530                 const gchar*** xpmp;
531                 
532                 pixbuf = gdk_pixbuf_new_from_data (default_image, ART_PIX_RGB, FALSE,
533                                                    DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
534                                                    NULL, NULL);
535                 new_testrgb_window (pixbuf, NULL);
536
537                 xpmp = xpms;
538                 while (*xpmp) {
539                         pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
540                         new_testrgb_window (pixbuf, NULL);
541                         ++xpmp;
542                 }
543                 
544                 found_valid = TRUE;
545         } else {
546                 for (i = 1; i < argc; i++) {
547
548                         pixbuf = gdk_pixbuf_new_from_file (argv[i]);
549 #if 0
550                         pixbuf = gdk_pixbuf_rotate(pixbuf, 10.0);
551 #endif
552
553                         if (pixbuf) {
554                                 new_testrgb_window (pixbuf, "File");
555                                 found_valid = TRUE;
556                         }
557                 }
558 #if 1
559                 {
560                         GtkWidget* rgb_window = NULL;
561                         ProgressFileStatus   status;
562
563                         pixbuf_loader = gdk_pixbuf_loader_new ();
564                         status.loader = pixbuf_loader;
565
566                         status.rgbwin = &rgb_window;
567
568                         status.buf = g_malloc (readlen);
569                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
570                                            "area_prepared",
571                                            GTK_SIGNAL_FUNC(progressive_prepared_callback),
572                                            &rgb_window);
573
574                         gtk_signal_connect(GTK_OBJECT(pixbuf_loader),
575                                            "area_updated",
576                                            GTK_SIGNAL_FUNC(progressive_updated_callback),
577                                            &rgb_window);
578
579                         
580                         status.imagefile = fopen (argv[1], "r");
581                         g_assert (status.imagefile != NULL);
582
583                         status.readlen = readlen;
584
585                         status.timeout = gtk_timeout_add(100, update_timeout, &status);
586                 }
587 #endif
588         }
589
590         if (found_valid)
591                 gtk_main ();
592
593         return 0;
594 }