2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-03-24 12:21:58 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-03-24 12:21:58 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-03-24 12:21:58 +00: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-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-03-24 12:21:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-04-15 16:52:25 +01:00
|
|
|
#include <cairo.h>
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-03-24 12:21:58 +00:00
|
|
|
|
2016-04-15 16:52:25 +01:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2003-03-24 12:21:58 +00:00
|
|
|
#include "core-types.h"
|
|
|
|
|
2012-04-28 15:18:55 +02:00
|
|
|
#include "gegl/gimp-babl.h"
|
2016-04-15 16:52:25 +01:00
|
|
|
#include "gegl/gimp-gegl-loops.h"
|
2012-04-28 15:18:55 +02:00
|
|
|
|
2003-03-24 12:21:58 +00:00
|
|
|
#include "gimpimage.h"
|
2016-04-15 16:52:25 +01:00
|
|
|
#include "gimpimage-color-profile.h"
|
2003-03-24 12:21:58 +00:00
|
|
|
#include "gimpimage-preview.h"
|
2012-06-20 21:44:09 +02:00
|
|
|
#include "gimppickable.h"
|
2012-04-22 00:42:00 +02:00
|
|
|
#include "gimpprojectable.h"
|
2007-06-07 14:25:28 +00:00
|
|
|
#include "gimpprojection.h"
|
2012-04-09 00:59:20 +02:00
|
|
|
#include "gimptempbuf.h"
|
2003-03-24 12:21:58 +00:00
|
|
|
|
|
|
|
|
2019-11-04 12:42:34 +02:00
|
|
|
const Babl *
|
|
|
|
gimp_image_get_preview_format (GimpImage *image)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
|
|
|
|
switch (gimp_image_get_base_type (image))
|
|
|
|
{
|
|
|
|
case GIMP_RGB:
|
|
|
|
case GIMP_GRAY:
|
2025-02-02 18:44:26 +00:00
|
|
|
return gimp_projectable_get_format (GIMP_PROJECTABLE (image));
|
2019-11-04 12:42:34 +02:00
|
|
|
|
|
|
|
case GIMP_INDEXED:
|
|
|
|
return babl_format ("R'G'B'A u8");
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
}
|
|
|
|
|
2003-03-24 12:21:58 +00:00
|
|
|
void
|
|
|
|
gimp_image_get_preview_size (GimpViewable *viewable,
|
|
|
|
gint size,
|
|
|
|
gboolean is_popup,
|
|
|
|
gboolean dot_for_dot,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image = GIMP_IMAGE (viewable);
|
2007-12-26 17:33:41 +00:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2003-03-24 12:21:58 +00:00
|
|
|
|
2007-12-25 16:21:40 +00:00
|
|
|
gimp_viewable_calc_preview_size (gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
2003-03-24 12:21:58 +00:00
|
|
|
size,
|
|
|
|
size,
|
|
|
|
dot_for_dot,
|
2007-12-26 17:33:41 +00:00
|
|
|
xres,
|
|
|
|
yres,
|
2003-03-24 12:21:58 +00:00
|
|
|
width,
|
|
|
|
height,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_image_get_popup_size (GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gboolean dot_for_dot,
|
|
|
|
gint *popup_width,
|
|
|
|
gint *popup_height)
|
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image = GIMP_IMAGE (viewable);
|
2003-03-24 12:21:58 +00:00
|
|
|
|
2007-12-25 16:21:40 +00:00
|
|
|
if (gimp_image_get_width (image) > width ||
|
|
|
|
gimp_image_get_height (image) > height)
|
2003-03-24 12:21:58 +00:00
|
|
|
{
|
|
|
|
gboolean scaling_up;
|
|
|
|
|
2007-12-25 16:21:40 +00:00
|
|
|
gimp_viewable_calc_preview_size (gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image),
|
2003-10-09 12:26:46 +00:00
|
|
|
width * 2,
|
|
|
|
height * 2,
|
2003-03-24 12:21:58 +00:00
|
|
|
dot_for_dot, 1.0, 1.0,
|
|
|
|
popup_width,
|
|
|
|
popup_height,
|
|
|
|
&scaling_up);
|
|
|
|
|
|
|
|
if (scaling_up)
|
|
|
|
{
|
2007-12-25 16:21:40 +00:00
|
|
|
*popup_width = gimp_image_get_width (image);
|
|
|
|
*popup_height = gimp_image_get_height (image);
|
2003-03-24 12:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-04-08 20:25:49 +02:00
|
|
|
GimpTempBuf *
|
2003-03-24 12:21:58 +00:00
|
|
|
gimp_image_get_new_preview (GimpViewable *viewable,
|
2006-08-29 21:44:51 +00:00
|
|
|
GimpContext *context,
|
2006-04-12 12:49:29 +00:00
|
|
|
gint width,
|
2025-04-22 20:33:49 +02:00
|
|
|
gint height,
|
2025-08-18 08:08:12 +02:00
|
|
|
GeglColor *fg_color G_GNUC_UNUSED)
|
2003-03-24 12:21:58 +00:00
|
|
|
{
|
2013-09-13 23:29:06 +02:00
|
|
|
GimpImage *image = GIMP_IMAGE (viewable);
|
|
|
|
const Babl *format;
|
|
|
|
GimpTempBuf *buf;
|
|
|
|
gdouble scale_x;
|
|
|
|
gdouble scale_y;
|
2003-03-24 12:21:58 +00:00
|
|
|
|
2007-12-25 16:21:40 +00:00
|
|
|
scale_x = (gdouble) width / (gdouble) gimp_image_get_width (image);
|
|
|
|
scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image);
|
2003-03-24 12:21:58 +00:00
|
|
|
|
2019-11-04 12:42:34 +02:00
|
|
|
format = gimp_image_get_preview_format (image);
|
2012-04-28 15:18:55 +02:00
|
|
|
|
2012-06-20 21:44:09 +02:00
|
|
|
buf = gimp_temp_buf_new (width, height, format);
|
2007-12-13 17:27:07 +00:00
|
|
|
|
2013-09-13 23:29:06 +02:00
|
|
|
gegl_buffer_get (gimp_pickable_get_buffer (GIMP_PICKABLE (image)),
|
2012-06-20 21:44:09 +02:00
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
MIN (scale_x, scale_y),
|
|
|
|
gimp_temp_buf_get_format (buf),
|
|
|
|
gimp_temp_buf_get_data (buf),
|
2014-03-09 10:49:46 -07:00
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
|
2007-12-13 17:27:07 +00:00
|
|
|
|
|
|
|
return buf;
|
2003-03-24 12:21:58 +00:00
|
|
|
}
|
2016-04-15 16:52:25 +01:00
|
|
|
|
|
|
|
GdkPixbuf *
|
|
|
|
gimp_image_get_new_pixbuf (GimpViewable *viewable,
|
|
|
|
GimpContext *context,
|
|
|
|
gint width,
|
2025-04-22 20:33:49 +02:00
|
|
|
gint height,
|
2025-08-18 08:08:12 +02:00
|
|
|
GeglColor *fg_color G_GNUC_UNUSED)
|
2016-04-15 16:52:25 +01:00
|
|
|
{
|
|
|
|
GimpImage *image = GIMP_IMAGE (viewable);
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
gdouble scale_x;
|
|
|
|
gdouble scale_y;
|
2016-05-25 21:35:54 +02:00
|
|
|
GimpColorTransform *transform;
|
2016-04-15 16:52:25 +01:00
|
|
|
|
|
|
|
scale_x = (gdouble) width / (gdouble) gimp_image_get_width (image);
|
|
|
|
scale_y = (gdouble) height / (gdouble) gimp_image_get_height (image);
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
|
|
|
|
width, height);
|
|
|
|
|
2016-05-25 21:35:54 +02:00
|
|
|
transform = gimp_image_get_color_transform_to_srgb_u8 (image);
|
2016-04-15 16:52:25 +01:00
|
|
|
|
|
|
|
if (transform)
|
|
|
|
{
|
|
|
|
GimpTempBuf *temp_buf;
|
|
|
|
GeglBuffer *src_buf;
|
|
|
|
GeglBuffer *dest_buf;
|
|
|
|
|
2016-05-25 21:35:54 +02:00
|
|
|
temp_buf = gimp_temp_buf_new (width, height,
|
|
|
|
gimp_pickable_get_format (GIMP_PICKABLE (image)));
|
2016-04-15 16:52:25 +01:00
|
|
|
|
|
|
|
gegl_buffer_get (gimp_pickable_get_buffer (GIMP_PICKABLE (image)),
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
MIN (scale_x, scale_y),
|
|
|
|
gimp_temp_buf_get_format (temp_buf),
|
|
|
|
gimp_temp_buf_get_data (temp_buf),
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP);
|
|
|
|
|
|
|
|
src_buf = gimp_temp_buf_create_buffer (temp_buf);
|
|
|
|
dest_buf = gimp_pixbuf_create_buffer (pixbuf);
|
|
|
|
|
|
|
|
gimp_temp_buf_unref (temp_buf);
|
|
|
|
|
2016-05-25 21:35:54 +02:00
|
|
|
gimp_color_transform_process_buffer (transform,
|
|
|
|
src_buf,
|
|
|
|
GEGL_RECTANGLE (0, 0,
|
|
|
|
width, height),
|
|
|
|
dest_buf,
|
|
|
|
GEGL_RECTANGLE (0, 0, 0, 0));
|
2016-04-15 16:52:25 +01:00
|
|
|
|
|
|
|
g_object_unref (src_buf);
|
|
|
|
g_object_unref (dest_buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gegl_buffer_get (gimp_pickable_get_buffer (GIMP_PICKABLE (image)),
|
|
|
|
GEGL_RECTANGLE (0, 0, width, height),
|
|
|
|
MIN (scale_x, scale_y),
|
|
|
|
gimp_pixbuf_get_format (pixbuf),
|
|
|
|
gdk_pixbuf_get_pixels (pixbuf),
|
|
|
|
gdk_pixbuf_get_rowstride (pixbuf),
|
|
|
|
GEGL_ABYSS_CLAMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pixbuf;
|
|
|
|
}
|