1997-11-25 06:05:25 +08:00
|
|
|
/* bmpread.c reads any bitmap I could get for testing */
|
|
|
|
/* except OS2 bitmaps (wrong colors) */
|
|
|
|
/* Alexander.Schulz@stud.uni-karlsruhe.de */
|
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
/*
|
|
|
|
* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "config.h"
|
2000-02-13 01:39:21 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-02-13 01:39:21 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-02-13 01:39:21 +08:00
|
|
|
|
2000-01-08 20:42:53 +08:00
|
|
|
#include <libgimp/gimp.h>
|
2000-02-13 01:39:21 +08:00
|
|
|
|
|
|
|
#include "bmp.h"
|
2000-03-25 03:25:47 +08:00
|
|
|
#include "bmpos2.h"
|
2000-02-13 01:39:21 +08:00
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
|
|
|
|
gint32
|
2000-02-13 01:39:21 +08:00
|
|
|
ReadBMP (gchar *name)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
FILE *fd;
|
2000-02-13 01:39:21 +08:00
|
|
|
gchar *temp_buf;
|
|
|
|
gchar buf[5];
|
|
|
|
gint ColormapSize, SpeicherZeile, Maps, Grey;
|
|
|
|
guchar ColorMap[256][3];
|
1998-03-17 17:39:40 +08:00
|
|
|
guchar puffer[50];
|
1999-12-19 20:20:38 +08:00
|
|
|
gint32 image_ID;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-03-17 17:39:40 +08:00
|
|
|
if (interactive_bmp)
|
|
|
|
{
|
1999-12-31 02:54:17 +08:00
|
|
|
temp_buf = g_strdup_printf (_("Loading %s:"), name);
|
1998-03-17 17:39:40 +08:00
|
|
|
gimp_progress_init (temp_buf);
|
|
|
|
g_free (temp_buf);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
filename = name;
|
|
|
|
fd = fopen (filename, "rb");
|
|
|
|
|
|
|
|
/* Is this a valid File? Should never be used because gimp tests it. */
|
|
|
|
|
|
|
|
if (!fd)
|
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: can't open \"%s\"\n"), prog_name, filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* It is a File. Now is it a Bitmap? */
|
|
|
|
|
|
|
|
if (!ReadOK(fd,buf,2) || (strncmp(buf,"BM",2)))
|
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: not a valid BMP file %s\n"), prog_name,buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* How long is the Header? */
|
|
|
|
|
1998-03-17 17:39:40 +08:00
|
|
|
if (!ReadOK (fd, puffer, 0x10))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: error reading BMP file header\n"), prog_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
1998-03-17 17:39:40 +08:00
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
/* bring them to the right byteorder. Not too nice, but it should work */
|
1998-03-17 17:39:40 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
Bitmap_File_Head.bfSize = ToL (&puffer[0]);
|
|
|
|
Bitmap_File_Head.reserverd = ToL (&puffer[4]);
|
|
|
|
Bitmap_File_Head.bfOffs = ToL (&puffer[8]);
|
|
|
|
Bitmap_File_Head.biSize = ToL (&puffer[12]);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Is it a Windows (R) Bitmap or not */
|
|
|
|
|
2000-03-25 03:25:47 +08:00
|
|
|
if (Bitmap_File_Head.biSize == 12) /* OS/2 */
|
|
|
|
{
|
|
|
|
if (!read_os2_head1 (fd, Bitmap_File_Head.biSize - 4, &Bitmap_Head))
|
|
|
|
{
|
|
|
|
g_message (_("%s: error reading BMP file header\n"), prog_name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Maps = 3;
|
|
|
|
}
|
|
|
|
else if (Bitmap_File_Head.biSize != 40)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
g_warning ("OS/2 unsupported!\n");
|
1998-03-17 17:39:40 +08:00
|
|
|
if (!ReadOK (fd, puffer, Bitmap_File_Head.biSize))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: error reading BMP file header\n"), prog_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
1998-03-17 17:39:40 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
Bitmap_OS2_Head.bcWidth = ToS (&puffer[0]);
|
|
|
|
Bitmap_OS2_Head.bcHeight = ToS (&puffer[2]);
|
|
|
|
Bitmap_OS2_Head.bcPlanes = ToS (&puffer[4]);
|
|
|
|
Bitmap_OS2_Head.bcBitCnt = ToS (&puffer[6]);
|
|
|
|
|
|
|
|
Bitmap_Head.biPlanes = Bitmap_OS2_Head.bcPlanes;
|
|
|
|
Bitmap_Head.biBitCnt = Bitmap_OS2_Head.bcBitCnt;
|
|
|
|
Bitmap_File_Head.bfSize = ((Bitmap_File_Head.bfSize * 4) -
|
|
|
|
(Bitmap_File_Head.bfOffs * 3));
|
|
|
|
Bitmap_Head.biHeight = Bitmap_OS2_Head.bcHeight;
|
|
|
|
Bitmap_Head.biWidth = Bitmap_OS2_Head.bcWidth;
|
|
|
|
Bitmap_Head.biClrUsed = 0;
|
|
|
|
Bitmap_Head.biCompr = 0;
|
|
|
|
Maps = 3;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-03-17 17:39:40 +08:00
|
|
|
if (!ReadOK (fd, puffer, 36))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: error reading BMP file header\n"), prog_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
Bitmap_Head.biWidth =ToL (&puffer[0x00]); /* 12 */
|
|
|
|
Bitmap_Head.biHeight =ToL (&puffer[0x04]); /* 16 */
|
|
|
|
Bitmap_Head.biPlanes =ToS (&puffer[0x08]); /* 1A */
|
|
|
|
Bitmap_Head.biBitCnt =ToS (&puffer[0x0A]); /* 1C */
|
|
|
|
Bitmap_Head.biCompr =ToL (&puffer[0x0C]); /* 1E */
|
|
|
|
Bitmap_Head.biSizeIm =ToL (&puffer[0x10]); /* 22 */
|
|
|
|
Bitmap_Head.biXPels =ToL (&puffer[0x14]); /* 26 */
|
|
|
|
Bitmap_Head.biYPels =ToL (&puffer[0x18]); /* 2A */
|
|
|
|
Bitmap_Head.biClrUsed =ToL (&puffer[0x1C]); /* 2E */
|
|
|
|
Bitmap_Head.biClrImp =ToL (&puffer[0x20]); /* 32 */
|
1998-03-17 17:39:40 +08:00
|
|
|
/* 36 */
|
2000-02-13 01:39:21 +08:00
|
|
|
Maps = 4;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
/* This means wrong file Format. I test this because it could crash the
|
|
|
|
* entire gimp.
|
|
|
|
*/
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
if (Bitmap_Head.biBitCnt > 24)
|
|
|
|
{
|
|
|
|
g_message (_("%s: too many colors: %u\n"), prog_name,
|
|
|
|
(guint) Bitmap_Head.biBitCnt);
|
|
|
|
return -1;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* There should be some colors used! */
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
ColormapSize = (Bitmap_File_Head.bfOffs - Bitmap_File_Head.biSize - 14) / Maps;
|
|
|
|
|
|
|
|
if ((Bitmap_Head.biClrUsed == 0) &&
|
|
|
|
(Bitmap_Head.biBitCnt < 24))
|
|
|
|
Bitmap_Head.biClrUsed = ColormapSize;
|
|
|
|
|
|
|
|
if (Bitmap_Head.biBitCnt == 24)
|
|
|
|
SpeicherZeile = ((Bitmap_File_Head.bfSize - Bitmap_File_Head.bfOffs) /
|
|
|
|
Bitmap_Head.biHeight);
|
|
|
|
else
|
|
|
|
SpeicherZeile = ((Bitmap_File_Head.bfSize - Bitmap_File_Head.bfOffs) /
|
|
|
|
Bitmap_Head.biHeight) * (8 / Bitmap_Head.biBitCnt);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("\nSize: %u, Colors: %u, Bits: %u, Width: %u, Height: %u, Comp: %u, Zeile: %u\n",
|
1998-03-17 17:39:40 +08:00
|
|
|
Bitmap_File_Head.bfSize,Bitmap_Head.biClrUsed,Bitmap_Head.biBitCnt,Bitmap_Head.biWidth,
|
1997-11-25 06:05:25 +08:00
|
|
|
Bitmap_Head.biHeight, Bitmap_Head.biCompr, SpeicherZeile);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the Colormap */
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
if (ReadColorMap (fd, ColorMap, ColormapSize, Maps, &Grey) == -1)
|
|
|
|
return -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Colormap read\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the Image and return the ID or -1 on error*/
|
1999-12-19 20:20:38 +08:00
|
|
|
image_ID = ReadImage (fd,
|
|
|
|
Bitmap_Head.biWidth,
|
|
|
|
Bitmap_Head.biHeight,
|
|
|
|
ColorMap,
|
|
|
|
Bitmap_Head.biClrUsed,
|
|
|
|
Bitmap_Head.biBitCnt,
|
|
|
|
Bitmap_Head.biCompr,
|
|
|
|
SpeicherZeile,
|
|
|
|
Grey);
|
|
|
|
|
|
|
|
#ifdef GIMP_HAVE_RESOLUTION_INFO
|
|
|
|
{
|
|
|
|
/* quick hack by the muppet, scott@asofyet.org, 19 dec 1999 */
|
2000-02-13 01:39:21 +08:00
|
|
|
gdouble xresolution;
|
|
|
|
gdouble yresolution;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
/*
|
|
|
|
* xresolution and yresolution are in dots per inch.
|
|
|
|
* the BMP spec says that biXPels and biYPels are in
|
|
|
|
* pixels per meter as long ints (actually, "DWORDS").
|
|
|
|
* this means we've lost some accuracy in the numbers.
|
|
|
|
* typically, the dots per inch settings on BMPs will
|
|
|
|
* be integer numbers of dots per inch, which is freaky
|
|
|
|
* because they're stored in the BMP as metric. *sigh*
|
|
|
|
* so, we'll round this off, even though the gimp wants
|
|
|
|
* a floating point number...
|
|
|
|
*/
|
|
|
|
#define LROUND(x) ((long int)((x)+0.5))
|
|
|
|
xresolution = LROUND((Bitmap_Head.biXPels * 2.54 / 100.0));
|
|
|
|
yresolution = LROUND((Bitmap_Head.biYPels * 2.54 / 100.0));
|
|
|
|
#undef LROUND
|
2000-01-08 20:42:53 +08:00
|
|
|
|
|
|
|
gimp_image_set_resolution (image_ID, xresolution, yresolution);
|
1999-12-19 20:20:38 +08:00
|
|
|
}
|
|
|
|
#endif /* GIMP_HAVE_RESOLUTION_INFO */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
return (image_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
gint
|
2000-02-13 01:39:21 +08:00
|
|
|
ReadColorMap (FILE *fd,
|
|
|
|
guchar buffer[256][3],
|
|
|
|
gint number,
|
|
|
|
gint size,
|
|
|
|
gint *grey)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
gint i;
|
|
|
|
guchar rgb[4];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
*grey=(number>2);
|
|
|
|
for (i = 0; i < number ; i++)
|
|
|
|
{
|
|
|
|
if (!ReadOK (fd, rgb, size))
|
|
|
|
{
|
1999-05-30 00:35:47 +08:00
|
|
|
g_message (_("%s: bad colormap\n"), prog_name);
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bitmap save the colors in another order! But change only once! */
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
if (size == 4)
|
|
|
|
{
|
|
|
|
buffer[i][0] = rgb[2];
|
|
|
|
buffer[i][1] = rgb[1];
|
|
|
|
buffer[i][2] = rgb[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-25 03:25:47 +08:00
|
|
|
/* this one is for old os2 Bitmaps */
|
|
|
|
buffer[i][0] = rgb[2];
|
|
|
|
buffer[i][1] = rgb[1];
|
|
|
|
buffer[i][2] = rgb[0];
|
2000-02-13 01:39:21 +08:00
|
|
|
}
|
|
|
|
*grey = ((*grey) && (rgb[0]==rgb[1]) && (rgb[1]==rgb[2]));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
return 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-12-19 20:20:38 +08:00
|
|
|
Image
|
2000-02-13 01:39:21 +08:00
|
|
|
ReadImage (FILE *fd,
|
|
|
|
gint len,
|
|
|
|
gint height,
|
|
|
|
guchar cmap[256][3],
|
|
|
|
gint ncols,
|
|
|
|
gint bpp,
|
|
|
|
gint compression,
|
|
|
|
gint spzeile,
|
|
|
|
gint grey)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
gchar *name_buf;
|
|
|
|
guchar v,wieviel;
|
1997-11-25 06:05:25 +08:00
|
|
|
GPixelRgn pixel_rgn;
|
2000-02-13 01:39:21 +08:00
|
|
|
gchar buf[16];
|
|
|
|
gint xpos = 0, ypos = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
Image image;
|
|
|
|
gint32 layer;
|
|
|
|
GDrawable *drawable;
|
|
|
|
guchar *dest, *temp;
|
|
|
|
guchar gimp_cmap[768];
|
|
|
|
long rowstride, channels;
|
2000-02-13 01:39:21 +08:00
|
|
|
gint i, j, cur_progress, max_progress, egal;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Make a new image in the gimp */
|
|
|
|
|
|
|
|
if (grey)
|
|
|
|
{
|
1998-03-17 17:39:40 +08:00
|
|
|
image = gimp_image_new (len, height, GRAY);
|
2000-02-13 01:39:21 +08:00
|
|
|
layer = gimp_layer_new (image, _("Background"),
|
|
|
|
len, height, GRAY_IMAGE, 100, NORMAL_MODE);
|
1998-03-17 17:39:40 +08:00
|
|
|
channels = 1;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
1999-11-04 02:47:35 +08:00
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-03-17 17:39:40 +08:00
|
|
|
if (bpp<24)
|
|
|
|
{
|
|
|
|
image = gimp_image_new (len, height, INDEXED);
|
2000-02-13 01:39:21 +08:00
|
|
|
layer = gimp_layer_new (image, _("Background"),
|
|
|
|
len, height, INDEXED_IMAGE, 100, NORMAL_MODE);
|
1998-03-17 17:39:40 +08:00
|
|
|
channels = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image = gimp_image_new (len, height, RGB);
|
2000-02-13 01:39:21 +08:00
|
|
|
layer = gimp_layer_new (image, _("Background"),
|
|
|
|
len, height, RGB_IMAGE, 100, NORMAL_MODE);
|
1998-03-17 17:39:40 +08:00
|
|
|
channels = 3;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
name_buf = g_malloc (strlen (filename) + 10);
|
1999-05-30 00:35:47 +08:00
|
|
|
strcpy (name_buf, filename);
|
1997-11-25 06:05:25 +08:00
|
|
|
gimp_image_set_filename(image,name_buf);
|
applied gimp-lecorfec-99041[02]-0, changes follow
* applied gimp-lecorfec-99041[02]-0, changes follow
* plug-ins/FractalExplorer/Dialogs.h (make_color_map):
replaced free with g_free to fix segfault.
* plug-ins/Lighting/lighting_preview.c (compute_preview):
allocate xpostab and ypostab only when needed (it could also be
allocated on stack with a compilation-fixed size like MapObject).
It avoids to lose some Kb on each preview :)
Also reindented (unfortunate C-c C-q) some other lines.
* plug-ins/Lighting/lighting_main.c (run):
release allocated postabs.
* plug-ins/Lighting/lighting_ui.c:
callbacks now have only one argument because gck widget use
gtk_signal_connect_object. Caused segfault for scale widget.
* plug-ins/autocrop/autocrop.c (doit):
return if image has only background (thus fixing a segfault).
* plug-ins/emboss/emboss.c (pluginCore, emboss_do_preview):
replaced malloc/free with g_malloc/g_free (unneeded, but
shouldn't everyone use glib calls ? :)
* plug-ins/flame/flame.c :
replaced a segfaulting free, and several harmless malloc/free pairs.
* plug-ins/flame/megawidget.c (mw_preview_build):
replaced harmless malloc/free pair.
Note : mwp->bits is malloc'ed but seems to be never freed.
* plug-ins/fractaltrace/fractaltrace.c (pixels_free):
replaced a bunch of segfaulting free.
(pixels_get, dialog_show): replaced gtk_signal_connect_object
with gtk_signal_connect to accomodate callbacks (caused STRANGE
dialog behaviour, coz you destroyed buttons one by one).
* plug-ins/illusion/illusion.c (dialog):
same gtk_signal_connect_object replacement for same reasons.
* plug-ins/libgck/gck/gckcolor.c :
changed all gck_rgb_to_color* functions to use a static GdkColor
instead of a malloc'ed area. Provided reentrant functions with
the old behaviour (gck_rgb_to_color*_r). Made some private functions
static, too.
gck_rgb_to_gdkcolor now use the new functions while
gck_rgb_to_gdkcolor_r is the reentrant version.
Also affected by this change: gck_gc_set_foreground and
gck_gc_set_background (no more free(color)).
* plug-ins/libgck/gck/gckcolor.h :
added the gck_rgb_to_gdkcolor_r proto.
* plug-ins/lic/lic.c (ok_button_clicked, cancel_button_clicked) :
segfault on gtk_widget_destroy, now calls gtk_main_quit.
(dialog_destroy) : segfault on window closure when called by
"destroy" event. Now called by "delete_event".
* plug-ins/megawidget/megawidget.c (mw_preview_build):
replaced harmless malloc/free pair.
Note : mwp->bits is malloc'ed but seems to be never freed.
* plug-ins/png/png.c (load_image):
replaced 2 segfaulting free.
* plug-ins/print/print-ps.c (ps_print):
replaced a segfaulting free (called many times :).
* plug-ins/sgi/sgi.c (load_image, save_image):
replaced a bunch of segfaulting free, and did some harmless
inits to avoid a few gcc warnings.
* plug-ins/wind/wind.c (render_wind):
replaced a segfaulting free.
(render_blast): replaced harmless malloc/free pair.
* plug-ins/bmp/bmpread.c (ReadImage):
yet another free()/g_free() problem fixed.
* plug-ins/exchange/exchange.c (real_exchange):
ditto.
* plug-ins/fp/fp.h: added Frames_Check_Button_In_A_Box proto.
* plug-ins/fp/fp_gtk.c: closing subdialogs via window manager
wasn't handled, thus leading to errors and crashes.
Now delete_event signals the dialog control button
to close a dialog with the good way.
* plug-ins/ifscompose/ifscompose.c (value_pair_create):
tried to set events mask on scale widget (a NO_WINDOW widget).
* plug-ins/png/png.c (save_image):
Replaced 2 free() with g_free() for g_malloc'ed memory.
Mysteriously I corrected the loading bug but not the saving one :)
-Yosh
1999-04-16 05:49:09 +08:00
|
|
|
g_free (name_buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gimp_image_add_layer(image,layer,0);
|
|
|
|
drawable = gimp_drawable_get(layer);
|
1998-03-17 17:39:40 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
dest = g_malloc(drawable->width*drawable->height*channels);
|
|
|
|
rowstride = drawable->width * channels;
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
ypos = height - 1; /* Bitmaps begin in the lower left corner */
|
1997-11-25 06:05:25 +08:00
|
|
|
cur_progress = 0;
|
|
|
|
max_progress = height;
|
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
if (bpp == 24)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
while (ReadOK (fd, buf, 3))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
temp = dest + (ypos * rowstride) + (xpos * channels);
|
|
|
|
*temp=buf[2];
|
|
|
|
temp++;
|
|
|
|
*temp=buf[1];
|
|
|
|
temp++;
|
|
|
|
*temp=buf[0];
|
|
|
|
xpos++;
|
|
|
|
if (xpos == len)
|
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
egal=ReadOK (fd, buf, spzeile - (len * 3));
|
1997-11-25 06:05:25 +08:00
|
|
|
ypos--;
|
2000-02-13 01:39:21 +08:00
|
|
|
xpos = 0;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
cur_progress++;
|
2000-02-13 01:39:21 +08:00
|
|
|
if ((interactive_bmp) &&
|
|
|
|
((cur_progress % 5) == 0))
|
|
|
|
gimp_progress_update ((gdouble) cur_progress /
|
|
|
|
(gdouble) max_progress);
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
if (ypos < 0)
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
else
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
switch(compression)
|
|
|
|
{
|
|
|
|
case 0: /* uncompressed */
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
while (ReadOK (fd, &v, 1))
|
|
|
|
{
|
|
|
|
for (i = 1; (i <= (8 / bpp)) && (xpos < len); i++, xpos++)
|
|
|
|
{
|
|
|
|
temp = dest + (ypos * rowstride) + (xpos * channels);
|
|
|
|
*temp=( v & ( ((1<<bpp)-1) << (8-(i*bpp)) ) ) >> (8-(i*bpp));
|
|
|
|
if (grey)
|
|
|
|
*temp = cmap[*temp][0];
|
|
|
|
}
|
|
|
|
if (xpos == len)
|
|
|
|
{
|
|
|
|
egal = ReadOK (fd, buf, (spzeile - len) / (8 / bpp));
|
|
|
|
ypos--;
|
|
|
|
xpos = 0;
|
|
|
|
|
|
|
|
cur_progress++;
|
|
|
|
if ((interactive_bmp) &&
|
|
|
|
((cur_progress % 5) == 0))
|
|
|
|
gimp_progress_update ((gdouble) cur_progress /
|
|
|
|
(gdouble) max_progress);
|
|
|
|
}
|
|
|
|
if (ypos < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
default: /* Compressed images */
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
while (TRUE)
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
egal = ReadOK (fd, buf, 2);
|
|
|
|
if ((guchar) buf[0] != 0)
|
|
|
|
/* Count + Color - record */
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
for (j = 0; ((guchar) j < (guchar) buf[0]) && (xpos < len);)
|
|
|
|
{
|
1998-03-17 17:39:40 +08:00
|
|
|
#ifdef DEBUG2
|
2000-02-13 01:39:21 +08:00
|
|
|
printf("%u %u | ",xpos,len);
|
1998-03-17 17:39:40 +08:00
|
|
|
#endif
|
2000-02-13 01:39:21 +08:00
|
|
|
for (i = 1;
|
|
|
|
((i <= (8 / bpp)) &&
|
|
|
|
(xpos < len) &&
|
|
|
|
((guchar) j < (unsigned char) buf[0]));
|
|
|
|
i++, xpos++, j++)
|
|
|
|
{
|
|
|
|
temp = dest + (ypos * rowstride) + (xpos * channels);
|
|
|
|
*temp = (buf[1] & (((1<<bpp)-1) << (8 - (i * bpp)))) >> (8 - (i * bpp));
|
|
|
|
if (grey)
|
|
|
|
*temp = cmap[*temp][0];
|
|
|
|
}
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
if (((guchar) buf[0] == 0) && ((guchar) buf[1] > 2))
|
|
|
|
/* uncompressed record */
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
wieviel = buf[1];
|
|
|
|
for (j = 0; j < wieviel; j += (8 / bpp))
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-02-13 01:39:21 +08:00
|
|
|
egal = ReadOK (fd, &v, 1);
|
|
|
|
i = 1;
|
|
|
|
while ((i <= (8 / bpp)) && (xpos < len))
|
|
|
|
{
|
|
|
|
temp = dest + (ypos * rowstride) + (xpos * channels);
|
|
|
|
*temp = (v & (((1<<bpp)-1) << (8-(i*bpp)))) >> (8-(i*bpp));
|
|
|
|
if (grey)
|
|
|
|
*temp = cmap[*temp][0];
|
|
|
|
i++;
|
|
|
|
xpos++;
|
|
|
|
}
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
|
|
|
|
if ((wieviel % 2) && (bpp==4))
|
|
|
|
wieviel++;
|
|
|
|
|
|
|
|
if ((wieviel / (8 / bpp)) % 2)
|
|
|
|
egal = ReadOK (fd, &v, 1);
|
|
|
|
/*if odd(x div (8 div bpp )) then blockread(f,z^,1);*/
|
|
|
|
}
|
|
|
|
if (((guchar) buf[0] == 0) && ((guchar) buf[1]==0))
|
|
|
|
/* Zeilenende */
|
|
|
|
{
|
|
|
|
ypos--;
|
|
|
|
xpos = 0;
|
|
|
|
|
|
|
|
cur_progress++;
|
|
|
|
if ((interactive_bmp) &&
|
|
|
|
((cur_progress % 5) == 0))
|
|
|
|
gimp_progress_update ((gdouble) cur_progress /
|
|
|
|
(gdouble) max_progress);
|
|
|
|
}
|
|
|
|
if (((guchar) buf[0]==0) && ((guchar) buf[1]==1))
|
|
|
|
/* Bitmapende */
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (((guchar) buf[0]==0) && ((guchar) buf[1]==2))
|
|
|
|
/* Deltarecord */
|
|
|
|
{
|
|
|
|
xpos += (guchar) buf[2];
|
|
|
|
ypos += (guchar) buf[3];
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
break;
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
2000-02-13 01:39:21 +08:00
|
|
|
}
|
1998-03-17 17:39:40 +08:00
|
|
|
}
|
1999-11-04 02:47:35 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
fclose (fd);
|
|
|
|
if (bpp < 24)
|
|
|
|
for (i = 0, j = 0; i < ncols; i++)
|
|
|
|
{
|
|
|
|
gimp_cmap[j++] = cmap[i][0];
|
|
|
|
gimp_cmap[j++] = cmap[i][1];
|
|
|
|
gimp_cmap[j++] = cmap[i][2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive_bmp)
|
|
|
|
gimp_progress_update (1);
|
|
|
|
|
|
|
|
gimp_pixel_rgn_init (&pixel_rgn, drawable,
|
|
|
|
0, 0, drawable->width, drawable->height, TRUE, FALSE);
|
|
|
|
gimp_pixel_rgn_set_rect (&pixel_rgn, dest,
|
|
|
|
0, 0, drawable->width, drawable->height);
|
|
|
|
|
|
|
|
if ((!grey) && (bpp<24))
|
|
|
|
gimp_image_set_cmap (image, gimp_cmap, ncols);
|
1999-11-04 02:47:35 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
gimp_drawable_flush (drawable);
|
|
|
|
gimp_drawable_detach (drawable);
|
|
|
|
g_free (dest);
|
1999-12-19 20:20:38 +08:00
|
|
|
|
2000-02-13 01:39:21 +08:00
|
|
|
return image;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|