io-bmp.c 1.45 KB
Newer Older
Mark Crichton's avatar
Mark Crichton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*
 * io-bmp.c: GdkPixBuf I/O for BMP files.
 *
 * Copyright (C) 1999 Mark Crichton
 * Author: Mark Crichton <crichton@gimp.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
 *
 */

#include <config.h>
#include <stdio.h>
#include <glib.h>
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-io.h"
Mark Crichton's avatar
Mark Crichton committed
28
#include "io-bmp.h"
Mark Crichton's avatar
Mark Crichton committed
29

Mark Crichton's avatar
Mark Crichton committed
30
/* Loosely based off the BMP loader from The GIMP, hence it's complexity */
Mark Crichton's avatar
Mark Crichton committed
31 32 33 34 35

/* Shared library entry point */
GdkPixBuf *image_load(FILE * f)
{
    art_u8 *pixels;
Michael Meeks's avatar
Michael Meeks committed
36
    ArtPixBuf *art_pixbuf;
Mark Crichton's avatar
Mark Crichton committed
37 38 39 40

    /* Ok, now stuff the GdkPixBuf with goodies */

    if (is_trans)
Michael Meeks's avatar
Michael Meeks committed
41
	    art_pixbuf = art_pixbuf_new_rgba (pixels, w, h, (w * 4));
Mark Crichton's avatar
Mark Crichton committed
42
    else
Michael Meeks's avatar
Michael Meeks committed
43
	    art_pixbuf = art_pixbuf_new_rgb  (pixels, w, h, (w * 3));
Mark Crichton's avatar
Mark Crichton committed
44 45

    /* Ok, I'm anal...shoot me */
Michael Meeks's avatar
Michael Meeks committed
46
    return gdk_pixbuf_new (art_pixbuf, NULL);
Mark Crichton's avatar
Mark Crichton committed
47
}