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