~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to app/vectors/gimpvectors-preview.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The GIMP -- an image manipulation program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <string.h>
 
22
 
 
23
#include <glib-object.h>
 
24
 
 
25
#include "vectors-types.h"
 
26
 
 
27
#include "base/temp-buf.h"
 
28
 
 
29
#include "core/gimpimage.h"
 
30
 
 
31
#include "gimpstroke.h"
 
32
#include "gimpvectors.h"
 
33
#include "gimpvectors-preview.h"
 
34
 
 
35
 
 
36
/*  public functions  */
 
37
 
 
38
TempBuf *
 
39
gimp_vectors_get_new_preview (GimpViewable *viewable,
 
40
                              gint          width,
 
41
                              gint          height)
 
42
{
 
43
  GimpVectors *vectors;
 
44
  GimpItem    *item;
 
45
  GimpStroke  *cur_stroke;
 
46
  gdouble      xscale, yscale;
 
47
  guchar      *data;
 
48
  TempBuf     *temp_buf;
 
49
  guchar       white[1] = { 255 };
 
50
 
 
51
  vectors = GIMP_VECTORS (viewable);
 
52
  item    = GIMP_ITEM (viewable);
 
53
 
 
54
  xscale = ((gdouble) width)  / gimp_image_get_width  (item->gimage);
 
55
  yscale = ((gdouble) height) / gimp_image_get_height (item->gimage);
 
56
 
 
57
  temp_buf = temp_buf_new (width, height, 1, 0, 0, white);
 
58
  data = temp_buf_data (temp_buf);
 
59
 
 
60
  for (cur_stroke = gimp_vectors_stroke_get_next (vectors, NULL);
 
61
       cur_stroke;
 
62
       cur_stroke = gimp_vectors_stroke_get_next (vectors, cur_stroke))
 
63
    {
 
64
      GArray   *coords;
 
65
      gboolean  closed;
 
66
      gint      i;
 
67
 
 
68
      coords = gimp_stroke_interpolate (cur_stroke, 0.5, &closed);
 
69
 
 
70
      if (coords)
 
71
        {
 
72
          for (i = 0; i < coords->len; i++)
 
73
            {
 
74
              GimpCoords point;
 
75
              gint       x, y;
 
76
 
 
77
              point = g_array_index (coords, GimpCoords, i);
 
78
 
 
79
              x = ROUND (point.x * xscale);
 
80
              y = ROUND (point.y * yscale);
 
81
 
 
82
              if (x >= 0 && y >= 0 && x < width && y < height)
 
83
                data[y * width + x] = 0;
 
84
            }
 
85
 
 
86
          g_array_free (coords, TRUE);
 
87
        }
 
88
    }
 
89
 
 
90
  return temp_buf;
 
91
}