2001-02-07 10:37:49 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-03-01 11:53:41 +08:00
|
|
|
* gimppreviewrendererimage.c
|
|
|
|
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
|
2001-02-07 10:37:49 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2003-03-24 22:31:59 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-08 11:48:54 +08:00
|
|
|
#include "widgets-types.h"
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/temp-buf.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
#include "gimppreviewrendererimage.h"
|
2001-05-08 11:48:54 +08:00
|
|
|
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_image_class_init (GimpPreviewRendererImageClass *klass);
|
2003-03-04 01:19:30 +08:00
|
|
|
static void gimp_preview_renderer_image_init (GimpPreviewRendererImage *renderer);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static void gimp_preview_renderer_image_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
static GimpPreviewRendererClass *parent_class = NULL;
|
2001-02-07 10:37:49 +08:00
|
|
|
|
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
GType
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_image_get_type (void)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static GType renderer_type = 0;
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
if (! renderer_type)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
static const GTypeInfo renderer_info =
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererImageClass),
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GClassInitFunc) gimp_preview_renderer_image_class_init,
|
2001-10-17 19:33:43 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2003-03-01 11:53:41 +08:00
|
|
|
sizeof (GimpPreviewRendererImage),
|
2001-10-17 19:33:43 +08:00
|
|
|
0, /* n_preallocs */
|
2003-03-01 11:53:41 +08:00
|
|
|
(GInstanceInitFunc) gimp_preview_renderer_image_init,
|
2001-02-07 10:37:49 +08:00
|
|
|
};
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_type = g_type_register_static (GIMP_TYPE_PREVIEW_RENDERER,
|
|
|
|
"GimpPreviewRendererImage",
|
|
|
|
&renderer_info, 0);
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
return renderer_type;
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_image_class_init (GimpPreviewRendererImageClass *klass)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
GimpPreviewRendererClass *renderer_class;
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_class = GIMP_PREVIEW_RENDERER_CLASS (klass);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2001-08-10 22:41:39 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer_class->render = gimp_preview_renderer_image_render;
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_image_init (GimpPreviewRendererImage *renderer)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->channel = -1;
|
2001-05-03 20:26:05 +08:00
|
|
|
}
|
|
|
|
|
2001-02-08 04:35:18 +08:00
|
|
|
static void
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_preview_renderer_image_render (GimpPreviewRenderer *renderer,
|
|
|
|
GtkWidget *widget)
|
2001-02-07 10:37:49 +08:00
|
|
|
{
|
2003-03-24 22:31:59 +08:00
|
|
|
GimpPreviewRendererImage *rendererimage;
|
|
|
|
GimpImage *gimage;
|
|
|
|
gint preview_width;
|
|
|
|
gint preview_height;
|
|
|
|
gboolean scaling_up;
|
|
|
|
TempBuf *render_buf = NULL;
|
|
|
|
|
|
|
|
rendererimage = GIMP_PREVIEW_RENDERER_IMAGE (renderer);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
gimage = GIMP_IMAGE (renderer->viewable);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
gimp_viewable_calc_preview_size (renderer->viewable,
|
2003-02-22 03:03:19 +08:00
|
|
|
gimage->width,
|
|
|
|
gimage->height,
|
2003-03-01 11:53:41 +08:00
|
|
|
renderer->width,
|
|
|
|
renderer->height,
|
|
|
|
renderer->dot_for_dot,
|
2003-02-22 03:03:19 +08:00
|
|
|
gimage->xresolution,
|
|
|
|
gimage->yresolution,
|
|
|
|
&preview_width,
|
|
|
|
&preview_height,
|
|
|
|
&scaling_up);
|
2001-02-07 10:37:49 +08:00
|
|
|
|
|
|
|
if (scaling_up)
|
|
|
|
{
|
|
|
|
TempBuf *temp_buf;
|
|
|
|
|
2003-03-01 11:53:41 +08:00
|
|
|
temp_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
2001-02-07 10:37:49 +08:00
|
|
|
gimage->width,
|
|
|
|
gimage->height);
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (temp_buf)
|
|
|
|
{
|
|
|
|
render_buf = temp_buf_scale (temp_buf, preview_width, preview_height);
|
|
|
|
|
|
|
|
temp_buf_free (temp_buf);
|
|
|
|
}
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-03-01 11:53:41 +08:00
|
|
|
render_buf = gimp_viewable_get_new_preview (renderer->viewable,
|
2001-02-07 10:37:49 +08:00
|
|
|
preview_width,
|
|
|
|
preview_height);
|
|
|
|
}
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (render_buf)
|
2002-05-06 03:17:41 +08:00
|
|
|
{
|
2003-03-24 22:31:59 +08:00
|
|
|
gint component_index = -1;
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
/* xresolution != yresolution */
|
|
|
|
if (preview_width > renderer->width || preview_height > renderer->height)
|
|
|
|
{
|
|
|
|
TempBuf *temp_buf;
|
2002-05-06 03:17:41 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
temp_buf = temp_buf_scale (render_buf,
|
|
|
|
renderer->width, renderer->height);
|
2002-05-06 03:17:41 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
temp_buf_free (render_buf);
|
|
|
|
render_buf = temp_buf;
|
|
|
|
}
|
2002-05-06 03:17:41 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (preview_width < renderer->width)
|
|
|
|
render_buf->x = (renderer->width - preview_width) / 2;
|
2003-03-01 11:53:41 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
if (preview_height < renderer->height)
|
|
|
|
render_buf->y = (renderer->height - preview_height) / 2;
|
2001-02-07 10:37:49 +08:00
|
|
|
|
2003-03-24 22:31:59 +08:00
|
|
|
if (rendererimage->channel != -1)
|
|
|
|
component_index =
|
|
|
|
gimp_image_get_component_index (gimage, rendererimage->channel);
|
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
gimp_preview_renderer_render_buffer (renderer, render_buf,
|
2003-03-24 22:31:59 +08:00
|
|
|
component_index,
|
2003-03-07 00:47:34 +08:00
|
|
|
GIMP_PREVIEW_BG_CHECKS,
|
|
|
|
GIMP_PREVIEW_BG_WHITE);
|
2001-02-08 04:35:18 +08:00
|
|
|
|
2003-03-07 00:47:34 +08:00
|
|
|
temp_buf_free (render_buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const gchar *stock_id;
|
|
|
|
|
2003-03-24 22:31:59 +08:00
|
|
|
switch (rendererimage->channel)
|
|
|
|
{
|
|
|
|
case GIMP_RED_CHANNEL: stock_id = GIMP_STOCK_CHANNEL_RED; break;
|
|
|
|
case GIMP_GREEN_CHANNEL: stock_id = GIMP_STOCK_CHANNEL_GREEN; break;
|
|
|
|
case GIMP_BLUE_CHANNEL: stock_id = GIMP_STOCK_CHANNEL_BLUE; break;
|
|
|
|
case GIMP_GRAY_CHANNEL: stock_id = GIMP_STOCK_CHANNEL_GRAY; break;
|
|
|
|
case GIMP_INDEXED_CHANNEL: stock_id = GIMP_STOCK_QUESTION; break;
|
|
|
|
case GIMP_ALPHA_CHANNEL: stock_id = GIMP_STOCK_CHANNEL_ALPHA; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
stock_id = gimp_viewable_get_stock_id (renderer->viewable);
|
|
|
|
break;
|
|
|
|
}
|
2003-03-07 00:47:34 +08:00
|
|
|
|
|
|
|
gimp_preview_renderer_default_render_stock (renderer, widget, stock_id);
|
|
|
|
}
|
2001-02-07 10:37:49 +08:00
|
|
|
}
|