testpixbuf.c 22.5 KB
Newer Older
Mark Crichton's avatar
Mark Crichton committed
1 2
/* testpixbuf -- test program for gdk-pixbuf code
 * Copyright (C) 1999 Mark Crichton, Larry Ewing
Mark Crichton's avatar
Mark Crichton committed
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
Mark Crichton's avatar
Mark Crichton committed
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
Mark Crichton's avatar
Mark Crichton committed
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
Mark Crichton's avatar
Mark Crichton committed
15 16 17 18 19
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

20
#include "config.h"
21
#include <stdio.h>
Mark Crichton's avatar
Mark Crichton committed
22 23 24 25
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
26
#include <gdk-pixbuf/gdk-pixbuf.h>
Mark Crichton's avatar
Mark Crichton committed
27

Havoc Pennington's avatar
Havoc Pennington committed
28 29
#include "test-inline-pixbufs.h"

30 31 32
typedef struct {
	FILE             *imagefile;
	GdkPixbufLoader  *loader;
33
	GtkWidget        **rgbwin;
34 35 36 37 38 39
	guchar           *buf;
	guint            timeout;
	guint            readlen;
} ProgressFileStatus;


40 41 42 43
#define DEFAULT_WIDTH  24
#define DEFAULT_HEIGHT 24

static const unsigned char default_image[] = {
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0xae, 0xb3, 0xb3, 0xc6, 0xc9, 0xcd, 0xd7, 0xd4, 0xdf,
	0xec, 0xde, 0xf3, 0xe7, 0xcb, 0xe9, 0xd9, 0xb5, 0xd3, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0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ff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xc9, 0xaf, 0xaf,
	0xc5, 0xb5, 0xb8, 0xb8, 0xb1, 0xb1, 0xb6, 0xbb, 0xad, 0xd0, 0xd6, 0xb5,
	0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xaf, 0xdd, 0xb4, 0xa9, 0xdb, 0x92, 0x9a,
	0xc6, 0x84, 0xa7, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0xac, 0xaa, 0xa6, 0xbd, 0xc3, 0xb0, 0xd2, 0xd7, 0xb5,
	0xe3, 0xd7, 0xb5, 0xe2, 0xbf, 0xae, 0xdb, 0xb6, 0xa8, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff,
	0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff
188 189
};

190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309

static const char * book_open_xpm[] = {
"16 16 4 1",
"       c None s None",
".      c black",
"X      c #808080",
"o      c white",
"                ",
"  ..            ",
" .Xo.    ...    ",
" .Xoo. ..oo.    ",
" .Xooo.Xooo...  ",
" .Xooo.oooo.X.  ",
" .Xooo.Xooo.X.  ",
" .Xooo.oooo.X.  ",
" .Xooo.Xooo.X.  ",
" .Xooo.oooo.X.  ",
"  .Xoo.Xoo..X.  ",
"   .Xo.o..ooX.  ",
"    .X..XXXXX.  ",
"    ..X.......  ",
"     ..         ",
"                "};

static const char * book_closed_xpm[] = {
"16 16 6 1",
"       c None s None",
".      c black",
"X      c red",
"o      c yellow",
"O      c #808080",
"#      c white",
"                ",
"       ..       ",
"     ..XX.      ",
"   ..XXXXX.     ",
" ..XXXXXXXX.    ",
".ooXXXXXXXXX.   ",
"..ooXXXXXXXXX.  ",
".X.ooXXXXXXXXX. ",
".XX.ooXXXXXX..  ",
" .XX.ooXXX..#O  ",
"  .XX.oo..##OO. ",
"   .XX..##OO..  ",
"    .X.#OO..    ",
"     ..O..      ",
"      ..        ",
"                "};

static const char * mini_page_xpm[] = {
"16 16 4 1",
"       c None s None",
".      c black",
"X      c white",
"o      c #808080",
"                ",
"   .......      ",
"   .XXXXX..     ",
"   .XoooX.X.    ",
"   .XXXXX....   ",
"   .XooooXoo.o  ",
"   .XXXXXXXX.o  ",
"   .XooooooX.o  ",
"   .XXXXXXXX.o  ",
"   .XooooooX.o  ",
"   .XXXXXXXX.o  ",
"   .XooooooX.o  ",
"   .XXXXXXXX.o  ",
"   ..........o  ",
"    oooooooooo  ",
"                "};

static const char * gtk_mini_xpm[] = {
"15 20 17 1",
"       c None",
".      c #14121F",
"+      c #278828",
"@      c #9B3334",
"#      c #284C72",
"$      c #24692A",
"%      c #69282E",
"&      c #37C539",
"*      c #1D2F4D",
"=      c #6D7076",
"-      c #7D8482",
";      c #E24A49",
">      c #515357",
",      c #9B9C9B",
"'      c #2FA232",
")      c #3CE23D",
"!      c #3B6CCB",
"               ",
"      ***>     ",
"    >.*!!!*    ",
"   ***....#*=  ",
"  *!*.!!!**!!# ",
" .!!#*!#*!!!!# ",
" @%#!.##.*!!$& ",
" @;%*!*.#!#')) ",
" @;;@%!!*$&)'' ",
" @%.%@%$'&)$+' ",
" @;...@$'*'*)+ ",
" @;%..@$+*.')$ ",
" @;%%;;$+..$)# ",
" @;%%;@$$$'.$# ",
" %;@@;;$$+))&* ",
"  %;;;@+$&)&*  ",
"   %;;@'))+>   ",
"    %;@'&#     ",
"     >%$$      ",
"      >=       "};

const gchar ** xpms[] = { 
  book_open_xpm,
  book_closed_xpm,
  mini_page_xpm,
  gtk_mini_xpm,
  NULL
};

Mark Crichton's avatar
Mark Crichton committed
310 311 312
static void
quit_func (GtkWidget *widget, gpointer dummy)
{
313
	gtk_main_quit ();
Mark Crichton's avatar
Mark Crichton committed
314 315
}

316
static void
Mark Crichton's avatar
Mark Crichton committed
317
expose_func (GtkWidget *drawing_area, GdkEventExpose *event, gpointer data)
Mark Crichton's avatar
Mark Crichton committed
318
{
319 320
	GdkPixbuf *pixbuf;

321
	pixbuf = (GdkPixbuf *)g_object_get_data (G_OBJECT (drawing_area), "pixbuf");
322

323
	if (gdk_pixbuf_get_has_alpha (pixbuf)) {
Matthias Clasen's avatar
Matthias Clasen committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337
		GdkPixbuf *dest;
	  
		gdk_window_set_back_pixmap (drawing_area->window, NULL, FALSE);
	  
		dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, event->area.width, event->area.height);
		
		gdk_pixbuf_composite_color (pixbuf, dest,
					    0, 0, event->area.width, event->area.height,
					    -event->area.x, -event->area.y,
					    (double) drawing_area->allocation.width / gdk_pixbuf_get_width (pixbuf),
					    (double) drawing_area->allocation.height / gdk_pixbuf_get_height (pixbuf),
					    GDK_INTERP_BILINEAR, 255,
					    event->area.x, event->area.y, 16, 0xaaaaaa, 0x555555);
		
338 339 340 341
		gdk_draw_pixbuf (drawing_area->window, drawing_area->style->fg_gc[GTK_STATE_NORMAL], dest,
				 0, 0, event->area.x, event->area.y,
				 event->area.width, event->area.height,
				 GDK_RGB_DITHER_NORMAL, event->area.x, event->area.y);
Matthias Clasen's avatar
Matthias Clasen committed
342 343
		
		g_object_unref (dest);
344 345 346 347 348 349 350
	} else {
		gdk_draw_rgb_image (drawing_area->window,
				    drawing_area->style->white_gc,
				    event->area.x, event->area.y, 
				    event->area.width, 
				    event->area.height,
				    GDK_RGB_DITHER_NORMAL,
351 352 353 354
				    gdk_pixbuf_get_pixels (pixbuf)
				    + (event->area.y * gdk_pixbuf_get_rowstride (pixbuf))
				    + (event->area.x * gdk_pixbuf_get_n_channels (pixbuf)),
				    gdk_pixbuf_get_rowstride (pixbuf));
355
	}
Havoc Pennington's avatar
Havoc Pennington committed
356
}
Mark Crichton's avatar
Mark Crichton committed
357

358
static void
359 360
config_func (GtkWidget *drawing_area, GdkEventConfigure *event, gpointer data)
{
361
#if 0
362
	GdkPixbuf *pixbuf;
363
    
364
	pixbuf = (GdkPixbuf *)g_object_get_data (G_OBJECT (drawing_area), "pixbuf");
365

366 367
	if (((event->width) != gdk_pixbuf_get_width (pixbuf)) ||
	    ((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)
Mark Crichton's avatar
Mark Crichton committed
374
{
375 376
	GtkWidget *window;
	GtkWidget *vbox;
Jonathan Blandford's avatar
Jonathan Blandford committed
377
	GtkWidget *temp_box;
378 379 380
	GtkWidget *button;
	GtkWidget *drawing_area;
	gint w, h;
Havoc Pennington's avatar
Havoc Pennington committed
381 382

        g_return_val_if_fail (pixbuf != NULL, NULL);
383 384
	w = gdk_pixbuf_get_width (pixbuf);
	h = gdk_pixbuf_get_height (pixbuf);
Mark Crichton's avatar
Mark Crichton committed
385

386
	window = g_object_new (gtk_window_get_type (),
387 388
				 "GtkObject::user_data", NULL,
				 "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
Havoc Pennington's avatar
Havoc Pennington committed
389
				 "GtkWindow::title", title ? title : "testrgb",
390 391
				 "GtkWindow::allow_shrink", TRUE,
				 NULL);
392 393
	g_signal_connect (window, "destroy",
			  G_CALLBACK (quit_func), NULL);
Mark Crichton's avatar
Mark Crichton committed
394

395
	vbox = gtk_vbox_new (FALSE, 0);
Mark Crichton's avatar
Mark Crichton committed
396

397 398 399 400
	if (title)
		gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new (title),
				    TRUE, TRUE, 0);

401
	drawing_area = gtk_drawing_area_new ();
Mark Crichton's avatar
Mark Crichton committed
402

Jonathan Blandford's avatar
Jonathan Blandford committed
403
	temp_box = gtk_hbox_new (FALSE, 0);
404
	gtk_widget_set_size_request (GTK_WIDGET (drawing_area), w, h);
Jonathan Blandford's avatar
Jonathan Blandford committed
405 406 407
	gtk_box_pack_start (GTK_BOX (temp_box), drawing_area, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox), temp_box, FALSE, FALSE, 0);
	
Mark Crichton's avatar
Mark Crichton committed
408

409 410 411 412
	g_signal_connect (drawing_area, "expose_event",
			  G_CALLBACK (expose_func), NULL);
	g_signal_connect (drawing_area, "configure_event",
			  G_CALLBACK (config_func), NULL);
413

414
	g_object_set_data (G_OBJECT (drawing_area), "pixbuf", pixbuf);
Mark Crichton's avatar
Mark Crichton committed
415

416
	gtk_widget_show (drawing_area);
Mark Crichton's avatar
Mark Crichton committed
417

418 419
	button = gtk_button_new_with_label ("Quit");
	gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
420 421
	g_signal_connect_swapped (button, "clicked",
				  G_CALLBACK (gtk_widget_destroy), window);
Mark Crichton's avatar
Mark Crichton committed
422

423
	gtk_widget_show (button);
Mark Crichton's avatar
Mark Crichton committed
424

425
	gtk_container_add (GTK_CONTAINER (window), vbox);
426
	gtk_widget_show_all (vbox);
Mark Crichton's avatar
Mark Crichton committed
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;
Havoc Pennington's avatar
Havoc Pennington committed
438 439
	gboolean done;
        GError *error;
Havoc Pennington's avatar
Havoc Pennington committed
440 441
        
	done = FALSE;
442 443
        error = NULL;

444
	if (!feof (status->imagefile)) {
445
		gint nbytes;
Havoc Pennington's avatar
Havoc Pennington committed
446
                
447
		nbytes = fread (status->buf, 1, status->readlen, 
448
			       status->imagefile);
449

Havoc Pennington's avatar
Havoc Pennington committed
450

Havoc Pennington's avatar
Havoc Pennington committed
451 452 453 454 455
                if (!gdk_pixbuf_loader_write (GDK_PIXBUF_LOADER (status->loader), status->buf, nbytes, &error)) {
                        g_warning ("Error writing to loader: %s",
                                   error->message);
                        g_error_free (error);
                        done = TRUE;
Havoc Pennington's avatar
Havoc Pennington committed
456
                }
Havoc Pennington's avatar
Havoc Pennington committed
457 458
                        
                        
459 460
        } 
	else 
461
                done = TRUE;
462
	  
463
	if (done) {
464 465
                /* ignoring errors, we should not do that. */
		gdk_pixbuf_loader_close (GDK_PIXBUF_LOADER (status->loader), NULL);
466
		gtk_widget_queue_draw (*status->rgbwin);
Manish Singh's avatar
Manish Singh committed
467
		g_object_unref (status->loader);
468 469 470 471 472
		fclose (status->imagefile);
		g_free (status->buf);
	}

	return !done;
473 474
}

475

476
static void
477
progressive_prepared_callback (GdkPixbufLoader* loader, gpointer data)
478 479 480 481
{
        GtkWidget** retloc = data;
        GdkPixbuf* pixbuf;

482
        pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
Matthias Clasen's avatar
Matthias Clasen committed
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;
Mark Crichton's avatar
Mark Crichton committed
491 492
}

Jonathan Blandford's avatar
Jonathan Blandford committed
493 494

static void
495
progressive_updated_callback (GdkPixbufLoader* loader, guint x, guint y, guint width, guint height, gpointer data)
Jonathan Blandford's avatar
Jonathan Blandford committed
496
{
497 498 499
        GtkWidget** window_loc = data;

        if (*window_loc != NULL)
500
                gtk_widget_queue_draw_area (*window_loc,
501
					   x, y, width, height);
Jonathan Blandford's avatar
Jonathan Blandford committed
502 503 504
        return;
}

505
static int readlen = 4096;
506

507
extern void pixbuf_init (void);
Owen Taylor's avatar
Owen Taylor committed
508

Matthias Clasen's avatar
Matthias Clasen committed
509 510
void size_func (GdkPixbufLoader *loader, gint width, gint height, gpointer data)
{
511
        gdk_pixbuf_loader_set_size (loader, width*2, height*2);
Matthias Clasen's avatar
Matthias Clasen committed
512 513 514
}


Mark Crichton's avatar
Mark Crichton committed
515 516 517
int
main (int argc, char **argv)
{
518
	int i;
519
	int found_valid = FALSE;
520 521

	GdkPixbuf *pixbuf;
522
	GdkPixbufLoader *pixbuf_loader;
523

Owen Taylor's avatar
Owen Taylor committed
524
	pixbuf_init ();
525

526 527
	gtk_init (&argc, &argv);

528
	/*	gdk_rgb_set_verbose (TRUE);*/
529

530
	gtk_widget_set_default_colormap (gdk_rgb_get_colormap ());
531

532
	{
533 534
		char *tbf_readlen = getenv ("TBF_READLEN");
		if (tbf_readlen) readlen = atoi (tbf_readlen);
535 536
	}

537
	{
538
		char *tbf_bps = getenv ("TBF_KBPS");
539 540 541
		guint bps;

		if (tbf_bps) {
542
			bps = atoi (tbf_bps);
543
			g_print ("Simulating %d kBytes/sec\n", bps);
544 545 546 547
			readlen = (bps*1024)/10;
		}
	}

548 549
	i = 1;
	if (argc == 1) {
550
                const gchar*** xpmp;
551 552
                GError *error = NULL;
		
553
		pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
554 555
						   DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
						   NULL, NULL);
556
		new_testrgb_window (pixbuf, NULL);
557 558 559 560

                xpmp = xpms;
                while (*xpmp) {
                        pixbuf = gdk_pixbuf_new_from_xpm_data (*xpmp);
561
                        new_testrgb_window (pixbuf, NULL);
562 563
                        ++xpmp;
                }
Havoc Pennington's avatar
Havoc Pennington committed
564 565

                /* Test loading from inline data. */
566
                pixbuf = gdk_pixbuf_new_from_inline (-1, apple_red, FALSE, &error);
567 568 569 570 571 572 573 574 575
		if (!pixbuf)
		  {
		    fprintf (stderr, "failed to construct \"red apple\" pixbuf: %s\n",
			     error->message);
		    g_error_free (error);
		  }
		else
		  new_testrgb_window (pixbuf, "Red apple from inlined RLE data");

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 581
	} else {
		for (i = 1; i < argc; i++) {
Havoc Pennington's avatar
Havoc Pennington committed
582 583 584 585
                        GError *error;

                        error = NULL;
			pixbuf = gdk_pixbuf_new_from_file (argv[i], &error);
586

Havoc Pennington's avatar
Havoc Pennington committed
587 588 589 590 591 592
                        if (pixbuf == NULL) {
                                g_warning ("Error loading image: %s",
                                           error->message);
                                g_error_free (error);
                        }
                        
593
#if 0
594
			pixbuf = gdk_pixbuf_rotate (pixbuf, 10.0);
595 596
#endif

597
			if (pixbuf) {
598
				new_testrgb_window (pixbuf, "File");
599 600 601
				found_valid = TRUE;
			}
		}
Matthias Clasen's avatar
Matthias Clasen committed
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 611
			status.rgbwin = &rgb_window;

612
			status.buf = g_malloc (readlen);
Matthias Clasen's avatar
Matthias Clasen committed
613

614
#if 0
Matthias Clasen's avatar
Matthias Clasen committed
615 616
			g_signal_connect (pixbuf_loader, "size_prepared", 
					  G_CALLBACK (size_func), NULL);
617
#endif
Matthias Clasen's avatar
Matthias Clasen committed
618

619 620
                        g_signal_connect (pixbuf_loader, "area_prepared",
					  G_CALLBACK (progressive_prepared_callback),
621
					  &rgb_window);
622 623
                        g_signal_connect (pixbuf_loader, "area_updated",
					  G_CALLBACK (progressive_updated_callback),
624
					  &rgb_window);
625 626 627 628 629 630
			
                        status.imagefile = fopen (argv[1], "r");
                        g_assert (status.imagefile != NULL);

			status.readlen = readlen;

631
                        status.timeout = gdk_threads_add_timeout (100, update_timeout, &status);
632
                }
633
#endif
634 635
	}

636 637 638 639
	if (found_valid)
		gtk_main ();

	return 0;
Mark Crichton's avatar
Mark Crichton committed
640
}