1 /* LIBGIMP - The GIMP Library
2 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
5 * Copyright (C) 2012 Michael Natterer <mitch@gimp.org>
7 * This library is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library. If not, see
19 * <https://www.gnu.org/licenses/>.
25 #include <gdk-pixbuf/gdk-pixbuf.h>
27 #include "gimpcolortypes.h"
29 #include "gimppixbuf.h"
35 * @short_description: Definitions and Functions relating to GdkPixbuf.
37 * Definitions and Functions relating to GdkPixbuf.
41 * gimp_pixbuf_get_format:
42 * @pixbuf: a #GdkPixbuf
44 * Returns the Babl format that corresponds to the @pixbuf's pixel format.
46 * Return value: the @pixbuf's pixel format
51 gimp_pixbuf_get_format (GdkPixbuf
*pixbuf
)
53 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf
), NULL
);
55 switch (gdk_pixbuf_get_n_channels (pixbuf
))
57 case 3: return babl_format ("R'G'B' u8");
58 case 4: return babl_format ("R'G'B'A u8");
61 g_return_val_if_reached (NULL
);
65 * gimp_pixbuf_create_buffer:
66 * @pixbuf: a #GdkPixbuf
68 * Returns a #GeglBuffer that's either backed by the @pixbuf's pixels,
69 * or a copy of them. This function tries to not copy the @pixbuf's
70 * pixels. If the pixbuf's rowstride is a multiple of its bpp, a
71 * simple reference to the @pixbuf's pixels is made and @pixbuf will
72 * be kept around for as long as the buffer exists; otherwise the
75 * Return value: a new #GeglBuffer.
80 gimp_pixbuf_create_buffer (GdkPixbuf
*pixbuf
)
87 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf
), NULL
);
89 width
= gdk_pixbuf_get_width (pixbuf
);
90 height
= gdk_pixbuf_get_height (pixbuf
);
91 rowstride
= gdk_pixbuf_get_rowstride (pixbuf
);
92 bpp
= gdk_pixbuf_get_n_channels (pixbuf
);
94 if ((rowstride
% bpp
) == 0)
96 return gegl_buffer_linear_new_from_data (gdk_pixbuf_get_pixels (pixbuf
),
97 gimp_pixbuf_get_format (pixbuf
),
101 (GDestroyNotify
) g_object_unref
,
102 g_object_ref (pixbuf
));
106 GeglBuffer
*buffer
= gegl_buffer_new (GEGL_RECTANGLE (0, 0,
108 gimp_pixbuf_get_format (pixbuf
));
110 gegl_buffer_set (buffer
, NULL
, 0, NULL
,
111 gdk_pixbuf_get_pixels (pixbuf
),
112 gdk_pixbuf_get_rowstride (pixbuf
));
119 * gimp_pixbuf_get_icc_profile:
120 * @pixbuf: a #GdkPixbuf
121 * @length: return location for the ICC profile's length
123 * Returns the ICC profile attached to the @pixbuf, or %NULL if there
126 * Return value: The ICC profile data, or %NULL. The value should be freed
132 gimp_pixbuf_get_icc_profile (GdkPixbuf
*pixbuf
,
135 const gchar
*icc_base64
;
137 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf
), NULL
);
138 g_return_val_if_fail (length
!= NULL
, NULL
);
140 icc_base64
= gdk_pixbuf_get_option (pixbuf
, "icc-profile");
146 icc_data
= g_base64_decode (icc_base64
, length
);