]> Pileus Git - ~andy/gtk/blob - demos/testpixbuf.c
Updated Basque translation.
[~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 <gdk-pixbuf/gdk-pixbuf.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 *)g_object_get_data (G_OBJECT (drawing_area), "pixbuf");
322
323         if (gdk_pixbuf_get_has_alpha (pixbuf)) {
324                 GdkPixbuf *dest;
325           
326                 gdk_window_set_back_pixmap (drawing_area->window, NULL, FALSE);
327           
328                 dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
329                 
330                 gdk_pixbuf_composite_color (pixbuf, dest,
331                                             0, 0, event->area.width, event->area.height,
332                                             -event->area.x, -event->area.y,
333                                             (double) drawing_area->allocation.width / gdk_pixbuf_get_width (pixbuf),
334                                             (double) drawing_area->allocation.height / gdk_pixbuf_get_height (pixbuf),
335                                             GDK_INTERP_BILINEAR, 255,
336                                             event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
337                 
338                 gdk_draw_pixbuf (drawing_area->window, drawing_area->style->fg_gc[GTK_STATE_NORMAL], dest,
339                                  0, 0, event->area.x, event->area.y,
340                                  event->area.width, event->area.height,
341                                  GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
342                 
343                 g_object_unref (dest);
344         } else {
345                 gdk_draw_rgb_image (drawing_area->window,
346                                     drawing_area->style->white_gc,
347                                     event->area.x, event->area.y, 
348                                     event->area.width, 
349                                     event->area.height,
350                                     GDK_RGB_DITHER_NORMAL,
351                                     gdk_pixbuf_get_pixels (pixbuf)
352                                     + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
353                                     + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
354                                     gdk_pixbuf_get_rowstride (pixbuf));
355         }
356 }
357
358 static void
359 config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
360 {
361 #if 0
362         GdkPixbuf *pixbuf;
363     
364         pixbuf = (GdkPixbuf *)g_object_get_data (G_OBJECT (drawing_area), "pixbuf");
365
366         if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
367             ((event->height) != gdk_pixbuf_get_height (pixbuf)))
368                 gdk_pixbuf_scale (pixbuf, event->width, event->height);
369 #endif
370 }
371
372 static GtkWidget*
373 new_testrgb_window (GdkPixbuf *pixbuf, gchar *title)
374 {
375         GtkWidget *window;
376         GtkWidget *vbox;
377         GtkWidget *temp_box;
378         GtkWidget *button;
379         GtkWidget *drawing_area;
380         gint w, h;
381
382         g_return_val_if_fail (pixbuf != NULL, NULL);
383         w = gdk_pixbuf_get_width (pixbuf);
384         h = gdk_pixbuf_get_height (pixbuf);
385
386         window = g_object_new (gtk_window_get_type (),
387                                  "GtkObject::user_data", NULL,
388                                  "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
389                                  "GtkWindow::title", title ? title : "testrgb",
390                                  "GtkWindow::allow_shrink", TRUE,
391                                  NULL);
392         g_signal_connect (window, "destroy",
393                           G_CALLBACK (quit_func), NULL);
394
395         vbox = gtk_vbox_new (FALSE, 0);
396
397         if (title)
398                 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
399                                     TRUE, TRUE, 0);
400
401         drawing_area = gtk_drawing_area_new ();
402
403         temp_box = gtk_hbox_new (FALSE, 0);
404         gtk_widget_set_size_request (GTK_WIDGET (drawing_area), w, h);
405         gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
406         gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
407         
408
409         g_signal_connect (drawing_area, "expose_event",
410                           G_CALLBACK (expose_func), NULL);
411         g_signal_connect (drawing_area, "configure_event",
412                           G_CALLBACK (config_func), NULL);
413
414         g_object_set_data (G_OBJECT (drawing_area), "pixbuf", pixbuf);
415
416         gtk_widget_show (drawing_area);
417
418         button = gtk_button_new_with_label ("Quit");
419         gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
420         g_signal_connect_swapped (button, "clicked",
421                                   G_CALLBACK (gtk_widget_destroy), window);
422
423         gtk_widget_show (button);
424
425         gtk_container_add (GTK_CONTAINER (window), vbox);
426         gtk_widget_show_all (vbox);
427
428         gtk_widget_show (window);
429
430         return drawing_area;
431 }
432
433
434 static gint
435 update_timeout (gpointer data)
436 {
437         ProgressFileStatus *status = data;
438         gboolean done;
439         GError *error;
440         
441         done = FALSE;
442         error = NULL;
443
444         if (!feof (status->imagefile)) {
445                 gint nbytes;
446                 
447                 nbytes = fread (status->buf, 1, status->readlen, 
448                                status->imagefile);
449
450
451                 if (!gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes, &error)) {
452                         g_warning ("Error writing to loader: %s",
453                                    error->message);
454                         g_error_free (error);
455                         done = TRUE;
456                 }
457                         
458                         
459         } 
460         else 
461                 done = TRUE;
462           
463         if (done) {
464                 /* ignoring errors, we should not do that. */
465                 gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader), NULL);
466                 gtk_widget_queue_draw (*status->rgbwin);
467                 g_object_unref (status->loader);
468                 fclose (status->imagefile);
469                 g_free (status->buf);
470         }
471
472         return !done;
473 }
474
475
476 static void
477 progressive_prepared_callback (GdkPixbufLoader* loader, gpointer data)
478 {
479         GtkWidget** retloc = data;
480         GdkPixbuf* pixbuf;
481
482         pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
483
484         g_assert (pixbuf != NULL);
485
486         g_object_ref (pixbuf); /* for the RGB window */
487
488         *retloc = new_testrgb_window (pixbuf, "Progressive");
489
490         return;
491 }
492
493
494 static void
495 progressive_updated_callback (GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
496 {
497         GtkWidget** window_loc = data;
498
499         if (*window_loc != NULL)
500                 gtk_widget_queue_draw_area (*window_loc,
501                                            x, y, width, height);
502         return;
503 }
504
505 static int readlen = 4096;
506
507 extern void pixbuf_init (void);
508
509 void size_func (GdkPixbufLoader *loader, gint width, gint height, gpointer data)
510 {
511         gdk_pixbuf_loader_set_size (loader, width*2, height*2);
512 }
513
514
515 int
516 main (int argc, char **argv)
517 {
518         int i;
519         int found_valid = FALSE;
520
521         GdkPixbuf *pixbuf;
522         GdkPixbufLoader *pixbuf_loader;
523
524         pixbuf_init ();
525
526         gtk_init (&argc, &argv);
527
528         /*      gdk_rgb_set_verbose (TRUE);*/
529
530         gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
531
532         {
533                 char *tbf_readlen = getenv ("TBF_READLEN");
534                 if (tbf_readlen) readlen = atoi (tbf_readlen);
535         }
536
537         {
538                 char *tbf_bps = getenv ("TBF_KBPS");
539                 guint bps;
540
541                 if (tbf_bps) {
542                         bps = atoi (tbf_bps);
543                         g_print ("Simulating %d kBytes/sec\n", bps);
544                         readlen = (bps*1024)/10;
545                 }
546         }
547
548         i = 1;
549         if (argc == 1) {
550                 const gchar*** xpmp;
551                 GError *error = NULL;
552                 
553                 pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
554                                                    DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
555                                                    NULL, NULL);
556                 new_testrgb_window (pixbuf, NULL);
557
558                 xpmp = xpms;
559                 while (*xpmp) {
560                         pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
561                         new_testrgb_window (pixbuf, NULL);
562                         ++xpmp;
563                 }
564
565                 /* Test loading from inline data. */
566                 pixbuf = gdk_pixbuf_new_from_inline (-1, apple_red, FALSE, &error);
567                 if (!pixbuf)
568                   {
569                     fprintf (stderr, "failed to construct \"red apple\" pixbuf: %s\n",
570                              error->message);
571                     g_error_free (error);
572                   }
573                 else
574                   new_testrgb_window (pixbuf, "Red apple from inlined RLE data");
575
576                 pixbuf = gdk_pixbuf_new_from_inline (sizeof (gnome_foot), gnome_foot, TRUE, NULL);
577                 new_testrgb_window (pixbuf, "GNOME Foot from inlined RLE data");
578                 
579                 found_valid = TRUE;
580         } else {
581                 for (i = 1; i < argc; i++) {
582                         GError *error;
583
584                         error = NULL;
585                         pixbuf = gdk_pixbuf_new_from_file (argv[i], &error);
586
587                         if (pixbuf == NULL) {
588                                 g_warning ("Error loading image: %s",
589                                            error->message);
590                                 g_error_free (error);
591                         }
592                         
593 #if 0
594                         pixbuf = gdk_pixbuf_rotate (pixbuf, 10.0);
595 #endif
596
597                         if (pixbuf) {
598                                 new_testrgb_window (pixbuf, "File");
599                                 found_valid = TRUE;
600                         }
601                 }
602 #if 1   
603                 {
604                         GtkWidget* rgb_window = NULL;
605                         ProgressFileStatus   status;
606
607                         pixbuf_loader = gdk_pixbuf_loader_new ();
608                         status.loader = pixbuf_loader;
609
610                         status.rgbwin = &rgb_window;
611
612                         status.buf = g_malloc (readlen);
613
614 #if 0
615                         g_signal_connect (pixbuf_loader, "size_prepared", 
616                                           G_CALLBACK (size_func), NULL);
617 #endif
618
619                         g_signal_connect (pixbuf_loader, "area_prepared",
620                                           G_CALLBACK (progressive_prepared_callback),
621                                           &rgb_window);
622                         g_signal_connect (pixbuf_loader, "area_updated",
623                                           G_CALLBACK (progressive_updated_callback),
624                                           &rgb_window);
625                         
626                         status.imagefile = fopen (argv[1], "r");
627                         g_assert (status.imagefile != NULL);
628
629                         status.readlen = readlen;
630
631                         status.timeout = gdk_threads_add_timeout (100, update_timeout, &status);
632                 }
633 #endif
634         }
635
636         if (found_valid)
637                 gtk_main ();
638
639         return 0;
640 }