Add support for GdkPixbuf patterns, so now all of png, jpex, pnm, xbm,

2004-06-03  Dave Neary  <bolsh@gimp.org>

        * app/core/gimp.c:
        * app/core/gimpdatafactory.c:
        * app/core/gimppattern.[ch]: Add support for GdkPixbuf patterns,
        so now all of png, jpex, pnm, xbm, bmp, gif, ico, pcx, ras, tga,
        xpm and tiff can be used for patterns.
This commit is contained in:
Dave Neary 2004-06-03 11:03:53 +00:00 committed by David Neary
parent 421b2a0d0e
commit d088fd3fe1
6 changed files with 221 additions and 13 deletions

View File

@ -1,3 +1,11 @@
2004-06-03 Dave Neary <bolsh@gimp.org>
* app/core/gimp.c:
* app/core/gimpdatafactory.c:
* app/core/gimppattern.[ch]: Add support for GdkPixbuf patterns,
so now all of png, jpex, pnm, xbm, bmp, gif, ico, pcx, ras, tga,
xpm and tiff can be used for patterns.
2004-06-03 Michael Natterer <mitch@gimp.org>
* app/actions/vectors-actions.c: added alternative actions

View File

@ -567,19 +567,20 @@ gimp_real_initialize (Gimp *gimp,
static const GimpDataFactoryLoaderEntry pattern_loader_entries[] =
{
{ gimp_pattern_load, GIMP_PATTERN_FILE_EXTENSION }
{ gimp_pattern_native_load, GIMP_PATTERN_FILE_EXTENSION },
{ gimp_pattern_load, NULL /* Fallback - try to load all files */ }
};
static const GimpDataFactoryLoaderEntry gradient_loader_entries[] =
{
{ gimp_gradient_load, GIMP_GRADIENT_FILE_EXTENSION },
{ gimp_gradient_load, NULL /* legacy loader */ }
{ gimp_gradient_load, NULL /* fallback loader */ }
};
static const GimpDataFactoryLoaderEntry palette_loader_entries[] =
{
{ gimp_palette_load, GIMP_PALETTE_FILE_EXTENSION },
{ gimp_palette_load, NULL /* legacy loader */ }
{ gimp_palette_load, NULL /* fallback loader */ }
};
if (gimp->be_verbose)

View File

@ -579,10 +579,12 @@ gimp_data_factory_load_data (const GimpDatafileData *file_data,
}
else
{
g_message (_("Trying legacy loader on file '%s' "
"with unknown extension."),
gimp_filename_to_utf8 (file_data->filename));
goto insert;
/*
g_message (_("Trying fallback loader on file '%s' "
"with unknown extension."),
gimp_filename_to_utf8 (file_data->filename));
*/
goto insert;
}
}

View File

@ -307,9 +307,9 @@ gimp_pattern_get_standard (void)
}
GimpData *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
gimp_pattern_native_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpPattern *pattern = NULL;
gint fd;
@ -437,6 +437,103 @@ gimp_pattern_load (const gchar *filename,
return NULL;
}
GimpData *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpPattern *pattern = NULL;
GdkPixbuf *pat_buf = NULL;
guchar *pat_data, *buf_data;
gchar *name = NULL;
gint width,
height,
bytes,
rowstride,
i;
gchar *utf8_filename;
gsize filename_length;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
pat_buf = gdk_pixbuf_new_from_file (filename, error);
if (*error)
{
if ((*error)->domain == G_FILE_ERROR)
g_message (_("Could not open file %s: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
else if ((*error)->domain == GDK_PIXBUF_ERROR)
g_message (_("Filename %s is not a valid GdkPixbuf: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
return NULL;
}
/* Read in the pattern name -
First try to get a "comment" option, this could be set for pnm,
jpeg and gif (it isn't yet)
Then try the tEXt option, which is set for pngs,
Then fall back to filename
*/
utf8_filename = g_filename_to_utf8 (filename, -1, NULL, &filename_length,
error);
if (*error)
{
g_message (_("Problem converting filename to UTF8: %s"),
(*error)->message);
utf8_filename = "Unnamed";
g_clear_error (error);
}
name = g_strdup (gdk_pixbuf_get_option (pat_buf, "comment"));
if (name == NULL)
name = g_strdup (gdk_pixbuf_get_option (pat_buf, "tEXt"));
if (name == NULL)
name = g_strdup (utf8_filename);
pattern = g_object_new (GIMP_TYPE_PATTERN,
"name", name,
NULL);
g_free (name);
g_free (utf8_filename);
width = gdk_pixbuf_get_width (pat_buf);
height = gdk_pixbuf_get_height (pat_buf);
bytes = gdk_pixbuf_get_n_channels (pat_buf);
rowstride = gdk_pixbuf_get_rowstride (pat_buf);
pattern->mask = temp_buf_new (width, height, bytes,
0, 0, NULL);
pat_data = gdk_pixbuf_get_pixels (pat_buf);
buf_data = temp_buf_data (pattern->mask);
for (i = 0; i < height; i++)
{
memcpy(buf_data + i * width * bytes, pat_data, width * bytes);
pat_data += rowstride;
}
/* Free up loaded Pixbuf */
g_object_unref (pat_buf);
/* Swap the pattern to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
}
TempBuf *
gimp_pattern_get_mask (const GimpPattern *pattern)
{

View File

@ -307,9 +307,9 @@ gimp_pattern_get_standard (void)
}
GimpData *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
gimp_pattern_native_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpPattern *pattern = NULL;
gint fd;
@ -437,6 +437,103 @@ gimp_pattern_load (const gchar *filename,
return NULL;
}
GimpData *
gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error)
{
GimpPattern *pattern = NULL;
GdkPixbuf *pat_buf = NULL;
guchar *pat_data, *buf_data;
gchar *name = NULL;
gint width,
height,
bytes,
rowstride,
i;
gchar *utf8_filename;
gsize filename_length;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (filename), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
pat_buf = gdk_pixbuf_new_from_file (filename, error);
if (*error)
{
if ((*error)->domain == G_FILE_ERROR)
g_message (_("Could not open file %s: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
else if ((*error)->domain == GDK_PIXBUF_ERROR)
g_message (_("Filename %s is not a valid GdkPixbuf: %s"),
gimp_filename_to_utf8 (filename),
(*error)->message);
return NULL;
}
/* Read in the pattern name -
First try to get a "comment" option, this could be set for pnm,
jpeg and gif (it isn't yet)
Then try the tEXt option, which is set for pngs,
Then fall back to filename
*/
utf8_filename = g_filename_to_utf8 (filename, -1, NULL, &filename_length,
error);
if (*error)
{
g_message (_("Problem converting filename to UTF8: %s"),
(*error)->message);
utf8_filename = "Unnamed";
g_clear_error (error);
}
name = g_strdup (gdk_pixbuf_get_option (pat_buf, "comment"));
if (name == NULL)
name = g_strdup (gdk_pixbuf_get_option (pat_buf, "tEXt"));
if (name == NULL)
name = g_strdup (utf8_filename);
pattern = g_object_new (GIMP_TYPE_PATTERN,
"name", name,
NULL);
g_free (name);
g_free (utf8_filename);
width = gdk_pixbuf_get_width (pat_buf);
height = gdk_pixbuf_get_height (pat_buf);
bytes = gdk_pixbuf_get_n_channels (pat_buf);
rowstride = gdk_pixbuf_get_rowstride (pat_buf);
pattern->mask = temp_buf_new (width, height, bytes,
0, 0, NULL);
pat_data = gdk_pixbuf_get_pixels (pat_buf);
buf_data = temp_buf_data (pattern->mask);
for (i = 0; i < height; i++)
{
memcpy(buf_data + i * width * bytes, pat_data, width * bytes);
pat_data += rowstride;
}
/* Free up loaded Pixbuf */
g_object_unref (pat_buf);
/* Swap the pattern to disk (if we're being stingy with memory) */
if (stingy_memory_use)
temp_buf_swap (pattern->mask);
return GIMP_DATA (pattern);
}
TempBuf *
gimp_pattern_get_mask (const GimpPattern *pattern)
{

View File

@ -54,6 +54,9 @@ GType gimp_pattern_get_type (void) G_GNUC_CONST;
GimpData * gimp_pattern_new (const gchar *name,
gboolean stingy_memory_use);
GimpData * gimp_pattern_get_standard (void);
GimpData * gimp_pattern_native_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);
GimpData * gimp_pattern_load (const gchar *filename,
gboolean stingy_memory_use,
GError **error);