Commit d4f0062f authored by Tim Janik's avatar Tim Janik Committed by Tim Janik

use gdk_pixbuf_new_from_stream(). fixed up item factory so inlined pixbufs

Tue Jun 26 10:04:30 2001  Tim Janik  <timj@gtk.org>

        * gtk/gtkiconfactory.c:
        * gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
        item factory so inlined pixbufs actually work.

Tue Jun 26 09:48:02 2001  Tim Janik  <timj@gtk.org>

        * Makefile.am (noinst_PROGRAMS): get rid of make-inline-pixbuf

        * gdk-pixbuf-data.[hc]: provide gdk_pixbuf_new_from_stream()
        instead from gdk_pixbuf_new_from_inline().

        * gdk-pixdata.[hc]: auxillary GdkPixdata structure, public
        installed API for applications that need to serialize/deserialize
        on their own (gimp, BEAST).

        * gdk-pixbuf/gdk-pixbuf-csource.c: provide publically installed
        program that can dump images in CSource format and Pixbuf
        stream format. supports RLE encoding, MACRO formatting etc...
        invoke with --help.
parent 3704749e
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -24,6 +24,12 @@ Tue Jun 26 11:06:34 2001 Owen Taylor <otaylor@redhat.com>
with font lists in descriptions. (#56184, reported by
Jonas Borgström)
Tue Jun 26 10:04:30 2001 Tim Janik <timj@gtk.org>
* gtk/gtkiconfactory.c:
* gtk/gtkitemfactory.c: use gdk_pixbuf_new_from_stream(). fixed up
item factory so inlined pixbufs actually work.
2001-06-25 Havoc Pennington <hp@redhat.com>
* gtk/gtktreeviewcolumn.h, gtk/gtktreeviewcolumn.c:
......
......@@ -32,10 +32,12 @@ noinst_PROGRAMS = \
BUILT_SOURCES=test-inline-pixbufs.h
test-inline-pixbufs.h: $(top_builddir)/gdk-pixbuf/make-inline-pixbuf apple-red.png gnome-foot.png
test-inline-pixbufs.h: $(top_builddir)/gdk-pixbuf/gdk-pixbuf-csource apple-red.png gnome-foot.png
(topdir=`cd $(top_builddir) && pwd` ; curdir=`pwd` ; \
cd $(srcdir) && \
GDK_PIXBUF_MODULEDIR=$$topdir/gdk-pixbuf/.libs $$topdir/gdk-pixbuf/make-inline-pixbuf $$curdir/test-inline-pixbufs.h apple_red apple-red.png gnome_foot gnome-foot.png)
cd $(srcdir) && \
GDK_PIXBUF_MODULEDIR=$$topdir/gdk-pixbuf/.libs \
$$topdir/gdk-pixbuf/gdk-pixbuf-csource --build-list \
apple_red apple-red.png gnome_foot gnome-foot.png >$$curdir/test-inline-pixbufs.h)
testpixbuf_DEPENDENCIES = $(DEPS)
testpixbuf_drawable_DEPENDENCIES = $(DEPS)
......
......@@ -543,7 +543,8 @@ main (int argc, char **argv)
i = 1;
if (argc == 1) {
const gchar*** xpmp;
GError *error = NULL;
pixbuf = gdk_pixbuf_new_from_data (default_image, GDK_COLORSPACE_RGB, FALSE, 8,
DEFAULT_WIDTH, DEFAULT_HEIGHT, DEFAULT_WIDTH * 3,
NULL, NULL);
......@@ -557,11 +558,18 @@ main (int argc, char **argv)
}
/* Test loading from inline data. */
pixbuf = gdk_pixbuf_new_from_inline (apple_red, FALSE, -1, NULL);
new_testrgb_window (pixbuf, "Red apple from inline data");
pixbuf = gdk_pixbuf_new_from_inline (gnome_foot, TRUE, sizeof (gnome_foot), NULL);
new_testrgb_window (pixbuf, "Foot from inline data");
pixbuf = gdk_pixbuf_new_from_stream (-1, apple_red, FALSE, &error);
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");
pixbuf = gdk_pixbuf_new_from_stream (sizeof (gnome_foot), gnome_foot, TRUE, NULL);
new_testrgb_window (pixbuf, "GNOME Foot from inlined RLE data");
found_valid = TRUE;
} else {
......
......@@ -82,18 +82,6 @@ Creating a pixbuf from image data that is already in memory.
@Returns:
<!-- ##### FUNCTION gdk_pixbuf_new_from_inline ##### -->
<para>
</para>
@inline_pixbuf:
@copy_pixels:
@length:
@error:
@Returns:
<!-- ##### FUNCTION gdk_pixbuf_new_subpixbuf ##### -->
<para>
......
......@@ -552,3 +552,14 @@ End:
</para>
<!-- ##### FUNCTION gdk_pixbuf_new_from_inline ##### -->
<para>
</para>
@inline_pixbuf:
@copy_pixels:
@length:
@error:
@Returns:
......@@ -20,6 +20,9 @@ Information that describes an image.
</para>
@GDK_PIXBUF_ERROR_HEADER_CORRUPT:
@GDK_PIXBUF_ERROR_PIXEL_CORRUPT:
@GDK_PIXBUF_ERROR_UNKNOWN_FORMAT:
@GDK_PIXBUF_ERROR_CORRUPT_IMAGE:
@GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY:
@GDK_PIXBUF_ERROR_BAD_OPTION_VALUE:
......
......@@ -77,7 +77,6 @@ GtkItemFactory
@callback_action:
@item_type:
@extra_data:
@extra_data2:
<!-- ##### STRUCT GtkItemFactoryItem ##### -->
<para>
......
Tue Jun 26 09:48:02 2001 Tim Janik <timj@gtk.org>
* Makefile.am (noinst_PROGRAMS): get rid of make-inline-pixbuf
* gdk-pixbuf-data.[hc]: provide gdk_pixbuf_new_from_stream()
instead from gdk_pixbuf_new_from_inline().
* gdk-pixdata.[hc]: auxillary GdkPixdata structure, public
installed API for applications that need to serialize/deserialize
on their own (gimp, BEAST).
* gdk-pixbuf/gdk-pixbuf-csource.c: provide publically installed
program that can dump images in CSource format and Pixbuf
stream format. supports RLE encoding, MACRO formatting etc...
invoke with --help.
Mon Jun 25 00:28:11 2001 Owen Taylor <otaylor@redhat.com>
* Makefile.am: Actually update timestamps, so rules don't
......
......@@ -164,12 +164,15 @@ TESTS = test-gdk-pixbuf test-loaders
noinst_PROGRAMS = $(TESTS)
DEPS = libgdk_pixbuf-1.3.la
INCLUDES = -I$(top_srcdir) -I$(top_builddir) \
INCLUDES = @STRIP_BEGIN@ \
-I$(top_srcdir) -I$(top_builddir) \
-I$(top_srcdir)/gdk-pixbuf \
-I$(top_builddir)/gdk-pixbuf \
@INCLUDED_LOADER_DEFINE@ \
@GTK_DEBUG_FLAGS@ \
@GDK_PIXBUF_DEP_CFLAGS@
@GDK_PIXBUF_DEP_CFLAGS@ \
@STRIP_END@
AM_CPPFLAGS = "-DPIXBUF_LIBDIR=\"$(loaderdir)\"" "-DBUILT_MODULES_DIR=\"$(srcdir)/.libs\""
LDADDS = libgdk_pixbuf-1.3.la
......@@ -179,12 +182,13 @@ test_loaders_LDADD = $(LDADDS)
test_loaders_SOURCES = test-loaders.c test-images.h
bin_PROGRAMS=make-inline-pixbuf
make_inline_pixbuf_SOURCES=make-inline-pixbuf.c
make_inline_pixbuf_LDADD = $(LDADDS)
#noinst_PROGRAMS=make-inline-pixbuf
#make_inline_pixbuf_SOURCES=make-inline-pixbuf.c
#make_inline_pixbuf_LDADD = $(LDADDS)
bin_PROGRAMS = gdk-pixbuf-csource
gdk_pixbuf_csource_SOURCES = gdk-pixbuf-csource.c
gdk_pixbuf_csource_LDADD = $(LDADDS)
#
......@@ -195,7 +199,7 @@ BUILT_SOURCES=gdk-pixbuf-marshal.h gdk-pixbuf-marshal.c
libgdk_pixbufincludedir = $(includedir)/gtk-2.0/gdk-pixbuf
libgdk_pixbuf_1_3_la_SOURCES = \
libgdk_pixbuf_1_3_la_SOURCES = @STRIP_BEGIN@ \
gdk-pixbuf-i18n.h \
gdk-pixbuf.c \
gdk-pixbuf-animation.c \
......@@ -203,20 +207,26 @@ libgdk_pixbuf_1_3_la_SOURCES = \
gdk-pixbuf-io.c \
gdk-pixbuf-loader.c \
gdk-pixbuf-scale.c \
gdk-pixbuf-util.c
gdk-pixbuf-util.c \
gdk-pixdata.c \
@STRIP_END@
$(libgdk_pixbuf_1_3_la_OBJECTS): gdk-pixbuf-marshal.h gdk-pixbuf-marshal.c
libgdk_pixbuf_1_3_la_LDFLAGS = \
libgdk_pixbuf_1_3_la_LDFLAGS = @STRIP_BEGIN@ \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
@LIBTOOL_EXPORT_OPTIONS@
@LIBTOOL_EXPORT_OPTIONS@ \
@STRIP_END@
libgdk_pixbuf_1_3_la_LIBADD = pixops/libpixops.la $(builtin_objs) $(GDK_PIXBUF_DEP_LIBS)
libgdk_pixbuf_1_3_la_DEPENDENCIES = $(builtin_objs)
libgdk_pixbufinclude_HEADERS = \
libgdk_pixbufinclude_HEADERS = \
gdk-pixbuf.h \
gdk-pixbuf-loader.h \
gdk-pixbuf-features.h
gdk-pixbuf-features.h \
gdk-pixdata.h
noinst_HEADERS = \
gdk-pixbuf-io.h \
......
/* Gdk-Pixbuf-CSource - GdkPixbuf based image CSource generator
* Copyright (C) 1999, 2001 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "../gtk/gtkcompat.h" /* versioning */
#include "gdk-pixbuf.h"
#include "gdk-pixdata.h"
#include <stdio.h>
#include <string.h>
/* --- defines --- */
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "Gdk-Pixbuf-CSource"
#define PRG_NAME "gdk-pixbuf-csource"
#define PKG_NAME "Gtk+"
#define PKG_HTTP_HOME "http://www.gtk.org"
/* --- prototypes --- */
static void parse_args (gint *argc_p,
gchar ***argv_p);
static void print_blurb (FILE *bout,
gboolean print_help);
/* --- variables --- */
static guint gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
static guint gen_ctype = GDK_PIXDATA_DUMP_GTYPES | GDK_PIXDATA_DUMP_STATIC | GDK_PIXDATA_DUMP_CONST;
static gboolean use_rle = TRUE;
static gboolean with_decoder = FALSE;
static gchar *image_name = "my_pixbuf";
static gboolean build_list = FALSE;
/* --- functions --- */
static void
print_csource (FILE *f_out,
GdkPixbuf *pixbuf)
{
GdkPixdata pixdata;
gpointer free_me;
GString *gstring;
free_me = gdk_pixdata_from_pixbuf (&pixdata, pixbuf, use_rle);
gstring = gdk_pixdata_to_csource (&pixdata, image_name,
gen_type | gen_ctype |
(with_decoder ? GDK_PIXDATA_DUMP_RLE_DECODER : 0));
fprintf (f_out, "%s\n", gstring->str);
g_free (free_me);
}
int
main (int argc,
char *argv[])
{
GdkPixbuf *pixbuf;
GError *error = NULL;
/* initialize glib/GdkPixbuf */
g_type_init (0);
/* parse args and do fast exits */
parse_args (&argc, &argv);
if (!build_list)
{
if (argc != 2)
{
print_blurb (stderr, TRUE);
return 1;
}
pixbuf = gdk_pixbuf_new_from_file (argv[1], &error);
if (!pixbuf)
{
fprintf (stderr, "failed to load \"%s\": %s\n",
argv[1],
error->message);
g_error_free (error);
return 1;
}
print_csource (stdout, pixbuf);
gdk_pixbuf_unref (pixbuf);
}
else /* parse name, file pairs */
{
gchar **p = argv + 1;
guint j = argc - 1;
gboolean toggle = FALSE;
while (j--)
{
if (!toggle)
image_name = *p++;
else
{
pixbuf = gdk_pixbuf_new_from_file (*p, &error);
if (!pixbuf)
{
fprintf (stderr, "failed to load \"%s\": %s\n",
*p,
error->message);
g_error_free (error);
return 1;
}
print_csource (stdout, pixbuf);
gdk_pixbuf_unref (pixbuf);
p++;
}
toggle = !toggle;
}
}
return 0;
}
static void
parse_args (gint *argc_p,
gchar ***argv_p)
{
guint argc = *argc_p;
gchar **argv = *argv_p;
guint i, e;
for (i = 1; i < argc; i++)
{
if (strcmp ("--macros", argv[i]) == 0)
{
gen_type = GDK_PIXDATA_DUMP_MACROS;
argv[i] = NULL;
}
else if (strcmp ("--struct", argv[i]) == 0)
{
gen_type = GDK_PIXDATA_DUMP_PIXDATA_STRUCT;
argv[i] = NULL;
}
else if (strcmp ("--stream", argv[i]) == 0)
{
gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
argv[i] = NULL;
}
else if (strcmp ("--rle", argv[i]) == 0)
{
use_rle = TRUE;
argv[i] = NULL;
}
else if (strcmp ("--raw", argv[i]) == 0)
{
use_rle = FALSE;
argv[i] = NULL;
}
else if (strcmp ("--extern", argv[i]) == 0)
{
gen_ctype &= ~GDK_PIXDATA_DUMP_STATIC;
argv[i] = NULL;
}
else if (strcmp ("--static", argv[i]) == 0)
{
gen_ctype |= GDK_PIXDATA_DUMP_STATIC;
argv[i] = NULL;
}
else if (strcmp ("--decoder", argv[i]) == 0)
{
with_decoder = TRUE;
argv[i] = NULL;
}
else if ((strcmp ("--name", argv[i]) == 0) ||
(strncmp ("--name=", argv[i], 7) == 0))
{
gchar *equal = argv[i] + 6;
if (*equal == '=')
image_name = g_strdup (equal + 1);
else if (i + 1 < argc)
{
image_name = g_strdup (argv[i + 1]);
argv[i] = NULL;
i += 1;
}
argv[i] = NULL;
}
else if (strcmp ("--build-list", argv[i]) == 0)
{
build_list = TRUE;
argv[i] = NULL;
}
else if (strcmp ("-h", argv[i]) == 0 ||
strcmp ("--help", argv[i]) == 0)
{
print_blurb (stderr, TRUE);
argv[i] = NULL;
exit (0);
}
else if (strcmp ("-v", argv[i]) == 0 ||
strcmp ("--version", argv[i]) == 0)
{
print_blurb (stderr, FALSE);
argv[i] = NULL;
exit (0);
}
else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
{
GLogLevelFlags fatal_mask;
fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
g_log_set_always_fatal (fatal_mask);
argv[i] = NULL;
}
}
e = 0;
for (i = 1; i < argc; i++)
{
if (e)
{
if (argv[i])
{
argv[e++] = argv[i];
argv[i] = NULL;
}
}
else if (!argv[i])
e = i;
}
if (e)
*argc_p = e;
}
static void
print_blurb (FILE *bout,
gboolean print_help)
{
if (!print_help)
{
fprintf (bout, "%s version ", PRG_NAME);
fprintf (bout, "%u.%u.%u", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
fprintf (bout, "\n");
fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
fprintf (bout, "the GNU Lesser General Public License which can be found in the\n");
fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
}
else
{
fprintf (bout, "Usage: %s [options] [image]\n", PRG_NAME);
fprintf (bout, " %s [options] --build-list [[name image]...]\n", PRG_NAME);
fprintf (bout, " --stream generate pixbuf data stream\n");
fprintf (bout, " --struct generate GdkPixdata structure\n");
fprintf (bout, " --macros generate image size/pixel macros\n");
fprintf (bout, " --rle use one byte run-length-encoding\n");
fprintf (bout, " --raw provide raw image data copy\n");
fprintf (bout, " --extern generate extern symbols\n");
fprintf (bout, " --static generate static symbols\n");
fprintf (bout, " --decoder provide rle decoder\n");
fprintf (bout, " --name=identifier C macro/variable name\n");
fprintf (bout, " --build-list parse (name, image) pairs\n");
fprintf (bout, " -h, --help show this help message\n");
fprintf (bout, " -v, --version print version informations\n");
fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");
}
}
#include "x"
......@@ -78,254 +78,3 @@ gdk_pixbuf_new_from_data (const guchar *data, GdkColorspace colorspace, gboolean
return pixbuf;
}
static guint32
read_int (const guchar **p)
{
guint32 num;
/* Note most significant bytes are first in the byte stream */
num =
(*p)[3] |
((*p)[2] << 8) |
((*p)[1] << 16) |
((*p)[0] << 24);
*p += 4;
return num;
}
static gboolean
read_bool (const guchar **p)
{
gboolean val = **p != 0;
++(*p);
return val;
}
static GdkPixbuf*
read_raw_inline (const guchar *data,
gboolean copy_pixels,
int length,
GError **error)
{
GdkPixbuf *pixbuf;
const guchar *p = data;
guint32 rowstride, width, height, colorspace,
n_channels, bits_per_sample;
gboolean has_alpha;
if (length >= 0 && length < 12) {
/* Not enough buffer to hold the width/height/rowstride */
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image data is partially missing"));
return NULL;
}
rowstride = read_int (&p);
width = read_int (&p);
height = read_int (&p);
if (rowstride < width) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image has an incorrect pixel rowstride, perhaps the data was corrupted somehow."));
return NULL; /* bad data from untrusted source. */
}
/* rowstride >= width, so we can trust width */
length -= 12;
/* There's some better way like G_MAXINT/height > rowstride
* but I'm not sure it works, so stick to this for now.
*/
if (((double)height) * ((double)rowstride) > (double)G_MAXINT) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image size is impossibly large, perhaps the data was corrupted somehow"));
return NULL; /* overflow */
}
if (length >= 0 &&
length < (height * rowstride + 13)) {
/* Not enough buffer to hold the remaining header
* information plus the data.
*/
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image data is partially missing, probably it was corrupted somehow."));
return NULL;
}
/* Read the remaining 13 bytes of header information */
has_alpha = read_bool (&p) != FALSE;
colorspace = read_int (&p);
n_channels = read_int (&p);
bits_per_sample = read_int (&p);
if (colorspace != GDK_COLORSPACE_RGB) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image has an unknown colorspace code (%d), perhaps the image data was corrupted"),
colorspace);
return NULL;
}
if (bits_per_sample != 8) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image has an improper number of bits per sample (%d), perhaps the image data was corrupted"),
bits_per_sample);
return NULL;
}
if (has_alpha && n_channels != 4) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image has an improper number of channels (%d), perhaps the image data was corrupted"),
n_channels);
return NULL;
}
if (!has_alpha && n_channels != 3) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
_("Image has an improper number of channels (%d), perhaps the image data was corrupted"),
n_channels);
return NULL;
}
if (copy_pixels) {
guchar *pixels;
gint dest_rowstride;
gint row;
pixbuf = gdk_pixbuf_new (colorspace,
has_alpha, bits_per_sample,
width, height);
if (pixbuf == NULL) {
g_set_error (error,
GDK_PIXBUF_ERROR,
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
_("Not enough memory to store a %d by %d image; try exiting some applications to free memory."),