Commit 68f895bd authored by Mark Crichton's avatar Mark Crichton
Browse files

Massive update...



Massive update...

gdk-pixbuf-io.c: Fixed to compile and run in a very crippled state.

io-bpm.c: Rough start on a WIN/OS2 BMP loader

testpixbuf.c: Really crude test program for gdk-pixbuf

io-gif.c: Fixed some boneheaded uninitalized variables causing the
loader to choke
parent b10feaf1
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
/* Note: these #includes differ slightly from the testrgb.c file included
in the GdkRgb release. */
/* For gettimeofday */
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
#include "gdk-pixbuf.h"
static void
quit_func (GtkWidget *widget, gpointer dummy)
{
gtk_main_quit ();
}
static void
testrgb_rgb_test (GtkWidget *drawing_area, GdkPixBuf *pixbuf)
{
guchar *buf;
gint i, j;
gint offset;
guchar val;
gdouble start_time, total_time;
gint x, y;
gboolean dither;
int dith_max;
buf = pixbuf->art_pixbuf->pixels;
x = pixbuf->art_pixbuf->width;
y = pixbuf->art_pixbuf->height;
g_print("X: %d Y: %d\n", x, y);
while (TRUE) {
if (pixbuf->art_pixbuf->has_alpha){
g_print("32\n");
gdk_draw_rgb_32_image (drawing_area->window,
drawing_area->style->black_gc,
0, 0, x, y,
GDK_RGB_DITHER_MAX,
pixbuf->art_pixbuf->pixels,
pixbuf->art_pixbuf->rowstride);
}else{
g_print("24\n");
gdk_draw_rgb_image (drawing_area->window,
drawing_area->style->white_gc,
0, 0, x, y,
GDK_RGB_DITHER_NORMAL,
buf,
pixbuf->art_pixbuf->rowstride);
}}
}
void
new_testrgb_window (GdkPixBuf *pixbuf)
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *button;
GtkWidget *drawing_area;
gint w, h;
w = pixbuf->art_pixbuf->width;
h = pixbuf->art_pixbuf->height;
window = gtk_widget_new (gtk_window_get_type (),
"GtkObject::user_data", NULL,
"GtkWindow::type", GTK_WINDOW_TOPLEVEL,
"GtkWindow::title", "testrgb",
"GtkWindow::allow_shrink", FALSE,
NULL);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
(GtkSignalFunc) quit_func, NULL);
vbox = gtk_vbox_new (FALSE, 0);
drawing_area = gtk_drawing_area_new ();
gtk_widget_set_usize (drawing_area, w, h);
gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
gtk_widget_show (drawing_area);
button = gtk_button_new_with_label ("Quit");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
(GtkSignalFunc) gtk_widget_destroy,
GTK_OBJECT (window));
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER (window), vbox);
gtk_widget_show (vbox);
gtk_widget_show (window);
testrgb_rgb_test (drawing_area, pixbuf);
}
int
main (int argc, char **argv)
{
GdkPixBuf *pixbuf;
gtk_init (&argc, &argv);
gdk_rgb_set_verbose (TRUE);
gdk_rgb_init ();
gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
gtk_widget_set_default_visual (gdk_rgb_get_visual ());
pixbuf = gdk_pixbuf_load_image ("test.gif");
new_testrgb_window (pixbuf);
gtk_main ();
return 0;
}
Makefile.in
Makefile
.deps
.xvpics
......@@ -7,10 +7,18 @@ lib_LTLIBRARIES = \
libpixbuf-xpm.la \
libpixbuf-tiff.la
noinst_PROGRAMS = testpixbuf
DEPS = libgdk-pixbuf.la
LDADDS = libgdk-pixbuf.la @GNOME_LIBDIR@ @GNOMEUI_LIBS@
testpixbuf_DEPENDENCIES = $(DEPS)
testpixbuf_LDADD = $(LDADDS)
testpixbuf_CFLAGS = $(GNOME_INCLUDEDIR)
#
# The GdkPixBuf library
#
libgdk_pixbufincludedir = $(includedir)/gdk-pixbuf
libgdk_pixbufincludedir = $(includedir)/gdk-pixbuf $(GNOME_INCLUDEDIR)
libgdk_pixbuf_la_SOURCES = \
gdk-pixbuf.c \
......@@ -24,12 +32,16 @@ libgdk_pixbufinclude_HEADERS = \
#
libpixbuf_png_la_SOURCES = \
io-png.c
libpixbuf_png_la_LDFLAGS = -avoid-version
libpixbuf_png_la_LIBADD = -lpng -lz
#
# The JPEG loader
#
libpixbuf_jpeg_la_SOURCES = \
io-jpeg.c
libpixbuf_jpeg_la_LDFLAGS = -avoid-version
libpixbuf_jpeg_la_LIBADD = -ljpeg
#
# The XPM loader
......@@ -42,9 +54,11 @@ libpixbuf_xpm_la_SOURCES = \
#
libpixbuf_gif_la_SOURCES = \
io-gif.c
libpixbuf_gif_la_LDFLAGS = -avoid-version
libpixbuf_gif_la_LIBADD= -lungif
#
# The TIFF loader
#
libpixbuf_gif_la_SOURCES= \
libpixbuf_tiff_la_SOURCES= \
io-tiff.c
......@@ -6,8 +6,12 @@
*/
#include <config.h>
#include <stdio.h>
#include <glib.h>
#include <gmodule.h>
#include "gdk-pixbuf.h"
#define PIXBUF_LIBDIR "."
static gboolean
pixbuf_check_png (unsigned char *buffer, int size)
{
......@@ -112,23 +116,23 @@ static struct {
char *module_name;
gboolean (*format_check)(unsigned char *buffer, int size);
GModule *module;
GdkPixBuf *(*load)(FILE *f)
GdkPixBuf *(*load)(FILE *f);
int (*save)(char *filename, ...);
} file_formats [] = {
{ "png", pixbuf_check_png, NULL, NULL, NULL },
{ "jpeg", pixbuf_check_jpeg, NULL, NULL, NULL },
{ "tiff", pixbuf_check_tiff, NULL, NULL, NULL },
{ "gif", pixbuf_check_gif, NULL, NULL, NULL },
{ "xpm", pixbuf_check_xpm, NULL, NULL, NULL }
{ "bmp", pixbuf_check_bmp, NULL, NULL, NULL },
{ "ppm", pixbuf_check_ppm, NULL, NULL, NULL },
{ NULL, NULL, NULL, NULL, NULL },
{ "xpm", pixbuf_check_xpm, NULL, NULL, NULL },
/* { "bmp", pixbuf_check_bmp, NULL, NULL, NULL },
{ "ppm", pixbuf_check_ppm, NULL, NULL, NULL },*/
{ NULL, NULL, NULL, NULL, NULL }
};
static int
image_file_format (const char *file)
{
FILE *f = fopen (file);
FILE *f = fopen (file, "r");
if (!f)
return -1;
......@@ -162,11 +166,11 @@ GdkPixBuf *
gdk_pixbuf_load_image (const char *file)
{
GdkPixBuf *pixbuf;
FormatLoader format_loader;
gint n, i;
FILE *f;
char buffer [128];
f = fopen (file);
f = fopen (file, "r");
if (!f)
return NULL;
n = fread (&buffer, 1, sizeof (buffer), f);
......@@ -186,7 +190,7 @@ gdk_pixbuf_load_image (const char *file)
return NULL;
}
rewind (f);
fseek(f, 0, SEEK_SET);
pixbuf = (*file_formats [i].load)(f);
fclose (f);
return pixbuf;
......
/* Nothing here yet */
......@@ -5,6 +5,7 @@
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <glib.h>
#include "gdk-pixbuf.h"
......
/*
* 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"
/* Loosely based off the BMP loader from The GIMP */
/* Shared library entry point */
GdkPixBuf *image_load(FILE * f)
{
GdkPixBuf *pixbuf;
art_u8 *pixels;
/* Ok, now stuff the GdkPixBuf with goodies */
pixbuf = g_new(GdkPixBuf, 1);
if (is_trans)
pixbuf->art_pixbuf = art_pixbuf_new_rgba(pixels, w, h, (w * 4));
else
pixbuf->art_pixbuf = art_pixbuf_new_rgb(pixels, w, h, (w * 3));
/* Ok, I'm anal...shoot me */
if (!(pixbuf->art_pixbuf))
return NULL;
pixbuf->ref_count = 0;
pixbuf->unref_func = NULL;
return pixbuf;
}
......@@ -31,7 +31,8 @@
/* Shared library entry point */
GdkPixBuf *image_load(FILE * f)
{
gint fn, is_trans, done;
gint fn, is_trans = FALSE;
gint done = 0;
gint t_color = -1;
gint w, h, i, j;
art_u8 *pixels, *tmpptr;
......@@ -49,6 +50,7 @@ GdkPixBuf *image_load(FILE * f)
g_return_val_if_fail(f != NULL, NULL);
fn = fileno(f);
/* lseek(fn, 0, 0);*/
gif = DGifOpenFileHandle(fn);
if (!gif) {
......@@ -74,13 +76,13 @@ GdkPixBuf *image_load(FILE * f)
}
w = gif->Image.Width;
h = gif->Image.Height;
rows = g_malloc(h * sizeof(GifRowType *));
rows = g_malloc0(h * sizeof(GifRowType *));
if (!rows) {
DGifCloseFile(gif);
return NULL;
}
for (i = 0; i < h; i++) {
rows[i] = g_malloc(w * sizeof(GifPixelType));
rows[i] = g_malloc0(w * sizeof(GifPixelType));
if (!rows[i]) {
DGifCloseFile(gif);
for (i = 0; i < h; i++)
......@@ -99,14 +101,14 @@ GdkPixBuf *image_load(FILE * f)
for (i = 0; i < h; i++)
DGifGetLine(gif, rows[i], w);
}
done = TRUE;
done = 1;
} else if (rec == EXTENSION_RECORD_TYPE) {
gint ext_code;
GifByteType *ext;
DGifGetExtension(gif, &ext_code, &ext);
while (ext) {
if ((ext_code == GRAPHICS_EXT_FUNC_CODE) &&
if ((ext_code == 0xf9) &&
(ext[1] & 1) && (t_color < 0)) {
is_trans = TRUE;
t_color = (gint) ext[4];
......@@ -150,7 +152,7 @@ GdkPixBuf *image_load(FILE * f)
tmpptr[3] = 0;
else
tmpptr[3] = 0xFF;
tmpptr += (is_trans ? 3 : 4);
tmpptr += (is_trans ? 4 : 3);
}
}
......@@ -171,3 +173,5 @@ GdkPixBuf *image_load(FILE * f)
return pixbuf;
}
image_save() {}
......@@ -53,12 +53,12 @@ struct file_handle {
FILE *infile;
gchar *buffer;
guint buffer_size;
};
} file_handle;
struct mem_handle {
gchar **data;
int offset;
};
} mem_handle;
static gint
xpm_seek_string(FILE * infile,
......@@ -423,14 +423,13 @@ static GdkPixBuf *
GdkPixBuf *image_load(FILE * f)
{
GdkPixBuf *pixbuf;
struct file_handler h;
struct file_handle h;
g_return_val_if_fail(f != NULL, NULL);
h = g_new(file_handler, 1);
h.infile = f;
pixbuf = _pixbuf_create_from_xpm(file_buffer, &h);
g_free(h);
g_free(h.buffer);
return pixbuf;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment