2005-01-26 03:11:26 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
2002-03-28 07:15:00 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpscanner.c
|
|
|
|
* Copyright (C) 2002 Sven Neumann <sven@gimp.org>
|
|
|
|
* Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2005-01-26 03:11:26 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2002-03-28 07:15:00 +08:00
|
|
|
*
|
2005-01-26 03:11:26 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2002-03-28 07:15:00 +08:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-01-26 03:11:26 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
2002-03-28 07:15:00 +08:00
|
|
|
*
|
2005-01-26 03:11:26 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2002-03-28 07:15:00 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-09-07 06:25:19 +08:00
|
|
|
#include <string.h>
|
2002-05-31 21:58:18 +08:00
|
|
|
#include <errno.h>
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2003-07-08 00:22:45 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2002-05-31 21:58:18 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2003-07-08 00:22:45 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2002-05-31 21:58:18 +08:00
|
|
|
|
2003-07-24 22:14:23 +08:00
|
|
|
#include "gimpconfig-error.h"
|
2002-03-28 07:15:00 +08:00
|
|
|
#include "gimpscanner.h"
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimp/libgimp-intl.h"
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
|
2003-06-24 19:46:19 +08:00
|
|
|
typedef struct
|
|
|
|
{
|
2005-09-29 02:48:42 +08:00
|
|
|
gchar *name;
|
|
|
|
GMappedFile *file;
|
|
|
|
GError **error;
|
2003-06-24 19:46:19 +08:00
|
|
|
} GimpScannerData;
|
|
|
|
|
|
|
|
|
2002-05-31 21:58:18 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2003-06-24 19:46:19 +08:00
|
|
|
static GScanner * gimp_scanner_new (const gchar *name,
|
2005-09-29 02:48:42 +08:00
|
|
|
GMappedFile *file,
|
2003-06-24 19:46:19 +08:00
|
|
|
GError **error);
|
|
|
|
static void gimp_scanner_message (GScanner *scanner,
|
|
|
|
gchar *message,
|
|
|
|
gboolean is_error);
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_new_file:
|
|
|
|
* @filename:
|
|
|
|
* @error:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
GScanner *
|
2003-06-24 06:02:56 +08:00
|
|
|
gimp_scanner_new_file (const gchar *filename,
|
2006-04-12 18:53:28 +08:00
|
|
|
GError **error)
|
2002-03-28 07:15:00 +08:00
|
|
|
{
|
2005-09-29 02:48:42 +08:00
|
|
|
GScanner *scanner;
|
|
|
|
GMappedFile *file;
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (filename != NULL, NULL);
|
2003-06-24 06:02:56 +08:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
file = g_mapped_file_new (filename, FALSE, error);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
if (! file)
|
2002-05-31 21:58:18 +08:00
|
|
|
{
|
2005-09-29 02:48:42 +08:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
(*error)->domain = GIMP_CONFIG_ERROR;
|
|
|
|
(*error)->code = ((*error)->code == G_FILE_ERROR_NOENT ?
|
|
|
|
GIMP_CONFIG_ERROR_OPEN_ENOENT :
|
|
|
|
GIMP_CONFIG_ERROR_OPEN);
|
|
|
|
}
|
2003-09-23 23:22:30 +08:00
|
|
|
|
2002-05-31 21:58:18 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
/* gimp_scanner_new() takes a "name" for the scanner, not a filename */
|
|
|
|
scanner = gimp_scanner_new (gimp_filename_to_utf8 (filename), file, error);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
g_scanner_input_text (scanner,
|
|
|
|
g_mapped_file_get_contents (file),
|
|
|
|
g_mapped_file_get_length (file));
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
return scanner;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_new_string:
|
|
|
|
* @text:
|
|
|
|
* @text_len:
|
|
|
|
* @error:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2003-06-24 06:02:56 +08:00
|
|
|
GScanner *
|
|
|
|
gimp_scanner_new_string (const gchar *text,
|
2006-04-12 18:53:28 +08:00
|
|
|
gint text_len,
|
|
|
|
GError **error)
|
2003-06-24 06:02:56 +08:00
|
|
|
{
|
|
|
|
GScanner *scanner;
|
|
|
|
|
|
|
|
g_return_val_if_fail (text != NULL || text_len == 0, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
if (text_len < 0)
|
|
|
|
text_len = strlen (text);
|
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
scanner = gimp_scanner_new (NULL, NULL, error);
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
g_scanner_input_text (scanner, text, text_len);
|
|
|
|
|
|
|
|
return scanner;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GScanner *
|
2003-06-24 19:46:19 +08:00
|
|
|
gimp_scanner_new (const gchar *name,
|
2005-09-29 02:48:42 +08:00
|
|
|
GMappedFile *file,
|
2003-06-24 19:46:19 +08:00
|
|
|
GError **error)
|
2003-06-24 06:02:56 +08:00
|
|
|
{
|
2003-06-24 19:46:19 +08:00
|
|
|
GScanner *scanner;
|
|
|
|
GimpScannerData *data;
|
2003-06-24 06:02:56 +08:00
|
|
|
|
|
|
|
scanner = g_scanner_new (NULL);
|
2002-05-31 21:58:18 +08:00
|
|
|
|
2003-06-24 19:46:19 +08:00
|
|
|
data = g_new0 (GimpScannerData, 1);
|
|
|
|
|
|
|
|
data->name = g_strdup (name);
|
2005-09-29 02:48:42 +08:00
|
|
|
data->file = file;
|
2003-06-24 19:46:19 +08:00
|
|
|
data->error = error;
|
|
|
|
|
|
|
|
scanner->user_data = data;
|
2002-05-31 21:58:18 +08:00
|
|
|
scanner->msg_handler = gimp_scanner_message;
|
|
|
|
|
|
|
|
scanner->config->cset_identifier_first = ( G_CSET_a_2_z G_CSET_A_2_Z );
|
2003-02-09 07:48:29 +08:00
|
|
|
scanner->config->cset_identifier_nth = ( G_CSET_a_2_z G_CSET_A_2_Z
|
|
|
|
G_CSET_DIGITS "-_" );
|
2002-05-31 21:58:18 +08:00
|
|
|
scanner->config->scan_identifier_1char = TRUE;
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2003-11-14 21:41:16 +08:00
|
|
|
scanner->config->store_int64 = TRUE;
|
|
|
|
|
2002-03-28 07:15:00 +08:00
|
|
|
return scanner;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_destroy:
|
|
|
|
* @scanner:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
void
|
|
|
|
gimp_scanner_destroy (GScanner *scanner)
|
|
|
|
{
|
2003-06-24 19:46:19 +08:00
|
|
|
GimpScannerData *data;
|
|
|
|
|
2002-03-28 07:15:00 +08:00
|
|
|
g_return_if_fail (scanner != NULL);
|
|
|
|
|
2003-06-24 19:46:19 +08:00
|
|
|
data = scanner->user_data;
|
|
|
|
|
2005-09-29 02:48:42 +08:00
|
|
|
if (data->file)
|
|
|
|
g_mapped_file_free (data->file);
|
2003-06-24 19:46:19 +08:00
|
|
|
|
|
|
|
g_free (data->name);
|
|
|
|
g_free (data);
|
|
|
|
|
2002-03-28 07:15:00 +08:00
|
|
|
g_scanner_destroy (scanner);
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_token:
|
|
|
|
* @scanner:
|
|
|
|
* @token:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_token (GScanner *scanner,
|
|
|
|
GTokenType token)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != token)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_identifier:
|
|
|
|
* @scanner:
|
|
|
|
* @identifier:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-05-24 10:53:20 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_identifier (GScanner *scanner,
|
|
|
|
const gchar *identifier)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_IDENTIFIER)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
if (strcmp (scanner->value.v_identifier, identifier))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_string:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_string (GScanner *scanner,
|
|
|
|
gchar **dest)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
if (*scanner->value.v_string)
|
|
|
|
{
|
|
|
|
if (! g_utf8_validate (scanner->value.v_string, -1, NULL))
|
|
|
|
{
|
|
|
|
g_scanner_warn (scanner, _("invalid UTF-8 string"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-14 21:41:16 +08:00
|
|
|
|
2002-03-28 07:15:00 +08:00
|
|
|
*dest = g_strdup (scanner->value.v_string);
|
|
|
|
}
|
2003-02-03 22:48:39 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*dest = NULL;
|
|
|
|
}
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_string_no_validate:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_string_no_validate (GScanner *scanner,
|
|
|
|
gchar **dest)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
if (*scanner->value.v_string)
|
|
|
|
*dest = g_strdup (scanner->value.v_string);
|
2003-02-03 22:48:39 +08:00
|
|
|
else
|
|
|
|
*dest = NULL;
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_data:
|
|
|
|
* @scanner:
|
|
|
|
* @length:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2004-05-19 05:19:43 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_data (GScanner *scanner,
|
|
|
|
gint length,
|
|
|
|
guint8 **dest)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_STRING)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
if (scanner->value.v_string)
|
|
|
|
*dest = g_memdup (scanner->value.v_string, length);
|
|
|
|
else
|
|
|
|
*dest = NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_int:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_int (GScanner *scanner,
|
|
|
|
gint *dest)
|
|
|
|
{
|
2003-02-03 22:48:39 +08:00
|
|
|
gboolean negate = FALSE;
|
|
|
|
|
|
|
|
if (g_scanner_peek_next_token (scanner) == '-')
|
|
|
|
{
|
|
|
|
negate = TRUE;
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
}
|
|
|
|
|
2002-03-28 07:15:00 +08:00
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_INT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
2003-02-03 22:48:39 +08:00
|
|
|
if (negate)
|
2003-11-14 21:41:16 +08:00
|
|
|
*dest = -scanner->value.v_int64;
|
2003-02-03 22:48:39 +08:00
|
|
|
else
|
2003-11-14 21:41:16 +08:00
|
|
|
*dest = scanner->value.v_int64;
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_float:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-03-28 07:15:00 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_float (GScanner *scanner,
|
|
|
|
gdouble *dest)
|
|
|
|
{
|
|
|
|
if (g_scanner_peek_next_token (scanner) != G_TOKEN_FLOAT)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
*dest = scanner->value.v_float;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLOR_RGB = 1,
|
|
|
|
COLOR_RGBA,
|
|
|
|
COLOR_HSV,
|
|
|
|
COLOR_HSVA
|
|
|
|
};
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_color:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2002-05-31 21:58:18 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_color (GScanner *scanner,
|
|
|
|
GimpRGB *dest)
|
|
|
|
{
|
|
|
|
guint scope_id;
|
|
|
|
guint old_scope_id;
|
|
|
|
GTokenType token;
|
2002-06-03 03:48:01 +08:00
|
|
|
GimpRGB color;
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
scope_id = g_quark_from_static_string ("gimp_scanner_parse_color");
|
|
|
|
old_scope_id = g_scanner_set_scope (scanner, scope_id);
|
|
|
|
|
|
|
|
if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "color-rgb"))
|
|
|
|
{
|
2004-07-27 03:56:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id,
|
2002-05-31 21:58:18 +08:00
|
|
|
"color-rgb", GINT_TO_POINTER (COLOR_RGB));
|
2004-07-27 03:56:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id,
|
2002-05-31 21:58:18 +08:00
|
|
|
"color-rgba", GINT_TO_POINTER (COLOR_RGBA));
|
2004-07-27 03:56:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id,
|
2002-05-31 21:58:18 +08:00
|
|
|
"color-hsv", GINT_TO_POINTER (COLOR_HSV));
|
2004-07-27 03:56:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id,
|
2002-05-31 21:58:18 +08:00
|
|
|
"color-hsva", GINT_TO_POINTER (COLOR_HSVA));
|
|
|
|
}
|
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
{
|
|
|
|
gdouble col[4] = { 0.0, 0.0, 0.0, 1.0 };
|
|
|
|
gint n_channels = 4;
|
|
|
|
gboolean is_hsv = FALSE;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
switch (GPOINTER_TO_INT (scanner->value.v_symbol))
|
|
|
|
{
|
|
|
|
case COLOR_RGB:
|
|
|
|
n_channels = 3;
|
|
|
|
/* fallthrough */
|
|
|
|
case COLOR_RGBA:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COLOR_HSV:
|
|
|
|
n_channels = 3;
|
|
|
|
/* fallthrough */
|
|
|
|
case COLOR_HSVA:
|
|
|
|
is_hsv = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
token = G_TOKEN_FLOAT;
|
|
|
|
|
|
|
|
for (i = 0; i < n_channels; i++)
|
|
|
|
{
|
|
|
|
if (! gimp_scanner_parse_float (scanner, &col[i]))
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_hsv)
|
|
|
|
{
|
|
|
|
GimpHSV hsv;
|
|
|
|
|
|
|
|
gimp_hsva_set (&hsv, col[0], col[1], col[2], col[3]);
|
|
|
|
gimp_hsv_clamp (&hsv);
|
|
|
|
|
|
|
|
gimp_hsv_to_rgb (&hsv, &color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_rgba_set (&color, col[0], col[1], col[2], col[3]);
|
|
|
|
gimp_rgb_clamp (&color);
|
|
|
|
}
|
2003-07-08 00:22:45 +08:00
|
|
|
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
2002-05-31 21:58:18 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
2002-06-03 03:48:01 +08:00
|
|
|
token = G_TOKEN_NONE; /* indicates success */
|
2002-05-31 21:58:18 +08:00
|
|
|
goto finish;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
2002-06-03 03:48:01 +08:00
|
|
|
if (token != G_TOKEN_NONE)
|
2002-05-31 21:58:18 +08:00
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
|
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
}
|
2002-06-03 03:48:01 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*dest = color;
|
|
|
|
}
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
g_scanner_set_scope (scanner, old_scope_id);
|
|
|
|
|
2002-06-03 03:48:01 +08:00
|
|
|
return (token == G_TOKEN_NONE);
|
|
|
|
}
|
|
|
|
|
2005-01-29 20:54:48 +08:00
|
|
|
/**
|
|
|
|
* gimp_scanner_parse_matrix2:
|
|
|
|
* @scanner:
|
|
|
|
* @dest:
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.4
|
|
|
|
**/
|
2003-07-08 00:22:45 +08:00
|
|
|
gboolean
|
|
|
|
gimp_scanner_parse_matrix2 (GScanner *scanner,
|
|
|
|
GimpMatrix2 *dest)
|
|
|
|
{
|
|
|
|
guint scope_id;
|
|
|
|
guint old_scope_id;
|
|
|
|
GTokenType token;
|
|
|
|
GimpMatrix2 matrix;
|
|
|
|
|
|
|
|
scope_id = g_quark_from_static_string ("gimp_scanner_parse_matrix");
|
|
|
|
old_scope_id = g_scanner_set_scope (scanner, scope_id);
|
|
|
|
|
|
|
|
if (! g_scanner_scope_lookup_symbol (scanner, scope_id, "matrix"))
|
2004-11-14 10:50:33 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, scope_id,
|
|
|
|
"matrix", GINT_TO_POINTER (0));
|
2003-07-08 00:22:45 +08:00
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
{
|
|
|
|
token = G_TOKEN_FLOAT;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][0]))
|
|
|
|
goto finish;
|
|
|
|
if (! gimp_scanner_parse_float (scanner, &matrix.coeff[0][1]))
|
|
|
|
goto finish;
|
|
|
|
if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][0]))
|
|
|
|
goto finish;
|
|
|
|
if (! gimp_scanner_parse_float (scanner, &matrix.coeff[1][1]))
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_NONE; /* indicates success */
|
|
|
|
goto finish;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
if (token != G_TOKEN_NONE)
|
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
|
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*dest = matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_scanner_set_scope (scanner, old_scope_id);
|
|
|
|
|
|
|
|
return (token == G_TOKEN_NONE);
|
|
|
|
}
|
|
|
|
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_scanner_message (GScanner *scanner,
|
|
|
|
gchar *message,
|
|
|
|
gboolean is_error)
|
|
|
|
{
|
2003-06-24 19:46:19 +08:00
|
|
|
GimpScannerData *data = scanner->user_data;
|
2002-05-31 21:58:18 +08:00
|
|
|
|
|
|
|
/* we don't expect warnings */
|
|
|
|
g_return_if_fail (is_error);
|
|
|
|
|
2003-06-24 19:46:19 +08:00
|
|
|
if (data->name)
|
2003-11-14 23:33:40 +08:00
|
|
|
g_set_error (data->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
|
|
|
|
_("Error while parsing '%s' in line %d: %s"),
|
2003-06-24 19:46:19 +08:00
|
|
|
data->name, scanner->line, message);
|
2003-06-24 06:02:56 +08:00
|
|
|
else
|
2003-06-24 19:46:19 +08:00
|
|
|
/* should never happen, thus not marked for translation */
|
2003-11-14 23:33:40 +08:00
|
|
|
g_set_error (data->error, GIMP_CONFIG_ERROR, GIMP_CONFIG_ERROR_PARSE,
|
|
|
|
"Error parsing internal buffer: %s", message);
|
2002-05-31 21:58:18 +08:00
|
|
|
}
|