1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
* Copyright (C) 1997-2004 Adam D. Moss <adam@gimp.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <glib-object.h>
24
#include "libgimpcolor/gimpcolor.h"
26
#include "core-types.h"
28
#include "base/pixel-region.h"
29
#include "base/tile-manager.h"
31
#include "gimpdrawable.h"
32
#include "gimpdrawable-convert.h"
36
gimp_drawable_convert_rgb (GimpDrawable *drawable,
37
TileManager *new_tiles,
38
GimpImageBaseType old_base_type)
40
PixelRegion srcPR, destPR;
44
const guchar *src, *s;
49
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
50
g_return_if_fail (new_tiles != NULL);
52
has_alpha = gimp_drawable_has_alpha (drawable);
54
g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 4 : 3));
56
cmap = gimp_drawable_get_colormap (drawable);
58
pixel_region_init (&srcPR, drawable->tiles,
60
GIMP_ITEM (drawable)->width,
61
GIMP_ITEM (drawable)->height,
63
pixel_region_init (&destPR, new_tiles,
65
GIMP_ITEM (drawable)->width,
66
GIMP_ITEM (drawable)->height,
70
switch (old_base_type)
73
for (pr = pixel_regions_register (2, &srcPR, &destPR);
75
pr = pixel_regions_process (pr))
80
for (row = 0; row < srcPR.h; row++)
85
for (col = 0; col < srcPR.w; col++)
97
src += srcPR.rowstride;
98
dest += destPR.rowstride;
104
for (pr = pixel_regions_register (2, &srcPR, &destPR);
106
pr = pixel_regions_process (pr))
111
for (row = 0; row < srcPR.h; row++)
116
for (col = 0; col < srcPR.w; col++)
119
d[RED_PIX] = cmap[offset + 0];
120
d[GREEN_PIX] = cmap[offset + 1];
121
d[BLUE_PIX] = cmap[offset + 2];
128
src += srcPR.rowstride;
129
dest += destPR.rowstride;
140
gimp_drawable_convert_grayscale (GimpDrawable *drawable,
141
TileManager *new_tiles,
142
GimpImageBaseType old_base_type)
144
PixelRegion srcPR, destPR;
148
const guchar *src, *s;
153
g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
154
g_return_if_fail (new_tiles != NULL);
156
has_alpha = gimp_drawable_has_alpha (drawable);
158
g_return_if_fail (tile_manager_bpp (new_tiles) == (has_alpha ? 2 : 1));
160
cmap = gimp_drawable_get_colormap (drawable);
162
pixel_region_init (&srcPR, drawable->tiles,
164
GIMP_ITEM (drawable)->width,
165
GIMP_ITEM (drawable)->height,
167
pixel_region_init (&destPR, new_tiles,
169
GIMP_ITEM (drawable)->width,
170
GIMP_ITEM (drawable)->height,
173
switch (old_base_type)
176
for (pr = pixel_regions_register (2, &srcPR, &destPR);
178
pr = pixel_regions_process (pr))
183
for (row = 0; row < srcPR.h; row++)
187
for (col = 0; col < srcPR.w; col++)
189
val = GIMP_RGB_LUMINANCE (s[RED_PIX],
198
src += srcPR.rowstride;
199
dest += destPR.rowstride;
205
for (pr = pixel_regions_register (2, &srcPR, &destPR);
207
pr = pixel_regions_process (pr))
212
for (row = 0; row < srcPR.h; row++)
217
for (col = 0; col < srcPR.w; col++)
220
val = GIMP_RGB_LUMINANCE (cmap[offset+0],
222
cmap[offset+2]) + 0.5;
228
src += srcPR.rowstride;
229
dest += destPR.rowstride;