1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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.
20
* This file is supposed to contain the generic (read: C) implementation
21
* of the pixel fiddling paint-functions.
24
#ifndef __PAINT_FUNCS_GENERIC_H__
25
#define __PAINT_FUNCS_GENERIC_H__
28
#define INT_MULT(a,b,t) ((t) = (a) * (b) + 0x80, ((((t) >> 8) + (t)) >> 8))
30
/* This version of INT_MULT3 is very fast, but suffers from some
31
slight roundoff errors. It returns the correct result 99.987
32
percent of the time */
33
#define INT_MULT3(a,b,c,t) ((t) = (a) * (b) * (c) + 0x7F5B, \
34
((((t) >> 7) + (t)) >> 16))
36
This version of INT_MULT3 always gives the correct result, but runs at
37
approximatly one third the speed. */
38
/* #define INT_MULT3(a,b,c,t) (((a) * (b) * (c) + 32512) / 65025.0)
41
#define INT_BLEND(a,b,alpha,tmp) (INT_MULT((a) - (b), alpha, tmp) + (b))
43
#define RANDOM_TABLE_SIZE 4096
45
/* A drawable has an alphachannel if contains either 4 or 2 bytes data
46
* aka GRAYA and RGBA and thus the macro below works. This will have
47
* to change if we support bigger formats. We'll do it so for now because
48
* masking is always cheaper than passing parameters over the stack. */
49
/* FIXME: Move to a global place */
50
#define HAS_ALPHA(bytes) (~bytes & 1)
52
/* FIXME: Move to a more global place */
53
struct apply_layer_mode_struct
65
CombinationMode combine;
68
static guchar add_lut[511];
69
static gint32 random_table[RANDOM_TABLE_SIZE];
72
color_pixels (guchar *dest,
80
memset (dest, *color, w);
84
#if defined(sparc) || defined(__sparc__)
86
const guchar c0 = color[0];
87
const guchar c1 = color[1];
98
const guint16 shortc = ((const guint16 *) color)[0];
99
guint16 *shortd = (guint16 *) dest;
107
#endif /* sparc || __sparc__ */
112
const guchar c0 = color[0];
113
const guchar c1 = color[1];
114
const guchar c2 = color[2];
127
#if defined(sparc) || defined(__sparc__)
129
const guchar c0 = color[0];
130
const guchar c1 = color[1];
131
const guchar c2 = color[2];
132
const guchar c3 = color[3];
145
const guint32 longc = ((const guint32 *) color)[0];
146
guint32 *longd = (guint32 *) dest;
154
#endif /* sparc || __sparc__ */
160
memcpy (dest, color, bytes);
167
color_pixels_mask (guchar *dest,
176
alpha = HAS_ALPHA (bytes) ? bytes - 1 : bytes;
181
memset (dest, *color, w);
224
pattern_pixels_mask (guchar *dest,
236
/* Get a pointer to the appropriate scanline of the pattern buffer */
237
pat = (temp_buf_data (pattern) +
238
(y % pattern->height) * pattern->width * pattern->bytes);
240
alpha = HAS_ALPHA (bytes) ? bytes - 1 : bytes;
243
* image data = pattern data for all but alpha
245
* If (image has alpha)
246
* if (there's a mask)
247
* image data = mask for alpha;
249
* image data = opaque for alpha.
251
* if (pattern has alpha)
252
* multiply existing alpha channel by pattern alpha
253
* (normalised to (0..1))
256
for (i = 0; i < w; i++)
258
p = pat + ((i + x) % pattern->width) * pattern->bytes;
260
for (b = 0; b < alpha; b++)
263
if (HAS_ALPHA (bytes))
266
dest[alpha] = *mask++;
268
dest[alpha] = OPAQUE_OPACITY;
270
if (HAS_ALPHA (pattern->bytes))
271
dest[alpha] = (guchar) (dest[alpha] *
272
p[alpha] / (gdouble) OPAQUE_OPACITY);
280
blend_pixels (const guchar *src1,
289
if (HAS_ALPHA (bytes))
291
const guint blend1 = 256 - blend;
292
const guint blend2 = blend + 1;
293
const guint c = bytes - 1;
297
guint a1 = blend1 * src1[c];
298
guint a2 = blend2 * src2[c];
303
for (b = 0; b < bytes; b++)
308
for (b = 0; b < c; b++)
309
dest[b] = (src1[b] * a1 + src2[b] * a2) / a;
321
const guchar blend1 = 255 - blend;
325
for (b = 0; b < bytes; b++)
326
dest[b] = (src1[b] * blend1 + src2[b] * blend) / 255;
336
shade_pixels (const guchar *src,
344
const guchar blend2 = (255 - blend);
345
const guint alpha = (has_alpha) ? bytes - 1 : bytes;
350
for (b = 0; b < alpha; b++)
351
dest[b] = (src[b] * blend2 + col[b] * blend) / 255;
354
dest[alpha] = src[alpha]; /* alpha channel */
363
extract_alpha_pixels (const guchar *src,
369
const guint alpha = bytes - 1;
374
const guchar *m = mask;
377
*dest++ = INT_MULT(src[alpha], *m, tmp);
386
*dest++ = INT_MULT(src[alpha], OPAQUE_OPACITY, tmp);
394
darken_pixels (const guchar *src1,
401
const guint has_alpha1 = HAS_ALPHA (bytes1);
402
const guint has_alpha2 = HAS_ALPHA (bytes2);
403
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
409
for (b = 0; b < alpha; b++)
413
dest[b] = (s1 < s2) ? s1 : s2;
416
if (has_alpha1 && has_alpha2)
417
dest[alpha] = MIN (src1[alpha], src2[alpha]);
419
dest[alpha] = src2[alpha];
429
lighten_pixels (const guchar *src1,
436
const guint has_alpha1 = HAS_ALPHA (bytes1);
437
const guint has_alpha2 = HAS_ALPHA (bytes2);
438
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
444
for (b = 0; b < alpha; b++)
448
dest[b] = (s1 < s2) ? s2 : s1;
451
if (has_alpha1 && has_alpha2)
452
dest[alpha] = MIN (src1[alpha], src2[alpha]);
454
dest[alpha] = src2[alpha];
464
hue_only_pixels (const guchar *src1,
471
const guint has_alpha1 = HAS_ALPHA (bytes1);
472
const guint has_alpha2 = HAS_ALPHA (bytes2);
476
/* assumes inputs are only 4 byte RGBA pixels */
479
r1 = src1[0]; g1 = src1[1]; b1 = src1[2];
480
r2 = src2[0]; g2 = src2[1]; b2 = src2[2];
481
gimp_rgb_to_hsv_int (&r1, &g1, &b1);
482
gimp_rgb_to_hsv_int (&r2, &g2, &b2);
486
/* set the destination */
487
gimp_hsv_to_rgb_int (&r1, &g1, &b1);
489
dest[0] = r1; dest[1] = g1; dest[2] = b1;
491
if (has_alpha1 && has_alpha2)
492
dest[3] = MIN (src1[3], src2[3]);
504
saturation_only_pixels (const guchar *src1,
511
const guint has_alpha1 = HAS_ALPHA (bytes1);
512
const guint has_alpha2 = HAS_ALPHA (bytes2);
516
/* assumes inputs are only 4 byte RGBA pixels */
519
r1 = src1[0]; g1 = src1[1]; b1 = src1[2];
520
r2 = src2[0]; g2 = src2[1]; b2 = src2[2];
521
gimp_rgb_to_hsv_int (&r1, &g1, &b1);
522
gimp_rgb_to_hsv_int (&r2, &g2, &b2);
526
/* set the destination */
527
gimp_hsv_to_rgb_int (&r1, &g1, &b1);
529
dest[0] = r1; dest[1] = g1; dest[2] = b1;
531
if (has_alpha1 && has_alpha2)
532
dest[3] = MIN (src1[3], src2[3]);
544
value_only_pixels (const guchar *src1,
551
const guint has_alpha1 = HAS_ALPHA (bytes1);
552
const guint has_alpha2 = HAS_ALPHA (bytes2);
556
/* assumes inputs are only 4 byte RGBA pixels */
559
r1 = src1[0]; g1 = src1[1]; b1 = src1[2];
560
r2 = src2[0]; g2 = src2[1]; b2 = src2[2];
561
gimp_rgb_to_hsv_int (&r1, &g1, &b1);
562
gimp_rgb_to_hsv_int (&r2, &g2, &b2);
566
/* set the destination */
567
gimp_hsv_to_rgb_int (&r1, &g1, &b1);
569
dest[0] = r1; dest[1] = g1; dest[2] = b1;
571
if (has_alpha1 && has_alpha2)
572
dest[3] = MIN (src1[3], src2[3]);
584
color_only_pixels (const guchar *src1,
591
const guint has_alpha1 = HAS_ALPHA (bytes1);
592
const guint has_alpha2 = HAS_ALPHA (bytes2);
596
/* assumes inputs are only 4 byte RGBA pixels */
599
r1 = src1[0]; g1 = src1[1]; b1 = src1[2];
600
r2 = src2[0]; g2 = src2[1]; b2 = src2[2];
601
gimp_rgb_to_hsl_int (&r1, &g1, &b1);
602
gimp_rgb_to_hsl_int (&r2, &g2, &b2);
604
/* transfer hue and saturation to the source pixel */
608
/* set the destination */
609
gimp_hsl_to_rgb_int (&r1, &g1, &b1);
611
dest[0] = r1; dest[1] = g1; dest[2] = b1;
613
if (has_alpha1 && has_alpha2)
614
dest[3] = MIN (src1[3], src2[3]);
626
multiply_pixels (const guchar *src1,
633
const guint has_alpha1 = HAS_ALPHA (bytes1);
634
const guint has_alpha2 = HAS_ALPHA (bytes2);
635
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
638
if (has_alpha1 && has_alpha2)
642
for (b = 0; b < alpha; b++)
643
dest[b] = INT_MULT(src1[b], src2[b], tmp);
645
dest[alpha] = MIN (src1[alpha], src2[alpha]);
656
for (b = 0; b < alpha; b++)
657
dest[b] = INT_MULT(src1[b], src2[b], tmp);
659
dest[alpha] = src2[alpha];
670
for (b = 0; b < alpha; b++)
671
dest[b] = INT_MULT(src1[b], src2[b], tmp);
682
divide_pixels (const guchar *src1,
689
const guint has_alpha1 = HAS_ALPHA (bytes1);
690
const guint has_alpha2 = HAS_ALPHA (bytes2);
691
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
696
for (b = 0; b < alpha; b++)
698
result = ((src1[b] * 256) / (1+src2[b]));
699
dest[b] = MIN (result, 255);
702
if (has_alpha1 && has_alpha2)
703
dest[alpha] = MIN (src1[alpha], src2[alpha]);
705
dest[alpha] = src2[alpha];
715
screen_pixels (const guchar *src1,
722
const guint has_alpha1 = HAS_ALPHA (bytes1);
723
const guint has_alpha2 = HAS_ALPHA (bytes2);
724
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
729
for (b = 0; b < alpha; b++)
730
dest[b] = 255 - INT_MULT((255 - src1[b]), (255 - src2[b]), tmp);
732
if (has_alpha1 && has_alpha2)
733
dest[alpha] = MIN (src1[alpha], src2[alpha]);
735
dest[alpha] = src2[alpha];
745
overlay_pixels (const guchar *src1,
752
const guint has_alpha1 = HAS_ALPHA (bytes1);
753
const guint has_alpha2 = HAS_ALPHA (bytes2);
754
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
759
for (b = 0; b < alpha; b++)
761
dest[b] = INT_MULT(src1[b], src1[b] + INT_MULT(2 * src2[b],
766
if (has_alpha1 && has_alpha2)
767
dest[alpha] = MIN (src1[alpha], src2[alpha]);
769
dest[alpha] = src2[alpha];
779
dodge_pixels (const guchar *src1,
786
const guint has_alpha1 = HAS_ALPHA (bytes1);
787
const guint has_alpha2 = HAS_ALPHA (bytes2);
788
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
793
for (b = 0; b < alpha; b++)
796
tmp /= 256 - src2[b];
797
dest[b] = (guchar) MIN (tmp, 255);
800
if (has_alpha1 && has_alpha2)
801
dest[alpha] = MIN (src1[alpha], src2[alpha]);
803
dest[alpha] = src2[alpha];
813
burn_pixels (const guchar *src1,
820
const guint has_alpha1 = HAS_ALPHA (bytes1);
821
const guint has_alpha2 = HAS_ALPHA (bytes2);
822
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
825
/* FIXME: Is the burn effect supposed to be dependant on the sign of this
826
* temporary variable? */
831
for (b = 0; b < alpha; b++)
833
tmp = (255 - src1[b]) << 8;
835
dest[b] = (guchar) CLAMP (255 - tmp, 0, 255);
838
if (has_alpha1 && has_alpha2)
839
dest[alpha] = MIN (src1[alpha], src2[alpha]);
841
dest[alpha] = src2[alpha];
851
hardlight_pixels (const guchar *src1,
858
const guint has_alpha1 = HAS_ALPHA (bytes1);
859
const guint has_alpha2 = HAS_ALPHA (bytes2);
860
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
865
for (b = 0; b < alpha; b++)
868
tmp = ((gint)255 - src1[b]) * ((gint)255 - ((src2[b] - 128) << 1));
869
dest[b] = (guchar) MIN (255 - (tmp >> 8), 255);
871
tmp = (gint)src1[b] * ((gint)src2[b] << 1);
872
dest[b] = (guchar) MIN (tmp >> 8, 255);
876
if (has_alpha1 && has_alpha2)
877
dest[alpha] = MIN (src1[alpha], src2[alpha]);
879
dest[alpha] = src2[alpha];
889
softlight_pixels (const guchar *src1,
896
const guint has_alpha1 = HAS_ALPHA (bytes1);
897
const guint has_alpha2 = HAS_ALPHA (bytes2);
898
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
899
guint b, tmpS, tmpM, tmp1, tmp2, tmp3;
903
for (b = 0; b < alpha; b++)
905
/* Mix multiply and screen */
906
tmpM = INT_MULT (src1[b], src2[b], tmpM);
907
tmpS = 255 - INT_MULT((255 - src1[b]), (255 - src2[b]), tmp1);
908
dest[b] = INT_MULT ((255 - src1[b]), tmpM, tmp2) +
909
INT_MULT (src1[b], tmpS, tmp3);
912
if (has_alpha1 && has_alpha2)
913
dest[alpha] = MIN (src1[alpha], src2[alpha]);
915
dest[alpha] = src2[alpha];
925
grain_extract_pixels (const guchar *src1,
934
const guint has_alpha1 = HAS_ALPHA (bytes1);
935
const guint has_alpha2 = HAS_ALPHA (bytes2);
937
alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
941
for (b = 0; b < alpha; b++)
943
diff = src1[b] - src2[b] + 128;
944
dest[b] = (guchar) CLAMP (diff, 0, 255);
947
if (has_alpha1 && has_alpha2)
948
dest[alpha] = MIN (src1[alpha], src2[alpha]);
950
dest[alpha] = src2[alpha];
960
grain_merge_pixels (const guchar *src1,
969
const guint has_alpha1 = HAS_ALPHA (bytes1);
970
const guint has_alpha2 = HAS_ALPHA (bytes2);
972
alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
976
for (b = 0; b < alpha; b++)
978
/* Add, re-center and clip. */
979
sum = src1[b] + src2[b] - 128;
980
dest[b] = (guchar) CLAMP (sum, 0, 255);
983
if (has_alpha1 && has_alpha2)
984
dest[alpha] = MIN (src1[alpha], src2[alpha]);
986
dest[alpha] = src2[alpha];
996
add_pixels (const guchar *src1,
1003
const guint has_alpha1 = HAS_ALPHA (bytes1);
1004
const guint has_alpha2 = HAS_ALPHA (bytes2);
1005
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
1010
for (b = 0; b < alpha; b++)
1011
dest[b] = add_lut[src1[b] + src2[b]];
1013
if (has_alpha1 && has_alpha2)
1014
dest[alpha] = MIN (src1[alpha], src2[alpha]);
1015
else if (has_alpha2)
1016
dest[alpha] = src2[alpha];
1026
subtract_pixels (const guchar *src1,
1033
const guint has_alpha1 = HAS_ALPHA (bytes1);
1034
const guint has_alpha2 = HAS_ALPHA (bytes2);
1035
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
1041
for (b = 0; b < alpha; b++)
1043
diff = src1[b] - src2[b];
1044
dest[b] = (diff < 0) ? 0 : diff;
1047
if (has_alpha1 && has_alpha2)
1048
dest[alpha] = MIN (src1[alpha], src2[alpha]);
1049
else if (has_alpha2)
1050
dest[alpha] = src2[alpha];
1060
difference_pixels (const guchar *src1,
1067
const guint has_alpha1 = HAS_ALPHA (bytes1);
1068
const guint has_alpha2 = HAS_ALPHA (bytes2);
1069
const guint alpha = (has_alpha1 || has_alpha2) ? MAX (bytes1, bytes2) - 1 : bytes1;
1075
for (b = 0; b < alpha; b++)
1077
diff = src1[b] - src2[b];
1078
dest[b] = (diff < 0) ? -diff : diff;
1081
if (has_alpha1 && has_alpha2)
1082
dest[alpha] = MIN (src1[alpha], src2[alpha]);
1083
else if (has_alpha2)
1084
dest[alpha] = src2[alpha];
1094
dissolve_pixels (const guchar *src,
1107
gint combined_opacity;
1110
gr = g_rand_new_with_seed (random_table[y % RANDOM_TABLE_SIZE]);
1112
/* Ignore x random values so we get a deterministic result */
1113
for (b = 0; b < x; b ++)
1120
/* preserve the intensity values */
1121
for (b = 0; b < alpha; b++)
1124
/* dissolve if random value is >= opacity */
1125
rand_val = g_rand_int_range (gr, 0, 255);
1130
combined_opacity = opacity * src[alpha] * *mask / (255 * 255);
1132
combined_opacity = opacity * *mask / 255;
1139
combined_opacity = opacity * src[alpha] / 255;
1141
combined_opacity = opacity;
1144
dest[alpha] = (rand_val >= combined_opacity) ? 0 : OPAQUE_OPACITY;
1155
replace_pixels (guchar *src1,
1161
const gboolean *affect,
1167
gdouble a_val, a_recip, mask_val;
1168
gdouble norm_opacity;
1172
if (bytes1 != bytes2)
1174
g_warning ("replace_pixels only works on commensurate pixel regions");
1179
norm_opacity = opacity * (1.0 / 65536.0);
1183
mask_val = mask[0] * norm_opacity;
1184
/* calculate new alpha first. */
1187
a_val = s1_a + mask_val * (s2_a - s1_a);
1189
if (a_val == 0) /* In any case, write out versions of the blending function */
1190
/* that result when combinations of s1_a, s2_a, and */
1191
/* mask_val --> 0 (or mask_val -->1) */
1193
/* Case 1: s1_a, s2_a, AND mask_val all approach 0+: */
1194
/* Case 2: s1_a AND s2_a both approach 0+, regardless of mask_val: */
1196
if (s1_a + s2_a == 0.0)
1198
for (b = 0; b < alpha; b++)
1200
new_val = 0.5 + (gdouble) src1[b] +
1201
mask_val * ((gdouble) src2[b] - (gdouble) src1[b]);
1203
dest[b] = affect[b] ? MIN (new_val, 255) : src1[b];
1207
/* Case 3: mask_val AND s1_a both approach 0+, regardless of s2_a */
1208
else if (s1_a + mask_val == 0.0)
1210
for (b = 0; b < alpha; b++)
1216
/* Case 4: mask_val -->1 AND s2_a -->0, regardless of s1_a */
1217
else if (1.0 - mask_val + s2_a == 0.0)
1219
for (b = 0; b < alpha; b++)
1221
dest[b] = affect[b] ? src2[b] : src1[b];
1227
a_recip = 1.0 / a_val;
1228
/* possible optimization: fold a_recip into s1_a and s2_a */
1229
for (b = 0; b < alpha; b++)
1231
new_val = 0.5 + a_recip * (src1[b] * s1_a + mask_val *
1232
(src2[b] * s2_a - src1[b] * s1_a));
1233
dest[b] = affect[b] ? MIN (new_val, 255) : src1[b];
1237
dest[alpha] = affect[alpha] ? a_val + 0.5: s1_a;
1246
swap_pixels (guchar *src,
1252
*src = *src ^ *dest;
1253
*dest = *dest ^ *src;
1254
*src = *src ^ *dest;
1261
scale_pixels (const guchar *src,
1270
*dest++ = (guchar) INT_MULT (*src, scale, tmp);
1276
add_alpha_pixels (const guchar *src,
1287
for (b = 0; b < bytes; b++)
1290
dest[b] = OPAQUE_OPACITY;
1299
flatten_pixels (const guchar *src,
1311
for (b = 0; b < alpha; b++)
1312
dest[b] = INT_MULT (src[b], src[alpha], t1) +
1313
INT_MULT (bg[b], (255 - src[alpha]), t2);
1322
gray_to_rgb_pixels (const guchar *src,
1331
has_alpha = (bytes == 2) ? TRUE : FALSE;
1332
dest_bytes = (has_alpha) ? 4 : 3;
1336
for (b = 0; b < bytes; b++)
1349
apply_mask_to_alpha_channel (guchar *src,
1363
*src = INT_MULT(*src, *mask, tmp);
1372
*src = INT_MULT3(*src, *mask, opacity, tmp);
1381
combine_mask_and_alpha_channel_stipple (guchar *src,
1390
/* align with alpha channel */
1396
mask_val = INT_MULT(*mask, opacity, tmp);
1397
*src = *src + INT_MULT((255 - *src) , mask_val, tmp);
1405
*src = *src + INT_MULT((255 - *src) , *mask, tmp);
1414
combine_mask_and_alpha_channel_stroke (guchar *src,
1423
/* align with alpha channel */
1431
mask_val = INT_MULT(*mask, opacity, tmp);
1432
*src = *src + INT_MULT((opacity - *src) , mask_val, tmp);
1441
*src = *src + INT_MULT((255 - *src) , *mask, tmp);
1450
copy_gray_to_inten_a_pixels (const guchar *src,
1462
for (b = 0; b < alpha; b++)
1464
dest[b] = OPAQUE_OPACITY;
1473
initial_channel_pixels (const guchar *src,
1484
for (b = 0; b < alpha; b++)
1487
dest[alpha] = OPAQUE_OPACITY;
1496
initial_indexed_pixels (const guchar *src,
1503
/* This function assumes always that we're mapping from
1504
* an RGB colormap to an RGBA image...
1508
col_index = *src++ * 3;
1509
*dest++ = cmap[col_index++];
1510
*dest++ = cmap[col_index++];
1511
*dest++ = cmap[col_index++];
1512
*dest++ = OPAQUE_OPACITY;
1518
initial_indexed_a_pixels (const guchar *src,
1521
const guchar *no_mask,
1538
col_index = *src++ * 3;
1539
new_alpha = INT_MULT3(*src, *m, opacity, tmp);
1541
*dest++ = cmap[col_index++];
1542
*dest++ = cmap[col_index++];
1543
*dest++ = cmap[col_index++];
1544
/* Set the alpha channel */
1545
*dest++ = (new_alpha > 127) ? OPAQUE_OPACITY : TRANSPARENT_OPACITY;
1554
initial_inten_pixels (const guchar *src,
1557
const guchar *no_mask,
1559
const gboolean *affect,
1569
const gint dest_bytes = bytes + 1;
1575
/* This function assumes the source has no alpha channel and
1576
* the destination has an alpha channel. So dest_bytes = bytes + 1
1579
if (bytes == 3 && affect[0] && affect[1] && affect[2])
1584
destp = dest + bytes;
1592
dest[3] = INT_MULT(opacity, *m, tmp);
1610
for (b =0; b < bytes; b++)
1621
destp += dest_bytes;
1627
destp += dest_bytes;
1631
/* fill the alpha channel */
1635
destp = dest + bytes;
1640
*destp = INT_MULT(opacity , *m, tmp);
1641
destp += dest_bytes;
1648
destp += dest_bytes;
1651
else /* If no mask */
1653
/* This function assumes the source has no alpha channel and
1654
* the destination has an alpha channel. So dest_bytes = bytes + 1
1657
if (bytes == 3 && affect[0] && affect[1] && affect[2])
1662
destp = dest + bytes;
1676
for (b = 0; b < bytes; b++)
1687
destp += dest_bytes;
1693
destp += dest_bytes;
1697
/* fill the alpha channel */
1701
destp = dest + bytes;
1706
destp += dest_bytes;
1713
initial_inten_a_pixels (const guchar *src,
1717
const gboolean *affect,
1731
for (b = 0; b < alpha; b++)
1732
dest[b] = src[b] * affect[b];
1734
/* Set the alpha channel */
1735
dest[alpha] = affect [alpha] ? INT_MULT3(opacity, src[alpha], *m, tmp)
1748
for (b = 0; b < alpha; b++)
1749
dest[b] = src[b] * affect[b];
1751
/* Set the alpha channel */
1752
dest[alpha] = affect [alpha] ? INT_MULT(opacity , src[alpha], tmp) : 0;
1761
component_pixels (const guchar *src,
1780
layer_normal_mode (struct apply_layer_mode_struct *alms)
1782
/* assumes we're applying src2 TO src1 */
1783
*(alms->dest) = alms->src2;
1787
layer_dissolve_mode (struct apply_layer_mode_struct *alms)
1789
const guint has_alpha1 = HAS_ALPHA (alms->bytes1);
1790
const guint has_alpha2 = HAS_ALPHA (alms->bytes2);
1793
/* Since dissolve requires an alpha channel... */
1795
dest_bytes = alms->bytes2;
1797
dest_bytes = alms->bytes2 + 1;
1799
dissolve_pixels (alms->src2, alms->mask, *(alms->dest),
1801
alms->opacity, alms->length,
1802
alms->bytes2, dest_bytes,
1805
alms->combine = has_alpha1 ? COMBINE_INTEN_A_INTEN_A : COMBINE_INTEN_INTEN_A;
1809
layer_multiply_mode (struct apply_layer_mode_struct *alms)
1811
multiply_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1812
alms->bytes1, alms->bytes2);
1816
layer_divide_mode (struct apply_layer_mode_struct *alms)
1818
divide_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1819
alms->bytes1, alms->bytes2);
1823
layer_screen_mode (struct apply_layer_mode_struct *alms)
1825
screen_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1826
alms->bytes1, alms->bytes2);
1830
layer_overlay_mode (struct apply_layer_mode_struct *alms)
1832
overlay_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1833
alms->bytes1, alms->bytes2);
1837
layer_difference_mode (struct apply_layer_mode_struct *alms)
1839
difference_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1840
alms->bytes1, alms->bytes2);
1844
layer_addition_mode (struct apply_layer_mode_struct *alms)
1846
add_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1847
alms->bytes1, alms->bytes2);
1851
layer_subtract_mode (struct apply_layer_mode_struct *alms)
1853
subtract_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1854
alms->bytes1, alms->bytes2);
1858
layer_darken_only_mode (struct apply_layer_mode_struct *alms)
1860
darken_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1861
alms->bytes1, alms->bytes2);
1865
layer_lighten_only_mode (struct apply_layer_mode_struct *alms)
1867
lighten_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1868
alms->bytes1, alms->bytes2);
1872
layer_hue_mode (struct apply_layer_mode_struct *alms)
1874
/* only works on RGB color images */
1875
if (alms->bytes1 > 2)
1876
hue_only_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1877
alms->bytes1, alms->bytes2);
1879
*(alms->dest) = alms->src2;
1883
layer_saturation_mode (struct apply_layer_mode_struct *alms)
1885
/* only works on RGB color images */
1886
if (alms->bytes1 > 2)
1887
saturation_only_pixels (alms->src1, alms->src2, *(alms->dest),
1888
alms->length, alms->bytes1, alms->bytes2);
1890
*(alms->dest) = alms->src2;
1894
layer_value_mode (struct apply_layer_mode_struct *alms)
1896
/* only works on RGB color images */
1897
if (alms->bytes1 > 2)
1898
value_only_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1899
alms->bytes1, alms->bytes2);
1901
*(alms->dest) = alms->src2;
1905
layer_color_mode (struct apply_layer_mode_struct *alms)
1907
/* only works on RGB color images */
1908
if (alms->bytes1 > 2)
1909
color_only_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1910
alms->bytes1, alms->bytes2);
1912
*(alms->dest) = alms->src2;
1916
layer_behind_mode (struct apply_layer_mode_struct *alms)
1918
*(alms->dest) = alms->src2;
1919
if (HAS_ALPHA (alms->bytes1))
1920
alms->combine = BEHIND_INTEN;
1922
alms->combine = NO_COMBINATION;
1926
layer_replace_mode (struct apply_layer_mode_struct *alms)
1928
*(alms->dest) = alms->src2;
1929
alms->combine = REPLACE_INTEN;
1933
layer_erase_mode (struct apply_layer_mode_struct *alms)
1935
*(alms->dest) = alms->src2;
1936
/* If both sources have alpha channels, call erase function.
1937
* Otherwise, just combine in the normal manner
1940
(HAS_ALPHA (alms->bytes1) && HAS_ALPHA (alms->bytes2)) ? ERASE_INTEN : 0;
1944
layer_anti_erase_mode (struct apply_layer_mode_struct *alms)
1946
*(alms->dest) = alms->src2;
1948
(HAS_ALPHA (alms->bytes1) && HAS_ALPHA (alms->bytes2)) ? ANTI_ERASE_INTEN : 0;
1952
layer_color_erase_mode (struct apply_layer_mode_struct *alms)
1954
*(alms->dest) = alms->src2;
1956
(HAS_ALPHA (alms->bytes1) && HAS_ALPHA (alms->bytes2)) ? COLOR_ERASE_INTEN : 0;
1960
layer_dodge_mode (struct apply_layer_mode_struct *alms)
1962
dodge_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1963
alms->bytes1, alms->bytes2);
1967
layer_burn_mode (struct apply_layer_mode_struct *alms)
1969
burn_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1970
alms->bytes1, alms->bytes2);
1974
layer_hardlight_mode (struct apply_layer_mode_struct *alms)
1976
hardlight_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1977
alms->bytes1, alms->bytes2);
1981
layer_softlight_mode (struct apply_layer_mode_struct *alms)
1983
softlight_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1984
alms->bytes1, alms->bytes2);
1988
layer_grain_extract_mode (struct apply_layer_mode_struct *alms)
1990
grain_extract_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1991
alms->bytes1, alms->bytes2);
1995
layer_grain_merge_mode (struct apply_layer_mode_struct *alms)
1997
grain_merge_pixels (alms->src1, alms->src2, *(alms->dest), alms->length,
1998
alms->bytes1, alms->bytes2);
2001
#endif /* __PAINT_FUNCS_GENERIC_H__ */