~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/maze/handy.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: handy.c,v 1.13 2004/09/22 18:43:08 mitch Exp $
 
1
/* $Id: handy.c 21431 2006-11-24 11:10:10Z neo $
2
2
 * These routines are useful for working with the GIMP and need not be
3
3
 * specific to plug-in-maze.
4
4
 *
29
29
 
30
30
#include "libgimp/gimp.h"
31
31
 
 
32
#include "maze.h"
 
33
 
 
34
 
32
35
/* get_colors Returns the current foreground and background colors in
33
36
   nice little arrays.  It works nicely for RGB and grayscale images,
34
37
   however handling of indexed images is somewhat broken.  Patches
35
38
   appreciated. */
36
39
 
37
 
void 
38
 
get_colors (GimpDrawable *drawable, 
39
 
            guint8       *fg, 
40
 
            guint8       *bg) 
 
40
void
 
41
get_colors (GimpDrawable *drawable,
 
42
            guint8       *fg,
 
43
            guint8       *bg)
41
44
{
42
45
  GimpRGB foreground;
43
46
  GimpRGB background;
52
55
    {
53
56
    case GIMP_RGB_IMAGE:
54
57
    case GIMP_RGBA_IMAGE:
55
 
      gimp_rgb_get_uchar (&foreground, &fg[0], &fg[1], &fg[2]); 
56
 
      gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]); 
 
58
      gimp_rgb_get_uchar (&foreground, &fg[0], &fg[1], &fg[2]);
 
59
      gimp_rgb_get_uchar (&background, &bg[0], &bg[1], &bg[2]);
57
60
      break;
58
61
 
59
62
    case GIMP_GRAYA_IMAGE:
60
63
    case GIMP_GRAY_IMAGE:
61
 
      fg[0] = gimp_rgb_intensity_uchar (&foreground);
62
 
      bg[0] = gimp_rgb_intensity_uchar (&background); 
 
64
      fg[0] = gimp_rgb_luminance_uchar (&foreground);
 
65
      bg[0] = gimp_rgb_luminance_uchar (&background);
63
66
      break;
64
67
 
65
68
    case GIMP_INDEXEDA_IMAGE:
77
80
/* Draws a solid color box in a GimpPixelRgn. */
78
81
/* Optimization assumptions:
79
82
 * (Or, "Why Maze is Faster Than Checkerboard.")
80
 
 * 
 
83
 *
81
84
 * Assuming calling memcpy is faster than using loops.
82
85
 * Row buffers are nice...
83
86
 *
84
 
 * Assume allocating memory for row buffers takes a significant amount 
 
87
 * Assume allocating memory for row buffers takes a significant amount
85
88
 * of time.  Assume drawbox will be called many times.
86
89
 * Only allocate memory once.
87
90
 *
88
91
 * Do not assume the row buffer will always be the same size.  Allow
89
 
 * for reallocating to make it bigger if needed.  However, I don't see 
 
92
 * for reallocating to make it bigger if needed.  However, I don't see
90
93
 * reason to bother ever shrinking it again.
91
94
 * (Under further investigation, assuming the row buffer never grows
92
95
 * may be a safe assumption in this case.)
93
96
 *
94
97
 * Also assume that the program calling drawbox is short-lived, so
95
 
 * memory leaks aren't of particular concern-- the memory allocated to 
 
98
 * memory leaks aren't of particular concern-- the memory allocated to
96
99
 * the row buffer is never set free.
97
100
 */
98
101
 
103
106
 *  We could keep a row of each color on hand so we wouldn't have to
104
107
 *  re-fill it every time...  */
105
108
 
106
 
void 
107
 
drawbox( GimpPixelRgn *dest_rgn, 
108
 
         guint x, guint y, guint w, guint h, 
 
109
#include "config.h"
 
110
 
 
111
#include <stdlib.h>
 
112
 
 
113
#include "libgimp/gimp.h"
 
114
 
 
115
#include "maze.h"
 
116
 
 
117
 
 
118
void
 
119
drawbox( GimpPixelRgn *dest_rgn,
 
120
         guint x, guint y, guint w, guint h,
109
121
         guint8 clr[4])
110
122
{
111
123
     const guint bpp = dest_rgn->bpp;
114
126
     /* x_max = dest_rgn->bpp * MIN(dest_rgn->w, (x + w)); */
115
127
     /* rowsize = x_max - x_min */
116
128
     const guint rowsize = bpp * MIN(dest_rgn->w, (x + w)) - x_min;
117
 
  
 
129
 
118
130
     /* The maximum [xy] value is that of the far end of the box, or
119
131
      * the edge of the region, whichever comes first. */
120
132
     const guint y_max = dest_rgn->rowstride * MIN(dest_rgn->h, (y + h));
121
 
     
 
133
 
122
134
     static guint8 *rowbuf;
123
 
     static guint high_size = 0; 
124
 
     
 
135
     static guint high_size = 0;
 
136
 
125
137
     guint xx, yy;
126
 
     
 
138
 
127
139
     /* Does the row buffer need to be (re)allocated? */
128
 
     if (high_size == 0) 
 
140
     if (high_size == 0)
129
141
       {
130
142
         rowbuf = g_new (guint8, rowsize);
131
 
       } 
132
 
     else if (rowsize > high_size) 
 
143
       }
 
144
     else if (rowsize > high_size)
133
145
       {
134
146
         rowbuf = g_renew (guint8, rowbuf, rowsize);
135
147
       }
136
 
     
 
148
 
137
149
     high_size = MAX(high_size, rowsize);
138
 
     
 
150
 
139
151
     /* Fill the row buffer with the color. */
140
 
     for (xx = 0; xx < rowsize; xx += bpp) 
 
152
     for (xx = 0; xx < rowsize; xx += bpp)
141
153
       {
142
154
         memcpy (&rowbuf[xx], clr, bpp);
143
155
       }
144
 
     
 
156
 
145
157
     /* Fill in the box in the region with rows... */
146
158
     for (yy = dest_rgn->rowstride * y; yy < y_max; yy += dest_rgn->rowstride)
147
159
       {