3 * Macros to mix two pixels accordingly to percentage.
5 * Copyright (C) 2011-2014 Cyril Hrubis <metan@ucw.cz>
8 #include "core/GP_Pixmap.h"
9 #include "core/GP_Pixel.h"
10 #include "core/GP_GetPutPixel.h"
11 #include "core/GP_GammaCorrection.h"
13 @ for pt in pixeltypes:
14 @ if not pt.is_unknown():
17 * Mixes two {{ pt.name }} pixels.
19 * The percentage is expected as 8 bit unsigned integer [0 .. 255]
21 #define GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc) ({ \
22 @ for c in pt.chanslist:
23 GP_Pixel {{ c[0] }}; \
25 {{ c[0] }} = GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1) * (perc); \
26 {{ c[0] }} += GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix2) * (255 - (perc)); \
27 {{ c[0] }} = ({{ c[0] }} + 128) / 255; \
31 GP_Pixel_CREATE_{{ pt.name }}({{ ', '.join(pt.chan_names) }}); \
35 * Mixes two {{ pt.name }} pixels.
37 * The percentage is expected as 8 bit unsigned integer [0 .. 255]
39 #define GP_MIX_PIXELS_GAMMA_{{ pt.name }}(pix1, pix2, perc) ({ \
40 @ for c in pt.chanslist:
41 GP_Pixel {{ c[0] }}; \
43 {{ c[0] }} = GP_Gamma{{ c[2] }}ToLinear10(GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix1)) * (perc); \
44 {{ c[0] }} += GP_Gamma{{ c[2] }}ToLinear10(GP_Pixel_GET_{{ c[0] }}_{{ pt.name }}(pix2)) * (255 - (perc)); \
45 {{ c[0] }} = ({{ c[0] }} + 128) / 255; \
46 {{ c[0] }} = GP_Linear10ToGamma{{ c[2] }}({{ c[0] }}); \
50 GP_Pixel_CREATE_{{ pt.name }}({{ ", ".join(pt.chan_names) }}); \
53 #define GP_MIX_PIXELS_{{ pt.name }}(pix1, pix2, perc) \
55 GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc)
57 GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc)
60 static inline GP_Pixel GP_MixPixels(GP_Pixel pix1, GP_Pixel pix2,
61 uint8_t perc, GP_PixelType pixel_type)
64 @ for pt in pixeltypes:
65 @ if not pt.is_unknown():
66 case GP_PIXEL_{{ pt.name }}:
67 return GP_MIX_PIXELS_LINEAR_{{ pt.name }}(pix1, pix2, perc);
70 GP_ABORT("Unknown pixeltype");
75 @ for pt in pixeltypes:
76 @ if not pt.is_unknown():
77 static inline void GP_MixPixel_Raw_{{ pt.name }}(GP_Pixmap *pixmap,
78 GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
80 GP_Pixel pix = GP_GetPixel_Raw_{{ pt.pixelsize.suffix }}(pixmap, x, y);
81 pix = GP_MIX_PIXELS_{{ pt.name }}(pixel, pix, perc);
82 GP_PutPixel_Raw_{{ pt.pixelsize.suffix }}(pixmap, x, y, pix);
87 @ for pt in pixeltypes:
88 @ if not pt.is_unknown():
89 static inline void GP_MixPixel_Raw_Clipped_{{ pt.name }}(GP_Pixmap *pixmap,
90 GP_Coord x, GP_Coord y, GP_Pixel pixel, uint8_t perc)
92 if (GP_PIXEL_IS_CLIPPED(pixmap, x, y))
95 GP_MixPixel_Raw_{{ pt.name }}(pixmap, x, y, pixel, perc);
100 static inline void GP_MixPixel_Raw(GP_Pixmap *pixmap, GP_Coord x, GP_Coord y,
101 GP_Pixel pixel, uint8_t perc)
103 switch (pixmap->pixel_type) {
104 @ for pt in pixeltypes:
105 @ if not pt.is_unknown():
106 case GP_PIXEL_{{ pt.name }}:
107 GP_MixPixel_Raw_{{ pt.name }}(pixmap, x, y, pixel, perc);
111 GP_ABORT("Unknown pixeltype");
115 static inline void GP_MixPixel_Raw_Clipped(GP_Pixmap *pixmap,
116 GP_Coord x, GP_Coord y,
117 GP_Pixel pixel, uint8_t perc)
119 switch (pixmap->pixel_type) {
120 @ for pt in pixeltypes:
121 @ if not pt.is_unknown():
122 case GP_PIXEL_{{ pt.name }}:
123 GP_MixPixel_Raw_Clipped_{{ pt.name }}(pixmap, x, y, pixel, perc);
127 GP_ABORT("Unknown pixeltype");