1 2 /* !!!! AUTOGENERATED FILE generated by svg-12-porter-duff.rb !!!!! 3 * 4 * This file is an image processing operation for GEGL 5 * 6 * GEGL is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 3 of the License, or (at your option) any later version. 10 * 11 * GEGL is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with GEGL; if not, see <https://www.gnu.org/licenses/>. 18 * 19 * Copyright 2006, 2007 Øyvind Kolås <pippin@gimp.org> 20 * 2007 John Marshall 21 * 2013 Daniel Sabo 22 * 23 * SVG rendering modes; see: 24 * http://www.w3.org/TR/SVG12/rendering.html 25 * http://www.w3.org/TR/2004/WD-SVG12-20041027/rendering.html#comp-op-prop 26 * 27 * aA = aux(src) alpha aB = in(dst) alpha aD = out alpha 28 * cA = aux(src) colour cB = in(dst) colour cD = out colour 29 * 30 * !!!! AUTOGENERATED FILE !!!!! 31 */ 32 #include "config.h" 33 #include <glib/gi18n-lib.h> 34 35 36 #ifdef GEGL_PROPERTIES 37 38 property_boolean (srgb, _("sRGB"), FALSE) 39 description (_("Use sRGB gamma instead of linear")) 40 41 #else 42 43 #define GEGL_OP_POINT_COMPOSER 44 #define GEGL_OP_NAME xor 45 #define GEGL_OP_C_FILE "xor.c" 46 47 #include "gegl-op.h" 48 49 static void prepare (GeglOperation *operation) 50 { 51 const Babl *format = gegl_operation_get_source_format (operation, "input"); 52 if (!format) 53 format = gegl_operation_get_source_format (operation, "aux"); 54 55 if(GEGL_PROPERTIES (operation)->srgb) 56 format = gegl_babl_variant (format, GEGL_BABL_VARIANT_PERCEPTUAL_PREMULTIPLIED); 57 else 58 format = gegl_babl_variant (format, GEGL_BABL_VARIANT_LINEAR_PREMULTIPLIED); 59 60 gegl_operation_set_format (operation, "input", format); 61 gegl_operation_set_format (operation, "aux", format); 62 gegl_operation_set_format (operation, "output", format); 63 } 64 65 static gboolean 66 process (GeglOperation *op, 67 void *in_buf, 68 void *aux_buf, 69 void *out_buf, 70 glong n_pixels, 71 const GeglRectangle *roi, 72 gint level) 73 { 74 gint i; 75 gfloat * GEGL_ALIGNED in = in_buf; 76 gfloat * GEGL_ALIGNED aux = aux_buf; 77 gfloat * GEGL_ALIGNED out = out_buf; 78 const Babl *format = gegl_operation_get_format (op, "output"); 79 gint components = babl_format_get_n_components (format); 80 gint alpha = components-1; 81 82 if (!aux) 83 { 84 for (i = 0; i < n_pixels; i++) 85 { 86 gint j; 87 gfloat aA G_GNUC_UNUSED, aB G_GNUC_UNUSED, aD G_GNUC_UNUSED; 88 89 aB = alpha?in[alpha]:1.0f; 90 aA = 0.0f; 91 aD = aA + aB - 2.0f * aA * aB; 92 93 for (j = 0; j < alpha; j++) 94 { 95 gfloat cA G_GNUC_UNUSED, cB G_GNUC_UNUSED; 96 97 cB = in[j]; 98 cA = 0.0f; 99 out[j] = cA * (1.0f - aB)+ cB * (1.0f - aA); 100 } 101 out[alpha] = aD; 102 in += components; 103 out += components; 104 } 105 } 106 else 107 { 108 for (i = 0; i < n_pixels; i++) 109 { 110 gint j; 111 gfloat aA G_GNUC_UNUSED, aB G_GNUC_UNUSED, aD G_GNUC_UNUSED; 112 113 aB = in[alpha]; 114 aA = aux[alpha]; 115 aD = aA + aB - 2.0f * aA * aB; 116 117 for (j = 0; j < alpha; j++) 118 { 119 gfloat cA G_GNUC_UNUSED, cB G_GNUC_UNUSED; 120 121 cB = in[j]; 122 cA = aux[j]; 123 out[j] = cA * (1.0f - aB)+ cB * (1.0f - aA); 124 } 125 out[alpha] = aD; 126 in += components; 127 aux += components; 128 out += components; 129 } 130 } 131 return TRUE; 132 } 133 134 135 static void 136 gegl_op_class_init (GeglOpClass *klass) 137 { 138 GeglOperationClass *operation_class; 139 GeglOperationPointComposerClass *point_composer_class; 140 141 operation_class = GEGL_OPERATION_CLASS (klass); 142 point_composer_class = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass); 143 144 point_composer_class->process = process; 145 operation_class->prepare = prepare; 146 147 148 gegl_operation_class_set_keys (operation_class, 149 "name" , "svg:xor", 150 "compat-name", "gegl:xor", 151 "title" , "Xor", 152 "reference-hash" , "d5c452c163acf983677da4dd5e5dca09", 153 "categories" , "compositors:porter-duff", 154 "description", 155 _("Porter Duff operation xor (d = cA * (1.0f - aB)+ cB * (1.0f - aA))"), 156 NULL); 157 158 159 } 160 161 #endif 162