|
Packit |
a4058c |
/* -*- mode: C; c-file-style: "linux" -*- */
|
|
Packit |
a4058c |
/* GdkPixbuf library - Windows Bitmap image loader
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Copyright (C) 1999 The Free Software Foundation
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Authors: Arjan van de Ven <arjan@fenrus.demon.nl>
|
|
Packit |
a4058c |
* Federico Mena-Quintero <federico@gimp.org>
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* Based on io-ras.c
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is free software; you can redistribute it and/or
|
|
Packit |
a4058c |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License as published by the Free Software Foundation; either
|
|
Packit |
a4058c |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
a4058c |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
a4058c |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
a4058c |
* Lesser General Public License for more details.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
a4058c |
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#include "config.h"
|
|
Packit |
a4058c |
#include <stdio.h>
|
|
Packit |
a4058c |
#ifdef HAVE_UNISTD_H
|
|
Packit |
a4058c |
#include <unistd.h>
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
#include <string.h>
|
|
Packit |
a4058c |
#include "gdk-pixbuf-private.h"
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define DUMPBIH 0
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#if 0
|
|
Packit |
a4058c |
/* If these structures were unpacked, they would define the two headers of the
|
|
Packit |
a4058c |
* BMP file. After them comes the palette, and then the image data.
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* We do not use these structures; we just keep them here for reference.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
struct BitmapFileHeader {
|
|
Packit |
a4058c |
guint16 magic;
|
|
Packit |
a4058c |
guint32 file_size;
|
|
Packit |
a4058c |
guint32 reserved;
|
|
Packit |
a4058c |
guint32 data_offset;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct BitmapInfoHeader {
|
|
Packit |
a4058c |
guint32 header_size;
|
|
Packit |
a4058c |
guint32 width;
|
|
Packit |
a4058c |
guint32 height;
|
|
Packit |
a4058c |
guint16 planes;
|
|
Packit |
a4058c |
guint16 bpp;
|
|
Packit |
a4058c |
guint32 compression;
|
|
Packit |
a4058c |
guint32 data_size;
|
|
Packit |
a4058c |
guint32 x_ppm;
|
|
Packit |
a4058c |
guint32 y_ppm;
|
|
Packit |
a4058c |
guint32 n_colors;
|
|
Packit |
a4058c |
guint32 n_important_colors;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Compression values */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define BI_RGB 0
|
|
Packit |
a4058c |
#define BI_RLE8 1
|
|
Packit |
a4058c |
#define BI_RLE4 2
|
|
Packit |
a4058c |
#define BI_BITFIELDS 3
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* State machine */
|
|
Packit |
a4058c |
typedef enum {
|
|
Packit |
a4058c |
READ_STATE_HEADERS, /* Reading the bitmap file header and bitmap info header */
|
|
Packit |
a4058c |
READ_STATE_PALETTE, /* Reading the palette */
|
|
Packit |
a4058c |
READ_STATE_BITMASKS, /* Reading the bitmasks for BI_BITFIELDS */
|
|
Packit |
a4058c |
READ_STATE_DATA, /* Reading the actual image data */
|
|
Packit |
a4058c |
READ_STATE_ERROR, /* An error occurred; further data will be ignored */
|
|
Packit |
a4058c |
READ_STATE_DONE /* Done reading the image; further data will be ignored */
|
|
Packit |
a4058c |
} ReadState;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/*
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
DumpBIH printf's the values in a BitmapInfoHeader to the screen, for
|
|
Packit |
a4058c |
debugging purposes.
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
#if DUMPBIH
|
|
Packit |
a4058c |
static void DumpBIH(unsigned char *BIH)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
printf("biSize = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[3] << 24) + (BIH[2] << 16) + (BIH[1] << 8) +
|
|
Packit |
a4058c |
(BIH[0]));
|
|
Packit |
a4058c |
printf("biWidth = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[7] << 24) + (BIH[6] << 16) + (BIH[5] << 8) +
|
|
Packit |
a4058c |
(BIH[4]));
|
|
Packit |
a4058c |
printf("biHeight = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[11] << 24) + (BIH[10] << 16) + (BIH[9] << 8) +
|
|
Packit |
a4058c |
(BIH[8]));
|
|
Packit |
a4058c |
printf("biPlanes = %i \n", (int) (BIH[13] << 8) + (BIH[12]));
|
|
Packit |
a4058c |
printf("biBitCount = %i \n", (int) (BIH[15] << 8) + (BIH[14]));
|
|
Packit |
a4058c |
printf("biCompress = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[19] << 24) + (BIH[18] << 16) + (BIH[17] << 8) +
|
|
Packit |
a4058c |
(BIH[16]));
|
|
Packit |
a4058c |
printf("biSizeImage = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[23] << 24) + (BIH[22] << 16) + (BIH[21] << 8) +
|
|
Packit |
a4058c |
(BIH[20]));
|
|
Packit |
a4058c |
printf("biXPels = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[27] << 24) + (BIH[26] << 16) + (BIH[25] << 8) +
|
|
Packit |
a4058c |
(BIH[24]));
|
|
Packit |
a4058c |
printf("biYPels = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[31] << 24) + (BIH[30] << 16) + (BIH[29] << 8) +
|
|
Packit |
a4058c |
(BIH[28]));
|
|
Packit |
a4058c |
printf("biClrUsed = %i \n",
|
|
Packit |
a4058c |
(int) (BIH[35] << 24) + (BIH[34] << 16) + (BIH[33] << 8) +
|
|
Packit |
a4058c |
(BIH[32]));
|
|
Packit |
a4058c |
printf("biClrImprtnt= %i \n",
|
|
Packit |
a4058c |
(int) (BIH[39] << 24) + (BIH[38] << 16) + (BIH[37] << 8) +
|
|
Packit |
a4058c |
(BIH[36]));
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
/* struct headerpair contains the decoded width/height/depth info for
|
|
Packit |
a4058c |
the current bitmap */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct headerpair {
|
|
Packit |
a4058c |
guint32 size;
|
|
Packit |
a4058c |
gint32 width;
|
|
Packit |
a4058c |
gint32 height;
|
|
Packit |
a4058c |
guint depth;
|
|
Packit |
a4058c |
guint Negative; /* Negative = 1 -> top down BMP,
|
|
Packit |
a4058c |
Negative = 0 -> bottom up BMP */
|
|
Packit |
a4058c |
guint n_colors;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Data needed for the "state" during decompression */
|
|
Packit |
a4058c |
struct bmp_compression_state {
|
|
Packit |
a4058c |
gint phase;
|
|
Packit |
a4058c |
gint run;
|
|
Packit |
a4058c |
gint count;
|
|
Packit |
a4058c |
gint x, y;
|
|
Packit |
a4058c |
guchar *p;
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Progressive loading */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct bmp_progressive_state {
|
|
Packit |
a4058c |
GdkPixbufModuleSizeFunc size_func;
|
|
Packit |
a4058c |
GdkPixbufModulePreparedFunc prepared_func;
|
|
Packit |
a4058c |
GdkPixbufModuleUpdatedFunc updated_func;
|
|
Packit |
a4058c |
gpointer user_data;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
ReadState read_state;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
guint LineWidth;
|
|
Packit |
a4058c |
guint Lines; /* # of finished lines */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
guchar *buff;
|
|
Packit |
a4058c |
guint BufferSize;
|
|
Packit |
a4058c |
guint BufferPadding;
|
|
Packit |
a4058c |
guint BufferDone;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
guchar (*Colormap)[3];
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
gint Type; /*
|
|
Packit |
a4058c |
32 = RGB + alpha
|
|
Packit |
a4058c |
24 = RGB
|
|
Packit |
a4058c |
16 = RGB
|
|
Packit |
a4058c |
4 = 4 bpp colormapped
|
|
Packit |
a4058c |
8 = 8 bpp colormapped
|
|
Packit |
a4058c |
1 = 1 bit bitonal
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
guint Compressed;
|
|
Packit |
a4058c |
struct bmp_compression_state compr;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct headerpair Header; /* Decoded (BE->CPU) header */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Bit masks, shift amounts, and significant bits for BI_BITFIELDS coding */
|
|
Packit |
a4058c |
int r_mask, r_shift, r_bits;
|
|
Packit |
a4058c |
int g_mask, g_shift, g_bits;
|
|
Packit |
a4058c |
int b_mask, b_shift, b_bits;
|
|
Packit |
a4058c |
int a_mask, a_shift, a_bits;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf; /* Our "target" */
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gpointer
|
|
Packit |
a4058c |
gdk_pixbuf__bmp_image_begin_load(GdkPixbufModuleSizeFunc size_func,
|
|
Packit |
a4058c |
GdkPixbufModulePreparedFunc prepared_func,
|
|
Packit |
a4058c |
GdkPixbufModuleUpdatedFunc updated_func,
|
|
Packit |
a4058c |
gpointer user_data,
|
|
Packit |
a4058c |
GError **error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf__bmp_image_stop_load(gpointer data, GError **error);
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf__bmp_image_load_increment(gpointer data,
|
|
Packit |
a4058c |
const guchar * buf,
|
|
Packit |
a4058c |
guint size,
|
|
Packit |
a4058c |
GError **error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Picks up a 32-bit little-endian integer starting at the specified location.
|
|
Packit |
a4058c |
* Does it by hand instead of dereferencing a simple (gint *) cast due to
|
|
Packit |
a4058c |
* alignment constraints many platforms.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
static int
|
|
Packit |
a4058c |
lsb_32 (guchar *src)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Same as above, but for 16-bit little-endian integers. */
|
|
Packit |
a4058c |
static short
|
|
Packit |
a4058c |
lsb_16 (guchar *src)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return src[0] | (src[1] << 8);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean grow_buffer (struct bmp_progressive_state *State,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
guchar *tmp;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->BufferSize == 0) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
tmp = g_try_realloc (State->buff, State->BufferSize);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!tmp) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
Packit |
a4058c |
_("Not enough memory to load bitmap image"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->buff = tmp;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
decode_bitmasks (guchar *buf,
|
|
Packit |
a4058c |
struct bmp_progressive_state *State,
|
|
Packit |
a4058c |
GError **error);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean DecodeHeader(unsigned char *BFH, unsigned char *BIH,
|
|
Packit |
a4058c |
struct bmp_progressive_state *State,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint clrUsed;
|
|
Packit |
a4058c |
guint bytesPerPixel;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* First check for the two first bytes content. A sane
|
|
Packit |
a4058c |
BMP file must start with bytes 0x42 0x4D. */
|
|
Packit |
a4058c |
if (*BFH != 0x42 || *(BFH + 1) != 0x4D) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* FIXME this is totally unrobust against bogus image data. */
|
|
Packit |
a4058c |
if (State->BufferSize < lsb_32 (&BIH[0]) + 14) {
|
|
Packit |
a4058c |
State->BufferSize = lsb_32 (&BIH[0]) + 14;
|
|
Packit |
a4058c |
if (!grow_buffer (State, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#if DUMPBIH
|
|
Packit |
a4058c |
DumpBIH(BIH);
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->Header.size = lsb_32 (&BIH[0]);
|
|
Packit |
a4058c |
if (State->Header.size == 124) {
|
|
Packit |
a4058c |
/* BMP v5 */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 108) {
|
|
Packit |
a4058c |
/* BMP v4 */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 64) {
|
|
Packit |
a4058c |
/* BMP OS/2 v2 */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 56) {
|
|
Packit |
a4058c |
/* BMP v3 with RGBA bitmasks */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 52) {
|
|
Packit |
a4058c |
/* BMP v3 with RGB bitmasks */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 40) {
|
|
Packit |
a4058c |
/* BMP v3 */
|
|
Packit |
a4058c |
State->Header.width = lsb_32 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_32 (&BIH[8]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[14]);
|
|
Packit |
a4058c |
State->Compressed = lsb_32 (&BIH[16]);
|
|
Packit |
a4058c |
} else if (State->Header.size == 12) {
|
|
Packit |
a4058c |
/* BMP OS/2 */
|
|
Packit |
a4058c |
State->Header.width = lsb_16 (&BIH[4]);
|
|
Packit |
a4058c |
State->Header.height = lsb_16 (&BIH[6]);
|
|
Packit |
a4058c |
State->Header.depth = lsb_16 (&BIH[10]);
|
|
Packit |
a4058c |
State->Compressed = BI_RGB;
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has unsupported header size"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->Header.depth > 32)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has unsupported depth"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->Header.size == 12)
|
|
Packit |
a4058c |
clrUsed = 1 << State->Header.depth;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
clrUsed = (int) (BIH[35] << 24) + (BIH[34] << 16) + (BIH[33] << 8) + (BIH[32]);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (clrUsed > (1 << State->Header.depth))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has oversize palette"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (clrUsed != 0)
|
|
Packit |
a4058c |
State->Header.n_colors = clrUsed;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
State->Header.n_colors = (1 << State->Header.depth);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->Type = State->Header.depth; /* This may be less trivial someday */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Negative heights indicates bottom-down pixelorder */
|
|
Packit |
a4058c |
if (State->Header.height < 0) {
|
|
Packit |
a4058c |
if (State->Header.height == INT_MIN) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
State->Header.height = -State->Header.height;
|
|
Packit |
a4058c |
State->Header.Negative = 1;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->Header.Negative &&
|
|
Packit |
a4058c |
(State->Compressed != BI_RGB && State->Compressed != BI_BITFIELDS))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("Topdown BMP images cannot be compressed"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->Header.width <= 0 || State->Header.height == 0 ||
|
|
Packit |
a4058c |
(State->Compressed == BI_RLE4 && State->Type != 4) ||
|
|
Packit |
a4058c |
(State->Compressed == BI_RLE8 && State->Type != 8) ||
|
|
Packit |
a4058c |
(State->Compressed == BI_BITFIELDS && !(State->Type == 16 || State->Type == 32)) ||
|
|
Packit |
a4058c |
(State->Compressed > BI_BITFIELDS)) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if ((State->Type >= 8) && (State->Type <= 32) && (State->Type % 8 == 0)) {
|
|
Packit |
a4058c |
bytesPerPixel = State->Type / 8;
|
|
Packit |
a4058c |
State->LineWidth = State->Header.width * bytesPerPixel;
|
|
Packit |
a4058c |
if (State->Header.width != State->LineWidth / bytesPerPixel) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image width too large"));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else if (State->Type == 4)
|
|
Packit |
a4058c |
State->LineWidth = (State->Header.width + 1) / 2;
|
|
Packit |
a4058c |
else if (State->Type == 1) {
|
|
Packit |
a4058c |
State->LineWidth = State->Header.width / 8;
|
|
Packit |
a4058c |
if ((State->Header.width & 7) != 0)
|
|
Packit |
a4058c |
State->LineWidth++;
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Pad to a 32 bit boundary */
|
|
Packit |
a4058c |
if (((State->LineWidth % 4) > 0)
|
|
Packit |
a4058c |
&& (State->Compressed == BI_RGB || State->Compressed == BI_BITFIELDS))
|
|
Packit |
a4058c |
State->LineWidth = (State->LineWidth / 4) * 4 + 4;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->pixbuf == NULL) {
|
|
Packit |
a4058c |
guint64 len;
|
|
Packit |
a4058c |
int rowstride;
|
|
Packit |
a4058c |
gboolean has_alpha;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->size_func) {
|
|
Packit |
a4058c |
gint width = State->Header.width;
|
|
Packit |
a4058c |
gint height = State->Header.height;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
(*State->size_func) (&width, &height, State->user_data);
|
|
Packit |
a4058c |
if (width == 0 || height == 0) {
|
|
Packit |
a4058c |
State->read_state = READ_STATE_DONE;
|
|
Packit |
a4058c |
State->BufferSize = 0;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* rowstride is always >= width, so do an early check for bogus header */
|
|
Packit |
a4058c |
if (State->Header.width <= 0 ||
|
|
Packit |
a4058c |
State->Header.height <= 0 ||
|
|
Packit |
a4058c |
!g_uint64_checked_mul (&len, State->Header.width, State->Header.height) ||
|
|
Packit |
a4058c |
len > G_MAXINT) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->Type == 32 ||
|
|
Packit |
a4058c |
State->Compressed == BI_RLE4 ||
|
|
Packit |
a4058c |
State->Compressed == BI_RLE8)
|
|
Packit |
a4058c |
has_alpha = TRUE;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
has_alpha = FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
rowstride = gdk_pixbuf_calculate_rowstride (GDK_COLORSPACE_RGB, has_alpha, 8,
|
|
Packit |
a4058c |
(gint) State->Header.width,
|
|
Packit |
a4058c |
(gint) State->Header.height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (rowstride <= 0 ||
|
|
Packit |
a4058c |
!g_uint64_checked_mul (&len, rowstride, State->Header.height) ||
|
|
Packit |
a4058c |
len > G_MAXINT) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, has_alpha, 8,
|
|
Packit |
a4058c |
(gint) State->Header.width,
|
|
Packit |
a4058c |
(gint) State->Header.height);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->pixbuf == NULL) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
Packit |
a4058c |
_("Not enough memory to load bitmap image"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->prepared_func != NULL)
|
|
Packit |
a4058c |
/* Notify the client that we are ready to go */
|
|
Packit |
a4058c |
(*State->prepared_func) (State->pixbuf, NULL, State->user_data);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* make all pixels initially transparent */
|
|
Packit |
a4058c |
if (State->Compressed == BI_RLE4 || State->Compressed == BI_RLE8) {
|
|
Packit |
a4058c |
memset (State->pixbuf->pixels, 0, State->pixbuf->rowstride * State->Header.height);
|
|
Packit |
a4058c |
State->compr.p = State->pixbuf->pixels
|
|
Packit |
a4058c |
+ State->pixbuf->rowstride * (State->Header.height- 1);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->BufferDone = 0;
|
|
Packit |
a4058c |
if (State->Type <= 8) {
|
|
Packit |
a4058c |
gint samples;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->read_state = READ_STATE_PALETTE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Allocate enough to hold the palette */
|
|
Packit |
a4058c |
samples = (State->Header.size == 12 ? 3 : 4);
|
|
Packit |
a4058c |
State->BufferSize = State->Header.n_colors * samples;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Skip over everything between the palette and the data.
|
|
Packit |
a4058c |
This protects us against a malicious BFH[10] value.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
State->BufferPadding = (lsb_32 (&BFH[10]) - 14 - State->Header.size) - State->BufferSize;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
} else if (State->Compressed == BI_RGB) {
|
|
Packit |
a4058c |
if (State->BufferSize < lsb_32 (&BFH[10]))
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
/* skip over padding between headers and image data */
|
|
Packit |
a4058c |
State->read_state = READ_STATE_HEADERS;
|
|
Packit |
a4058c |
State->BufferDone = State->BufferSize;
|
|
Packit |
a4058c |
State->BufferSize = lsb_32 (&BFH[10]);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
State->read_state = READ_STATE_DATA;
|
|
Packit |
a4058c |
State->BufferSize = State->LineWidth;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else if (State->Compressed == BI_BITFIELDS) {
|
|
Packit |
a4058c |
if (State->Header.size == 52 || State->Header.size == 56 ||
|
|
Packit |
a4058c |
State->Header.size == 108 || State->Header.size == 124)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
/* extended v3, v4 and v5 have the bitmasks in the header */
|
|
Packit |
a4058c |
if (!decode_bitmasks (&BIH[40], State, error)) {
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
State->read_state = READ_STATE_BITMASKS;
|
|
Packit |
a4058c |
State->BufferSize = 12;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("BMP image has bogus header data"));
|
|
Packit |
a4058c |
State->read_state = READ_STATE_ERROR;
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!grow_buffer (State, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean DecodeColormap (guchar *buff,
|
|
Packit |
a4058c |
struct bmp_progressive_state *State,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint i;
|
|
Packit |
a4058c |
gint samples;
|
|
Packit |
a4058c |
guint newbuffersize;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_assert (State->read_state == READ_STATE_PALETTE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
samples = (State->Header.size == 12 ? 3 : 4);
|
|
Packit |
a4058c |
newbuffersize = State->Header.n_colors * samples;
|
|
Packit |
a4058c |
if (newbuffersize / samples != State->Header.n_colors) /* Integer overflow check */
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
if (State->BufferSize < newbuffersize) {
|
|
Packit |
a4058c |
State->BufferSize = newbuffersize;
|
|
Packit |
a4058c |
if (!grow_buffer (State, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->Colormap = g_malloc0 ((1 << State->Header.depth) * sizeof (*State->Colormap));
|
|
Packit |
a4058c |
for (i = 0; i < State->Header.n_colors; i++)
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
State->Colormap[i][0] = buff[i * samples];
|
|
Packit |
a4058c |
State->Colormap[i][1] = buff[i * samples + 1];
|
|
Packit |
a4058c |
State->Colormap[i][2] = buff[i * samples + 2];
|
|
Packit |
a4058c |
#ifdef DUMPCMAP
|
|
Packit |
a4058c |
g_print ("color %d %x %x %x\n", i,
|
|
Packit |
a4058c |
State->Colormap[i][0],
|
|
Packit |
a4058c |
State->Colormap[i][1],
|
|
Packit |
a4058c |
State->Colormap[i][2]);
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->read_state = READ_STATE_DATA;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->BufferDone = 0;
|
|
Packit |
a4058c |
if (!(State->Compressed == BI_RGB || State->Compressed == BI_BITFIELDS))
|
|
Packit |
a4058c |
State->BufferSize = 2;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
State->BufferSize = State->LineWidth;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!grow_buffer (State, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Finds the lowest set bit and the number of set bits */
|
|
Packit |
a4058c |
static void
|
|
Packit |
a4058c |
find_bits (int n, int *lowest, int *n_set)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
int i;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*n_set = 0;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (i = 31; i >= 0; i--)
|
|
Packit |
a4058c |
if (n & (1 << i)) {
|
|
Packit |
a4058c |
*lowest = i;
|
|
Packit |
a4058c |
(*n_set)++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* Decodes the bitmasks for BI_BITFIELDS coding */
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
decode_bitmasks (guchar *buf,
|
|
Packit |
a4058c |
struct bmp_progressive_state *State,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
State->a_mask = State->a_shift = State->a_bits = 0;
|
|
Packit |
a4058c |
State->r_mask = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
|
Packit |
a4058c |
buf += 4;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->g_mask = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
|
Packit |
a4058c |
buf += 4;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->b_mask = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
find_bits (State->r_mask, &State->r_shift, &State->r_bits);
|
|
Packit |
a4058c |
find_bits (State->g_mask, &State->g_shift, &State->g_bits);
|
|
Packit |
a4058c |
find_bits (State->b_mask, &State->b_shift, &State->b_bits);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* extended v3, v4 and v5 have an alpha mask */
|
|
Packit |
a4058c |
if (State->Header.size == 56 || State->Header.size == 108 || State->Header.size == 124) {
|
|
Packit |
a4058c |
buf += 4;
|
|
Packit |
a4058c |
State->a_mask = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
|
Packit |
a4058c |
find_bits (State->a_mask, &State->a_shift, &State->a_bits);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->r_bits == 0 || State->g_bits == 0 || State->b_bits == 0) {
|
|
Packit |
a4058c |
if (State->Type == 16) {
|
|
Packit |
a4058c |
State->r_mask = 0x7c00;
|
|
Packit |
a4058c |
State->r_shift = 10;
|
|
Packit |
a4058c |
State->g_mask = 0x03e0;
|
|
Packit |
a4058c |
State->g_shift = 5;
|
|
Packit |
a4058c |
State->b_mask = 0x001f;
|
|
Packit |
a4058c |
State->b_shift = 0;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->r_bits = State->g_bits = State->b_bits = 5;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else {
|
|
Packit |
a4058c |
State->r_mask = 0x00ff0000;
|
|
Packit |
a4058c |
State->r_shift = 16;
|
|
Packit |
a4058c |
State->g_mask = 0x0000ff00;
|
|
Packit |
a4058c |
State->g_shift = 8;
|
|
Packit |
a4058c |
State->b_mask = 0x000000ff;
|
|
Packit |
a4058c |
State->b_shift = 0;
|
|
Packit |
a4058c |
State->a_mask = 0xff000000;
|
|
Packit |
a4058c |
State->a_shift = 24;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->r_bits = State->g_bits = State->b_bits = State->a_bits = 8;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (State->r_bits > 8) {
|
|
Packit |
a4058c |
State->r_shift += State->r_bits - 8;
|
|
Packit |
a4058c |
State->r_bits = 8;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
if (State->g_bits > 8) {
|
|
Packit |
a4058c |
State->g_shift += State->g_bits - 8;
|
|
Packit |
a4058c |
State->g_bits = 8;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
if (State->b_bits > 8) {
|
|
Packit |
a4058c |
State->b_shift += State->b_bits - 8;
|
|
Packit |
a4058c |
State->b_bits = 8;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
if (State->a_bits > 8) {
|
|
Packit |
a4058c |
State->a_shift += State->a_bits - 8;
|
|
Packit |
a4058c |
State->a_bits = 8;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
State->read_state = READ_STATE_DATA;
|
|
Packit |
a4058c |
State->BufferDone = 0;
|
|
Packit |
a4058c |
State->BufferSize = State->LineWidth;
|
|
Packit |
a4058c |
if (!grow_buffer (State, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/*
|
|
Packit |
a4058c |
* func - called when we have pixmap created (but no image data)
|
|
Packit |
a4058c |
* user_data - passed as arg 1 to func
|
|
Packit |
a4058c |
* return context (opaque to user)
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gpointer
|
|
Packit |
a4058c |
gdk_pixbuf__bmp_image_begin_load(GdkPixbufModuleSizeFunc size_func,
|
|
Packit |
a4058c |
GdkPixbufModulePreparedFunc prepared_func,
|
|
Packit |
a4058c |
GdkPixbufModuleUpdatedFunc updated_func,
|
|
Packit |
a4058c |
gpointer user_data,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
struct bmp_progressive_state *context;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context = g_new0(struct bmp_progressive_state, 1);
|
|
Packit |
a4058c |
context->size_func = size_func;
|
|
Packit |
a4058c |
context->prepared_func = prepared_func;
|
|
Packit |
a4058c |
context->updated_func = updated_func;
|
|
Packit |
a4058c |
context->user_data = user_data;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->read_state = READ_STATE_HEADERS;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->BufferSize = 26;
|
|
Packit |
a4058c |
context->BufferPadding = 0;
|
|
Packit |
a4058c |
context->buff = g_malloc(26);
|
|
Packit |
a4058c |
context->BufferDone = 0;
|
|
Packit |
a4058c |
/* 14 for the BitmapFileHeader, 12 for the BitmapImageHeader */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->Colormap = NULL;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->Lines = 0;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->Type = 0;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
memset(&context->Header, 0, sizeof(struct headerpair));
|
|
Packit |
a4058c |
memset(&context->compr, 0, sizeof(struct bmp_compression_state));
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->pixbuf = NULL;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return (gpointer) context;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/*
|
|
Packit |
a4058c |
* context - returned from image_begin_load
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* free context, unref gdk_pixbuf
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
static gboolean gdk_pixbuf__bmp_image_stop_load(gpointer data, GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gboolean retval = TRUE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
struct bmp_progressive_state *context =
|
|
Packit |
a4058c |
(struct bmp_progressive_state *) data;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* FIXME this thing needs to report errors if
|
|
Packit |
a4058c |
* we have unused image data
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_return_val_if_fail(context != NULL, TRUE);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_free(context->Colormap);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->pixbuf)
|
|
Packit |
a4058c |
g_object_unref(context->pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->read_state == READ_STATE_HEADERS) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("Premature end-of-file encountered"));
|
|
Packit |
a4058c |
retval = FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
g_free(context->buff);
|
|
Packit |
a4058c |
g_free(context);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return retval;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/*
|
|
Packit |
a4058c |
The OneLineXX functions are called when 1 line worth of data is present.
|
|
Packit |
a4058c |
OneLine24 is the 24 bpp-version.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
static void OneLine32(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
int i;
|
|
Packit |
a4058c |
guchar *pixels;
|
|
Packit |
a4058c |
guchar *src;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!context->Header.Negative)
|
|
Packit |
a4058c |
pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride * (context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride * context->Lines);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src = context->buff;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->Compressed == BI_BITFIELDS) {
|
|
Packit |
a4058c |
int r_lshift, r_rshift;
|
|
Packit |
a4058c |
int g_lshift, g_rshift;
|
|
Packit |
a4058c |
int b_lshift, b_rshift;
|
|
Packit |
a4058c |
int a_lshift, a_rshift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r_lshift = 8 - context->r_bits;
|
|
Packit |
a4058c |
g_lshift = 8 - context->g_bits;
|
|
Packit |
a4058c |
b_lshift = 8 - context->b_bits;
|
|
Packit |
a4058c |
a_lshift = 8 - context->a_bits;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r_rshift = context->r_bits - r_lshift;
|
|
Packit |
a4058c |
g_rshift = context->g_bits - g_lshift;
|
|
Packit |
a4058c |
b_rshift = context->b_bits - b_lshift;
|
|
Packit |
a4058c |
a_rshift = context->a_bits - a_lshift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (i = 0; i < context->Header.width; i++) {
|
|
Packit |
a4058c |
unsigned int v, r, g, b, a;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
v = src[0] | (src[1] << 8) | (src[2] << 16) | (src[3] << 24);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r = (v & context->r_mask) >> context->r_shift;
|
|
Packit |
a4058c |
g = (v & context->g_mask) >> context->g_shift;
|
|
Packit |
a4058c |
b = (v & context->b_mask) >> context->b_shift;
|
|
Packit |
a4058c |
a = (v & context->a_mask) >> context->a_shift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*pixels++ = (r << r_lshift) | (r >> r_rshift);
|
|
Packit |
a4058c |
*pixels++ = (g << g_lshift) | (g >> g_rshift);
|
|
Packit |
a4058c |
*pixels++ = (b << b_lshift) | (b >> b_rshift);
|
|
Packit |
a4058c |
if (context->a_bits)
|
|
Packit |
a4058c |
*pixels++ = (a << a_lshift) | (a >> a_rshift);
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
*pixels++ = 0xff;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src += 4;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else
|
|
Packit |
a4058c |
for (i = 0; i < context->Header.width; i++) {
|
|
Packit |
a4058c |
*pixels++ = src[2];
|
|
Packit |
a4058c |
*pixels++ = src[1];
|
|
Packit |
a4058c |
*pixels++ = src[0];
|
|
Packit |
a4058c |
*pixels++ = 0xff;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src += 4;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine24(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint X;
|
|
Packit |
a4058c |
guchar *Pixels;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
X = 0;
|
|
Packit |
a4058c |
if (context->Header.Negative == 0)
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
(context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
context->Lines);
|
|
Packit |
a4058c |
while (X < context->Header.width) {
|
|
Packit |
a4058c |
Pixels[X * 3 + 0] = context->buff[X * 3 + 2];
|
|
Packit |
a4058c |
Pixels[X * 3 + 1] = context->buff[X * 3 + 1];
|
|
Packit |
a4058c |
Pixels[X * 3 + 2] = context->buff[X * 3 + 0];
|
|
Packit |
a4058c |
X++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine16(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
int i;
|
|
Packit |
a4058c |
guchar *pixels;
|
|
Packit |
a4058c |
guchar *src;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!context->Header.Negative)
|
|
Packit |
a4058c |
pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride * (context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride * context->Lines);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src = context->buff;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->Compressed == BI_BITFIELDS) {
|
|
Packit |
a4058c |
int r_lshift, r_rshift;
|
|
Packit |
a4058c |
int g_lshift, g_rshift;
|
|
Packit |
a4058c |
int b_lshift, b_rshift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r_lshift = 8 - context->r_bits;
|
|
Packit |
a4058c |
g_lshift = 8 - context->g_bits;
|
|
Packit |
a4058c |
b_lshift = 8 - context->b_bits;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r_rshift = context->r_bits - r_lshift;
|
|
Packit |
a4058c |
g_rshift = context->g_bits - g_lshift;
|
|
Packit |
a4058c |
b_rshift = context->b_bits - b_lshift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (i = 0; i < context->Header.width; i++) {
|
|
Packit |
a4058c |
int v, r, g, b;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
v = (int) src[0] | ((int) src[1] << 8);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r = (v & context->r_mask) >> context->r_shift;
|
|
Packit |
a4058c |
g = (v & context->g_mask) >> context->g_shift;
|
|
Packit |
a4058c |
b = (v & context->b_mask) >> context->b_shift;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*pixels++ = (r << r_lshift) | (r >> r_rshift);
|
|
Packit |
a4058c |
*pixels++ = (g << g_lshift) | (g >> g_rshift);
|
|
Packit |
a4058c |
*pixels++ = (b << b_lshift) | (b >> b_rshift);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src += 2;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
} else
|
|
Packit |
a4058c |
for (i = 0; i < context->Header.width; i++) {
|
|
Packit |
a4058c |
int v, r, g, b;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
v = src[0] | (src[1] << 8);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
r = (v >> 10) & 0x1f;
|
|
Packit |
a4058c |
g = (v >> 5) & 0x1f;
|
|
Packit |
a4058c |
b = v & 0x1f;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
*pixels++ = (r << 3) | (r >> 2);
|
|
Packit |
a4058c |
*pixels++ = (g << 3) | (g >> 2);
|
|
Packit |
a4058c |
*pixels++ = (b << 3) | (b >> 2);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
src += 2;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine8(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint X;
|
|
Packit |
a4058c |
guchar *Pixels;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
X = 0;
|
|
Packit |
a4058c |
if (context->Header.Negative == 0)
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
(context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
context->Lines);
|
|
Packit |
a4058c |
while (X < context->Header.width) {
|
|
Packit |
a4058c |
Pixels[X * 3 + 0] =
|
|
Packit |
a4058c |
context->Colormap[context->buff[X]][2];
|
|
Packit |
a4058c |
Pixels[X * 3 + 1] =
|
|
Packit |
a4058c |
context->Colormap[context->buff[X]][1];
|
|
Packit |
a4058c |
Pixels[X * 3 + 2] =
|
|
Packit |
a4058c |
context->Colormap[context->buff[X]][0];
|
|
Packit |
a4058c |
X++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine4(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint X;
|
|
Packit |
a4058c |
guchar *Pixels;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
X = 0;
|
|
Packit |
a4058c |
if (context->Header.Negative == 0)
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
(context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
context->Lines);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
while (X < context->Header.width) {
|
|
Packit |
a4058c |
guchar Pix;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
Pix = context->buff[X / 2];
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
Pixels[X * 3 + 0] =
|
|
Packit |
a4058c |
context->Colormap[Pix >> 4][2];
|
|
Packit |
a4058c |
Pixels[X * 3 + 1] =
|
|
Packit |
a4058c |
context->Colormap[Pix >> 4][1];
|
|
Packit |
a4058c |
Pixels[X * 3 + 2] =
|
|
Packit |
a4058c |
context->Colormap[Pix >> 4][0];
|
|
Packit |
a4058c |
X++;
|
|
Packit |
a4058c |
if (X < context->Header.width) {
|
|
Packit |
a4058c |
/* Handle the other 4 bit pixel only when there is one */
|
|
Packit |
a4058c |
Pixels[X * 3 + 0] =
|
|
Packit |
a4058c |
context->Colormap[Pix & 15][2];
|
|
Packit |
a4058c |
Pixels[X * 3 + 1] =
|
|
Packit |
a4058c |
context->Colormap[Pix & 15][1];
|
|
Packit |
a4058c |
Pixels[X * 3 + 2] =
|
|
Packit |
a4058c |
context->Colormap[Pix & 15][0];
|
|
Packit |
a4058c |
X++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine1(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint X;
|
|
Packit |
a4058c |
guchar *Pixels;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
X = 0;
|
|
Packit |
a4058c |
if (context->Header.Negative == 0)
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
(context->Header.height - context->Lines - 1));
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
Pixels = (context->pixbuf->pixels +
|
|
Packit |
a4058c |
context->pixbuf->rowstride *
|
|
Packit |
a4058c |
context->Lines);
|
|
Packit |
a4058c |
while (X < context->Header.width) {
|
|
Packit |
a4058c |
gint Bit;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
Bit = (context->buff[X / 8]) >> (7 - (X & 7));
|
|
Packit |
a4058c |
Bit = Bit & 1;
|
|
Packit |
a4058c |
Pixels[X * 3 + 0] = context->Colormap[Bit][2];
|
|
Packit |
a4058c |
Pixels[X * 3 + 1] = context->Colormap[Bit][1];
|
|
Packit |
a4058c |
Pixels[X * 3 + 2] = context->Colormap[Bit][0];
|
|
Packit |
a4058c |
X++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static void OneLine(struct bmp_progressive_state *context)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
context->BufferDone = 0;
|
|
Packit |
a4058c |
if (context->Lines >= context->Header.height)
|
|
Packit |
a4058c |
return;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->Type == 32)
|
|
Packit |
a4058c |
OneLine32(context);
|
|
Packit |
a4058c |
else if (context->Type == 24)
|
|
Packit |
a4058c |
OneLine24(context);
|
|
Packit |
a4058c |
else if (context->Type == 16)
|
|
Packit |
a4058c |
OneLine16(context);
|
|
Packit |
a4058c |
else if (context->Type == 8)
|
|
Packit |
a4058c |
OneLine8(context);
|
|
Packit |
a4058c |
else if (context->Type == 4)
|
|
Packit |
a4058c |
OneLine4(context);
|
|
Packit |
a4058c |
else if (context->Type == 1)
|
|
Packit |
a4058c |
OneLine1(context);
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
g_assert_not_reached ();
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->Lines++;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->updated_func != NULL) {
|
|
Packit |
a4058c |
(*context->updated_func) (context->pixbuf,
|
|
Packit |
a4058c |
0,
|
|
Packit |
a4058c |
(context->Header.Negative ?
|
|
Packit |
a4058c |
(context->Lines - 1) :
|
|
Packit |
a4058c |
(context->Header.height - context->Lines)),
|
|
Packit |
a4058c |
context->Header.width,
|
|
Packit |
a4058c |
1,
|
|
Packit |
a4058c |
context->user_data);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define NEUTRAL 0
|
|
Packit |
a4058c |
#define ENCODED 1
|
|
Packit |
a4058c |
#define ESCAPE 2
|
|
Packit |
a4058c |
#define DELTA_X 3
|
|
Packit |
a4058c |
#define DELTA_Y 4
|
|
Packit |
a4058c |
#define ABSOLUTE 5
|
|
Packit |
a4058c |
#define SKIP 6
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#define END_OF_LINE 0
|
|
Packit |
a4058c |
#define END_OF_BITMAP 1
|
|
Packit |
a4058c |
#define DELTA 2
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
DoCompressed(struct bmp_progressive_state *context, GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint i, j;
|
|
Packit |
a4058c |
gint y;
|
|
Packit |
a4058c |
guchar c;
|
|
Packit |
a4058c |
gint idx;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* context->compr.y might be past the last line because we are
|
|
Packit |
a4058c |
* on padding past the end of a valid data, or we might have hit
|
|
Packit |
a4058c |
* out-of-bounds data. Either way we just eat-and-ignore the
|
|
Packit |
a4058c |
* rest of the file. Doing the check only here and not when
|
|
Packit |
a4058c |
* we change y below is fine since BufferSize is always 2 here
|
|
Packit |
a4058c |
* and the BMP file format always starts new data on 16-bit
|
|
Packit |
a4058c |
* boundaries.
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
if (context->compr.y >= context->Header.height) {
|
|
Packit |
a4058c |
context->BufferDone = 0;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
y = context->compr.y;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
for (i = 0; i < context->BufferSize; i++) {
|
|
Packit |
a4058c |
c = context->buff[i];
|
|
Packit |
a4058c |
switch (context->compr.phase) {
|
|
Packit |
a4058c |
case NEUTRAL:
|
|
Packit |
a4058c |
if (c) {
|
|
Packit |
a4058c |
context->compr.run = c;
|
|
Packit |
a4058c |
context->compr.phase = ENCODED;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
context->compr.phase = ESCAPE;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case ENCODED:
|
|
Packit |
a4058c |
for (j = 0; j < context->compr.run; j++) {
|
|
Packit |
a4058c |
if (context->Compressed == BI_RLE8)
|
|
Packit |
a4058c |
idx = c;
|
|
Packit |
a4058c |
else if (j & 1)
|
|
Packit |
a4058c |
idx = c & 0x0f;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
idx = (c >> 4) & 0x0f;
|
|
Packit |
a4058c |
if (context->compr.x < context->Header.width) {
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][2];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][1];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][0];
|
|
Packit |
a4058c |
*context->compr.p++ = 0xff;
|
|
Packit |
a4058c |
context->compr.x++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case ESCAPE:
|
|
Packit |
a4058c |
switch (c) {
|
|
Packit |
a4058c |
case END_OF_LINE:
|
|
Packit |
a4058c |
context->compr.x = 0;
|
|
Packit |
a4058c |
context->compr.y++;
|
|
Packit |
a4058c |
context->compr.p = context->pixbuf->pixels
|
|
Packit |
a4058c |
+ (context->pixbuf->rowstride * (context->Header.height - context->compr.y - 1))
|
|
Packit |
a4058c |
+ (4 * context->compr.x);
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case END_OF_BITMAP:
|
|
Packit |
a4058c |
context->compr.x = 0;
|
|
Packit |
a4058c |
context->compr.y = context->Header.height;
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case DELTA:
|
|
Packit |
a4058c |
context->compr.phase = DELTA_X;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
default:
|
|
Packit |
a4058c |
context->compr.run = c;
|
|
Packit |
a4058c |
context->compr.count = 0;
|
|
Packit |
a4058c |
context->compr.phase = ABSOLUTE;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case DELTA_X:
|
|
Packit |
a4058c |
context->compr.x += c;
|
|
Packit |
a4058c |
context->compr.phase = DELTA_Y;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case DELTA_Y:
|
|
Packit |
a4058c |
context->compr.y += c;
|
|
Packit |
a4058c |
context->compr.p = context->pixbuf->pixels
|
|
Packit |
a4058c |
+ (context->pixbuf->rowstride * (context->Header.height - context->compr.y - 1))
|
|
Packit |
a4058c |
+ (4 * context->compr.x);
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case ABSOLUTE:
|
|
Packit |
a4058c |
if (context->Compressed == BI_RLE8) {
|
|
Packit |
a4058c |
idx = c;
|
|
Packit |
a4058c |
if (context->compr.x < context->Header.width) {
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][2];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][1];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][0];
|
|
Packit |
a4058c |
*context->compr.p++ = 0xff;
|
|
Packit |
a4058c |
context->compr.x++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
context->compr.count++;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->compr.count == context->compr.run) {
|
|
Packit |
a4058c |
if (context->compr.run & 1)
|
|
Packit |
a4058c |
context->compr.phase = SKIP;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
else {
|
|
Packit |
a4058c |
for (j = 0; j < 2; j++) {
|
|
Packit |
a4058c |
if (context->compr.count & 1)
|
|
Packit |
a4058c |
idx = c & 0x0f;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
idx = (c >> 4) & 0x0f;
|
|
Packit |
a4058c |
if (context->compr.x < context->Header.width) {
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][2];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][1];
|
|
Packit |
a4058c |
*context->compr.p++ = context->Colormap[idx][0];
|
|
Packit |
a4058c |
*context->compr.p++ = 0xff;
|
|
Packit |
a4058c |
context->compr.x++;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
context->compr.count++;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->compr.count == context->compr.run) {
|
|
Packit |
a4058c |
if ((context->compr.run & 3) == 1
|
|
Packit |
a4058c |
|| (context->compr.run & 3) == 2)
|
|
Packit |
a4058c |
context->compr.phase = SKIP;
|
|
Packit |
a4058c |
else
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case SKIP:
|
|
Packit |
a4058c |
context->compr.phase = NEUTRAL;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
if (context->updated_func != NULL) {
|
|
Packit |
a4058c |
if (context->compr.y > y)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint new_y = MIN (context->compr.y, context->Header.height);
|
|
Packit |
a4058c |
(*context->updated_func) (context->pixbuf,
|
|
Packit |
a4058c |
0,
|
|
Packit |
a4058c |
context->Header.height - new_y,
|
|
Packit |
a4058c |
context->Header.width,
|
|
Packit |
a4058c |
new_y - y,
|
|
Packit |
a4058c |
context->user_data);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
context->BufferDone = 0;
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/*
|
|
Packit |
a4058c |
* context - from image_begin_load
|
|
Packit |
a4058c |
* buf - new image data
|
|
Packit |
a4058c |
* size - length of new image data
|
|
Packit |
a4058c |
*
|
|
Packit |
a4058c |
* append image data onto incrementally built output image
|
|
Packit |
a4058c |
*/
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf__bmp_image_load_increment(gpointer data,
|
|
Packit |
a4058c |
const guchar * buf,
|
|
Packit |
a4058c |
guint size,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
struct bmp_progressive_state *context =
|
|
Packit |
a4058c |
(struct bmp_progressive_state *) data;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
gint BytesToCopy;
|
|
Packit |
a4058c |
gint BytesToRemove;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->read_state == READ_STATE_DONE)
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
else if (context->read_state == READ_STATE_ERROR)
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
while (size > 0) {
|
|
Packit |
a4058c |
if (context->BufferDone < context->BufferSize) { /* We still
|
|
Packit |
a4058c |
have headerbytes to do */
|
|
Packit |
a4058c |
BytesToCopy =
|
|
Packit |
a4058c |
context->BufferSize - context->BufferDone;
|
|
Packit |
a4058c |
if (BytesToCopy > size)
|
|
Packit |
a4058c |
BytesToCopy = size;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
memmove(context->buff + context->BufferDone,
|
|
Packit |
a4058c |
buf, BytesToCopy);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
size -= BytesToCopy;
|
|
Packit |
a4058c |
buf += BytesToCopy;
|
|
Packit |
a4058c |
context->BufferDone += BytesToCopy;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->BufferDone != context->BufferSize)
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* context->buff is full. Now we discard all "padding" */
|
|
Packit |
a4058c |
if (context->BufferPadding != 0) {
|
|
Packit |
a4058c |
BytesToRemove = context->BufferPadding - size;
|
|
Packit |
a4058c |
if (BytesToRemove > size) {
|
|
Packit |
a4058c |
BytesToRemove = size;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
size -= BytesToRemove;
|
|
Packit |
a4058c |
context->BufferPadding -= BytesToRemove;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (context->BufferPadding != 0)
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
switch (context->read_state) {
|
|
Packit |
a4058c |
case READ_STATE_HEADERS:
|
|
Packit |
a4058c |
if (!DecodeHeader (context->buff,
|
|
Packit |
a4058c |
context->buff + 14, context,
|
|
Packit |
a4058c |
error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
case READ_STATE_PALETTE:
|
|
Packit |
a4058c |
if (!DecodeColormap (context->buff, context, error)) {
|
|
Packit |
a4058c |
g_set_error (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_CORRUPT_IMAGE,
|
|
Packit |
a4058c |
_("Error while decoding colormap"));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
case READ_STATE_BITMASKS:
|
|
Packit |
a4058c |
if (!decode_bitmasks (context->buff, context, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
case READ_STATE_DATA:
|
|
Packit |
a4058c |
if (context->Compressed == BI_RGB || context->Compressed == BI_BITFIELDS)
|
|
Packit |
a4058c |
OneLine (context);
|
|
Packit |
a4058c |
else if (!DoCompressed (context, error))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
case READ_STATE_DONE:
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
default:
|
|
Packit |
a4058c |
g_assert_not_reached ();
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* for our convenience when filling file header */
|
|
Packit |
a4058c |
#define put16(buf,data) { guint16 x; \
|
|
Packit |
a4058c |
x = GUINT16_TO_LE (data); \
|
|
Packit |
a4058c |
memcpy(buf, &x, 2); \
|
|
Packit |
a4058c |
buf += 2; }
|
|
Packit |
a4058c |
#define put32(buf,data) { guint32 x; \
|
|
Packit |
a4058c |
x = GUINT32_TO_LE (data); \
|
|
Packit |
a4058c |
memcpy(buf, &x, 4); \
|
|
Packit |
a4058c |
buf += 4; }
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf__bmp_image_save_to_callback (GdkPixbufSaveFunc save_func,
|
|
Packit |
a4058c |
gpointer user_data,
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf,
|
|
Packit |
a4058c |
gchar **keys,
|
|
Packit |
a4058c |
gchar **values,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
guint width, height, channel, size, stride, src_stride, x, y;
|
|
Packit |
a4058c |
guint bf_size;
|
|
Packit |
a4058c |
guchar BFH_BIH[54], *pixels, *buf, *src, *dst, *dst_line;
|
|
Packit |
a4058c |
gboolean ret;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
width = gdk_pixbuf_get_width (pixbuf);
|
|
Packit |
a4058c |
height = gdk_pixbuf_get_height (pixbuf);
|
|
Packit |
a4058c |
channel = gdk_pixbuf_get_n_channels (pixbuf);
|
|
Packit |
a4058c |
pixels = gdk_pixbuf_get_pixels (pixbuf);
|
|
Packit |
a4058c |
src_stride = gdk_pixbuf_get_rowstride (pixbuf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* stride = (width * 3 + 3) & ~3 */
|
|
Packit |
a4058c |
if (!g_uint_checked_mul (&stride, width, 3) ||
|
|
Packit |
a4058c |
!g_uint_checked_add (&stride, stride, 3)) {
|
|
Packit |
a4058c |
g_set_error_literal (error, GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_FAILED,
|
|
Packit |
a4058c |
_("Image is too wide for BMP format."));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
stride &= ~3;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* size = stride * height
|
|
Packit |
a4058c |
* bf_size = size + 14 + 40 */
|
|
Packit |
a4058c |
if (!g_uint_checked_mul (&size, stride, height) ||
|
|
Packit |
a4058c |
!g_uint_checked_add (&bf_size, size, 14 + 40)) {
|
|
Packit |
a4058c |
g_set_error_literal (error, GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_FAILED,
|
|
Packit |
a4058c |
_("Image is too wide for BMP format."));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* filling BFH */
|
|
Packit |
a4058c |
dst = BFH_BIH;
|
|
Packit |
a4058c |
*dst++ = 'B'; /* bfType */
|
|
Packit |
a4058c |
*dst++ = 'M';
|
|
Packit |
a4058c |
put32 (dst, bf_size); /* bfSize */
|
|
Packit |
a4058c |
put32 (dst, 0); /* bfReserved1 + bfReserved2 */
|
|
Packit |
a4058c |
put32 (dst, 14 + 40); /* bfOffBits */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* filling BIH */
|
|
Packit |
a4058c |
put32 (dst, 40); /* biSize */
|
|
Packit |
a4058c |
put32 (dst, width); /* biWidth */
|
|
Packit |
a4058c |
put32 (dst, height); /* biHeight */
|
|
Packit |
a4058c |
put16 (dst, 1); /* biPlanes */
|
|
Packit |
a4058c |
put16 (dst, 24); /* biBitCount */
|
|
Packit |
a4058c |
put32 (dst, BI_RGB); /* biCompression */
|
|
Packit |
a4058c |
put32 (dst, size); /* biSizeImage */
|
|
Packit |
a4058c |
put32 (dst, 0); /* biXPelsPerMeter */
|
|
Packit |
a4058c |
put32 (dst, 0); /* biYPelsPerMeter */
|
|
Packit |
a4058c |
put32 (dst, 0); /* biClrUsed */
|
|
Packit |
a4058c |
put32 (dst, 0); /* biClrImportant */
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (!save_func ((gchar *)BFH_BIH, 14 + 40, error, user_data))
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
dst_line = buf = g_try_malloc (size);
|
|
Packit |
a4058c |
if (!buf) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY,
|
|
Packit |
a4058c |
_("Couldn't allocate memory for saving BMP file"));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
/* saving as a bottom-up bmp */
|
|
Packit |
a4058c |
pixels += (height - 1) * src_stride;
|
|
Packit |
a4058c |
for (y = 0; y < height; ++y, pixels -= src_stride, dst_line += stride) {
|
|
Packit |
a4058c |
dst = dst_line;
|
|
Packit |
a4058c |
src = pixels;
|
|
Packit |
a4058c |
for (x = 0; x < width; ++x, dst += 3, src += channel) {
|
|
Packit |
a4058c |
dst[0] = src[2];
|
|
Packit |
a4058c |
dst[1] = src[1];
|
|
Packit |
a4058c |
dst[2] = src[0];
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
ret = save_func ((gchar *)buf, size, error, user_data);
|
|
Packit |
a4058c |
g_free (buf);
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return ret;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
save_to_file_cb (const gchar *buf,
|
|
Packit |
a4058c |
gsize count,
|
|
Packit |
a4058c |
GError **error,
|
|
Packit |
a4058c |
gpointer data)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
gint bytes;
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
while (count > 0) {
|
|
Packit |
a4058c |
bytes = fwrite (buf, sizeof (gchar), count, (FILE *) data);
|
|
Packit |
a4058c |
if (bytes <= 0)
|
|
Packit |
a4058c |
break;
|
|
Packit |
a4058c |
count -= bytes;
|
|
Packit |
a4058c |
buf += bytes;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
if (count) {
|
|
Packit |
a4058c |
g_set_error_literal (error,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR,
|
|
Packit |
a4058c |
GDK_PIXBUF_ERROR_FAILED,
|
|
Packit |
a4058c |
_("Couldn't write to BMP file"));
|
|
Packit |
a4058c |
return FALSE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
return TRUE;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
static gboolean
|
|
Packit |
a4058c |
gdk_pixbuf__bmp_image_save (FILE *f,
|
|
Packit |
a4058c |
GdkPixbuf *pixbuf,
|
|
Packit |
a4058c |
gchar **keys,
|
|
Packit |
a4058c |
gchar **values,
|
|
Packit |
a4058c |
GError **error)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
return gdk_pixbuf__bmp_image_save_to_callback (save_to_file_cb,
|
|
Packit |
a4058c |
f, pixbuf, keys,
|
|
Packit |
a4058c |
values, error);
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
#ifndef INCLUDE_bmp
|
|
Packit |
a4058c |
#define MODULE_ENTRY(function) G_MODULE_EXPORT void function
|
|
Packit |
a4058c |
#else
|
|
Packit |
a4058c |
#define MODULE_ENTRY(function) void _gdk_pixbuf__bmp_ ## function
|
|
Packit |
a4058c |
#endif
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
MODULE_ENTRY (fill_vtable) (GdkPixbufModule *module)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
module->begin_load = gdk_pixbuf__bmp_image_begin_load;
|
|
Packit |
a4058c |
module->stop_load = gdk_pixbuf__bmp_image_stop_load;
|
|
Packit |
a4058c |
module->load_increment = gdk_pixbuf__bmp_image_load_increment;
|
|
Packit |
a4058c |
module->save = gdk_pixbuf__bmp_image_save;
|
|
Packit |
a4058c |
module->save_to_callback = gdk_pixbuf__bmp_image_save_to_callback;
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
MODULE_ENTRY (fill_info) (GdkPixbufFormat *info)
|
|
Packit |
a4058c |
{
|
|
Packit |
a4058c |
static const GdkPixbufModulePattern signature[] = {
|
|
Packit |
a4058c |
{ "BM", NULL, 100 },
|
|
Packit |
a4058c |
{ NULL, NULL, 0 }
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
static const gchar * mime_types[] = {
|
|
Packit |
a4058c |
"image/bmp",
|
|
Packit |
a4058c |
"image/x-bmp",
|
|
Packit |
a4058c |
"image/x-MS-bmp",
|
|
Packit |
a4058c |
NULL
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
static const gchar * extensions[] = {
|
|
Packit |
a4058c |
"bmp",
|
|
Packit |
a4058c |
NULL
|
|
Packit |
a4058c |
};
|
|
Packit |
a4058c |
|
|
Packit |
a4058c |
info->name = "bmp";
|
|
Packit |
a4058c |
info->signature = (GdkPixbufModulePattern *) signature;
|
|
Packit |
a4058c |
info->description = NC_("image format", "BMP");
|
|
Packit |
a4058c |
info->mime_types = (gchar **) mime_types;
|
|
Packit |
a4058c |
info->extensions = (gchar **) extensions;
|
|
Packit |
a4058c |
info->flags = GDK_PIXBUF_FORMAT_WRITABLE | GDK_PIXBUF_FORMAT_THREADSAFE;
|
|
Packit |
a4058c |
info->license = "LGPL";
|
|
Packit |
a4058c |
}
|
|
Packit |
a4058c |
|