2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1999-10-04 13:51:40 +08:00
|
|
|
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
#include <glib-object.h>
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
#include <cairo/cairo.h>
|
2002-03-07 04:25:31 +08:00
|
|
|
|
2006-08-29 22:46:32 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
#include "core-types.h"
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
2003-09-21 03:58:26 +08:00
|
|
|
#include "base/tile-manager.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
#include "gimpscanconvert.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
struct _GimpScanConvert
|
1999-10-04 13:51:40 +08:00
|
|
|
{
|
2005-08-06 22:54:13 +08:00
|
|
|
gdouble ratio_xy;
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2005-08-08 20:05:54 +08:00
|
|
|
gboolean clip;
|
|
|
|
gint clip_x;
|
|
|
|
gint clip_y;
|
|
|
|
gint clip_w;
|
|
|
|
gint clip_h;
|
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
/* stroking options */
|
|
|
|
gboolean do_stroke;
|
|
|
|
gdouble width;
|
|
|
|
GimpJoinStyle join;
|
|
|
|
GimpCapStyle cap;
|
|
|
|
gdouble miter;
|
|
|
|
gdouble dash_offset;
|
|
|
|
GArray *dash_info;
|
2001-12-16 21:33:58 +08:00
|
|
|
|
2005-08-06 22:54:13 +08:00
|
|
|
guint num_nodes;
|
2008-05-09 07:35:53 +08:00
|
|
|
GArray *path_data;
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2004-09-16 08:46:02 +08:00
|
|
|
/* stuff necessary for the rendering callback */
|
2005-08-06 22:54:13 +08:00
|
|
|
GimpChannelOps op;
|
|
|
|
guchar *buf;
|
|
|
|
gint rowstride;
|
|
|
|
gint x0, x1;
|
|
|
|
gboolean antialias;
|
|
|
|
gboolean value;
|
2004-09-16 08:46:02 +08:00
|
|
|
};
|
2003-10-01 02:06:19 +08:00
|
|
|
|
2005-07-29 09:48:56 +08:00
|
|
|
|
2003-10-01 02:06:19 +08:00
|
|
|
/* private functions */
|
|
|
|
|
2005-07-29 09:48:56 +08:00
|
|
|
static void gimp_scan_convert_render_internal (GimpScanConvert *sc,
|
2005-08-06 22:54:13 +08:00
|
|
|
GimpChannelOps op,
|
2005-07-29 09:48:56 +08:00
|
|
|
TileManager *tile_manager,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y,
|
|
|
|
gboolean antialias,
|
|
|
|
guchar value);
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2001-05-26 02:10:38 +08:00
|
|
|
/* public functions */
|
2003-10-01 02:06:19 +08:00
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_new:
|
|
|
|
*
|
|
|
|
* Create a new scan conversion context.
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated #GimpScanConvert context.
|
|
|
|
*/
|
2001-05-26 02:10:38 +08:00
|
|
|
GimpScanConvert *
|
2003-10-01 02:06:19 +08:00
|
|
|
gimp_scan_convert_new (void)
|
1999-10-04 13:51:40 +08:00
|
|
|
{
|
2007-05-23 18:22:09 +08:00
|
|
|
GimpScanConvert *sc = g_slice_new0 (GimpScanConvert);
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
sc->path_data = g_array_new (FALSE, FALSE, sizeof (cairo_path_data_t));
|
2005-07-31 19:53:32 +08:00
|
|
|
sc->ratio_xy = 1.0;
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
return sc;
|
1999-10-04 13:51:40 +08:00
|
|
|
}
|
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_free:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
*
|
|
|
|
* Frees the resources allocated for @sc.
|
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
void
|
2001-05-26 02:10:38 +08:00
|
|
|
gimp_scan_convert_free (GimpScanConvert *sc)
|
2000-12-29 23:22:01 +08:00
|
|
|
{
|
2003-09-29 04:13:59 +08:00
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
if (sc->path_data)
|
|
|
|
g_array_free (sc->path_data, TRUE);
|
2003-09-29 04:13:59 +08:00
|
|
|
|
2007-05-23 18:22:09 +08:00
|
|
|
g_slice_free (GimpScanConvert, sc);
|
2000-12-29 23:22:01 +08:00
|
|
|
}
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_set_pixel_ratio:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @ratio_xy: the aspect ratio of the major coordinate axes
|
|
|
|
*
|
|
|
|
* Sets the pixel aspect ratio.
|
2003-09-30 07:45:06 +08:00
|
|
|
*/
|
|
|
|
void
|
2003-09-30 09:03:25 +08:00
|
|
|
gimp_scan_convert_set_pixel_ratio (GimpScanConvert *sc,
|
|
|
|
gdouble ratio_xy)
|
2003-09-30 07:45:06 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
|
|
|
|
/* we only need the relative resolution */
|
2003-09-30 09:03:25 +08:00
|
|
|
sc->ratio_xy = ratio_xy;
|
2003-09-30 07:45:06 +08:00
|
|
|
}
|
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_set_clip_rectangle
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @x: horizontal offset of clip rectangle
|
|
|
|
* @y: vertical offset of clip rectangle
|
|
|
|
* @width: width of clip rectangle
|
|
|
|
* @height: height of clip rectangle
|
|
|
|
*
|
|
|
|
* Sets a clip rectangle on @sc. Subsequent render operations will be
|
|
|
|
* restricted to this area.
|
|
|
|
*/
|
2005-08-08 20:05:54 +08:00
|
|
|
void
|
|
|
|
gimp_scan_convert_set_clip_rectangle (GimpScanConvert *sc,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
|
|
|
|
sc->clip = TRUE;
|
|
|
|
sc->clip_x = x;
|
|
|
|
sc->clip_y = y;
|
|
|
|
sc->clip_w = width;
|
|
|
|
sc->clip_h = height;
|
|
|
|
}
|
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_add_polyline:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @n_points: number of points to add
|
|
|
|
* @points: array of points to add
|
|
|
|
* @closed: whether to close the polyline and make it a polygon
|
|
|
|
*
|
|
|
|
* Add a polyline with @n_points @points that may be open or closed.
|
2003-09-21 03:58:26 +08:00
|
|
|
*
|
2003-09-26 08:41:10 +08:00
|
|
|
* Please note that you should use gimp_scan_convert_stroke() if you
|
2003-09-21 03:58:26 +08:00
|
|
|
* specify open polygons.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_scan_convert_add_polyline (GimpScanConvert *sc,
|
|
|
|
guint n_points,
|
|
|
|
GimpVector2 *points,
|
|
|
|
gboolean closed)
|
|
|
|
{
|
2005-07-29 09:48:56 +08:00
|
|
|
GimpVector2 prev = { 0.0, 0.0, };
|
2008-05-09 07:35:53 +08:00
|
|
|
cairo_path_data_t pd;
|
2005-07-29 09:48:56 +08:00
|
|
|
gint i;
|
2003-09-21 03:58:26 +08:00
|
|
|
|
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
g_return_if_fail (points != NULL);
|
|
|
|
g_return_if_fail (n_points > 0);
|
|
|
|
|
|
|
|
for (i = 0; i < n_points; i++)
|
1999-10-04 13:51:40 +08:00
|
|
|
{
|
2003-09-21 03:58:26 +08:00
|
|
|
/* compress multiple identical coordinates */
|
|
|
|
if (i == 0 ||
|
|
|
|
prev.x != points[i].x ||
|
|
|
|
prev.y != points[i].y)
|
2003-05-21 09:01:09 +08:00
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
pd.header.type = (i == 0) ? CAIRO_PATH_MOVE_TO : CAIRO_PATH_LINE_TO;
|
|
|
|
pd.header.length = 2;
|
|
|
|
sc->path_data = g_array_append_val (sc->path_data, pd);
|
|
|
|
|
|
|
|
pd.point.x = points[i].x;
|
|
|
|
pd.point.y = points[i].y;
|
|
|
|
sc->path_data = g_array_append_val (sc->path_data, pd);
|
2003-05-21 09:01:09 +08:00
|
|
|
sc->num_nodes++;
|
2003-09-21 03:58:26 +08:00
|
|
|
prev = points[i];
|
2003-05-21 09:01:09 +08:00
|
|
|
}
|
2003-09-21 03:58:26 +08:00
|
|
|
}
|
|
|
|
|
2004-01-28 07:38:03 +08:00
|
|
|
/* close the polyline when needed */
|
2008-05-09 07:35:53 +08:00
|
|
|
if (closed)
|
2004-01-21 09:29:00 +08:00
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
pd.header.type = CAIRO_PATH_CLOSE_PATH;
|
|
|
|
pd.header.length = 1;
|
|
|
|
sc->path_data = g_array_append_val (sc->path_data, pd);
|
2004-01-21 09:29:00 +08:00
|
|
|
}
|
2003-09-21 03:58:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_stroke:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @width: line width in pixels
|
|
|
|
* @join: how lines should be joined
|
|
|
|
* @cap: how to render the end of lines
|
|
|
|
* @miter: convert a mitered join to a bevelled join if the miter would
|
|
|
|
* extend to a distance of more than @miter times @width from
|
|
|
|
* the actual join point
|
|
|
|
* @dash_offset: offset to apply on the dash pattern
|
|
|
|
* @dash_info: dash pattern or %NULL for a solid line
|
|
|
|
*
|
|
|
|
* Stroke the content of a GimpScanConvert. The next
|
|
|
|
* gimp_scan_convert_render() will result in the outline of the
|
|
|
|
* polygon defined with the commands above.
|
2003-09-21 03:58:26 +08:00
|
|
|
*
|
|
|
|
* You cannot add additional polygons after this command.
|
2005-08-23 00:08:08 +08:00
|
|
|
*
|
|
|
|
* Note that if you have nonstandard resolution, "width" gives the
|
|
|
|
* width (in pixels) for a vertical stroke, i.e. use the X resolution
|
|
|
|
* to calculate the width of a stroke when operating with real world
|
|
|
|
* units.
|
2003-09-21 03:58:26 +08:00
|
|
|
*/
|
|
|
|
void
|
2003-09-21 18:45:19 +08:00
|
|
|
gimp_scan_convert_stroke (GimpScanConvert *sc,
|
2003-09-26 08:41:10 +08:00
|
|
|
gdouble width,
|
2003-09-21 18:45:19 +08:00
|
|
|
GimpJoinStyle join,
|
|
|
|
GimpCapStyle cap,
|
2003-09-26 08:41:10 +08:00
|
|
|
gdouble miter,
|
|
|
|
gdouble dash_offset,
|
|
|
|
GArray *dash_info)
|
2003-09-21 03:58:26 +08:00
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
sc->do_stroke = TRUE;
|
|
|
|
sc->width = width;
|
|
|
|
sc->join = join;
|
|
|
|
sc->cap = cap;
|
|
|
|
sc->miter = miter;
|
|
|
|
sc->dash_offset = dash_offset;
|
|
|
|
if (dash_info && dash_info->len)
|
|
|
|
g_printerr ("Dashing not yet implemented\n");
|
|
|
|
|
|
|
|
#if 0
|
2003-12-28 03:25:19 +08:00
|
|
|
if (dash_info && dash_info->len >= 2)
|
2003-09-26 08:41:10 +08:00
|
|
|
{
|
|
|
|
ArtVpath *dash_vpath;
|
|
|
|
ArtVpathDash dash;
|
|
|
|
gdouble *dashes;
|
|
|
|
gint i;
|
|
|
|
|
2003-09-29 06:33:08 +08:00
|
|
|
dash.offset = dash_offset * MAX (width, 1.0);
|
2003-09-26 08:41:10 +08:00
|
|
|
|
|
|
|
dashes = g_new (gdouble, dash_info->len);
|
2003-09-29 04:13:59 +08:00
|
|
|
|
2005-07-31 19:53:32 +08:00
|
|
|
for (i = 0; i < dash_info->len ; i++)
|
2003-09-29 06:33:08 +08:00
|
|
|
dashes[i] = MAX (width, 1.0) * g_array_index (dash_info, gdouble, i);
|
2003-09-26 08:41:10 +08:00
|
|
|
|
|
|
|
dash.n_dash = dash_info->len;
|
|
|
|
dash.dash = dashes;
|
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
/* correct 0.0 in the first element (starts with a gap) */
|
|
|
|
|
|
|
|
if (dash.dash[0] == 0.0)
|
|
|
|
{
|
|
|
|
gdouble first;
|
|
|
|
|
|
|
|
first = dash.dash[1];
|
|
|
|
|
|
|
|
/* shift the pattern to really starts with a dash and
|
|
|
|
* use the offset to skip into it.
|
|
|
|
*/
|
2005-07-31 19:53:32 +08:00
|
|
|
for (i = 0; i < dash_info->len - 2; i++)
|
2003-12-28 03:25:19 +08:00
|
|
|
{
|
|
|
|
dash.dash[i] = dash.dash[i+2];
|
|
|
|
dash.offset += dash.dash[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dash_info->len % 2 == 1)
|
|
|
|
{
|
|
|
|
dash.dash[dash_info->len - 2] = first;
|
|
|
|
dash.n_dash --;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dash_info->len < 3)
|
|
|
|
{
|
|
|
|
/* empty stroke */
|
|
|
|
art_free (sc->vpath);
|
|
|
|
sc->vpath = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dash.dash [dash_info->len - 3] += first;
|
|
|
|
dash.n_dash -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-16 08:46:02 +08:00
|
|
|
|
2003-12-28 03:25:19 +08:00
|
|
|
/* correct odd number of dash specifiers */
|
|
|
|
|
|
|
|
if (dash.n_dash % 2 == 1)
|
|
|
|
{
|
|
|
|
gdouble last;
|
|
|
|
|
|
|
|
last = dash.dash[dash.n_dash - 1];
|
|
|
|
dash.dash[0] += last;
|
|
|
|
dash.offset += last;
|
|
|
|
dash.n_dash --;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (sc->vpath)
|
|
|
|
{
|
|
|
|
dash_vpath = art_vpath_dash (sc->vpath, &dash);
|
|
|
|
art_free (sc->vpath);
|
|
|
|
sc->vpath = dash_vpath;
|
|
|
|
}
|
2003-09-26 08:41:10 +08:00
|
|
|
|
|
|
|
g_free (dashes);
|
|
|
|
}
|
2008-05-09 07:35:53 +08:00
|
|
|
#endif
|
2003-09-21 03:58:26 +08:00
|
|
|
}
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2003-05-21 09:01:09 +08:00
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_render:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @tile_manager: the #TileManager to render to
|
|
|
|
* @off_x: horizontal offset into the @tile_manager
|
|
|
|
* @off_y: vertical offset into the @tile_manager
|
|
|
|
* @antialias: whether to apply antialiasiing
|
|
|
|
*
|
|
|
|
* Actually renders the @sc to a mask. This function expects a tile
|
|
|
|
* manager of depth 1.
|
2003-09-21 03:58:26 +08:00
|
|
|
*
|
|
|
|
* You cannot add additional polygons after this command.
|
|
|
|
*/
|
2003-09-21 18:45:19 +08:00
|
|
|
void
|
2003-09-21 03:58:26 +08:00
|
|
|
gimp_scan_convert_render (GimpScanConvert *sc,
|
2003-10-01 02:06:19 +08:00
|
|
|
TileManager *tile_manager,
|
2003-10-07 00:43:05 +08:00
|
|
|
gint off_x,
|
|
|
|
gint off_y,
|
2003-10-01 02:06:19 +08:00
|
|
|
gboolean antialias)
|
2003-09-21 03:58:26 +08:00
|
|
|
{
|
2005-07-29 09:48:56 +08:00
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
g_return_if_fail (tile_manager != NULL);
|
|
|
|
|
2005-08-06 22:54:13 +08:00
|
|
|
gimp_scan_convert_render_internal (sc, GIMP_CHANNEL_OP_REPLACE,
|
2005-07-31 22:27:46 +08:00
|
|
|
tile_manager, off_x, off_y,
|
|
|
|
antialias, 255);
|
2005-07-29 09:48:56 +08:00
|
|
|
}
|
2003-09-21 18:45:19 +08:00
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_render_value:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @tile_manager: the #TileManager to render to
|
|
|
|
* @off_x: horizontal offset into the @tile_manager
|
|
|
|
* @off_y: vertical offset into the @tile_manager
|
|
|
|
* @value: value to use for covered pixels
|
|
|
|
*
|
|
|
|
* A variant of gimp_scan_convert_render() that doesn't do
|
|
|
|
* antialiasing but gives control over the value that should be used
|
|
|
|
* for pixels covered by the scan conversion . Uncovered pixels are
|
|
|
|
* set to zero.
|
|
|
|
*
|
|
|
|
* You cannot add additional polygons after this command.
|
|
|
|
*/
|
2005-07-29 09:48:56 +08:00
|
|
|
void
|
|
|
|
gimp_scan_convert_render_value (GimpScanConvert *sc,
|
|
|
|
TileManager *tile_manager,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y,
|
|
|
|
guchar value)
|
|
|
|
{
|
2003-09-21 03:58:26 +08:00
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
g_return_if_fail (tile_manager != NULL);
|
2003-09-21 18:45:19 +08:00
|
|
|
|
2005-08-06 22:54:13 +08:00
|
|
|
gimp_scan_convert_render_internal (sc, GIMP_CHANNEL_OP_REPLACE,
|
2005-07-31 22:27:46 +08:00
|
|
|
tile_manager, off_x, off_y,
|
|
|
|
FALSE, value);
|
2005-07-29 09:48:56 +08:00
|
|
|
}
|
|
|
|
|
2005-08-23 00:08:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_scan_convert_compose:
|
|
|
|
* @sc: a #GimpScanConvert context
|
|
|
|
* @tile_manager: the #TileManager to render to
|
|
|
|
* @off_x: horizontal offset into the @tile_manager
|
|
|
|
* @off_y: vertical offset into the @tile_manager
|
|
|
|
*
|
|
|
|
* This is a variant of gimp_scan_convert_render() that composes the
|
|
|
|
* (aliased) scan conversion with the content of the @tile_manager.
|
|
|
|
*
|
|
|
|
* You cannot add additional polygons after this command.
|
|
|
|
*/
|
2005-08-06 22:54:13 +08:00
|
|
|
void
|
|
|
|
gimp_scan_convert_compose (GimpScanConvert *sc,
|
|
|
|
GimpChannelOps op,
|
|
|
|
TileManager *tile_manager,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (sc != NULL);
|
|
|
|
g_return_if_fail (tile_manager != NULL);
|
|
|
|
|
|
|
|
gimp_scan_convert_render_internal (sc, op,
|
|
|
|
tile_manager, off_x, off_y,
|
|
|
|
FALSE, 255);
|
|
|
|
}
|
|
|
|
|
2005-07-29 09:48:56 +08:00
|
|
|
static void
|
|
|
|
gimp_scan_convert_render_internal (GimpScanConvert *sc,
|
2005-08-06 22:54:13 +08:00
|
|
|
GimpChannelOps op,
|
2005-07-29 09:48:56 +08:00
|
|
|
TileManager *tile_manager,
|
|
|
|
gint off_x,
|
|
|
|
gint off_y,
|
|
|
|
gboolean antialias,
|
|
|
|
guchar value)
|
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
PixelRegion maskPR;
|
|
|
|
gpointer pr;
|
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
2005-07-29 09:48:56 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
cairo_t *cr;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_path_t path;
|
|
|
|
gint i;
|
2003-12-28 03:25:19 +08:00
|
|
|
|
2005-08-08 20:05:54 +08:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
width = tile_manager_width (tile_manager);
|
|
|
|
height = tile_manager_height (tile_manager);
|
|
|
|
|
|
|
|
if (sc->clip &&
|
|
|
|
! gimp_rectangle_intersect (x, y, width, height,
|
|
|
|
sc->clip_x, sc->clip_y,
|
|
|
|
sc->clip_w, sc->clip_h,
|
|
|
|
&x, &y, &width, &height))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pixel_region_init (&maskPR, tile_manager, x, y, width, height, TRUE);
|
1999-10-04 13:51:40 +08:00
|
|
|
|
2003-09-21 03:58:26 +08:00
|
|
|
g_return_if_fail (maskPR.bytes == 1);
|
2002-03-07 04:25:31 +08:00
|
|
|
|
2004-09-16 08:46:02 +08:00
|
|
|
sc->antialias = antialias;
|
2005-07-29 09:48:56 +08:00
|
|
|
sc->value = value;
|
2005-08-06 22:54:13 +08:00
|
|
|
sc->op = op;
|
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
path.status = CAIRO_STATUS_SUCCESS;
|
|
|
|
path.data = (cairo_path_data_t *) sc->path_data->data;
|
|
|
|
path.num_data = sc->path_data->len;
|
2004-09-16 08:46:02 +08:00
|
|
|
|
2002-03-07 04:25:31 +08:00
|
|
|
for (pr = pixel_regions_register (1, &maskPR);
|
|
|
|
pr != NULL;
|
|
|
|
pr = pixel_regions_process (pr))
|
1999-10-04 13:51:40 +08:00
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
guchar *tmp_buf = NULL;
|
|
|
|
int tmp_rs = 0;
|
|
|
|
|
2005-07-29 09:48:56 +08:00
|
|
|
sc->buf = maskPR.data;
|
2004-09-16 08:46:02 +08:00
|
|
|
sc->rowstride = maskPR.rowstride;
|
2005-07-29 09:48:56 +08:00
|
|
|
sc->x0 = off_x + maskPR.x;
|
|
|
|
sc->x1 = off_x + maskPR.x + maskPR.w;
|
2004-09-16 08:46:02 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
if (maskPR.rowstride % 4 != 0)
|
2004-09-16 08:46:02 +08:00
|
|
|
{
|
2008-05-09 07:35:53 +08:00
|
|
|
/* this is necessary to work around a cairo bug
|
|
|
|
* for rowstride % 4 != 0 */
|
|
|
|
tmp_rs = ((maskPR.rowstride + 3) / 4) * 4;
|
|
|
|
tmp_buf = g_slice_alloc0 (tmp_rs * maskPR.h);
|
|
|
|
}
|
2004-09-16 19:31:30 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
surface = cairo_image_surface_create_for_data (tmp_buf ? tmp_buf : maskPR.data,
|
|
|
|
CAIRO_FORMAT_A8,
|
|
|
|
maskPR.w, maskPR.h,
|
|
|
|
tmp_buf ? tmp_rs : maskPR.rowstride);
|
|
|
|
cairo_surface_set_device_offset (surface,
|
|
|
|
-off_x - maskPR.x,
|
|
|
|
-off_y - maskPR.y);
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
cairo_set_source_rgb (cr, value / 255.0, value / 255.0, value / 255.0);
|
|
|
|
cairo_append_path (cr, &path);
|
|
|
|
cairo_set_antialias (cr, sc->antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE);
|
|
|
|
if (sc->do_stroke)
|
|
|
|
{
|
|
|
|
cairo_set_line_cap (cr, sc->cap == GIMP_CAP_BUTT ? CAIRO_LINE_CAP_BUTT :
|
|
|
|
sc->cap == GIMP_CAP_ROUND ? CAIRO_LINE_CAP_ROUND :
|
|
|
|
CAIRO_LINE_CAP_SQUARE);
|
|
|
|
cairo_set_line_join (cr, sc->join == GIMP_JOIN_MITER ? CAIRO_LINE_JOIN_MITER :
|
|
|
|
sc->join == GIMP_JOIN_ROUND ? CAIRO_LINE_JOIN_ROUND :
|
|
|
|
CAIRO_LINE_JOIN_BEVEL);
|
|
|
|
#warning cairo_set_dash() still missing!
|
|
|
|
cairo_set_line_width (cr, sc->width);
|
|
|
|
cairo_scale (cr, 1.0, sc->ratio_xy);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
|
|
|
cairo_fill (cr);
|
2004-09-16 08:46:02 +08:00
|
|
|
}
|
2008-05-09 07:35:53 +08:00
|
|
|
cairo_surface_flush (surface);
|
|
|
|
cairo_destroy (cr);
|
|
|
|
cairo_surface_destroy (surface);
|
2004-09-16 08:46:02 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
if (tmp_buf)
|
|
|
|
{
|
|
|
|
for (i = 0; i < maskPR.h; i++)
|
|
|
|
memcpy (maskPR.data + i * maskPR.rowstride,
|
|
|
|
tmp_buf + i * tmp_rs,
|
|
|
|
maskPR.w);
|
2004-09-16 19:31:30 +08:00
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
g_slice_free1 (tmp_rs * maskPR.h, tmp_buf);
|
|
|
|
}
|
2004-09-16 08:46:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-09 07:35:53 +08:00
|
|
|
|
2005-08-06 22:54:13 +08:00
|
|
|
static inline void
|
|
|
|
compose (GimpChannelOps op,
|
|
|
|
guchar *buf,
|
|
|
|
guchar value,
|
|
|
|
gint len)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
if (value)
|
|
|
|
memset (buf, value, len);
|
|
|
|
break;
|
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
|
|
|
if (value)
|
|
|
|
memset (buf, 0, len);
|
|
|
|
break;
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
|
|
|
memset (buf, value, len);
|
|
|
|
break;
|
|
|
|
case GIMP_CHANNEL_OP_INTERSECT:
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*buf)
|
|
|
|
*buf = value;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
while (--len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|