2012-05-03 09:36:22 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimppixbuf.c
|
|
|
|
* Copyright (C) 2012 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* 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 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2012-05-03 09:36:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gegl.h>
|
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
|
|
|
|
#include "gimpcolortypes.h"
|
|
|
|
|
|
|
|
#include "gimppixbuf.h"
|
|
|
|
|
|
|
|
|
2015-06-01 03:18:09 +08:00
|
|
|
/**
|
|
|
|
* SECTION: gimppixbuf
|
|
|
|
* @title: GimpPixbuf
|
|
|
|
* @short_description: Definitions and Functions relating to GdkPixbuf.
|
|
|
|
*
|
|
|
|
* Definitions and Functions relating to GdkPixbuf.
|
|
|
|
**/
|
|
|
|
|
2012-05-03 09:36:22 +08:00
|
|
|
/**
|
|
|
|
* gimp_pixbuf_get_format:
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
|
|
|
*
|
|
|
|
* Returns the Babl format that corresponds to the @pixbuf's pixel format.
|
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the @pixbuf's pixel format
|
2012-05-03 09:36:22 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2012-05-03 09:36:22 +08:00
|
|
|
**/
|
|
|
|
const Babl *
|
|
|
|
gimp_pixbuf_get_format (GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
|
|
|
switch (gdk_pixbuf_get_n_channels (pixbuf))
|
|
|
|
{
|
|
|
|
case 3: return babl_format ("R'G'B' u8");
|
|
|
|
case 4: return babl_format ("R'G'B'A u8");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pixbuf_create_buffer:
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
|
|
|
*
|
2014-02-21 01:20:17 +08:00
|
|
|
* Returns a #GeglBuffer that's either backed by the @pixbuf's pixels,
|
|
|
|
* or a copy of them. This function tries to not copy the @pixbuf's
|
|
|
|
* pixels. If the pixbuf's rowstride is a multiple of its bpp, a
|
|
|
|
* simple reference to the @pixbuf's pixels is made and @pixbuf will
|
|
|
|
* be kept around for as long as the buffer exists; otherwise the
|
|
|
|
* pixels are copied.
|
2012-05-03 09:36:22 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: (transfer full): a new #GeglBuffer.
|
2012-05-03 09:36:22 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.10
|
2012-05-03 09:36:22 +08:00
|
|
|
**/
|
|
|
|
GeglBuffer *
|
|
|
|
gimp_pixbuf_create_buffer (GdkPixbuf *pixbuf)
|
|
|
|
{
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint rowstride;
|
2014-02-21 01:20:17 +08:00
|
|
|
gint bpp;
|
2012-05-03 09:36:22 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
|
|
|
|
width = gdk_pixbuf_get_width (pixbuf);
|
|
|
|
height = gdk_pixbuf_get_height (pixbuf);
|
|
|
|
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
|
2014-02-21 01:20:17 +08:00
|
|
|
bpp = gdk_pixbuf_get_n_channels (pixbuf);
|
2012-05-03 09:36:22 +08:00
|
|
|
|
2014-02-21 01:20:17 +08:00
|
|
|
if ((rowstride % bpp) == 0)
|
|
|
|
{
|
|
|
|
return gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
gimp_pixbuf_get_format (pixbuf),
|
|
|
|
GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height),
|
|
|
|
rowstride,
|
|
|
|
(GDestroyNotify) g_object_unref,
|
|
|
|
g_object_ref (pixbuf));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GeglBuffer *buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height),
|
|
|
|
gimp_pixbuf_get_format (pixbuf));
|
|
|
|
|
|
|
|
gegl_buffer_set (buffer, NULL, 0, NULL,
|
|
|
|
gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf));
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2012-05-03 09:36:22 +08:00
|
|
|
}
|
2015-06-17 05:43:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pixbuf_get_icc_profile:
|
|
|
|
* @pixbuf: a #GdkPixbuf
|
2020-05-04 08:10:55 +08:00
|
|
|
* @length: (out): return location for the ICC profile's length
|
2015-06-17 05:43:40 +08:00
|
|
|
*
|
|
|
|
* Returns the ICC profile attached to the @pixbuf, or %NULL if there
|
|
|
|
* is none.
|
|
|
|
*
|
2020-05-04 08:10:55 +08:00
|
|
|
* Returns: (array length=length) (nullable): The ICC profile data, or %NULL.
|
2019-08-03 06:36:59 +08:00
|
|
|
* The value should be freed with g_free().
|
2015-06-17 05:43:40 +08:00
|
|
|
*
|
|
|
|
* Since: 2.10
|
|
|
|
**/
|
|
|
|
guint8 *
|
|
|
|
gimp_pixbuf_get_icc_profile (GdkPixbuf *pixbuf,
|
|
|
|
gsize *length)
|
|
|
|
{
|
2015-06-30 18:01:06 +08:00
|
|
|
const gchar *icc_base64;
|
2015-06-17 05:43:40 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
|
|
|
|
g_return_val_if_fail (length != NULL, NULL);
|
|
|
|
|
2015-06-30 18:01:06 +08:00
|
|
|
icc_base64 = gdk_pixbuf_get_option (pixbuf, "icc-profile");
|
2015-06-17 05:43:40 +08:00
|
|
|
|
|
|
|
if (icc_base64)
|
|
|
|
{
|
|
|
|
guint8 *icc_data;
|
|
|
|
|
|
|
|
icc_data = g_base64_decode (icc_base64, length);
|
|
|
|
|
|
|
|
return icc_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|