2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2013-10-04 04:06:24 +08:00
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
* PNM reading and writing code Copyright (C) 1996 Erik Nygren
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06:05:25 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* does not contain any code from the netpbm or pbmplus distributions.
|
2006-05-29 05:29:59 +08:00
|
|
|
*
|
|
|
|
* 2006: pbm saving written by Martin K Collins (martin@mkcollins.org)
|
2015-01-16 22:37:24 +08:00
|
|
|
* 2015: pfm reading written by Tobias Ellinghaus (me@houz.org)
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <setjmp.h>
|
2013-10-04 03:44:24 +08:00
|
|
|
#include <stdlib.h>
|
2015-01-16 22:37:24 +08:00
|
|
|
#include <math.h>
|
|
|
|
#include <errno.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
|
1999-05-29 09:28:24 +08:00
|
|
|
#include <libgimp/gimp.h>
|
1999-10-14 10:11:52 +08:00
|
|
|
#include <libgimp/gimpui.h>
|
2000-01-08 23:23:28 +08:00
|
|
|
|
2000-01-03 21:01:51 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1999-05-29 09:28:24 +08:00
|
|
|
|
2000-05-02 01:01:18 +08:00
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
#define LOAD_PROC "file-pnm-load"
|
|
|
|
#define PNM_SAVE_PROC "file-pnm-save"
|
2006-05-29 05:29:59 +08:00
|
|
|
#define PBM_SAVE_PROC "file-pbm-save"
|
2005-08-18 16:57:43 +08:00
|
|
|
#define PGM_SAVE_PROC "file-pgm-save"
|
|
|
|
#define PPM_SAVE_PROC "file-ppm-save"
|
2015-01-20 22:44:07 +08:00
|
|
|
#define PFM_SAVE_PROC "file-pfm-save"
|
2008-08-11 18:06:13 +08:00
|
|
|
#define PLUG_IN_BINARY "file-pnm"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-file-pnm"
|
2005-08-18 16:57:43 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Declare local data types
|
|
|
|
*/
|
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
typedef struct _PNMScanner PNMScanner;
|
2013-10-04 04:06:24 +08:00
|
|
|
typedef struct _PNMInfo PNMInfo;
|
|
|
|
typedef struct _PNMRowInfo PNMRowInfo;
|
|
|
|
|
|
|
|
typedef void (* PNMLoaderFunc) (PNMScanner *scanner,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
|
|
|
typedef gboolean (* PNMSaverowFunc) (PNMRowInfo *info,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 04:06:24 +08:00
|
|
|
GError **error);
|
2013-10-04 01:59:54 +08:00
|
|
|
|
|
|
|
struct _PNMScanner
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
GInputStream *input; /* The input stream of the file being read */
|
|
|
|
gchar cur; /* The current character in the input stream */
|
|
|
|
gint eof; /* Have we reached end of file? */
|
|
|
|
gchar *inbuf; /* Input buffer - initially 0 */
|
|
|
|
gint inbufsize; /* Size of input buffer */
|
|
|
|
gint inbufvalidsize; /* Size of input buffer with valid data */
|
|
|
|
gint inbufpos; /* Position in input buffer */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _PNMInfo
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2013-10-04 04:06:24 +08:00
|
|
|
gint xres, yres; /* The size of the image */
|
2015-01-16 22:37:24 +08:00
|
|
|
gboolean float_format; /* Whether it is a floating point format */
|
2017-02-21 05:46:21 +08:00
|
|
|
gint maxval; /* For integer format image files, the max value
|
2006-02-04 09:02:25 +08:00
|
|
|
* which we need to normalize to */
|
2015-01-16 22:37:24 +08:00
|
|
|
gfloat scale_factor; /* PFM files have a scale factor */
|
2013-10-04 04:06:24 +08:00
|
|
|
gint np; /* Number of image planes (0 for pbm) */
|
|
|
|
gboolean asciibody; /* 1 if ascii body, 0 if raw body */
|
|
|
|
jmp_buf jmpbuf; /* Where to jump to on an error loading */
|
|
|
|
|
|
|
|
PNMLoaderFunc loader; /* Routine to use to load the pnm body */
|
2013-10-04 01:59:54 +08:00
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Contains the information needed to write out PNM rows */
|
2013-10-04 04:06:24 +08:00
|
|
|
struct _PNMRowInfo
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2013-10-04 03:44:24 +08:00
|
|
|
GOutputStream *output; /* Output stream */
|
|
|
|
gchar *rowbuf; /* Buffer for writing out rows */
|
|
|
|
gint xres; /* X resolution */
|
|
|
|
gint np; /* Number of planes */
|
2017-02-21 07:12:05 +08:00
|
|
|
gint bpc; /* Bytes per color */
|
2013-10-04 03:44:24 +08:00
|
|
|
guchar *red; /* Colormap red */
|
|
|
|
guchar *grn; /* Colormap green */
|
|
|
|
guchar *blu; /* Colormap blue */
|
|
|
|
gboolean zero_is_black; /* index zero is black (PBM only) */
|
2013-10-04 04:06:24 +08:00
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-02-16 09:35:43 +08:00
|
|
|
/* Export info */
|
1997-11-25 06:05:25 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2007-10-28 00:50:55 +08:00
|
|
|
gint raw; /* raw or ascii */
|
1997-11-25 06:05:25 +08:00
|
|
|
} PNMSaveVals;
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
#define BUFLEN 512 /* The input buffer size for data returned
|
|
|
|
* from the scanner. Note that lines
|
|
|
|
* aren't allowed to be over 256 characters
|
|
|
|
* by the spec anyways so this shouldn't
|
|
|
|
* be an issue. */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Declare some local functions.
|
|
|
|
*/
|
2013-10-04 03:44:24 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
static gint32 load_image (GFile *file,
|
|
|
|
GError **error);
|
|
|
|
static gint save_image (GFile *file,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
gboolean pbm,
|
2015-01-20 22:44:07 +08:00
|
|
|
gboolean float_format,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
|
2013-10-04 04:06:24 +08:00
|
|
|
static gboolean save_dialog (void);
|
2013-10-04 03:44:24 +08:00
|
|
|
|
|
|
|
static void pnm_load_ascii (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
|
|
|
static void pnm_load_raw (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
|
|
|
static void pnm_load_rawpbm (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
2015-01-16 22:37:24 +08:00
|
|
|
static void pnm_load_rawpfm (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
2013-10-04 03:44:24 +08:00
|
|
|
|
|
|
|
static gboolean pnmsaverow_ascii (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean pnmsaverow_raw (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean pnmsaverow_raw_pbm (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean pnmsaverow_ascii_pbm (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean pnmsaverow_ascii_indexed (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean pnmsaverow_raw_indexed (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error);
|
|
|
|
|
|
|
|
static void pnmscanner_destroy (PNMScanner *s);
|
|
|
|
static void pnmscanner_createbuffer (PNMScanner *s,
|
|
|
|
gint bufsize);
|
|
|
|
static void pnmscanner_getchar (PNMScanner *s);
|
|
|
|
static void pnmscanner_eatwhitespace (PNMScanner *s);
|
|
|
|
static void pnmscanner_gettoken (PNMScanner *s,
|
|
|
|
gchar *buf,
|
|
|
|
gint bufsize);
|
|
|
|
static void pnmscanner_getsmalltoken (PNMScanner *s,
|
|
|
|
gchar *buf);
|
|
|
|
|
|
|
|
static PNMScanner * pnmscanner_create (GInputStream *input);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
#define pnmscanner_eof(s) ((s)->eof)
|
|
|
|
#define pnmscanner_input(s) ((s)->input)
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Checks for a fatal error */
|
2013-10-04 01:59:54 +08:00
|
|
|
#define CHECK_FOR_ERROR(predicate, jmpbuf, ...) \
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((predicate)) \
|
2013-10-04 01:59:54 +08:00
|
|
|
{ g_message (__VA_ARGS__); longjmp ((jmpbuf), 1); }
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-10-04 04:06:24 +08:00
|
|
|
static const struct
|
2000-01-26 01:46:56 +08:00
|
|
|
{
|
2013-10-04 04:06:24 +08:00
|
|
|
gchar name;
|
|
|
|
gint np;
|
|
|
|
gint asciibody;
|
|
|
|
gint maxval;
|
|
|
|
PNMLoaderFunc loader;
|
2000-01-26 01:46:56 +08:00
|
|
|
} pnm_types[] =
|
|
|
|
{
|
2015-01-16 22:37:24 +08:00
|
|
|
{ '1', 0, 1, 1, pnm_load_ascii }, /* ASCII PBM */
|
|
|
|
{ '2', 1, 1, 255, pnm_load_ascii }, /* ASCII PGM */
|
|
|
|
{ '3', 3, 1, 255, pnm_load_ascii }, /* ASCII PPM */
|
|
|
|
{ '4', 0, 0, 1, pnm_load_rawpbm }, /* RAW PBM */
|
|
|
|
{ '5', 1, 0, 255, pnm_load_raw }, /* RAW PGM */
|
|
|
|
{ '6', 3, 0, 255, pnm_load_raw }, /* RAW PPM */
|
|
|
|
{ 'F', 3, 0, 0, pnm_load_rawpfm }, /* RAW PFM (color) */
|
|
|
|
{ 'f', 1, 0, 0, pnm_load_rawpfm }, /* RAW PFM (grayscale) */
|
2000-01-26 01:46:56 +08:00
|
|
|
{ 0 , 0, 0, 0, NULL}
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static PNMSaveVals psvals =
|
|
|
|
{
|
|
|
|
TRUE /* raw? or ascii */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
MAIN ()
|
|
|
|
|
|
|
|
static void
|
2000-01-08 23:23:28 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-08-18 16:57:43 +08:00
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_return_vals[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Output image" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef save_args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2005-08-18 16:57:43 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
2016-02-16 09:35:43 +08:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to export" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to export the image in" },
|
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to export the image in" },
|
2013-10-04 04:06:24 +08:00
|
|
|
{ GIMP_PDB_INT32, "raw", "TRUE for raw output, FALSE for ascii output" }
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
static const GimpParamDef pfm_save_args[] =
|
|
|
|
{
|
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
2016-02-16 09:35:43 +08:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to export" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to export the image in" },
|
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to export the image in" }
|
2015-01-20 22:44:07 +08:00
|
|
|
};
|
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_install_procedure (LOAD_PROC,
|
2011-12-06 23:12:30 +08:00
|
|
|
"Loads files in the PNM file format",
|
2011-12-06 23:13:55 +08:00
|
|
|
"This plug-in loads files in the various Netpbm portable file formats.",
|
1997-11-25 06:05:25 +08:00
|
|
|
"Erik Nygren",
|
|
|
|
"Erik Nygren",
|
|
|
|
"1996",
|
2004-05-14 08:42:38 +08:00
|
|
|
N_("PNM Image"),
|
2006-02-04 09:02:25 +08:00
|
|
|
NULL,
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (load_args),
|
|
|
|
G_N_ELEMENTS (load_return_vals),
|
1997-11-25 06:05:25 +08:00
|
|
|
load_args, load_return_vals);
|
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_register_file_handler_mime (LOAD_PROC, "image/x-portable-anymap");
|
2019-08-19 18:05:12 +08:00
|
|
|
gimp_register_file_handler_remote (LOAD_PROC);
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_register_magic_load_handler (LOAD_PROC,
|
2015-01-16 22:37:24 +08:00
|
|
|
"pnm,ppm,pgm,pbm,pfm",
|
2006-02-04 09:02:25 +08:00
|
|
|
"",
|
2015-01-16 22:37:24 +08:00
|
|
|
"0,string,P1,0,string,P2,0,string,P3,"
|
|
|
|
"0,string,P4,0,string,P5,0,string,P6,"
|
|
|
|
"0,string,PF,0,string,Pf");
|
2004-05-14 08:42:38 +08:00
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_install_procedure (PNM_SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Exports files in the PNM file format",
|
|
|
|
"PNM exporting handles all image types without transparency.",
|
1997-11-25 06:05:25 +08:00
|
|
|
"Erik Nygren",
|
|
|
|
"Erik Nygren",
|
|
|
|
"1996",
|
2004-05-14 08:42:38 +08:00
|
|
|
N_("PNM image"),
|
2006-02-04 09:02:25 +08:00
|
|
|
"RGB, GRAY, INDEXED",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (save_args), 0,
|
1997-11-25 06:05:25 +08:00
|
|
|
save_args, NULL);
|
|
|
|
|
2006-05-29 05:29:59 +08:00
|
|
|
gimp_install_procedure (PBM_SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Exports files in the PBM file format",
|
|
|
|
"PBM exporting produces mono images without transparency.",
|
2006-05-29 05:29:59 +08:00
|
|
|
"Martin K Collins",
|
|
|
|
"Erik Nygren",
|
|
|
|
"2006",
|
|
|
|
N_("PBM image"),
|
|
|
|
"RGB, GRAY, INDEXED",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (save_args), 0,
|
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_install_procedure (PGM_SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Exports files in the PGM file format",
|
|
|
|
"PGM exporting produces grayscale images without transparency.",
|
2004-12-13 01:18:03 +08:00
|
|
|
"Erik Nygren",
|
|
|
|
"Erik Nygren",
|
|
|
|
"1996",
|
|
|
|
N_("PGM image"),
|
2006-02-04 09:02:25 +08:00
|
|
|
"RGB, GRAY, INDEXED",
|
2004-12-13 01:18:03 +08:00
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (save_args), 0,
|
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_install_procedure (PPM_SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Exports files in the PPM file format",
|
|
|
|
"PPM exporting handles RGB images without transparency.",
|
2004-12-13 01:18:03 +08:00
|
|
|
"Erik Nygren",
|
|
|
|
"Erik Nygren",
|
|
|
|
"1996",
|
|
|
|
N_("PPM image"),
|
2006-02-04 09:02:25 +08:00
|
|
|
"RGB, GRAY, INDEXED",
|
2004-12-13 01:18:03 +08:00
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (save_args), 0,
|
|
|
|
save_args, NULL);
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
gimp_install_procedure (PFM_SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Exports files in the PFM file format",
|
|
|
|
"PFM exporting handles all images without transparency.",
|
2015-01-20 22:44:07 +08:00
|
|
|
"Mukund Sivaraman",
|
|
|
|
"Mukund Sivaraman",
|
|
|
|
"2015",
|
|
|
|
N_("PFM image"),
|
|
|
|
"RGB, GRAY, INDEXED",
|
|
|
|
GIMP_PLUGIN,
|
|
|
|
G_N_ELEMENTS (pfm_save_args), 0,
|
|
|
|
pfm_save_args, NULL);
|
|
|
|
|
2007-03-20 18:41:35 +08:00
|
|
|
gimp_register_file_handler_mime (PNM_SAVE_PROC, "image/x-portable-anymap");
|
2006-05-29 05:29:59 +08:00
|
|
|
gimp_register_file_handler_mime (PBM_SAVE_PROC, "image/x-portable-bitmap");
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_register_file_handler_mime (PGM_SAVE_PROC, "image/x-portable-graymap");
|
|
|
|
gimp_register_file_handler_mime (PPM_SAVE_PROC, "image/x-portable-pixmap");
|
2015-01-20 22:44:07 +08:00
|
|
|
gimp_register_file_handler_mime (PPM_SAVE_PROC, "image/x-portable-floatmap");
|
2013-10-04 01:59:54 +08:00
|
|
|
|
2019-08-19 18:05:12 +08:00
|
|
|
gimp_register_file_handler_remote (PNM_SAVE_PROC);
|
|
|
|
gimp_register_file_handler_remote (PBM_SAVE_PROC);
|
|
|
|
gimp_register_file_handler_remote (PGM_SAVE_PROC);
|
|
|
|
gimp_register_file_handler_remote (PPM_SAVE_PROC);
|
|
|
|
gimp_register_file_handler_remote (PFM_SAVE_PROC);
|
2013-10-04 03:44:24 +08:00
|
|
|
|
2007-03-20 18:41:35 +08:00
|
|
|
gimp_register_save_handler (PNM_SAVE_PROC, "pnm", "");
|
2006-05-29 05:29:59 +08:00
|
|
|
gimp_register_save_handler (PBM_SAVE_PROC, "pbm", "");
|
2005-08-18 16:57:43 +08:00
|
|
|
gimp_register_save_handler (PGM_SAVE_PROC, "pgm", "");
|
|
|
|
gimp_register_save_handler (PPM_SAVE_PROC, "ppm", "");
|
2015-01-20 22:44:07 +08:00
|
|
|
gimp_register_save_handler (PFM_SAVE_PROC, "pfm", "");
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 20:03:08 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2008-08-18 14:53:21 +08:00
|
|
|
static GimpParam values[2];
|
|
|
|
GimpRunMode run_mode;
|
2015-01-20 22:44:07 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2008-08-18 14:53:21 +08:00
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
2015-01-20 22:44:07 +08:00
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
|
|
|
GError *error = NULL;
|
|
|
|
gboolean pbm = FALSE; /* flag for PBM output */
|
|
|
|
gboolean float_format = FALSE; /* flag for PFM output */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
INIT_I18N ();
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
*nreturn_vals = 1;
|
|
|
|
*return_vals = values;
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
if (strcmp (name, LOAD_PROC) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
image_ID = load_image (g_file_new_for_uri (param[1].data.d_string),
|
|
|
|
&error);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (image_ID != -1)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_IMAGE;
|
|
|
|
values[1].data.d_image = image_ID;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2005-08-18 16:57:43 +08:00
|
|
|
else if (strcmp (name, PNM_SAVE_PROC) == 0 ||
|
2006-05-29 05:29:59 +08:00
|
|
|
strcmp (name, PBM_SAVE_PROC) == 0 ||
|
2005-08-18 16:57:43 +08:00
|
|
|
strcmp (name, PGM_SAVE_PROC) == 0 ||
|
2015-01-20 22:44:07 +08:00
|
|
|
strcmp (name, PPM_SAVE_PROC) == 0 ||
|
|
|
|
strcmp (name, PFM_SAVE_PROC) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-08-18 16:57:43 +08:00
|
|
|
image_ID = param[1].data.d_int32;
|
|
|
|
drawable_ID = param[2].data.d_int32;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
|
|
|
/* eventually export the image */
|
1999-10-14 10:11:52 +08:00
|
|
|
switch (run_mode)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2005-08-18 16:57:43 +08:00
|
|
|
if (strcmp (name, PNM_SAVE_PROC) == 0)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
2013-11-10 07:18:48 +08:00
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "PNM",
|
2006-05-29 05:29:59 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
|
|
|
}
|
|
|
|
else if (strcmp (name, PBM_SAVE_PROC) == 0)
|
|
|
|
{
|
2013-11-10 07:18:48 +08:00
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "PBM",
|
2006-05-29 05:29:59 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_BITMAP);
|
|
|
|
pbm = TRUE; /* gimp has no mono image type so hack it */
|
|
|
|
}
|
2005-08-18 16:57:43 +08:00
|
|
|
else if (strcmp (name, PGM_SAVE_PROC) == 0)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
2013-11-10 07:18:48 +08:00
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "PGM",
|
2006-05-29 05:29:59 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY);
|
|
|
|
}
|
2015-01-20 22:44:07 +08:00
|
|
|
else if (strcmp (name, PPM_SAVE_PROC) == 0)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
2013-11-10 07:18:48 +08:00
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "PPM",
|
2006-05-29 05:29:59 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
|
|
|
}
|
2015-01-20 22:44:07 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "PFM",
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY);
|
|
|
|
float_format = TRUE;
|
|
|
|
}
|
2004-12-13 01:18:03 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
{
|
|
|
|
values[0].data.d_status = GIMP_PDB_CANCEL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
if (strcmp (name, PFM_SAVE_PROC) != 0)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
switch (run_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (name, &psvals);
|
2006-02-04 09:02:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
/* First acquire information with a dialog */
|
|
|
|
if (! save_dialog ())
|
|
|
|
status = GIMP_PDB_CANCEL;
|
|
|
|
break;
|
2006-02-04 09:02:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 6)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psvals.raw = (param[5].data.d_int32) ? TRUE : FALSE;
|
|
|
|
pbm = (strcmp (name, PBM_SAVE_PROC) == 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (name, &psvals);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
2015-01-20 22:44:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (run_mode)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
/* Make sure all the arguments are there! */
|
|
|
|
if (nparams != 5)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
2006-02-04 09:02:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2013-10-04 03:44:24 +08:00
|
|
|
if (save_image (g_file_new_for_uri (param[3].data.d_string),
|
2015-01-20 22:44:07 +08:00
|
|
|
image_ID, drawable_ID, pbm, float_format,
|
2008-08-18 14:53:21 +08:00
|
|
|
&error))
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
if (strcmp (name, PFM_SAVE_PROC) != 0)
|
|
|
|
{
|
|
|
|
/* Store psvals data */
|
|
|
|
gimp_set_data (name, &psvals, sizeof (PNMSaveVals));
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
1999-10-14 10:11:52 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2006-02-04 09:02:25 +08:00
|
|
|
gimp_image_delete (image_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-26 01:46:56 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2008-08-18 14:53:21 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && error)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = error->message;
|
|
|
|
}
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
values[0].data.d_status = status;
|
2016-04-19 08:20:28 +08:00
|
|
|
|
|
|
|
gegl_exit ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint32
|
2013-10-04 01:59:54 +08:00
|
|
|
load_image (GFile *file,
|
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
GInputStream *input;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint32 volatile image_ID = -1;
|
|
|
|
gint32 layer_ID;
|
|
|
|
char buf[BUFLEN + 4]; /* buffer for random things like scanning */
|
|
|
|
PNMInfo *pnminfo;
|
|
|
|
PNMScanner *volatile scan;
|
2005-08-18 16:57:43 +08:00
|
|
|
int ctr;
|
2017-02-21 05:46:21 +08:00
|
|
|
GimpPrecision precision;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2014-07-23 22:39:00 +08:00
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
|
|
|
g_file_get_parse_name (file));
|
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
|
|
|
|
if (! input)
|
|
|
|
return -1;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* allocate the necessary structures */
|
2001-12-06 10:28:58 +08:00
|
|
|
pnminfo = g_new (PNMInfo, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
scan = NULL;
|
|
|
|
/* set error handling */
|
|
|
|
if (setjmp (pnminfo->jmpbuf))
|
|
|
|
{
|
|
|
|
/* If we get here, we had a problem reading the file */
|
|
|
|
if (scan)
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_destroy (scan);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
g_object_unref (input);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (pnminfo);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2000-02-20 03:36:10 +08:00
|
|
|
if (image_ID != -1)
|
2006-02-04 09:02:25 +08:00
|
|
|
gimp_image_delete (image_ID);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
if (! (scan = pnmscanner_create (input)))
|
2005-08-18 16:57:43 +08:00
|
|
|
longjmp (pnminfo->jmpbuf, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Get magic number */
|
2000-01-26 01:46:56 +08:00
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
2006-02-04 09:02:25 +08:00
|
|
|
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Premature end of file."));
|
2006-02-04 09:02:25 +08:00
|
|
|
CHECK_FOR_ERROR ((buf[0] != 'P' || buf[2]), pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Invalid file."));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Look up magic number to see what type of PNM this is */
|
2006-02-04 09:02:25 +08:00
|
|
|
for (ctr = 0; pnm_types[ctr].name; ctr++)
|
1997-11-25 06:05:25 +08:00
|
|
|
if (buf[1] == pnm_types[ctr].name)
|
|
|
|
{
|
2015-01-16 22:37:24 +08:00
|
|
|
pnminfo->np = pnm_types[ctr].np;
|
|
|
|
pnminfo->asciibody = pnm_types[ctr].asciibody;
|
|
|
|
pnminfo->float_format = g_ascii_tolower (pnm_types[ctr].name) == 'f';
|
|
|
|
pnminfo->maxval = pnm_types[ctr].maxval;
|
|
|
|
pnminfo->loader = pnm_types[ctr].loader;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2005-08-18 16:57:43 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (!pnminfo->loader)
|
|
|
|
{
|
2003-06-13 22:37:00 +08:00
|
|
|
g_message (_("File not in a supported format."));
|
2007-10-28 00:50:55 +08:00
|
|
|
longjmp (pnminfo->jmpbuf, 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
|
|
|
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Premature end of file."));
|
2006-02-04 09:02:25 +08:00
|
|
|
pnminfo->xres = g_ascii_isdigit(*buf) ? atoi (buf) : 0;
|
|
|
|
CHECK_FOR_ERROR (pnminfo->xres <= 0, pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Invalid X resolution."));
|
2007-07-05 07:32:15 +08:00
|
|
|
CHECK_FOR_ERROR (pnminfo->xres > GIMP_MAX_IMAGE_SIZE, pnminfo->jmpbuf,
|
|
|
|
_("Image width is larger than GIMP can handle."));
|
2006-02-04 09:02:25 +08:00
|
|
|
|
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
|
|
|
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Premature end of file."));
|
2006-02-04 09:02:25 +08:00
|
|
|
pnminfo->yres = g_ascii_isdigit (*buf) ? atoi (buf) : 0;
|
|
|
|
CHECK_FOR_ERROR (pnminfo->yres <= 0, pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Invalid Y resolution."));
|
2007-07-05 07:32:15 +08:00
|
|
|
CHECK_FOR_ERROR (pnminfo->yres > GIMP_MAX_IMAGE_SIZE, pnminfo->jmpbuf,
|
|
|
|
_("Image height is larger than GIMP can handle."));
|
2006-02-04 09:02:25 +08:00
|
|
|
|
2015-01-16 22:37:24 +08:00
|
|
|
if (pnminfo->float_format)
|
|
|
|
{
|
|
|
|
gchar *endptr = NULL;
|
|
|
|
|
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
|
|
|
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
|
|
|
|
_("Premature end of file."));
|
|
|
|
|
|
|
|
pnminfo->scale_factor = g_ascii_strtod (buf, &endptr);
|
|
|
|
CHECK_FOR_ERROR (endptr == NULL || *endptr != 0 || errno == ERANGE,
|
|
|
|
pnminfo->jmpbuf, _("Bogus scale factor."));
|
|
|
|
CHECK_FOR_ERROR (!isnormal (pnminfo->scale_factor),
|
|
|
|
pnminfo->jmpbuf, _("Unsupported scale factor."));
|
2017-02-21 05:46:21 +08:00
|
|
|
precision = GIMP_PRECISION_FLOAT_LINEAR;
|
2015-01-16 22:37:24 +08:00
|
|
|
}
|
|
|
|
else if (pnminfo->np != 0) /* pbm's don't have a maxval field */
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
|
|
|
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
|
2006-05-29 05:29:59 +08:00
|
|
|
_("Premature end of file."));
|
2006-02-04 09:02:25 +08:00
|
|
|
|
|
|
|
pnminfo->maxval = g_ascii_isdigit (*buf) ? atoi (buf) : 0;
|
2011-03-26 17:39:59 +08:00
|
|
|
CHECK_FOR_ERROR (((pnminfo->maxval<=0) || (pnminfo->maxval>65535)),
|
|
|
|
pnminfo->jmpbuf, _("Unsupported maximum value."));
|
2017-02-21 05:46:21 +08:00
|
|
|
if (pnminfo->maxval < 256)
|
|
|
|
{
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U8_NON_LINEAR;
|
2017-02-21 05:46:21 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U16_NON_LINEAR;
|
2017-02-21 05:46:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
precision = GIMP_PRECISION_U8_NON_LINEAR;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2015-01-18 09:25:56 +08:00
|
|
|
/* Create a new image of the proper size and associate the filename
|
|
|
|
with it. */
|
|
|
|
image_ID = gimp_image_new_with_precision
|
|
|
|
(pnminfo->xres, pnminfo->yres,
|
|
|
|
(pnminfo->np >= 3) ? GIMP_RGB : GIMP_GRAY,
|
2017-02-21 05:46:21 +08:00
|
|
|
precision);
|
2015-01-18 09:25:56 +08:00
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
gimp_image_set_filename (image_ID, g_file_get_uri (file));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-03 21:01:51 +08:00
|
|
|
layer_ID = gimp_layer_new (image_ID, _("Background"),
|
2006-02-04 09:02:25 +08:00
|
|
|
pnminfo->xres, pnminfo->yres,
|
2007-10-28 00:50:55 +08:00
|
|
|
(pnminfo->np >= 3 ?
|
|
|
|
GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE),
|
2017-08-22 02:04:25 +08:00
|
|
|
100,
|
|
|
|
gimp_image_get_default_new_layer_mode (image_ID));
|
2010-09-06 17:40:46 +08:00
|
|
|
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (layer_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
pnminfo->loader (scan, pnminfo, buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Destroy the scanner */
|
2000-01-26 01:46:56 +08:00
|
|
|
pnmscanner_destroy (scan);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
g_object_unref (buffer);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (pnminfo);
|
2013-10-04 01:59:54 +08:00
|
|
|
g_object_unref (input);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
return image_ID;
|
|
|
|
}
|
|
|
|
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
2012-11-26 08:31:39 +08:00
|
|
|
pnm_load_ascii (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2017-02-21 05:46:21 +08:00
|
|
|
gint bpc;
|
2007-10-28 01:05:55 +08:00
|
|
|
guchar *data, *d;
|
2017-02-21 05:46:21 +08:00
|
|
|
gushort *s;
|
2007-10-28 01:05:55 +08:00
|
|
|
gint x, y, i, b;
|
|
|
|
gint start, end, scanlines;
|
|
|
|
gint np;
|
|
|
|
gchar buf[BUFLEN];
|
|
|
|
gboolean aborted = FALSE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
np = (info->np) ? (info->np) : 1;
|
2017-02-21 05:46:21 +08:00
|
|
|
|
|
|
|
if (info->maxval > 255)
|
|
|
|
bpc = 2;
|
|
|
|
else
|
|
|
|
bpc = 1;
|
|
|
|
|
|
|
|
/* No overflow as long as gimp_tile_height() < 1365 = 2^(31 - 18) / 6 */
|
|
|
|
data = g_new (guchar, gimp_tile_height () * info->xres * np * bpc);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Buffer reads to increase performance */
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_createbuffer (scan, 4096);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2007-10-28 01:05:55 +08:00
|
|
|
for (y = 0; y < info->yres; y += scanlines)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
start = y;
|
2007-10-28 01:05:55 +08:00
|
|
|
end = y + gimp_tile_height ();
|
|
|
|
end = MIN (end, info->yres);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
scanlines = end - start;
|
2007-10-28 01:05:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
d = data;
|
2017-02-21 05:46:21 +08:00
|
|
|
s = (gushort *)d;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < scanlines; i++)
|
2006-02-04 09:02:25 +08:00
|
|
|
for (x = 0; x < info->xres; x++)
|
|
|
|
{
|
|
|
|
for (b = 0; b < np; b++)
|
|
|
|
{
|
2007-10-28 01:05:55 +08:00
|
|
|
if (aborted)
|
|
|
|
{
|
|
|
|
d[b] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Truncated files will just have all 0's
|
|
|
|
at the end of the images */
|
2006-05-29 05:29:59 +08:00
|
|
|
if (pnmscanner_eof (scan))
|
2007-10-28 01:05:55 +08:00
|
|
|
{
|
|
|
|
g_message (_("Premature end of file."));
|
|
|
|
aborted = TRUE;
|
|
|
|
|
|
|
|
d[b] = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2007-09-12 15:15:38 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
if (info->np)
|
|
|
|
pnmscanner_gettoken (scan, buf, BUFLEN);
|
|
|
|
else
|
|
|
|
pnmscanner_getsmalltoken (scan, buf);
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2017-02-21 05:46:21 +08:00
|
|
|
if (info->maxval == 1)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2007-09-12 15:15:38 +08:00
|
|
|
if (info->np)
|
|
|
|
d[b] = (*buf == '0') ? 0x00 : 0xff;
|
|
|
|
else
|
|
|
|
d[b] = (*buf == '0') ? 0xff : 0x00; /* invert for PBM */
|
2017-02-21 05:46:21 +08:00
|
|
|
}
|
|
|
|
else if (bpc > 1)
|
|
|
|
{
|
|
|
|
s[b] = (65535.0 * (((gdouble) (g_ascii_isdigit (*buf) ?
|
|
|
|
atoi (buf) : 0))
|
|
|
|
/ (gdouble) (info->maxval)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-09-12 15:15:38 +08:00
|
|
|
d[b] = (255.0 * (((gdouble) (g_ascii_isdigit (*buf) ?
|
|
|
|
atoi (buf) : 0))
|
|
|
|
/ (gdouble) (info->maxval)));
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2017-02-21 05:46:21 +08:00
|
|
|
if (bpc > 1)
|
|
|
|
{
|
|
|
|
s += np;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
d += np;
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
|
|
|
|
NULL, data, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
2000-01-15 03:57:42 +08:00
|
|
|
gimp_progress_update ((double) y / (double) info->yres);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
2012-11-26 08:31:39 +08:00
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
2012-11-26 08:31:39 +08:00
|
|
|
pnm_load_raw (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
GInputStream *input;
|
|
|
|
gint bpc;
|
2017-02-21 05:46:21 +08:00
|
|
|
guchar *data, *d;
|
|
|
|
gushort *s;
|
2013-10-04 01:59:54 +08:00
|
|
|
gint x, y, i;
|
|
|
|
gint start, end, scanlines;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2011-03-26 17:39:59 +08:00
|
|
|
if (info->maxval > 255)
|
|
|
|
bpc = 2;
|
|
|
|
else
|
|
|
|
bpc = 1;
|
|
|
|
|
2017-02-21 05:46:21 +08:00
|
|
|
/* No overflow as long as gimp_tile_height() < 1365 = 2^(31 - 18) / 6 */
|
2011-03-26 17:39:59 +08:00
|
|
|
data = g_new (guchar, gimp_tile_height () * info->xres * info->np * bpc);
|
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
input = pnmscanner_input (scan);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
for (y = 0; y < info->yres; y += scanlines)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
start = y;
|
|
|
|
end = y + gimp_tile_height ();
|
|
|
|
end = MIN (end, info->yres);
|
|
|
|
scanlines = end - start;
|
|
|
|
d = data;
|
2017-02-21 05:46:21 +08:00
|
|
|
s = (gushort *)data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < scanlines; i++)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
gsize bytes_read;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (g_input_stream_read_all (input, d, info->xres * info->np * bpc,
|
|
|
|
&bytes_read, NULL, &error))
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR (info->xres * info->np * bpc != bytes_read,
|
|
|
|
info->jmpbuf,
|
|
|
|
_("Premature end of file."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
|
2011-03-26 17:39:59 +08:00
|
|
|
if (bpc > 1)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
|
|
|
for (x = 0; x < info->xres * info->np; x++)
|
|
|
|
{
|
2011-03-26 17:39:59 +08:00
|
|
|
int v;
|
|
|
|
|
|
|
|
v = *d++ << 8;
|
|
|
|
v += *d++;
|
|
|
|
|
2017-02-21 05:46:21 +08:00
|
|
|
s[x] = MIN (v, info->maxval); /* guard against overflow */
|
|
|
|
s[x] = 65535.0 * (gdouble) v / (gdouble) info->maxval;
|
2003-06-11 20:47:16 +08:00
|
|
|
}
|
2017-02-21 05:46:21 +08:00
|
|
|
s += info->xres * info->np;
|
2003-06-11 20:47:16 +08:00
|
|
|
}
|
2011-03-26 17:39:59 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (info->maxval != 255) /* Normalize if needed */
|
|
|
|
{
|
|
|
|
for (x = 0; x < info->xres * info->np; x++)
|
|
|
|
{
|
|
|
|
d[x] = MIN (d[x], info->maxval); /* guard against overflow */
|
|
|
|
d[x] = 255.0 * (gdouble) d[x] / (gdouble) info->maxval;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2011-03-26 17:39:59 +08:00
|
|
|
d += info->xres * info->np;
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2017-02-21 05:46:21 +08:00
|
|
|
gegl_buffer_set (buffer,
|
|
|
|
GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
|
|
|
|
NULL, data, GEGL_AUTO_ROWSTRIDE);
|
2011-03-26 17:39:59 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
gimp_progress_update ((double) y / (double) info->yres);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
2012-11-26 08:31:39 +08:00
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-10-14 10:11:52 +08:00
|
|
|
static void
|
2012-11-26 08:31:39 +08:00
|
|
|
pnm_load_rawpbm (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
GInputStream *input;
|
|
|
|
guchar *buf;
|
|
|
|
guchar curbyte;
|
|
|
|
guchar *data, *d;
|
|
|
|
gint x, y, i;
|
|
|
|
gint start, end, scanlines;
|
|
|
|
gint rowlen, bufpos;
|
|
|
|
|
|
|
|
input = pnmscanner_input (scan);
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
rowlen = (int)ceil ((double)(info->xres)/8.0);
|
|
|
|
data = g_new (guchar, gimp_tile_height () * info->xres);
|
|
|
|
buf = g_new (guchar, rowlen);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
for (y = 0; y < info->yres; y += scanlines)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
start = y;
|
|
|
|
end = y + gimp_tile_height ();
|
|
|
|
end = MIN (end, info->yres);
|
|
|
|
scanlines = end - start;
|
|
|
|
d = data;
|
|
|
|
|
|
|
|
for (i = 0; i < scanlines; i++)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
gsize bytes_read;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (g_input_stream_read_all (input, buf, rowlen,
|
|
|
|
&bytes_read, NULL, &error))
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR (rowlen != bytes_read,
|
|
|
|
info->jmpbuf,
|
|
|
|
_("Premature end of file."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
|
|
|
|
}
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
bufpos = 0;
|
|
|
|
curbyte = buf[0];
|
|
|
|
|
|
|
|
for (x = 0; x < info->xres; x++)
|
|
|
|
{
|
|
|
|
if ((x % 8) == 0)
|
|
|
|
curbyte = buf[bufpos++];
|
|
|
|
d[x] = (curbyte & 0x80) ? 0x00 : 0xff;
|
|
|
|
curbyte <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
d += info->xres;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
|
|
|
|
NULL, data, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
2000-01-15 03:57:42 +08:00
|
|
|
gimp_progress_update ((double) y / (double) info->yres);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
g_free (buf);
|
1997-11-25 06:05:25 +08:00
|
|
|
g_free (data);
|
2012-11-26 08:31:39 +08:00
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2015-01-16 22:37:24 +08:00
|
|
|
static void
|
|
|
|
pnm_load_rawpfm (PNMScanner *scan,
|
|
|
|
PNMInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
|
|
|
{
|
|
|
|
GInputStream *input;
|
|
|
|
gfloat *data;
|
|
|
|
gint x, y;
|
|
|
|
gboolean swap_byte_order;
|
|
|
|
|
|
|
|
swap_byte_order =
|
|
|
|
(info->scale_factor >= 0.0) ^ (G_BYTE_ORDER == G_BIG_ENDIAN);
|
|
|
|
|
|
|
|
data = g_new (gfloat, info->xres * info->np);
|
|
|
|
|
|
|
|
input = pnmscanner_input (scan);
|
|
|
|
|
|
|
|
for (y = info->yres - 1; y >= 0; y--)
|
|
|
|
{
|
|
|
|
gsize bytes_read;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
if (g_input_stream_read_all (input, data,
|
|
|
|
info->xres * info->np * sizeof (float),
|
|
|
|
&bytes_read, NULL, &error))
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR
|
|
|
|
(info->xres * info->np * sizeof (float) != bytes_read,
|
|
|
|
info->jmpbuf, _("Premature end of file."));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < info->xres * info->np; x++)
|
|
|
|
{
|
|
|
|
if (swap_byte_order)
|
|
|
|
{
|
|
|
|
union { gfloat f; guint32 i; } v;
|
|
|
|
|
|
|
|
v.f = data[x];
|
|
|
|
v.i = GUINT32_SWAP_LE_BE (v.i);
|
|
|
|
data[x] = v.f;
|
|
|
|
}
|
|
|
|
|
2015-01-18 09:25:56 +08:00
|
|
|
/* let's see if this is what people want, the PFM specs are a
|
|
|
|
* little vague about what the scale factor should be used
|
|
|
|
* for */
|
2015-01-16 22:37:24 +08:00
|
|
|
data[x] *= fabsf (info->scale_factor);
|
2018-10-30 20:37:07 +08:00
|
|
|
/* Keep values smaller than zero. That is in line with what the
|
|
|
|
* TIFF loader does. If the user doesn't want the negative numbers
|
|
|
|
* he has to get rid of them afterwards */
|
|
|
|
/* data[x] = fmaxf (0.0f, fminf (FLT_MAX, data[x])); */
|
2015-01-16 22:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gegl_buffer_set (buffer,
|
|
|
|
GEGL_RECTANGLE (0, y, info->xres, 1), 0,
|
|
|
|
NULL, data, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
|
|
|
if (y % 32 == 0)
|
2015-01-20 23:37:59 +08:00
|
|
|
gimp_progress_update ((double) (info->yres - y) / (double) info->yres);
|
2015-01-16 22:37:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
gimp_progress_update (1.0);
|
|
|
|
}
|
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
output_write (GOutputStream *output,
|
|
|
|
gconstpointer buffer,
|
|
|
|
gsize count,
|
|
|
|
GError **error)
|
|
|
|
{
|
2014-09-08 02:30:14 +08:00
|
|
|
return g_output_stream_write_all (output, buffer, count, NULL, NULL, error);
|
2013-10-04 03:44:24 +08:00
|
|
|
}
|
|
|
|
|
2006-05-29 05:29:59 +08:00
|
|
|
/* Writes out mono raw rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_raw_pbm (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
2009-03-05 22:08:56 +08:00
|
|
|
gint b, p = 0;
|
|
|
|
gchar *rbcur = ri->rowbuf;
|
|
|
|
gint32 len = (gint) ceil ((gdouble) (ri->xres) / 8.0);
|
2006-05-29 05:29:59 +08:00
|
|
|
|
|
|
|
for (b = 0; b < len; b++) /* each output byte */
|
|
|
|
{
|
2009-03-05 22:08:56 +08:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
rbcur[b] = 0;
|
|
|
|
|
2006-05-29 05:29:59 +08:00
|
|
|
for (i = 0; i < 8; i++) /* each bit in this byte */
|
|
|
|
{
|
|
|
|
if (p >= ri->xres)
|
2009-03-05 22:08:56 +08:00
|
|
|
break;
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2009-03-13 06:18:44 +08:00
|
|
|
if (data[p] != ri->zero_is_black)
|
2009-03-05 22:08:56 +08:00
|
|
|
rbcur[b] |= (char) (1 << (7 - i));
|
2006-05-29 05:29:59 +08:00
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
return output_write (ri->output, ri->rowbuf, len, error);
|
2006-05-29 05:29:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes out mono ascii rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_ascii_pbm (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
|
|
|
static gint line_len = 0; /* ascii pbm lines must be <= 70 chars long */
|
|
|
|
gint32 len = 0;
|
|
|
|
gint i;
|
|
|
|
gchar *rbcur = ri->rowbuf;
|
|
|
|
|
|
|
|
for (i = 0; i < ri->xres; i++)
|
|
|
|
{
|
|
|
|
if (line_len > 69)
|
|
|
|
{
|
2009-03-05 22:08:56 +08:00
|
|
|
rbcur[i] = '\n';
|
2006-05-29 05:29:59 +08:00
|
|
|
line_len = 0;
|
|
|
|
len++;
|
|
|
|
rbcur++;
|
|
|
|
}
|
|
|
|
|
2009-03-13 06:18:44 +08:00
|
|
|
if (data[i] == ri->zero_is_black)
|
2009-03-05 22:08:56 +08:00
|
|
|
rbcur[i] = '0';
|
2006-05-29 05:29:59 +08:00
|
|
|
else
|
2009-03-05 22:08:56 +08:00
|
|
|
rbcur[i] = '1';
|
2006-05-29 05:29:59 +08:00
|
|
|
|
|
|
|
line_len++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*(rbcur+i) = '\n';
|
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
return output_write (ri->output, ri->rowbuf, len, error);
|
2006-05-29 05:29:59 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 05:26:16 +08:00
|
|
|
/* Writes out RGB and grayscale raw rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_raw (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2017-02-21 07:12:05 +08:00
|
|
|
gint i;
|
|
|
|
if (ri->bpc == 2)
|
|
|
|
{
|
|
|
|
gushort *d = (gushort *)data;
|
|
|
|
for (i = 0; i < ri->xres * ri->np; i++)
|
|
|
|
{
|
|
|
|
*d = g_htons(*d);
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return output_write (ri->output, data, ri->xres * ri->np * ri->bpc, error);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
/* Writes out RGB and grayscale float rows */
|
|
|
|
static gboolean
|
|
|
|
pnmsaverow_float (PNMRowInfo *ri,
|
|
|
|
const float *data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return output_write (ri->output, data,
|
|
|
|
ri->xres * ri->np * sizeof (float),
|
|
|
|
error);
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Writes out indexed raw rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_raw_indexed (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
gint i;
|
|
|
|
gchar *rbcur = ri->rowbuf;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ri->xres; i++)
|
|
|
|
{
|
|
|
|
*(rbcur++) = ri->red[*data];
|
|
|
|
*(rbcur++) = ri->grn[*data];
|
|
|
|
*(rbcur++) = ri->blu[*(data++)];
|
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
return output_write (ri->output, ri->rowbuf, ri->xres * 3, error);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 05:26:16 +08:00
|
|
|
/* Writes out RGB and grayscale ascii rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_ascii (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
gint i;
|
|
|
|
gchar *rbcur = ri->rowbuf;
|
2017-02-21 07:12:05 +08:00
|
|
|
gushort *sdata = (gushort *)data;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
for (i = 0; i < ri->xres * ri->np; i++)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2017-02-21 07:12:05 +08:00
|
|
|
if (ri->bpc == 2)
|
|
|
|
{
|
|
|
|
sprintf ((gchar *) rbcur,"%d\n", 0xffff & *(sdata++));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf ((gchar *) rbcur,"%d\n", 0xff & *(data++));
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
rbcur += strlen (rbcur);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2017-02-21 07:12:05 +08:00
|
|
|
return output_write (ri->output, ri->rowbuf, rbcur - ri->rowbuf,
|
2013-10-04 03:44:24 +08:00
|
|
|
error);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 05:26:16 +08:00
|
|
|
/* Writes out RGB and grayscale ascii rows */
|
2013-10-04 03:44:24 +08:00
|
|
|
static gboolean
|
|
|
|
pnmsaverow_ascii_indexed (PNMRowInfo *ri,
|
2017-02-21 07:12:05 +08:00
|
|
|
guchar *data,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
gint i;
|
|
|
|
gchar *rbcur = ri->rowbuf;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ri->xres; i++)
|
|
|
|
{
|
2009-03-05 22:08:56 +08:00
|
|
|
sprintf (rbcur, "%d\n", 0xff & ri->red[*(data)]);
|
2006-02-04 09:02:25 +08:00
|
|
|
rbcur += strlen (rbcur);
|
2009-03-05 22:08:56 +08:00
|
|
|
sprintf (rbcur, "%d\n", 0xff & ri->grn[*(data)]);
|
2006-02-04 09:02:25 +08:00
|
|
|
rbcur += strlen (rbcur);
|
2009-03-05 22:08:56 +08:00
|
|
|
sprintf (rbcur, "%d\n", 0xff & ri->blu[*(data++)]);
|
2006-02-04 09:02:25 +08:00
|
|
|
rbcur += strlen (rbcur);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
return output_write (ri->output, ri->rowbuf, strlen ((char *) ri->rowbuf),
|
|
|
|
error);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
static gboolean
|
2013-10-04 03:44:24 +08:00
|
|
|
save_image (GFile *file,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
gboolean pbm,
|
2015-01-20 22:44:07 +08:00
|
|
|
gboolean float_format,
|
2013-10-04 03:44:24 +08:00
|
|
|
GError **error)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
gboolean status = FALSE;
|
|
|
|
GOutputStream *output = NULL;
|
|
|
|
GeglBuffer *buffer = NULL;
|
2012-11-26 08:31:39 +08:00
|
|
|
const Babl *format;
|
2013-10-04 03:44:24 +08:00
|
|
|
const gchar *header_string = NULL;
|
2005-08-18 16:57:43 +08:00
|
|
|
GimpImageType drawable_type;
|
|
|
|
PNMRowInfo rowinfo;
|
2013-10-04 04:06:24 +08:00
|
|
|
PNMSaverowFunc saverow = NULL;
|
2006-02-04 09:02:25 +08:00
|
|
|
guchar red[256];
|
|
|
|
guchar grn[256];
|
|
|
|
guchar blu[256];
|
|
|
|
gchar buf[BUFLEN];
|
|
|
|
gint np = 0;
|
|
|
|
gint xres, yres;
|
|
|
|
gint ypos, yend;
|
|
|
|
gint rowbufsize = 0;
|
2015-01-20 22:44:07 +08:00
|
|
|
gchar *comment = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Make sure we're not saving an image with an alpha channel */
|
|
|
|
if (gimp_drawable_has_alpha (drawable_ID))
|
|
|
|
{
|
2016-02-16 09:35:43 +08:00
|
|
|
g_message (_("Cannot export images with alpha channel."));
|
2015-01-20 22:44:07 +08:00
|
|
|
goto out;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2016-02-16 09:35:43 +08:00
|
|
|
gimp_progress_init_printf (_("Exporting '%s'"),
|
2014-07-23 22:39:00 +08:00
|
|
|
g_file_get_parse_name (file));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* open the file */
|
2014-10-04 08:44:54 +08:00
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
2013-10-04 03:44:24 +08:00
|
|
|
if (! output)
|
2015-01-20 22:44:07 +08:00
|
|
|
goto out;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable_ID);
|
|
|
|
|
|
|
|
xres = gegl_buffer_get_width (buffer);
|
|
|
|
yres = gegl_buffer_get_height (buffer);
|
|
|
|
|
|
|
|
drawable_type = gimp_drawable_type (drawable_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2017-02-21 07:12:05 +08:00
|
|
|
switch (gimp_image_get_precision (image_ID))
|
|
|
|
{
|
|
|
|
case GIMP_PRECISION_U8_LINEAR:
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
|
|
|
case GIMP_PRECISION_U8_NON_LINEAR:
|
|
|
|
case GIMP_PRECISION_U8_PERCEPTUAL:
|
2017-02-21 07:12:05 +08:00
|
|
|
rowinfo.bpc = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rowinfo.bpc = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* write out magic number */
|
2015-01-20 22:44:07 +08:00
|
|
|
if (!float_format && !psvals.raw)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
|
|
|
if (pbm)
|
|
|
|
{
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P1\n";
|
2016-09-04 23:19:08 +08:00
|
|
|
format = gegl_buffer_get_format (buffer);
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 0;
|
|
|
|
rowbufsize = xres + (int) (xres / 70) + 1;
|
|
|
|
saverow = pnmsaverow_ascii_pbm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (drawable_type)
|
|
|
|
{
|
|
|
|
case GIMP_GRAY_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P2\n";
|
2017-02-21 07:12:05 +08:00
|
|
|
if (rowinfo.bpc == 1)
|
|
|
|
{
|
|
|
|
format = babl_format ("Y' u8");
|
|
|
|
rowbufsize = xres * 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = babl_format ("Y' u16");
|
|
|
|
rowbufsize = xres * 6;
|
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 1;
|
|
|
|
saverow = pnmsaverow_ascii;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGB_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P3\n";
|
2017-02-21 07:12:05 +08:00
|
|
|
if (rowinfo.bpc == 1)
|
|
|
|
{
|
|
|
|
format = babl_format ("R'G'B' u8");
|
|
|
|
rowbufsize = xres * 12;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = babl_format ("R'G'B' u16");
|
|
|
|
rowbufsize = xres * 18;
|
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 3;
|
|
|
|
saverow = pnmsaverow_ascii;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P3\n";
|
2012-11-26 08:31:39 +08:00
|
|
|
format = gegl_buffer_get_format (buffer);
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 1;
|
|
|
|
rowbufsize = xres * 12;
|
|
|
|
saverow = pnmsaverow_ascii_indexed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-12-06 23:12:30 +08:00
|
|
|
g_warning ("PNM: Unknown drawable_type\n");
|
2015-01-20 22:44:07 +08:00
|
|
|
goto out;
|
2006-05-29 05:29:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-20 22:44:07 +08:00
|
|
|
else if (!float_format)
|
2006-05-29 05:29:59 +08:00
|
|
|
{
|
|
|
|
if (pbm)
|
|
|
|
{
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P4\n";
|
2016-09-04 23:19:08 +08:00
|
|
|
format = gegl_buffer_get_format (buffer);
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 0;
|
2013-10-04 04:06:24 +08:00
|
|
|
rowbufsize = (gint) ceil ((gdouble) xres / 8.0);
|
2006-05-29 05:29:59 +08:00
|
|
|
saverow = pnmsaverow_raw_pbm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (drawable_type)
|
|
|
|
{
|
|
|
|
case GIMP_GRAY_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P5\n";
|
2017-02-21 07:12:05 +08:00
|
|
|
if (rowinfo.bpc == 1)
|
|
|
|
{
|
|
|
|
format = babl_format ("Y' u8");
|
|
|
|
rowbufsize = xres;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = babl_format ("Y' u16");
|
|
|
|
rowbufsize = xres * 2;
|
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 1;
|
|
|
|
saverow = pnmsaverow_raw;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGB_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P6\n";
|
2017-02-21 07:12:05 +08:00
|
|
|
if (rowinfo.bpc == 1)
|
|
|
|
{
|
|
|
|
format = babl_format ("R'G'B' u8");
|
|
|
|
rowbufsize = xres * 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = babl_format ("R'G'B' u16");
|
|
|
|
rowbufsize = xres * 6;
|
|
|
|
}
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 3;
|
|
|
|
saverow = pnmsaverow_raw;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
2013-10-04 03:44:24 +08:00
|
|
|
header_string = "P6\n";
|
2012-11-26 08:31:39 +08:00
|
|
|
format = gegl_buffer_get_format (buffer);
|
2006-05-29 05:29:59 +08:00
|
|
|
np = 1;
|
|
|
|
rowbufsize = xres * 3;
|
|
|
|
saverow = pnmsaverow_raw_indexed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-12-06 23:12:30 +08:00
|
|
|
g_warning ("PNM: Unknown drawable_type\n");
|
2015-01-20 22:44:07 +08:00
|
|
|
goto out;
|
2006-05-29 05:29:59 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2015-01-20 22:44:07 +08:00
|
|
|
else
|
2013-10-04 03:44:24 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
switch (drawable_type)
|
|
|
|
{
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
header_string = "Pf\n";
|
|
|
|
format = babl_format ("Y float");
|
|
|
|
np = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
header_string = "PF\n";
|
|
|
|
format = babl_format ("RGB float");
|
|
|
|
np = 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("PFM: Unknown drawable_type\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2013-10-04 03:44:24 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
if (! output_write (output, header_string, strlen (header_string), error))
|
|
|
|
goto out;
|
|
|
|
|
2009-03-13 06:18:44 +08:00
|
|
|
rowinfo.zero_is_black = FALSE;
|
2009-03-05 22:08:56 +08:00
|
|
|
|
|
|
|
if (drawable_type == GIMP_INDEXED_IMAGE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
guchar *cmap;
|
2009-03-13 06:18:44 +08:00
|
|
|
gint num_colors;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-03-13 06:18:44 +08:00
|
|
|
cmap = gimp_image_get_colormap (image_ID, &num_colors);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-03-05 22:08:56 +08:00
|
|
|
if (pbm)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2009-03-13 06:18:44 +08:00
|
|
|
/* Test which of the two colors is white and which is black */
|
|
|
|
switch (num_colors)
|
2009-03-05 22:08:56 +08:00
|
|
|
{
|
2009-03-13 06:18:44 +08:00
|
|
|
case 1:
|
|
|
|
rowinfo.zero_is_black = (GIMP_RGB_LUMINANCE (cmap[0],
|
|
|
|
cmap[1],
|
|
|
|
cmap[2]) < 128);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
rowinfo.zero_is_black = (GIMP_RGB_LUMINANCE (cmap[0],
|
|
|
|
cmap[1],
|
|
|
|
cmap[2]) <
|
|
|
|
GIMP_RGB_LUMINANCE (cmap[3],
|
|
|
|
cmap[4],
|
|
|
|
cmap[5]));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-02-16 09:35:43 +08:00
|
|
|
g_warning ("Images exported as PBM should be black/white");
|
2009-03-13 06:18:44 +08:00
|
|
|
break;
|
2009-03-05 22:08:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-09 19:12:12 +08:00
|
|
|
const guchar *c = cmap;
|
|
|
|
gint i;
|
2009-03-05 22:08:56 +08:00
|
|
|
|
2009-03-13 06:18:44 +08:00
|
|
|
for (i = 0; i < num_colors; i++)
|
2009-03-05 22:08:56 +08:00
|
|
|
{
|
2010-01-09 19:12:12 +08:00
|
|
|
red[i] = *c++;
|
|
|
|
grn[i] = *c++;
|
|
|
|
blu[i] = *c++;
|
2009-03-05 22:08:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rowinfo.red = red;
|
|
|
|
rowinfo.grn = grn;
|
|
|
|
rowinfo.blu = blu;
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-03-05 22:08:56 +08:00
|
|
|
g_free (cmap);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2015-01-21 17:54:22 +08:00
|
|
|
if (!float_format)
|
|
|
|
{
|
|
|
|
/* write out comment string */
|
|
|
|
comment = g_strdup_printf("# Created by GIMP version %s PNM plug-in\n",
|
|
|
|
GIMP_VERSION);
|
2015-01-20 22:44:07 +08:00
|
|
|
|
2015-01-21 17:54:22 +08:00
|
|
|
if (! output_write (output, comment, strlen (comment), error))
|
|
|
|
goto out;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* write out resolution and maxval */
|
2006-05-29 05:29:59 +08:00
|
|
|
if (pbm)
|
2013-10-04 03:44:24 +08:00
|
|
|
g_snprintf (buf, sizeof (buf), "%d %d\n", xres, yres);
|
2015-01-20 22:44:07 +08:00
|
|
|
else if (!float_format)
|
2017-02-21 07:12:05 +08:00
|
|
|
g_snprintf (buf, sizeof (buf), "%d %d\n%d\n", xres, yres,
|
|
|
|
rowinfo.bpc == 1 ? 255 : 65535);
|
2015-01-20 22:44:07 +08:00
|
|
|
else
|
2018-04-17 05:54:45 +08:00
|
|
|
g_snprintf (buf, sizeof (buf), "%d %d\n%s\n", xres, yres,
|
|
|
|
G_BYTE_ORDER == G_BIG_ENDIAN ? "1.0" : "-1.0");
|
2006-05-29 05:29:59 +08:00
|
|
|
|
2013-10-04 03:44:24 +08:00
|
|
|
if (! output_write (output, buf, strlen (buf), error))
|
2015-01-20 22:44:07 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (!float_format)
|
2013-10-04 03:44:24 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
guchar *data;
|
|
|
|
guchar *d;
|
|
|
|
gchar *rowbuf = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
/* allocate a buffer for retrieving information from the pixel region */
|
|
|
|
data = g_new (guchar,
|
|
|
|
gimp_tile_height () * xres *
|
|
|
|
babl_format_get_bytes_per_pixel (format));
|
2013-10-04 04:06:24 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
rowbuf = g_new (gchar, rowbufsize + 1);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
rowinfo.output = output;
|
|
|
|
rowinfo.rowbuf = rowbuf;
|
|
|
|
rowinfo.xres = xres;
|
|
|
|
rowinfo.np = np;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
d = NULL; /* only to please the compiler */
|
1999-12-27 20:02:07 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
/* Write the body out */
|
|
|
|
for (ypos = 0; ypos < yres; ypos++)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2015-01-20 22:44:07 +08:00
|
|
|
if ((ypos % gimp_tile_height ()) == 0)
|
|
|
|
{
|
|
|
|
yend = ypos + gimp_tile_height ();
|
|
|
|
yend = MIN (yend, yres);
|
|
|
|
|
|
|
|
gegl_buffer_get (buffer,
|
|
|
|
GEGL_RECTANGLE (0, ypos, xres, yend - ypos), 1.0,
|
|
|
|
format, data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
|
|
|
d = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! saverow (&rowinfo, d, error))
|
|
|
|
{
|
|
|
|
g_free (rowbuf);
|
|
|
|
g_free (data);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-02-21 07:12:05 +08:00
|
|
|
d += xres * (np ? np : 1) * rowinfo.bpc;
|
2015-01-20 22:44:07 +08:00
|
|
|
|
|
|
|
if (ypos % 32 == 0)
|
|
|
|
gimp_progress_update ((double) ypos / (double) yres);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (rowbuf);
|
|
|
|
g_free (data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* allocate a buffer for retrieving information from the pixel
|
|
|
|
region */
|
|
|
|
gfloat *data = g_new (gfloat, xres * np);
|
|
|
|
|
|
|
|
rowinfo.output = output;
|
|
|
|
rowinfo.rowbuf = NULL;
|
|
|
|
rowinfo.xres = xres;
|
|
|
|
rowinfo.np = np;
|
2012-11-26 08:31:39 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
/* Write the body out in reverse row order */
|
|
|
|
for (ypos = yres - 1; ypos >= 0; ypos--)
|
|
|
|
{
|
2012-11-26 08:31:39 +08:00
|
|
|
gegl_buffer_get (buffer,
|
2015-01-20 22:44:07 +08:00
|
|
|
GEGL_RECTANGLE (0, ypos, xres, 1), 1.0,
|
2015-01-20 23:30:04 +08:00
|
|
|
format, data,
|
2012-11-26 08:31:39 +08:00
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
if (! pnmsaverow_float (&rowinfo, data, error))
|
|
|
|
{
|
|
|
|
g_free (data);
|
|
|
|
goto out;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
if (ypos % 32 == 0)
|
|
|
|
gimp_progress_update ((double) (yres - ypos) / (double) yres);
|
2013-10-04 03:44:24 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
g_free (data);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2012-11-26 08:31:39 +08:00
|
|
|
gimp_progress_update (1.0);
|
2015-01-20 22:44:07 +08:00
|
|
|
status = TRUE;
|
|
|
|
|
|
|
|
out:
|
2018-11-27 19:27:20 +08:00
|
|
|
if (! status)
|
|
|
|
{
|
|
|
|
GCancellable *cancellable = g_cancellable_new ();
|
|
|
|
|
|
|
|
g_cancellable_cancel (cancellable);
|
|
|
|
g_output_stream_close (output, cancellable, NULL);
|
|
|
|
g_object_unref (cancellable);
|
|
|
|
}
|
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
if (comment)
|
|
|
|
g_free (comment);
|
|
|
|
if (buffer)
|
|
|
|
g_object_unref (buffer);
|
|
|
|
if (output)
|
|
|
|
g_object_unref (output);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2015-01-20 22:44:07 +08:00
|
|
|
return status;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2013-10-04 04:06:24 +08:00
|
|
|
static gboolean
|
2000-01-08 23:23:28 +08:00
|
|
|
save_dialog (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2005-09-10 02:38:00 +08:00
|
|
|
GtkWidget *dialog;
|
1997-11-25 06:05:25 +08:00
|
|
|
GtkWidget *frame;
|
2003-11-06 23:27:05 +08:00
|
|
|
gboolean run;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-07-21 20:10:29 +08:00
|
|
|
dialog = gimp_export_dialog_new (_("PNM"), PLUG_IN_BINARY, PNM_SAVE_PROC);
|
2005-09-10 02:38:00 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* file save type */
|
2004-06-22 03:15:08 +08:00
|
|
|
frame = gimp_int_radio_group_new (TRUE, _("Data formatting"),
|
2006-02-04 09:02:25 +08:00
|
|
|
G_CALLBACK (gimp_radio_button_update),
|
|
|
|
&psvals.raw, psvals.raw,
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
_("Raw"), TRUE, NULL,
|
2011-12-06 23:07:42 +08:00
|
|
|
_("ASCII"), FALSE, NULL,
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
NULL);
|
2000-01-08 23:23:28 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
|
2009-07-21 20:10:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)),
|
2005-09-10 02:38:00 +08:00
|
|
|
frame, FALSE, TRUE, 0);
|
1997-11-25 06:05:25 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_show (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/**************** FILE SCANNER UTILITIES **************/
|
|
|
|
|
|
|
|
/* pnmscanner_create ---
|
|
|
|
* Creates a new scanner based on a file descriptor. The
|
|
|
|
* look ahead buffer is one character initially.
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static PNMScanner *
|
2013-10-04 01:59:54 +08:00
|
|
|
pnmscanner_create (GInputStream *input)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
PNMScanner *s;
|
2013-10-04 01:59:54 +08:00
|
|
|
gsize bytes_read;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-12-06 10:28:58 +08:00
|
|
|
s = g_new (PNMScanner, 1);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2013-10-04 01:59:54 +08:00
|
|
|
s->input = input;
|
2004-11-14 10:50:33 +08:00
|
|
|
s->inbuf = NULL;
|
2013-10-04 01:59:54 +08:00
|
|
|
s->eof = FALSE;
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (input, &s->cur, 1,
|
|
|
|
&bytes_read, NULL, NULL) ||
|
|
|
|
bytes_read != 1)
|
|
|
|
{
|
|
|
|
s->eof = TRUE;
|
|
|
|
}
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
return s;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pnmscanner_destroy ---
|
|
|
|
* Destroys a scanner and its resources. Doesn't close the fd.
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
pnmscanner_destroy (PNMScanner *s)
|
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
if (s->inbuf)
|
|
|
|
g_free (s->inbuf);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
g_free (s);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pnmscanner_createbuffer ---
|
|
|
|
* Creates a buffer so we can do buffered reads.
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
pnmscanner_createbuffer (PNMScanner *s,
|
2006-02-04 09:02:25 +08:00
|
|
|
gint bufsize)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
gsize bytes_read;
|
|
|
|
|
2007-10-28 00:50:55 +08:00
|
|
|
s->inbuf = g_new (gchar, bufsize);
|
|
|
|
s->inbufsize = bufsize;
|
|
|
|
s->inbufpos = 0;
|
2013-10-04 01:59:54 +08:00
|
|
|
s->inbufvalidsize = 0;
|
|
|
|
|
|
|
|
g_input_stream_read_all (s->input, s->inbuf, bufsize,
|
|
|
|
&bytes_read, NULL, NULL);
|
|
|
|
|
|
|
|
s->inbufvalidsize = bytes_read;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pnmscanner_gettoken ---
|
|
|
|
* Gets the next token, eating any leading whitespace.
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
pnmscanner_gettoken (PNMScanner *s,
|
2006-02-04 09:02:25 +08:00
|
|
|
gchar *buf,
|
|
|
|
gint bufsize)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-10-28 00:50:55 +08:00
|
|
|
gint ctr = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-11-27 03:20:24 +08:00
|
|
|
pnmscanner_eatwhitespace (s);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2003-11-27 03:20:24 +08:00
|
|
|
while (! s->eof &&
|
|
|
|
! g_ascii_isspace (s->cur) &&
|
|
|
|
(s->cur != '#') &&
|
|
|
|
(ctr < bufsize))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
buf[ctr++] = s->cur;
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_getchar (s);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2007-10-28 00:50:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
buf[ctr] = '\0';
|
|
|
|
}
|
|
|
|
|
2000-02-20 03:36:10 +08:00
|
|
|
/* pnmscanner_getsmalltoken ---
|
|
|
|
* Gets the next char, eating any leading whitespace.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pnmscanner_getsmalltoken (PNMScanner *s,
|
2006-02-04 09:02:25 +08:00
|
|
|
gchar *buf)
|
2000-02-20 03:36:10 +08:00
|
|
|
{
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_eatwhitespace (s);
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2013-10-04 04:06:24 +08:00
|
|
|
if (! s->eof && ! g_ascii_isspace (s->cur) && (s->cur != '#'))
|
2000-02-20 03:36:10 +08:00
|
|
|
{
|
|
|
|
*buf = s->cur;
|
2006-02-04 09:02:25 +08:00
|
|
|
pnmscanner_getchar (s);
|
2000-02-20 03:36:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* pnmscanner_getchar ---
|
|
|
|
* Reads a character from the input stream
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
pnmscanner_getchar (PNMScanner *s)
|
|
|
|
{
|
|
|
|
if (s->inbuf)
|
|
|
|
{
|
|
|
|
s->cur = s->inbuf[s->inbufpos++];
|
2007-10-28 00:50:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (s->inbufpos >= s->inbufvalidsize)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
2006-05-29 05:29:59 +08:00
|
|
|
if (s->inbufpos > s->inbufvalidsize)
|
2013-10-04 01:59:54 +08:00
|
|
|
{
|
|
|
|
s->eof = 1;
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
else
|
2013-10-04 01:59:54 +08:00
|
|
|
{
|
|
|
|
gsize bytes_read;
|
|
|
|
|
|
|
|
g_input_stream_read_all (s->input, s->inbuf, s->inbufsize,
|
|
|
|
&bytes_read, NULL, NULL);
|
|
|
|
|
|
|
|
s->inbufvalidsize = bytes_read;
|
|
|
|
}
|
2007-10-28 00:50:55 +08:00
|
|
|
|
2006-02-04 09:02:25 +08:00
|
|
|
s->inbufpos = 0;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2007-10-28 00:50:55 +08:00
|
|
|
{
|
2013-10-04 01:59:54 +08:00
|
|
|
gsize bytes_read;
|
|
|
|
|
|
|
|
s->eof = FALSE;
|
|
|
|
|
|
|
|
if (! g_input_stream_read_all (s->input, &s->cur, 1,
|
|
|
|
&bytes_read, NULL, NULL) ||
|
|
|
|
bytes_read != 1)
|
|
|
|
{
|
|
|
|
s->eof = TRUE;
|
|
|
|
}
|
2007-10-28 00:50:55 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pnmscanner_eatwhitespace ---
|
|
|
|
* Eats up whitespace from the input and returns when done or eof.
|
|
|
|
* Also deals with comments.
|
|
|
|
*/
|
1998-03-19 10:11:53 +08:00
|
|
|
static void
|
1997-11-25 06:05:25 +08:00
|
|
|
pnmscanner_eatwhitespace (PNMScanner *s)
|
|
|
|
{
|
2007-10-28 00:50:55 +08:00
|
|
|
gint state = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
while (!(s->eof) && (state != -1))
|
|
|
|
{
|
|
|
|
switch (state)
|
2006-02-04 09:02:25 +08:00
|
|
|
{
|
|
|
|
case 0: /* in whitespace */
|
|
|
|
if (s->cur == '#')
|
|
|
|
{
|
|
|
|
state = 1; /* goto comment */
|
2007-10-28 00:50:55 +08:00
|
|
|
pnmscanner_getchar (s);
|
2006-02-04 09:02:25 +08:00
|
|
|
}
|
2013-10-04 04:06:24 +08:00
|
|
|
else if (! g_ascii_isspace (s->cur))
|
2007-10-28 00:50:55 +08:00
|
|
|
{
|
|
|
|
state = -1;
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
else
|
2007-10-28 00:50:55 +08:00
|
|
|
{
|
|
|
|
pnmscanner_getchar (s);
|
|
|
|
}
|
2006-02-04 09:02:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* in comment */
|
|
|
|
if (s->cur == '\n')
|
|
|
|
state = 0; /* goto whitespace */
|
|
|
|
pnmscanner_getchar (s);
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|