plug-ins/common/file-header.c plug-ins/common/file-psp.c
2008-09-17 Michael Natterer <mitch@gimp.org> * plug-ins/common/file-header.c * plug-ins/common/file-psp.c * plug-ins/common/file-xbm.c * plug-ins/common/file-xpm.c * plug-ins/common/hot.c * plug-ins/common/mail.c: add const plus misc. cleanups. svn path=/trunk/; revision=26965
This commit is contained in:

committed by
Michael Natterer

parent
343b694195
commit
251c11aad3
@ -1,3 +1,12 @@
|
||||
2008-09-17 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* plug-ins/common/file-header.c
|
||||
* plug-ins/common/file-psp.c
|
||||
* plug-ins/common/file-xbm.c
|
||||
* plug-ins/common/file-xpm.c
|
||||
* plug-ins/common/hot.c
|
||||
* plug-ins/common/mail.c: add const plus misc. cleanups.
|
||||
|
||||
2008-09-17 Michael Natterer <mitch@gimp.org>
|
||||
|
||||
* plug-ins/file-fits/fits.c
|
||||
|
@ -40,7 +40,7 @@ static void run (const gchar *name,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
static gint save_image (const gchar *filename,
|
||||
static gboolean save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
|
||||
@ -94,9 +94,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;
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
@ -109,6 +106,10 @@ run (const gchar *name,
|
||||
|
||||
if (strcmp (name, SAVE_PROC) == 0)
|
||||
{
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
|
||||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
@ -127,6 +128,7 @@ run (const gchar *name,
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -147,7 +149,7 @@ run (const gchar *name,
|
||||
values[0].data.d_status = status;
|
||||
}
|
||||
|
||||
static int
|
||||
static gboolean
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID)
|
||||
@ -157,9 +159,9 @@ save_image (const gchar *filename,
|
||||
GimpImageType drawable_type;
|
||||
FILE *fp;
|
||||
gint x, y, b, c;
|
||||
gchar *backslash = "\\\\";
|
||||
gchar *quote = "\\\"";
|
||||
gchar *newline = "\"\n\t\"";
|
||||
const gchar *backslash = "\\\\";
|
||||
const gchar *quote = "\\\"";
|
||||
const gchar *newline = "\"\n\t\"";
|
||||
gchar buf[4];
|
||||
guchar *d = NULL;
|
||||
guchar *data;
|
||||
@ -179,10 +181,16 @@ save_image (const gchar *filename,
|
||||
fprintf (fp, "static unsigned int width = %d;\n", drawable->width);
|
||||
fprintf (fp, "static unsigned int height = %d;\n\n", drawable->height);
|
||||
fprintf (fp, "/* Call this macro repeatedly. After each use, the pixel data can be extracted */\n\n");
|
||||
|
||||
switch (drawable_type)
|
||||
{
|
||||
case GIMP_RGB_IMAGE:
|
||||
fprintf (fp, "#define HEADER_PIXEL(data,pixel) {\\\n pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \\\n pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \\\n pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \\\n data += 4; \\\n}\n");
|
||||
fprintf (fp,
|
||||
"#define HEADER_PIXEL(data,pixel) {\\\n"
|
||||
"pixel[0] = (((data[0] - 33) << 2) | ((data[1] - 33) >> 4)); \\\n"
|
||||
"pixel[1] = ((((data[1] - 33) & 0xF) << 4) | ((data[2] - 33) >> 2)); \\\n"
|
||||
"pixel[2] = ((((data[2] - 33) & 0x3) << 6) | ((data[3] - 33))); \\\n"
|
||||
"data += 4; \\\n}\n");
|
||||
fprintf (fp, "static char *header_data =\n\t\"");
|
||||
|
||||
data = g_new (guchar, drawable->width * drawable->bpp);
|
||||
@ -191,6 +199,7 @@ save_image (const gchar *filename,
|
||||
for (y = 0; y < drawable->height; y++)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&pixel_rgn, data, 0, y, drawable->width);
|
||||
|
||||
for (x = 0; x < drawable->width; x++)
|
||||
{
|
||||
d = data + x * drawable->bpp;
|
||||
@ -201,12 +210,14 @@ save_image (const gchar *filename,
|
||||
buf[3] = (d[2] & 0x3F) + 33;
|
||||
|
||||
for (b = 0; b < 4; b++)
|
||||
{
|
||||
if (buf[b] == '"')
|
||||
fwrite (quote, 1, 2, fp);
|
||||
else if (buf[b] == '\\')
|
||||
fwrite (backslash, 1, 2, fp);
|
||||
else
|
||||
fwrite (buf + b, 1, 1, fp);
|
||||
}
|
||||
|
||||
c++;
|
||||
if (c >= 16)
|
||||
@ -216,21 +227,30 @@ save_image (const gchar *filename,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf (fp, "\";\n");
|
||||
break;
|
||||
|
||||
case GIMP_INDEXED_IMAGE:
|
||||
fprintf (fp, "#define HEADER_PIXEL(data,pixel) {\\\n pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \\\n pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \\\n pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \\\n data ++; }\n\n");
|
||||
fprintf (fp,
|
||||
"#define HEADER_PIXEL(data,pixel) {\\\n"
|
||||
"pixel[0] = header_data_cmap[(unsigned char)data[0]][0]; \\\n"
|
||||
"pixel[1] = header_data_cmap[(unsigned char)data[0]][1]; \\\n"
|
||||
"pixel[2] = header_data_cmap[(unsigned char)data[0]][2]; \\\n"
|
||||
"data ++; }\n\n");
|
||||
/* save colormap */
|
||||
cmap = gimp_image_get_colormap (image_ID, &colors);
|
||||
|
||||
fprintf (fp, "static char header_data_cmap[256][3] = {");
|
||||
fprintf (fp, "\n\t{%3d,%3d,%3d}", (int)cmap[0], (int)cmap[1], (int)cmap[2]);
|
||||
|
||||
for (c = 1; c < colors; c++)
|
||||
fprintf (fp, ",\n\t{%3d,%3d,%3d}", (int)cmap[3*c], (int)cmap[3*c+1], (int)cmap[3*c+2]);
|
||||
|
||||
/* fill the rest */
|
||||
for ( ; c < 256; c++)
|
||||
fprintf (fp, ",\n\t{255,255,255}");
|
||||
|
||||
/* close bracket */
|
||||
fprintf (fp, "\n\t};\n");
|
||||
g_free (cmap);
|
||||
@ -244,6 +264,7 @@ save_image (const gchar *filename,
|
||||
for (y = 0; y < drawable->height; y++)
|
||||
{
|
||||
gimp_pixel_rgn_get_row (&pixel_rgn, data, 0, y, drawable->width);
|
||||
|
||||
for (x = 0; x < drawable->width-1; x++)
|
||||
{
|
||||
d = data + x * drawable->bpp;
|
||||
@ -262,14 +283,16 @@ save_image (const gchar *filename,
|
||||
fprintf (fp, "%d,\n\t", (int)d[1]);
|
||||
else
|
||||
fprintf (fp, "%d\n\t", (int)d[1]);
|
||||
|
||||
c = 0; /* reset line counter */
|
||||
}
|
||||
fprintf (fp, "};\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
g_warning ("unhandled drawable type (%d)", drawable_type);
|
||||
return FALSE;
|
||||
} /* switch (drawable_type) */
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
||||
|
@ -681,10 +681,10 @@ save_dialog (void)
|
||||
/* This helper method is used to get the name of the block for the known block
|
||||
* types. The enum PSPBlockID must cover the input values.
|
||||
*/
|
||||
static gchar *
|
||||
static const gchar *
|
||||
block_name (gint id)
|
||||
{
|
||||
static gchar *block_names[] =
|
||||
static const gchar *block_names[] =
|
||||
{
|
||||
"IMAGE",
|
||||
"CREATOR",
|
||||
@ -1082,10 +1082,10 @@ gimp_layer_mode_from_psp_blend_mode (PSPBlendModes mode)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
static const gchar *
|
||||
blend_mode_name (PSPBlendModes mode)
|
||||
{
|
||||
static gchar *blend_mode_names[] =
|
||||
static const gchar *blend_mode_names[] =
|
||||
{
|
||||
"NORMAL",
|
||||
"DARKEN",
|
||||
@ -1117,10 +1117,10 @@ blend_mode_name (PSPBlendModes mode)
|
||||
return err_name;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
static const gchar *
|
||||
bitmap_type_name (gint type)
|
||||
{
|
||||
static gchar *bitmap_type_names[] =
|
||||
static const gchar *bitmap_type_names[] =
|
||||
{
|
||||
"IMAGE",
|
||||
"TRANS_MASK",
|
||||
@ -1140,10 +1140,10 @@ bitmap_type_name (gint type)
|
||||
return err_name;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
static const gchar *
|
||||
channel_type_name (gint type)
|
||||
{
|
||||
static char *channel_type_names[] =
|
||||
static const gchar *channel_type_names[] =
|
||||
{
|
||||
"COMPOSITE",
|
||||
"RED",
|
||||
@ -1707,7 +1707,7 @@ read_tube_block (FILE *f,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gchar *
|
||||
static const gchar *
|
||||
compression_name (gint compression)
|
||||
{
|
||||
switch (compression)
|
||||
|
@ -630,7 +630,7 @@ cpp_fgetc (FILE *fp)
|
||||
/* Match a string with a file. */
|
||||
static gint
|
||||
match (FILE *fp,
|
||||
gchar *s)
|
||||
const gchar *s)
|
||||
{
|
||||
gint c;
|
||||
|
||||
@ -704,13 +704,12 @@ get_int (FILE *fp)
|
||||
}
|
||||
|
||||
|
||||
static gint
|
||||
static gint32
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
GimpPixelRgn pixel_rgn;
|
||||
GimpDrawable *drawable;
|
||||
|
||||
FILE *fp;
|
||||
gint32 image_ID;
|
||||
gint32 layer_ID;
|
||||
@ -978,7 +977,7 @@ save_image (const gchar *filename,
|
||||
gint bpp;
|
||||
|
||||
guchar *data, *cmap;
|
||||
gchar *intfmt;
|
||||
const gchar *intfmt;
|
||||
|
||||
#if 0
|
||||
if (save_mask)
|
||||
|
@ -570,7 +570,9 @@ set_XpmImage (XpmColor *array,
|
||||
{
|
||||
array[index].g_color = NULL;
|
||||
array[index].c_color = colorstring;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
array[index].c_color = NULL;
|
||||
array[index].g_color = colorstring;
|
||||
}
|
||||
|
@ -149,8 +149,8 @@ static void run (const gchar *name,
|
||||
gint *nretvals,
|
||||
GimpParam **retvals);
|
||||
|
||||
static gint pluginCore (piArgs *argp);
|
||||
static gint pluginCoreIA (piArgs *argp);
|
||||
static gboolean pluginCore (piArgs *argp);
|
||||
static gboolean plugin_dialog (piArgs *argp);
|
||||
static gboolean hotp (guint8 r,
|
||||
guint8 g,
|
||||
guint8 b);
|
||||
@ -238,7 +238,7 @@ run (const gchar *name,
|
||||
|
||||
INIT_I18N ();
|
||||
|
||||
memset (&args, (int) 0, sizeof (args));
|
||||
memset (&args, 0, sizeof (args));
|
||||
args.mode = -1;
|
||||
|
||||
gimp_get_data (PLUG_IN_PROC, &args);
|
||||
@ -260,12 +260,19 @@ run (const gchar *name,
|
||||
args.new_layerp = 1;
|
||||
}
|
||||
|
||||
if (pluginCoreIA(&args) == -1)
|
||||
if (plugin_dialog (&args))
|
||||
{
|
||||
if (! pluginCore (&args))
|
||||
{
|
||||
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
gimp_set_data (PLUG_IN_PROC, &args, sizeof (args));
|
||||
}
|
||||
else
|
||||
{
|
||||
rvals[0].data.d_status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
|
||||
gimp_set_data (PLUG_IN_PROC, &args, sizeof (args));
|
||||
break;
|
||||
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
@ -279,7 +286,7 @@ run (const gchar *name,
|
||||
args.action = param[4].data.d_int32;
|
||||
args.new_layerp = param[5].data.d_int32;
|
||||
|
||||
if (pluginCore(&args) == -1)
|
||||
if (! pluginCore (&args))
|
||||
{
|
||||
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
||||
break;
|
||||
@ -288,7 +295,7 @@ run (const gchar *name,
|
||||
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
/* XXX: add code here for last-values running */
|
||||
if (pluginCore (&args) == -1)
|
||||
if (! pluginCore (&args))
|
||||
{
|
||||
rvals[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
@ -296,14 +303,14 @@ run (const gchar *name,
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
static gboolean
|
||||
pluginCore (piArgs *argp)
|
||||
{
|
||||
GimpDrawable *drw, *ndrw = NULL;
|
||||
GimpPixelRgn srcPr, dstPr;
|
||||
gint retval = 0;
|
||||
gboolean success = TRUE;
|
||||
gint nl = 0;
|
||||
gint y, x, i;
|
||||
gint y, i;
|
||||
gint Y, I, Q;
|
||||
guint width, height, bpp;
|
||||
gint sel_x1, sel_x2, sel_y1, sel_y2;
|
||||
@ -321,15 +328,16 @@ pluginCore (piArgs *argp)
|
||||
width = drw->width;
|
||||
height = drw->height;
|
||||
bpp = drw->bpp;
|
||||
|
||||
if (argp->new_layerp)
|
||||
{
|
||||
gchar name[40];
|
||||
gchar *mode_names[] =
|
||||
const gchar *mode_names[] =
|
||||
{
|
||||
"ntsc",
|
||||
"pal",
|
||||
};
|
||||
gchar *action_names[] =
|
||||
const gchar *action_names[] =
|
||||
{
|
||||
"lum redux",
|
||||
"sat redux",
|
||||
@ -381,6 +389,8 @@ pluginCore (piArgs *argp)
|
||||
|
||||
for (y = sel_y1; y < sel_y2; y++)
|
||||
{
|
||||
gint x;
|
||||
|
||||
if (y % prog_interval == 0)
|
||||
gimp_progress_update ((double) y / (double) (sel_y2 - sel_y1));
|
||||
|
||||
@ -497,9 +507,11 @@ pluginCore (piArgs *argp)
|
||||
pr = gc (pr, argp->mode);
|
||||
pg = gc (pg, argp->mode);
|
||||
pb = gc (pb, argp->mode);
|
||||
py = pr * mode[argp->mode].code[0][0] + pg *
|
||||
mode[argp->mode].code[0][1] + pb *
|
||||
mode[argp->mode].code[0][2];
|
||||
|
||||
py = pr * mode[argp->mode].code[0][0] +
|
||||
pg * mode[argp->mode].code[0][1] +
|
||||
pb * mode[argp->mode].code[0][2];
|
||||
|
||||
r = pix_encode (inv_gc (py + scale * (pr - py),
|
||||
argp->mode));
|
||||
g = pix_encode (inv_gc (py + scale * (pg - py),
|
||||
@ -507,10 +519,13 @@ pluginCore (piArgs *argp)
|
||||
b = pix_encode (inv_gc (py + scale * (pb - py),
|
||||
argp->mode));
|
||||
}
|
||||
|
||||
*d++ = new_r = r;
|
||||
*d++ = new_g = g;
|
||||
*d++ = new_b = b;
|
||||
|
||||
s += 3;
|
||||
|
||||
if (bpp == 4)
|
||||
*d++ = *s++;
|
||||
else if (argp->new_layerp)
|
||||
@ -533,6 +548,7 @@ pluginCore (piArgs *argp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gimp_pixel_rgn_set_rect (&dstPr, dst, sel_x1, sel_y1, width, height);
|
||||
|
||||
g_free (src);
|
||||
@ -552,11 +568,11 @@ pluginCore (piArgs *argp)
|
||||
|
||||
gimp_displays_flush ();
|
||||
|
||||
return retval;
|
||||
return success;
|
||||
}
|
||||
|
||||
static gint
|
||||
pluginCoreIA (piArgs *argp)
|
||||
static gboolean
|
||||
plugin_dialog (piArgs *argp)
|
||||
{
|
||||
GtkWidget *dlg;
|
||||
GtkWidget *hbox;
|
||||
@ -632,10 +648,7 @@ pluginCoreIA (piArgs *argp)
|
||||
|
||||
gtk_widget_destroy (dlg);
|
||||
|
||||
if (run)
|
||||
return pluginCore (argp);
|
||||
else
|
||||
return -1;
|
||||
return run;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user