2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
* Copyright (C) 1997-2004 Adam D. Moss <adam@gimp.org>
5
* This program is free software; you can redistribute it and/or modify
5
* This program is free software: you can redistribute it and/or modify
6
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
7
* the Free Software Foundation; either version 3 of the License, or
8
8
* (at your option) any later version.
10
10
* This program is distributed in the hope that it will be useful,
13
13
* GNU General Public License for more details.
15
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.
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
145
145
#include "base/tile-manager.h"
147
147
#include "gimp.h"
148
#include "gimpcontainer.h"
148
149
#include "gimpdrawable.h"
149
#include "gimpdrawable-convert.h"
150
#include "gimperror.h"
150
151
#include "gimpimage.h"
151
152
#include "gimpimage-colormap.h"
152
153
#include "gimpimage-undo.h"
153
154
#include "gimpimage-undo-push.h"
154
#include "gimplist.h"
155
155
#include "gimplayer.h"
156
#include "gimplayer-floating-sel.h"
157
156
#include "gimppalette.h"
158
157
#include "gimpprogress.h"
693
692
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
695
gimp_item_width (GIMP_ITEM (layer)),
696
gimp_item_height (GIMP_ITEM (layer)),
694
gimp_item_get_width (GIMP_ITEM (layer)),
695
gimp_item_get_height (GIMP_ITEM (layer)),
698
697
pixel_region_init (&destPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
700
gimp_item_width (GIMP_ITEM (layer)),
701
gimp_item_height (GIMP_ITEM (layer)),
699
gimp_item_get_width (GIMP_ITEM (layer)),
700
gimp_item_get_height (GIMP_ITEM (layer)),
704
703
for (pr = pixel_regions_register (2, &srcPR, &destPR);
781
781
g_return_val_if_fail (custom_palette == NULL ||
782
782
GIMP_IS_PALETTE (custom_palette), FALSE);
783
783
g_return_val_if_fail (custom_palette == NULL ||
784
custom_palette->n_colors <= 256, FALSE);
784
gimp_palette_get_n_colors (custom_palette) <= 256,
786
787
if (! custom_palette)
787
788
palette_type = GIMP_MONO_PALETTE;
789
if (custom_palette->n_colors < 1)
790
if (gimp_palette_get_n_colors (custom_palette) == 0)
791
g_set_error (error, 0, 0,
792
_("Cannot convert image: palette is empty."));
792
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
793
_("Cannot convert image: palette is empty."));
799
800
gimp_set_busy (image->gimp);
801
n_layers = g_list_length (GIMP_LIST (image->layers)->list);
802
all_layers = gimp_image_get_layer_list (image);
804
n_layers = g_list_length (all_layers);
803
806
switch (new_type)
806
undo_desc = _("Convert Image to RGB");
809
undo_desc = C_("undo-type", "Convert Image to RGB");
810
undo_desc = _("Convert Image to Grayscale");
813
undo_desc = C_("undo-type", "Convert Image to Grayscale");
813
816
case GIMP_INDEXED:
814
undo_desc = _("Convert Image to Indexed");
817
undo_desc = C_("undo-type", "Convert Image to Indexed");
820
823
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
823
if (gimp_image_floating_sel (image))
824
floating_sel_relax (gimp_image_floating_sel (image), TRUE);
826
826
/* Push the image type to the stack */
827
827
gimp_image_undo_push_image_type (image, NULL);
956
956
quantobj->n_layers = n_layers;
958
for (list = GIMP_LIST (image->layers)->list, nth_layer = 0;
958
for (list = all_layers, nth_layer = 0;
960
960
list = g_list_next (list), nth_layer++)
962
GimpLayer *layer = list->data;
963
GimpImageType new_layer_type;
964
TileManager *new_tiles;
966
new_layer_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_type);
968
if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
969
new_layer_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_layer_type);
971
new_tiles = tile_manager_new (gimp_item_width (GIMP_ITEM (layer)),
972
gimp_item_height (GIMP_ITEM (layer)),
973
GIMP_IMAGE_TYPE_BYTES (new_layer_type));
962
GimpLayer *layer = list->data;
975
964
switch (new_type)
978
gimp_drawable_convert_rgb (GIMP_DRAWABLE (layer),
979
new_tiles, old_type);
982
gimp_drawable_convert_grayscale (GIMP_DRAWABLE (layer),
983
new_tiles, old_type);
968
gimp_drawable_convert_type (GIMP_DRAWABLE (layer), NULL, new_type,
985
972
case GIMP_INDEXED:
986
quantobj->nth_layer = nth_layer;
987
(* quantobj->second_pass) (quantobj, layer, new_tiles);
974
GimpImageType new_layer_type;
975
TileManager *new_tiles;
977
new_layer_type = GIMP_IMAGE_TYPE_FROM_BASE_TYPE (new_type);
979
if (gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)))
980
new_layer_type = GIMP_IMAGE_TYPE_WITH_ALPHA (new_layer_type);
982
new_tiles = tile_manager_new (gimp_item_get_width (GIMP_ITEM (layer)),
983
gimp_item_get_height (GIMP_ITEM (layer)),
984
GIMP_IMAGE_TYPE_BYTES (new_layer_type));
986
quantobj->nth_layer = nth_layer;
987
(* quantobj->second_pass) (quantobj, layer, new_tiles);
989
gimp_drawable_set_tiles (GIMP_DRAWABLE (layer), TRUE, NULL,
990
new_tiles, new_layer_type);
991
tile_manager_unref (new_tiles);
993
gimp_drawable_set_tiles_full (GIMP_DRAWABLE (layer), TRUE, NULL,
994
new_tiles, new_layer_type,
995
GIMP_ITEM (layer)->offset_x,
996
GIMP_ITEM (layer)->offset_y);
997
tile_manager_unref (new_tiles);
1000
1000
switch (new_type)
1031
1031
remap_table, &num_entries);
1033
1033
/* Convert all layers */
1034
for (list = GIMP_LIST (image->layers)->list;
1036
list = g_list_next (list))
1034
for (list = all_layers; list; list = g_list_next (list))
1038
1036
remap_indexed_layer (list->data, remap_table, num_entries);
1069
/* TODO: attach or remove the ICC profile */
1074
if (old_type == GIMP_GRAY)
1075
gimp_image_parasite_detach (image, "icc-profile");
1078
gimp_image_parasite_detach (image, "icc-profile");
1071
1084
/* Delete the quantizer object, if there is one */
1073
1086
quantobj->delete_func (quantobj);
1075
if (gimp_image_floating_sel (image))
1076
floating_sel_rigor (gimp_image_floating_sel (image), TRUE);
1078
1088
gimp_image_undo_group_end (image);
1080
gimp_image_invalidate_layer_previews (image);
1081
1090
gimp_image_mode_changed (image);
1082
1091
g_object_thaw_notify (G_OBJECT (image));
1093
g_list_free (all_layers);
1084
1095
gimp_unset_busy (image->gimp);
1121
1132
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
1123
gimp_item_width (GIMP_ITEM (layer)),
1124
gimp_item_height (GIMP_ITEM (layer)),
1134
gimp_item_get_width (GIMP_ITEM (layer)),
1135
gimp_item_get_height (GIMP_ITEM (layer)),
1127
1138
for (pr = pixel_regions_register (1, &srcPR);
1173
1184
gint count = 0;
1174
1185
gboolean has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
1176
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
1187
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
1178
1189
/* g_printerr ("col_limit = %d, nfc = %d\n", col_limit, num_found_cols); */
1180
1191
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
1182
gimp_item_width (GIMP_ITEM (layer)),
1183
gimp_item_height (GIMP_ITEM (layer)),
1193
gimp_item_get_width (GIMP_ITEM (layer)),
1194
gimp_item_get_height (GIMP_ITEM (layer)),
1186
layer_size = (gimp_item_width (GIMP_ITEM (layer)) *
1187
gimp_item_height (GIMP_ITEM (layer)));
1197
layer_size = (gimp_item_get_width (GIMP_ITEM (layer)) *
1198
gimp_item_get_height (GIMP_ITEM (layer)));
1190
1201
gimp_progress_set_value (progress, 0.0);
1298
(data[RED_PIX] == found_cols[nfc_iter][0])
1300
(data[GREEN_PIX] == found_cols[nfc_iter][1])
1302
(data[BLUE_PIX] == found_cols[nfc_iter][2])
1310
(data[RED] == found_cols[nfc_iter][0])
1312
(data[GREEN] == found_cols[nfc_iter][1])
1314
(data[BLUE] == found_cols[nfc_iter][2])
1304
1316
goto already_found;
1326
1338
/* Remember the new colour we just found.
1328
found_cols[num_found_cols-1][0] = data[RED_PIX];
1329
found_cols[num_found_cols-1][1] = data[GREEN_PIX];
1330
found_cols[num_found_cols-1][2] = data[BLUE_PIX];
1340
found_cols[num_found_cols-1][0] = data[RED];
1341
found_cols[num_found_cols-1][1] = data[GREEN];
1342
found_cols[num_found_cols-1][2] = data[BLUE];
1815
1827
if ( dist0 >= longest_length)
1817
1829
longest_length2 = longest_length;
1818
longest_ax2 = longest_ax;
1819
1830
longest_length = dist0;
1820
1831
longest_ax = AXIS_RED;
1822
1833
else if ( dist0 >= longest_length2)
1824
1835
longest_length2 = dist0;
1825
longest_ax2 = AXIS_RED;
1828
1838
if ( dist1 >= longest_length)
1830
1840
longest_length2 = longest_length;
1831
longest_ax2 = longest_ax;
1832
1841
longest_length = dist1;
1833
1842
longest_ax = AXIS_GREEN;
1835
1844
else if ( dist1 >= longest_length2)
1837
1846
longest_length2 = dist1;
1838
longest_ax2 = AXIS_GREEN;
1841
1849
if ( dist2 >= longest_length)
1843
1851
longest_length2 = longest_length;
1844
longest_ax2 = longest_ax;
1845
1852
longest_length = dist2;
1846
1853
longest_ax = AXIS_BLUE;
1848
1855
else if ( dist2 >= longest_length2)
1850
1857
longest_length2 = dist2;
1851
longest_ax2 = AXIS_BLUE;
1854
1860
if (longest_length2 == 0)
2521
2529
int inR, inG, inB; /* initial values for increments */
2523
2531
/* This array holds the distance to the nearest-so-far color for each cell */
2524
int bestdist[BOX_R_ELEMS * BOX_G_ELEMS * BOX_B_ELEMS];
2532
int bestdist[BOX_R_ELEMS * BOX_G_ELEMS * BOX_B_ELEMS] = { 0, };
2526
2534
/* Initialize best-distance for each cell of the update box */
2527
2535
bptr = bestdist;
2642
2650
int colorlist[MAXNUMCOLORS];
2643
2651
int numcolors; /* number of candidate colors */
2644
2652
/* This array holds the actually closest colormap index for each cell. */
2645
int bestcolor[BOX_R_ELEMS * BOX_G_ELEMS * BOX_B_ELEMS];
2653
int bestcolor[BOX_R_ELEMS * BOX_G_ELEMS * BOX_B_ELEMS] = { 0, };
2647
2655
/* Convert cell coordinates to update box id */
2648
2656
R >>= BOX_R_LOG;
2724
2732
custompal_pass1 (QuantizeObj *quantobj)
2728
GimpPaletteEntry *entry;
2731
2737
/* fprintf(stderr,
2732
2738
"custompal_pass1: using (theCustomPalette %s) from (file %s)\n",
2733
2739
theCustomPalette->name, theCustomPalette->filename); */
2735
for (i = 0, list = theCustomPalette->colors;
2741
for (i = 0, list = gimp_palette_get_colors (theCustomPalette);
2737
2743
i++, list = g_list_next (list))
2745
GimpPaletteEntry *entry = list->data;
2741
2748
gimp_rgb_get_uchar (&entry->color, &r, &g, &b);
2770
2777
gint offsetx, offsety;
2773
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
2780
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
2775
2782
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
2777
2784
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
2779
gimp_item_width (GIMP_ITEM (layer)),
2780
gimp_item_height (GIMP_ITEM (layer)),
2786
gimp_item_get_width (GIMP_ITEM (layer)),
2787
gimp_item_get_height (GIMP_ITEM (layer)),
2782
2789
pixel_region_init (&destPR, new_tiles,
2784
gimp_item_width (GIMP_ITEM (layer)),
2785
gimp_item_height (GIMP_ITEM (layer)),
2791
gimp_item_get_width (GIMP_ITEM (layer)),
2792
gimp_item_get_height (GIMP_ITEM (layer)),
2788
2795
for (pr = pixel_regions_register (2, &srcPR, &destPR);
2811
2818
if (alpha_dither)
2813
gint dither_x = (col+offsetx+srcPR.x) & DM_WIDTHMASK;
2814
gint dither_y = (row+offsety+srcPR.y) & DM_HEIGHTMASK;
2820
gint dither_x = (col + offsetx + srcPR.x) & DM_WIDTHMASK;
2821
gint dither_y = (row + offsety + srcPR.y) & DM_HEIGHTMASK;
2816
if ((src[ALPHA_G_PIX]) < DM[dither_x][dither_y])
2823
if ((src[ALPHA_G]) < DM[dither_x][dither_y])
2817
2824
transparent = TRUE;
2821
if (src[ALPHA_G_PIX] <= 127)
2828
if (src[ALPHA_G] <= 127)
2822
2829
transparent = TRUE;
2825
2832
if (transparent)
2827
dest[ALPHA_I_PIX] = 0;
2831
dest[ALPHA_I_PIX] = 255;
2832
index_used_count[dest[INDEXED_PIX] = *cachep - 1]++;
2838
dest[ALPHA_I] = 255;
2839
index_used_count[dest[INDEXED] = *cachep - 1]++;
2837
2844
/* Now emit the colormap index for this cell */
2838
index_used_count[dest[INDEXED_PIX] = *cachep - 1]++;
2845
index_used_count[dest[INDEXED] = *cachep - 1]++;
2841
2848
src += srcPR.bytes;
2867
2874
gint offsetx, offsety;
2870
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
2877
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
2872
2879
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
2874
2881
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
2876
gimp_item_width (GIMP_ITEM (layer)),
2877
gimp_item_height (GIMP_ITEM (layer)),
2883
gimp_item_get_width (GIMP_ITEM (layer)),
2884
gimp_item_get_height (GIMP_ITEM (layer)),
2879
2886
pixel_region_init (&destPR, new_tiles,
2881
gimp_item_width (GIMP_ITEM (layer)),
2882
gimp_item_height (GIMP_ITEM (layer)),
2888
gimp_item_get_width (GIMP_ITEM (layer)),
2889
gimp_item_get_height (GIMP_ITEM (layer)),
2885
2892
for (pr = pixel_regions_register (2, &srcPR, &destPR);
2894
2901
for (col = 0; col < srcPR.w; col++)
2896
2903
const int dmval =
2897
DM[(col+offsetx+srcPR.x) & DM_WIDTHMASK]
2898
[(row+offsety+srcPR.y) & DM_HEIGHTMASK];
2904
DM[(col + offsetx + srcPR.x) & DM_WIDTHMASK]
2905
[(row + offsety + srcPR.y) & DM_HEIGHTMASK];
2900
2907
/* get pixel value and index into the cache */
2901
pixel = src[GRAY_PIX];
2902
2909
cachep = &histogram[pixel];
2903
2910
/* If we have not seen this color before, find nearest colormap entry */
2904
2911
/* and update the cache */
2945
2952
color2 = &quantobj->cmap[pixval2];
2947
err1 = ABS(color1->red - src[GRAY_PIX]);
2948
err2 = ABS(color2->red - src[GRAY_PIX]);
2954
err1 = ABS(color1->red - src[GRAY]);
2955
err2 = ABS(color2->red - src[GRAY]);
2949
2956
if (err1 || err2) {
2950
2957
const int proportion2 = (256 * 255 * err2) / (err1 + err2);
2951
2958
if ((dmval * 256) > proportion2) {
2960
2967
if (alpha_dither)
2962
if (src[ALPHA_G_PIX] < dmval)
2969
if (src[ALPHA_G] < dmval)
2963
2970
transparent = TRUE;
2967
if (src[ALPHA_G_PIX] <= 127)
2974
if (src[ALPHA_G] <= 127)
2968
2975
transparent = TRUE;
2971
2978
if (transparent)
2973
dest[ALPHA_I_PIX] = 0;
2977
dest[ALPHA_I_PIX] = 255;
2978
index_used_count[dest[INDEXED_PIX] = pixval1]++;
2984
dest[ALPHA_I] = 255;
2985
index_used_count[dest[INDEXED] = pixval1]++;
2983
2990
/* Now emit the colormap index for this cell, barfbarf */
2984
index_used_count[dest[INDEXED_PIX] = pixval1]++;
2991
index_used_count[dest[INDEXED] = pixval1]++;
2987
2994
src += srcPR.bytes;
3018
3025
gint nth_layer = quantobj->nth_layer;
3019
3026
gint n_layers = quantobj->n_layers;
3021
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
3028
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
3023
3030
/* In the case of web/mono palettes, we actually force
3024
3031
* grayscale drawables through the rgb pass2 functions
3026
3033
if (gimp_drawable_is_gray (GIMP_DRAWABLE (layer)))
3028
red_pix = green_pix = blue_pix = GRAY_PIX;
3029
alpha_pix = ALPHA_G_PIX;
3035
red_pix = green_pix = blue_pix = GRAY;
3036
alpha_pix = ALPHA_G;
3032
3039
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
3034
3041
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
3036
gimp_item_width (GIMP_ITEM (layer)),
3037
gimp_item_height (GIMP_ITEM (layer)),
3043
gimp_item_get_width (GIMP_ITEM (layer)),
3044
gimp_item_get_height (GIMP_ITEM (layer)),
3039
3046
pixel_region_init (&destPR, new_tiles,
3041
gimp_item_width (GIMP_ITEM (layer)),
3042
gimp_item_height (GIMP_ITEM (layer)),
3048
gimp_item_get_width (GIMP_ITEM (layer)),
3049
gimp_item_get_height (GIMP_ITEM (layer)),
3045
layer_size = (gimp_item_width (GIMP_ITEM (layer)) *
3046
gimp_item_height (GIMP_ITEM (layer)));
3052
layer_size = (gimp_item_get_width (GIMP_ITEM (layer)) *
3053
gimp_item_get_height (GIMP_ITEM (layer)));
3048
3055
for (pr = pixel_regions_register (2, &srcPR, &destPR);
3096
3103
fill_inverse_cmap_rgb (quantobj, histogram, R, G, B);
3098
3105
/* Now emit the colormap index for this cell, barfbarf */
3099
index_used_count[dest[INDEXED_PIX] = *cachep - 1]++;
3106
index_used_count[dest[INDEXED] = *cachep - 1]++;
3143
3150
gint nth_layer = quantobj->nth_layer;
3144
3151
gint n_layers = quantobj->n_layers;
3146
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
3153
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
3148
3155
/* In the case of web/mono palettes, we actually force
3149
3156
* grayscale drawables through the rgb pass2 functions
3151
3158
if (gimp_drawable_is_gray (GIMP_DRAWABLE (layer)))
3153
red_pix = green_pix = blue_pix = GRAY_PIX;
3154
alpha_pix = ALPHA_G_PIX;
3160
red_pix = green_pix = blue_pix = GRAY;
3161
alpha_pix = ALPHA_G;
3157
3164
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
3159
3166
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
3161
gimp_item_width (GIMP_ITEM (layer)),
3162
gimp_item_height (GIMP_ITEM (layer)),
3168
gimp_item_get_width (GIMP_ITEM (layer)),
3169
gimp_item_get_height (GIMP_ITEM (layer)),
3164
3171
pixel_region_init (&destPR, new_tiles,
3166
gimp_item_width (GIMP_ITEM (layer)),
3167
gimp_item_height (GIMP_ITEM (layer)),
3173
gimp_item_get_width (GIMP_ITEM (layer)),
3174
gimp_item_get_height (GIMP_ITEM (layer)),
3170
layer_size = (gimp_item_width (GIMP_ITEM (layer)) *
3171
gimp_item_height (GIMP_ITEM (layer)));
3177
layer_size = (gimp_item_get_width (GIMP_ITEM (layer)) *
3178
gimp_item_get_height (GIMP_ITEM (layer)));
3173
3180
for (pr = pixel_regions_register (2, &srcPR, &destPR);
3346
3353
gint lastblue = -1;
3347
3354
gint offsetx, offsety;
3349
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
3356
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
3351
3358
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
3353
3360
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
3355
gimp_item_width (GIMP_ITEM (layer)),
3356
gimp_item_height (GIMP_ITEM (layer)),
3362
gimp_item_get_width (GIMP_ITEM (layer)),
3363
gimp_item_get_height (GIMP_ITEM (layer)),
3358
3365
pixel_region_init (&destPR, new_tiles, 0, 0,
3359
gimp_item_width (GIMP_ITEM (layer)),
3360
gimp_item_height (GIMP_ITEM (layer)),
3366
gimp_item_get_width (GIMP_ITEM (layer)),
3367
gimp_item_get_height (GIMP_ITEM (layer)),
3363
3370
for (pr = pixel_regions_register (2, &srcPR, &destPR);
3560
3567
gint width, height;
3561
3568
gulong *index_used_count = quantobj->index_used_count;
3563
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
3570
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
3565
3572
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
3567
3574
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
3569
gimp_item_width (GIMP_ITEM (layer)),
3570
gimp_item_height (GIMP_ITEM (layer)),
3576
gimp_item_get_width (GIMP_ITEM (layer)),
3577
gimp_item_get_height (GIMP_ITEM (layer)),
3572
3579
pixel_region_init (&destPR, new_tiles, 0, 0,
3573
gimp_item_width (GIMP_ITEM (layer)),
3574
gimp_item_height (GIMP_ITEM (layer)),
3580
gimp_item_get_width (GIMP_ITEM (layer)),
3581
gimp_item_get_height (GIMP_ITEM (layer)),
3577
src_bytes = GIMP_DRAWABLE (layer)->bytes;
3584
src_bytes = gimp_drawable_bytes (GIMP_DRAWABLE (layer));
3578
3585
dest_bytes = tile_manager_bpp (new_tiles);
3579
width = gimp_item_width (GIMP_ITEM (layer));
3580
height = gimp_item_height (GIMP_ITEM (layer));
3586
width = gimp_item_get_width (GIMP_ITEM (layer));
3587
height = gimp_item_get_height (GIMP_ITEM (layer));
3582
3589
error_limiter = init_error_limit (quantobj->error_freedom);
3583
3590
range_limiter = range_array + 256;
3671
dest[ALPHA_I_PIX] = 255;
3678
dest[ALPHA_I] = 255;
3676
3683
if (alpha_dither)
3678
gint dither_x = (col+offsetx) & DM_WIDTHMASK;
3679
gint dither_y = (row+offsety) & DM_HEIGHTMASK;
3685
gint dither_x = (col + offsetx) & DM_WIDTHMASK;
3686
gint dither_y = (row + offsety) & DM_HEIGHTMASK;
3681
if ((src[ALPHA_G_PIX]) < DM[dither_x][dither_y])
3688
if ((src[ALPHA_G]) < DM[dither_x][dither_y])
3682
3689
transparent = TRUE;
3686
if (src[ALPHA_G_PIX] <= 127)
3693
if (src[ALPHA_G] <= 127)
3687
3694
transparent = TRUE;
3690
3697
if (transparent)
3692
dest[ALPHA_I_PIX] = 0;
3820
3827
gint nth_layer = quantobj->nth_layer;
3821
3828
gint n_layers = quantobj->n_layers;
3823
gimp_item_offsets (GIMP_ITEM (layer), &offsetx, &offsety);
3830
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
3825
3832
/* In the case of web/mono palettes, we actually force
3826
3833
* grayscale drawables through the rgb pass2 functions
3828
3835
if (gimp_drawable_is_gray (GIMP_DRAWABLE (layer)))
3829
red_pix = green_pix = blue_pix = GRAY_PIX;
3836
red_pix = green_pix = blue_pix = GRAY;
3831
3838
has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
3833
3840
pixel_region_init (&srcPR, gimp_drawable_get_tiles (GIMP_DRAWABLE (layer)),
3835
gimp_item_width (GIMP_ITEM (layer)),
3836
gimp_item_height (GIMP_ITEM (layer)),
3842
gimp_item_get_width (GIMP_ITEM (layer)),
3843
gimp_item_get_height (GIMP_ITEM (layer)),
3838
3845
pixel_region_init (&destPR, new_tiles, 0, 0,
3839
gimp_item_width (GIMP_ITEM (layer)),
3840
gimp_item_height (GIMP_ITEM (layer)),
3846
gimp_item_get_width (GIMP_ITEM (layer)),
3847
gimp_item_get_height (GIMP_ITEM (layer)),
3843
src_bytes = GIMP_DRAWABLE(layer)->bytes;
3850
src_bytes = gimp_drawable_bytes (GIMP_DRAWABLE (layer));
3844
3851
dest_bytes = tile_manager_bpp (new_tiles);
3845
width = gimp_item_width (GIMP_ITEM (layer));
3846
height = gimp_item_height (GIMP_ITEM (layer));
3852
width = gimp_item_get_width (GIMP_ITEM (layer));
3853
height = gimp_item_get_height (GIMP_ITEM (layer));
3848
3855
error_limiter = init_error_limit (quantobj->error_freedom);
3849
3856
range_limiter = range_array + 256;