Commit f6a02b56 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: cleanup in file-bmp

Rename files, functions, variables, remove globals, indent, foo.
parent e6314755
......@@ -26,8 +26,10 @@ libexec_PROGRAMS = file-bmp
file_bmp_SOURCES = \
bmp.c \
bmp.h \
bmp-read.c \
bmp-write.c
bmp-load.c \
bmp-load.h \
bmp-save.c \
bmp-save.h
AM_CPPFLAGS = \
-I$(top_srcdir) \
......
/*
* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BMP_LOAD_H__
#define __BMP_LOAD_H__
gint32 load_image (const gchar *filename,
GError **error);
#endif /* __BMP_LOAD_H__ */
......@@ -37,9 +37,11 @@
#include <libgimp/gimpui.h>
#include "bmp.h"
#include "bmp-save.h"
#include "libgimp/stdplugins-intl.h"
typedef enum
{
RGB_565,
......@@ -50,18 +52,6 @@ typedef enum
RGBX_8888
} RGBMode;
static struct
{
RGBMode rgb_format;
gint use_run_length_encoding;
/* Whether or not to write BITMAPV5HEADER color space data */
gint dont_write_color_space_data;
} BMPSaveData;
static gint cur_progress = 0;
static gint max_progress = 0;
static void write_image (FILE *f,
guchar *src,
......@@ -79,6 +69,19 @@ static void write_image (FILE *f,
static gboolean save_dialog (gint channels);
static struct
{
RGBMode rgb_format;
gint use_run_length_encoding;
/* Whether or not to write BITMAPV5HEADER color space data */
gint dont_write_color_space_data;
} BMPSaveData;
static Bitmap_File_Head bitmap_file_head;
static Bitmap_Head bitmap_head;
static void
FromL (gint32 wert,
guchar *bopuffer)
......@@ -142,10 +145,11 @@ warning_dialog (const gchar *primary,
}
GimpPDBStatusType
WriteBMP (const gchar *filename,
gint32 image,
gint32 drawable_ID,
GError **error)
save_image (const gchar *filename,
gint32 image,
gint32 drawable_ID,
GimpRunMode run_mode,
GError **error)
{
FILE *outfile;
gint Red[MAXCOLORS];
......@@ -194,9 +198,10 @@ WriteBMP (const gchar *filename,
break;
case GIMP_GRAYA_IMAGE:
if (interactive && !warning_dialog (_("Cannot export indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
if (run_mode == GIMP_RUN_INTERACTIVE &&
! warning_dialog (_("Cannot export indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
return GIMP_PDB_CANCEL;
/* fallthrough */
......@@ -226,9 +231,10 @@ WriteBMP (const gchar *filename,
break;
case GIMP_INDEXEDA_IMAGE:
if (interactive && !warning_dialog (_("Cannot export indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
if (run_mode == GIMP_RUN_INTERACTIVE &&
! warning_dialog (_("Cannot export indexed image with "
"transparency in BMP file format."),
_("Alpha channel will be ignored.")))
return GIMP_PDB_CANCEL;
/* fallthrough */
......@@ -266,20 +272,25 @@ WriteBMP (const gchar *filename,
BMPSaveData.dont_write_color_space_data = 0;
mask_info_size = 0;
if (interactive || lastvals)
if (run_mode != GIMP_RUN_NONINTERACTIVE)
{
gimp_get_data (SAVE_PROC, &BMPSaveData);
}
if ((BitsPerPixel == 8 || BitsPerPixel == 4) && interactive)
if (run_mode == GIMP_RUN_INTERACTIVE &&
(BitsPerPixel == 8 ||
BitsPerPixel == 4))
{
if (! save_dialog (1))
return GIMP_PDB_CANCEL;
}
else if ((BitsPerPixel == 24 || BitsPerPixel == 32))
{
if (interactive && !save_dialog (channels))
return GIMP_PDB_CANCEL;
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (channels))
return GIMP_PDB_CANCEL;
}
/* mask_info_size is only set to non-zero for 16- and 32-bpp */
switch (BMPSaveData.rgb_format)
......@@ -338,9 +349,6 @@ WriteBMP (const gchar *filename,
g_object_unref (buffer);
cur_progress = 0;
max_progress = drawable_height;
/* Now, we need some further information ... */
cols = drawable_width;
rows = drawable_height;
......@@ -361,34 +369,40 @@ WriteBMP (const gchar *filename,
else
color_space_size = 0;
Bitmap_File_Head.bfSize = (0x36 + MapSize + (rows * SpZeile) +
bitmap_file_head.bfSize = (0x36 + MapSize + (rows * SpZeile) +
mask_info_size + color_space_size);
Bitmap_File_Head.zzHotX = 0;
Bitmap_File_Head.zzHotY = 0;
Bitmap_File_Head.bfOffs = (0x36 + MapSize +
bitmap_file_head.zzHotX = 0;
bitmap_file_head.zzHotY = 0;
bitmap_file_head.bfOffs = (0x36 + MapSize +
mask_info_size + color_space_size);
Bitmap_File_Head.biSize = 40 + mask_info_size + color_space_size;
bitmap_file_head.biSize = 40 + mask_info_size + color_space_size;
Bitmap_Head.biWidth = cols;
Bitmap_Head.biHeight = rows;
Bitmap_Head.biPlanes = 1;
Bitmap_Head.biBitCnt = BitsPerPixel;
bitmap_head.biWidth = cols;
bitmap_head.biHeight = rows;
bitmap_head.biPlanes = 1;
bitmap_head.biBitCnt = BitsPerPixel;
if (BMPSaveData.use_run_length_encoding == 0)
{
if (mask_info_size > 0)
Bitmap_Head.biCompr = 3; /* BI_BITFIELDS */
else
Bitmap_Head.biCompr = 0; /* BI_RGB */
}
{
if (mask_info_size > 0)
bitmap_head.biCompr = 3; /* BI_BITFIELDS */
else
bitmap_head.biCompr = 0; /* BI_RGB */
}
else if (BitsPerPixel == 8)
Bitmap_Head.biCompr = 1;
{
bitmap_head.biCompr = 1;
}
else if (BitsPerPixel == 4)
Bitmap_Head.biCompr = 2;
{
bitmap_head.biCompr = 2;
}
else
Bitmap_Head.biCompr = 0;
{
bitmap_head.biCompr = 0;
}
Bitmap_Head.biSizeIm = SpZeile * rows;
bitmap_head.biSizeIm = SpZeile * rows;
{
gdouble xresolution;
......@@ -409,46 +423,50 @@ WriteBMP (const gchar *filename,
*
* We add 0.5 for proper rounding.
*/
Bitmap_Head.biXPels = (long int) (xresolution * 100.0 / 2.54 + 0.5);
Bitmap_Head.biYPels = (long int) (yresolution * 100.0 / 2.54 + 0.5);
bitmap_head.biXPels = (long int) (xresolution * 100.0 / 2.54 + 0.5);
bitmap_head.biYPels = (long int) (yresolution * 100.0 / 2.54 + 0.5);
}
}
if (BitsPerPixel <= 8)
Bitmap_Head.biClrUsed = colors;
bitmap_head.biClrUsed = colors;
else
Bitmap_Head.biClrUsed = 0;
bitmap_head.biClrUsed = 0;
Bitmap_Head.biClrImp = Bitmap_Head.biClrUsed;
bitmap_head.biClrImp = bitmap_head.biClrUsed;
#ifdef DEBUG
printf("\nSize: %u, Colors: %u, Bits: %u, Width: %u, Height: %u, Comp: %u, Zeile: %u\n",
(int)Bitmap_File_Head.bfSize,(int)Bitmap_Head.biClrUsed,Bitmap_Head.biBitCnt,(int)Bitmap_Head.biWidth,
(int)Bitmap_Head.biHeight, (int)Bitmap_Head.biCompr,SpZeile);
printf ("\nSize: %u, Colors: %u, Bits: %u, Width: %u, Height: %u, Comp: %u, Zeile: %u\n",
(int)bitmap_file_head.bfSize,
(int)bitmap_head.biClrUsed,
bitmap_head.biBitCnt,
(int)bitmap_head.biWidth,
(int)bitmap_head.biHeight,
(int)bitmap_head.biCompr,SpZeile);
#endif
/* And now write the header and the colormap (if any) to disk */
Write (outfile, "BM", 2);
FromL (Bitmap_File_Head.bfSize, &puffer[0x00]);
FromS (Bitmap_File_Head.zzHotX, &puffer[0x04]);
FromS (Bitmap_File_Head.zzHotY, &puffer[0x06]);
FromL (Bitmap_File_Head.bfOffs, &puffer[0x08]);
FromL (Bitmap_File_Head.biSize, &puffer[0x0C]);
FromL (bitmap_file_head.bfSize, &puffer[0x00]);
FromS (bitmap_file_head.zzHotX, &puffer[0x04]);
FromS (bitmap_file_head.zzHotY, &puffer[0x06]);
FromL (bitmap_file_head.bfOffs, &puffer[0x08]);
FromL (bitmap_file_head.biSize, &puffer[0x0C]);
Write (outfile, puffer, 16);
FromL (Bitmap_Head.biWidth, &puffer[0x00]);
FromL (Bitmap_Head.biHeight, &puffer[0x04]);
FromS (Bitmap_Head.biPlanes, &puffer[0x08]);
FromS (Bitmap_Head.biBitCnt, &puffer[0x0A]);
FromL (Bitmap_Head.biCompr, &puffer[0x0C]);
FromL (Bitmap_Head.biSizeIm, &puffer[0x10]);
FromL (Bitmap_Head.biXPels, &puffer[0x14]);
FromL (Bitmap_Head.biYPels, &puffer[0x18]);
FromL (Bitmap_Head.biClrUsed, &puffer[0x1C]);
FromL (Bitmap_Head.biClrImp, &puffer[0x20]);
FromL (bitmap_head.biWidth, &puffer[0x00]);
FromL (bitmap_head.biHeight, &puffer[0x04]);
FromS (bitmap_head.biPlanes, &puffer[0x08]);
FromS (bitmap_head.biBitCnt, &puffer[0x0A]);
FromL (bitmap_head.biCompr, &puffer[0x0C]);
FromL (bitmap_head.biSizeIm, &puffer[0x10]);
FromL (bitmap_head.biXPels, &puffer[0x14]);
FromL (bitmap_head.biYPels, &puffer[0x18]);
FromL (bitmap_head.biClrUsed, &puffer[0x1C]);
FromL (bitmap_head.biClrImp, &puffer[0x20]);
Write (outfile, puffer, 36);
......@@ -597,10 +615,15 @@ write_image (FILE *f,
gint xpos, ypos, i, j, rowstride, length, thiswidth;
gint breite, k;
guchar n, r, g, b, a;
gint cur_progress;
gint max_progress;
xpos = 0;
rowstride = width * channels;
cur_progress = 0;
max_progress = height;
/* We'll begin with the 16/24/32 bit Bitmaps, they are easy :-) */
if (bpp > 8)
......
/*
* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BMP_SAVE_H__
#define __BMP_SAVE_H__
GimpPDBStatusType save_image (const gchar *filename,
gint32 image,
gint32 drawable_ID,
GimpRunMode run_mode,
GError **error);
#endif /* __BMP_SAVE_H__ */
......@@ -60,18 +60,12 @@
#include <libgimp/gimpui.h>
#include "bmp.h"
#include "bmp-load.h"
#include "bmp-save.h"
#include "libgimp/stdplugins-intl.h"
const gchar *filename = NULL;
gboolean interactive = FALSE;
gboolean lastvals = FALSE;
struct Bitmap_File_Head_Struct Bitmap_File_Head;
struct Bitmap_Head_Struct Bitmap_Head;
/* Declare some local functions.
*/
static void query (void);
......@@ -81,6 +75,7 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
const GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
......@@ -89,8 +84,10 @@ const GimpPlugInInfo PLUG_IN_INFO =
run, /* run_proc */
};
MAIN ()
static void
query (void)
{
......@@ -151,7 +148,7 @@ query (void)
static void
run (const gchar *name,
gint nparams,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
......@@ -159,9 +156,6 @@ run (const gchar *name,
static GimpParam values[2];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
INIT_I18N ();
......@@ -177,10 +171,9 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
switch (run_mode)
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
interactive = TRUE;
break;
case GIMP_RUN_NONINTERACTIVE:
......@@ -193,38 +186,34 @@ run (const gchar *name,
break;
}
if (status == GIMP_PDB_SUCCESS)
{
image_ID = ReadBMP (param[1].data.d_string, &error);
if (image_ID != -1)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
if (status == GIMP_PDB_SUCCESS)
{
gint32 image_ID = load_image (param[1].data.d_string,
&error);
if (image_ID != -1)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
}
else if (strcmp (name, SAVE_PROC) == 0)
{
image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
gint32 image_ID = param[1].data.d_int32;
gint32 drawable_ID = param[2].data.d_int32;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
/* eventually export the image */
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
interactive = TRUE;
/* fallthrough */
case GIMP_RUN_WITH_LAST_VALS:
if (run_mode == GIMP_RUN_WITH_LAST_VALS)
lastvals = TRUE;
gimp_ui_init (PLUG_IN_BINARY, FALSE);
export = gimp_export_image (&image_ID, &drawable_ID, "BMP",
......@@ -251,8 +240,10 @@ run (const gchar *name,
}
if (status == GIMP_PDB_SUCCESS)
status = WriteBMP (param[3].data.d_string, image_ID, drawable_ID,
&error);
status = save_image (param[3].data.d_string,
image_ID, drawable_ID,
run_mode,
&error);
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID);
......
......@@ -19,6 +19,7 @@
#ifndef __BMP_H__
#define __BMP_H__
#define LOAD_PROC "file-bmp-load"
#define SAVE_PROC "file-bmp-save"
#define PLUG_IN_BINARY "file-bmp"
......@@ -33,19 +34,7 @@
#define WriteOK(file,buffer,len) (Write(buffer, len, file) != 0)
gint32 ReadBMP (const gchar *filename,
GError **error);
GimpPDBStatusType WriteBMP (const gchar *filename,
gint32 image,
gint32 drawable_ID,
GError **error);
extern gboolean interactive;
extern gboolean lastvals;
extern const gchar *filename;
extern struct Bitmap_File_Head_Struct
typedef struct _Bitmap_File_Head
{
gchar zzMagic[2]; /* 00 "BM" */
gulong bfSize; /* 02 */
......@@ -55,7 +44,7 @@ extern struct Bitmap_File_Head_Struct
gulong biSize; /* 0E */
} Bitmap_File_Head;
extern struct Bitmap_Head_Struct
typedef struct _Bitmap_Head
{
glong biWidth; /* 12 */
glong biHeight; /* 16 */
......@@ -77,4 +66,5 @@ typedef struct _Bitmap_Channel
gfloat max_value;
} Bitmap_Channel;
#endif /* __BMP_H__ */
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