1 /* GdkPixbuf library - SUNRAS image loader
3 * Copyright (C) 1999 The Free Software Foundation
5 * Authors: Arjan van de Ven <arjan@fenrus.demon.nl>
6 * Federico Mena-Quintero <federico@gimp.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
27 #include "gdk-pixbuf.h"
28 #include "gdk-pixbuf-io.h"
33 Header structure for sunras files.
34 All values are in big-endian order on disk
49 This does a byte-order swap. Does glib have something like
53 unsigned int ByteOrder(unsigned int i)
57 ((i & 255) << 24) | (((i >> 8) & 255) << 16) |
58 (((i >> 16) & 255) << 8) | ((i >> 24) & 255);
63 Destroy notification function for the libart pixbuf
66 static void free_buffer(gpointer user_data, gpointer data)
73 OneLineBGR does what it says: Reads one line from file.
74 Note: It also changes BGR pixelorder to RGB as libart currently
75 doesn't support ART_PIX_BGR.
78 static OneLineBGR(FILE * f, guint Width, guchar * pixels, gint bpp)
83 result = fread(pixels, 1, Width * bpp, f);
85 g_assert(result == Width * bpp);
86 if (((Width * bpp) & 7) != 0) /* Not 16 bit aligned */
87 fread(&DummyByte, 1, 1, f);
91 Blue = pixels[X * bpp];
92 pixels[X * bpp] = pixels[X * bpp + 2];
93 pixels[X * bpp + 2] = Blue;
98 /* Shared library entry point */
99 GdkPixbuf *image_load(FILE * f)
103 struct rasterfile Header;
105 i = fread(&Header, 1, sizeof(Header), f);
108 /* Correct the byteorder of the header here */
109 Header.width = ByteOrder(Header.width);
110 Header.height = ByteOrder(Header.height);
111 Header.depth = ByteOrder(Header.depth);
112 Header.length = ByteOrder(Header.length);
113 Header.type = ByteOrder(Header.type);
114 Header.maptype = ByteOrder(Header.maptype);
115 Header.maplength = ByteOrder(Header.maplength);
119 if (Header.depth == 32)
124 g_assert(bpp != 0); /* Only 24 and 32 bpp for now */
126 pixels = (guchar *) malloc(Header.width * Header.height * bpp);
133 Loop through the file, one line at a time.
134 Only BGR-style files are handled right now.
138 while (Y < Header.height) {
139 OneLineBGR(f, Header.width,
140 &pixels[Y * Header.width * bpp], bpp);
146 return gdk_pixbuf_new_from_data(pixels, ART_PIX_RGB, TRUE,
152 return gdk_pixbuf_new_from_data(pixels, ART_PIX_RGB, FALSE,