formatting.

2007-10-27  Sven Neumann  <sven@gimp.org>

	* plug-ins/common/pnm.c: formatting.


svn path=/trunk/; revision=23967
This commit is contained in:
Sven Neumann 2007-10-27 16:50:55 +00:00 committed by Sven Neumann
parent dc6c91fd65
commit 3ef1a3cdb4
2 changed files with 100 additions and 78 deletions

View File

@ -1,3 +1,7 @@
2007-10-27 Sven Neumann <sven@gimp.org>
* plug-ins/common/pnm.c: formatting.
2007-10-27 Sven Neumann <sven@gimp.org>
* plug-ins/common/mkgen.pl: set the svn:ignore property instead of

View File

@ -17,8 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id$ */
/*
* The pnm reading and writing code was written from scratch by Erik Nygren
* (nygren@mit.edu) based on the specifications in the man pages and
@ -146,17 +144,17 @@ static void pnm_load_rawpbm (PNMScanner *scan,
GimpPixelRgn *pixel_rgn);
static void pnmsaverow_ascii (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmsaverow_raw (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmsaverow_raw_pbm (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmsaverow_ascii_pbm (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmsaverow_ascii_indexed (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmsaverow_raw_indexed (PNMRowInfo *ri,
guchar *data);
const guchar *data);
static void pnmscanner_destroy (PNMScanner *s);
static void pnmscanner_createbuffer (PNMScanner *s,
@ -178,9 +176,9 @@ static PNMScanner * pnmscanner_create (gint fd);
/* Checks for a fatal error */
#define CHECK_FOR_ERROR(predicate, jmpbuf, errmsg) \
if ((predicate)) \
{ g_message ((errmsg)); longjmp((jmpbuf),1); }
{ g_message ((errmsg)); longjmp ((jmpbuf), 1); }
static struct struct_pnm_types
static const struct struct_pnm_types
{
gchar name;
gint np;
@ -497,14 +495,17 @@ load_image (const gchar *filename)
/* If we get here, we had a problem reading the file */
if (scan)
pnmscanner_destroy (scan);
close (fd);
g_free (pnminfo);
if (image_ID != -1)
gimp_image_delete (image_ID);
return -1;
}
if (!(scan = pnmscanner_create (fd)))
if (! (scan = pnmscanner_create (fd)))
longjmp (pnminfo->jmpbuf, 1);
/* Get magic number */
@ -527,7 +528,7 @@ load_image (const gchar *filename)
if (!pnminfo->loader)
{
g_message (_("File not in a supported format."));
longjmp (pnminfo->jmpbuf,1);
longjmp (pnminfo->jmpbuf, 1);
}
pnmscanner_gettoken (scan, buf, BUFLEN);
@ -569,7 +570,8 @@ load_image (const gchar *filename)
layer_ID = gimp_layer_new (image_ID, _("Background"),
pnminfo->xres, pnminfo->yres,
(pnminfo->np >= 3) ? GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE,
(pnminfo->np >= 3 ?
GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE),
100, GIMP_NORMAL_MODE);
gimp_image_add_layer (image_ID, layer_ID, 0);
@ -660,6 +662,7 @@ pnm_load_ascii (PNMScanner *scan,
gimp_progress_update ((double) y / (double) info->yres);
gimp_pixel_rgn_set_rect (pixel_rgn, data, 0, y, info->xres, scanlines);
y += scanlines;
}
@ -691,8 +694,8 @@ pnm_load_raw (PNMScanner *scan,
for (i = 0; i < scanlines; i++)
{
CHECK_FOR_ERROR ((info->xres*info->np
!= read(fd, d, info->xres*info->np)),
CHECK_FOR_ERROR ((info->xres * info->np
!= read (fd, d, info->xres * info->np)),
info->jmpbuf,
_("Premature end of file."));
@ -746,7 +749,7 @@ pnm_load_rawpbm (PNMScanner *scan,
for (i = 0; i < scanlines; i++)
{
CHECK_FOR_ERROR ((rowlen != read(fd, buf, rowlen)),
CHECK_FOR_ERROR ((rowlen != read (fd, buf, rowlen)),
info->jmpbuf, _("Error reading file."));
bufpos = 0;
curbyte = buf[0];
@ -776,11 +779,11 @@ pnm_load_rawpbm (PNMScanner *scan,
/* Writes out mono raw rows */
static void
pnmsaverow_raw_pbm (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
gint b, i, p = 0;
gchar *rbcur = ri->rowbuf;
gint32 len = (int)ceil ((double)(ri->xres)/8.0);
gint32 len = (gint) ceil ((gdouble) (ri->xres) / 8.0);
for (b = 0; b < len; b++) /* each output byte */
{
@ -803,7 +806,7 @@ pnmsaverow_raw_pbm (PNMRowInfo *ri,
/* Writes out mono ascii rows */
static void
pnmsaverow_ascii_pbm (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
static gint line_len = 0; /* ascii pbm lines must be <= 70 chars long */
gint32 len = 0;
@ -837,15 +840,15 @@ pnmsaverow_ascii_pbm (PNMRowInfo *ri,
/* Writes out RGB and greyscale raw rows */
static void
pnmsaverow_raw (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
write (ri->fd, data, ri->xres*ri->np);
write (ri->fd, data, ri->xres * ri->np);
}
/* Writes out indexed raw rows */
static void
pnmsaverow_raw_indexed (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
gint i;
gchar *rbcur = ri->rowbuf;
@ -863,24 +866,24 @@ pnmsaverow_raw_indexed (PNMRowInfo *ri,
/* Writes out RGB and greyscale ascii rows */
static void
pnmsaverow_ascii (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
gint i;
gchar *rbcur = ri->rowbuf;
for (i = 0; i < ri->xres*ri->np; i++)
{
sprintf ((char *) rbcur,"%d\n", 0xff & *(data++));
sprintf ((gchar *) rbcur,"%d\n", 0xff & *(data++));
rbcur += strlen (rbcur);
}
write (ri->fd, ri->rowbuf, strlen ((char *) ri->rowbuf));
write (ri->fd, ri->rowbuf, strlen ((gchar *) ri->rowbuf));
}
/* Writes out RGB and greyscale ascii rows */
static void
pnmsaverow_ascii_indexed (PNMRowInfo *ri,
guchar *data)
const guchar *data)
{
gint i;
gchar *rbcur = ri->rowbuf;
@ -908,7 +911,7 @@ save_image (const gchar *filename,
GimpDrawable *drawable;
GimpImageType drawable_type;
PNMRowInfo rowinfo;
void (*saverow) (PNMRowInfo *, guchar *) = NULL;
void (*saverow) (PNMRowInfo *, const guchar *) = NULL;
guchar red[256];
guchar grn[256];
guchar blu[256];
@ -1033,9 +1036,9 @@ save_image (const gchar *filename,
if (drawable_type == GIMP_INDEXED_IMAGE && !pbm)
{
gint i;
guchar *cmap;
gint colors;
gint i;
cmap = gimp_image_get_colormap (image_ID, &colors);
@ -1066,6 +1069,7 @@ save_image (const gchar *filename,
write (fd, buf, strlen(buf));
rowbuf = g_new (gchar, rowbufsize + 1);
rowinfo.fd = fd;
rowinfo.rowbuf = rowbuf;
rowinfo.xres = xres;
@ -1164,9 +1168,11 @@ pnmscanner_create (gint fd)
PNMScanner *s;
s = g_new (PNMScanner, 1);
s->fd = fd;
s->inbuf = NULL;
s->eof = !read (s->fd, &(s->cur), 1);
return s;
}
@ -1178,6 +1184,7 @@ pnmscanner_destroy (PNMScanner *s)
{
if (s->inbuf)
g_free (s->inbuf);
g_free (s);
}
@ -1202,9 +1209,10 @@ pnmscanner_gettoken (PNMScanner *s,
gchar *buf,
gint bufsize)
{
int ctr=0;
gint ctr = 0;
pnmscanner_eatwhitespace (s);
while (! s->eof &&
! g_ascii_isspace (s->cur) &&
(s->cur != '#') &&
@ -1213,6 +1221,7 @@ pnmscanner_gettoken (PNMScanner *s,
buf[ctr++] = s->cur;
pnmscanner_getchar (s);
}
buf[ctr] = '\0';
}
@ -1224,6 +1233,7 @@ pnmscanner_getsmalltoken (PNMScanner *s,
gchar *buf)
{
pnmscanner_eatwhitespace (s);
if (!(s->eof) && !g_ascii_isspace (s->cur) && (s->cur != '#'))
{
*buf = s->cur;
@ -1240,17 +1250,21 @@ pnmscanner_getchar (PNMScanner *s)
if (s->inbuf)
{
s->cur = s->inbuf[s->inbufpos++];
if (s->inbufpos >= s->inbufvalidsize)
{
if (s->inbufpos > s->inbufvalidsize)
s->eof = 1;
else
s->inbufvalidsize = read (s->fd, s->inbuf, s->inbufsize);
s->inbufpos = 0;
}
}
else
{
s->eof = !read (s->fd, &(s->cur), 1);
}
}
/* pnmscanner_eatwhitespace ---
@ -1260,7 +1274,7 @@ pnmscanner_getchar (PNMScanner *s)
static void
pnmscanner_eatwhitespace (PNMScanner *s)
{
int state = 0;
gint state = 0;
while (!(s->eof) && (state != -1))
{
@ -1270,12 +1284,16 @@ pnmscanner_eatwhitespace (PNMScanner *s)
if (s->cur == '#')
{
state = 1; /* goto comment */
pnmscanner_getchar(s);
pnmscanner_getchar (s);
}
else if (!g_ascii_isspace (s->cur))
{
state = -1;
}
else
{
pnmscanner_getchar (s);
}
break;
case 1: /* in comment */