[gegl] ctx: update from upstream, better floating point support



commit 5563dad6207665628fa3be1eacaab460e7cd0a80
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Jul 1 04:42:24 2021 +0200

    ctx: update from upstream, better floating point support

 gegl/ctx/ctx.h | 155 +++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 95 insertions(+), 60 deletions(-)
---
diff --git a/gegl/ctx/ctx.h b/gegl/ctx/ctx.h
index d0fc0170b..0eb6f3098 100644
--- a/gegl/ctx/ctx.h
+++ b/gegl/ctx/ctx.h
@@ -29513,10 +29513,16 @@ ctx_fragment_linear_gradient_RGBAF (CtxRasterizer *rasterizer, float x, float y,
 {
   float *rgba = (float *) out;
   CtxSource *g = &rasterizer->state->gstate.source_fill;
-  float v = ( ( (g->linear_gradient.dx * x + g->linear_gradient.dy * y) /
-                g->linear_gradient.length) -
-              g->linear_gradient.start) * (g->linear_gradient.rdelta);
-  ctx_fragment_gradient_1d_RGBAF (rasterizer, v, 1.0f, rgba);
+  for (int i = 0; i < count; i++)
+  {
+    float v = ( ( (g->linear_gradient.dx * x + g->linear_gradient.dy * y) /
+                  g->linear_gradient.length) -
+                g->linear_gradient.start) * (g->linear_gradient.rdelta);
+    ctx_fragment_gradient_1d_RGBAF (rasterizer, v, 1.0f, rgba);
+    x += dx;
+    y += dy;
+    rgba += 4;
+  }
 }
 
 static void
@@ -29524,9 +29530,15 @@ ctx_fragment_radial_gradient_RGBAF (CtxRasterizer *rasterizer, float x, float y,
 {
   float *rgba = (float *) out;
   CtxSource *g = &rasterizer->state->gstate.source_fill;
+  for (int i = 0; i < count; i++)
+  {
   float v = ctx_hypotf (g->radial_gradient.x0 - x, g->radial_gradient.y0 - y);
         v = (v - g->radial_gradient.r0) * (g->radial_gradient.rdelta);
   ctx_fragment_gradient_1d_RGBAF (rasterizer, v, 0.0f, rgba);
+    x+=dx;
+    y+=dy;
+    rgba +=4;
+  }
 }
 #endif
 
@@ -29535,8 +29547,12 @@ static void
 ctx_fragment_color_RGBAF (CtxRasterizer *rasterizer, float x, float y, void *out, int count, float dx, float 
dy)
 {
   float *rgba = (float *) out;
-  CtxSource *g = &rasterizer->state->gstate.source_fill;
-  ctx_color_get_rgba (rasterizer->state, &g->color, rgba);
+  for (int i = 0; i < count; i++)
+  {
+    CtxSource *g = &rasterizer->state->gstate.source_fill;
+    ctx_color_get_rgba (rasterizer->state, &g->color, rgba);
+    rgba += 4;
+  }
 }
 
 static void ctx_fragment_image_RGBAF (CtxRasterizer *rasterizer, float x, float y, void *out, int count, 
float dx, float dy)
@@ -31895,12 +31911,7 @@ ctx_float_porter_duff (CtxRasterizer         *rasterizer,
     float u0 = 0; float v0 = 0;
     float ud = 0; float vd = 0;
 
-    if (fragment)
-    {
-      ctx_init_uv (rasterizer, x0, count, &u0, &v0, &ud, &vd);
-    }
-    else if (blend == CTX_BLEND_NORMAL)
-      ctx_float_blend (components, blend, dstf, srcf, tsrc);
+    ctx_init_uv (rasterizer, x0, count, &u0, &v0, &ud, &vd);
 
     while (count--)
     {
@@ -31922,17 +31933,9 @@ ctx_float_porter_duff (CtxRasterizer         *rasterizer,
       }
 #endif
 
-      if (fragment)
-      {
-        fragment (rasterizer, u0, v0, tsrc, 1, ud, vd);
-        if (blend != CTX_BLEND_NORMAL)
-          ctx_float_blend (components, blend, dstf, tsrc, tsrc);
-      }
-      else
-      {
-        if (blend != CTX_BLEND_NORMAL)
-          ctx_float_blend (components, blend, dstf, srcf, tsrc);
-      }
+      fragment (rasterizer, u0, v0, tsrc, 1, ud, vd);
+      if (blend != CTX_BLEND_NORMAL)
+        ctx_float_blend (components, blend, dstf, tsrc, tsrc);
       u0 += ud;
       v0 += vd;
       float covf = ctx_u8_to_float (cov);
@@ -32037,7 +32040,7 @@ ctx_##compformat##_porter_duff_##source (CTX_COMPOSITE_ARGUMENTS) \
 
 #if CTX_ENABLE_RGBAF
 
-ctx_float_porter_duff(RGBAF, 4,color,           NULL,                               
rasterizer->state->gstate.blend_mode)
+ctx_float_porter_duff(RGBAF, 4,color,           rasterizer->fragment,                               
rasterizer->state->gstate.blend_mode)
 ctx_float_porter_duff(RGBAF, 4,generic,         rasterizer->fragment,               
rasterizer->state->gstate.blend_mode)
 
 #if CTX_INLINED_NORMAL
@@ -32077,34 +32080,36 @@ ctx_RGBAF_clear_normal (CTX_COMPOSITE_ARGUMENTS)
   ctx_float_clear_normal (4, rasterizer, dst, src, x0, coverage, count);
 }
 
+#if 0
 static void
 ctx_RGBAF_source_over_normal_opaque_color (CTX_COMPOSITE_ARGUMENTS)
 {
   ctx_float_source_over_normal_opaque_color (4, rasterizer, dst, rasterizer->color, x0, coverage, count);
 }
 #endif
+#endif
 
 static void
 ctx_setup_RGBAF (CtxRasterizer *rasterizer)
 {
   CtxGState *gstate = &rasterizer->state->gstate;
   int components = 4;
+  rasterizer->fragment = ctx_rasterizer_get_fragment_RGBAF (rasterizer);
+#if 1
   if (gstate->source_fill.type == CTX_SOURCE_COLOR)
     {
       rasterizer->comp_op = ctx_RGBAF_porter_duff_color;
-      rasterizer->fragment = NULL;
       ctx_color_get_rgba (rasterizer->state, &gstate->source_fill.color, (float*)rasterizer->color);
       if (gstate->global_alpha_u8 != 255)
         for (int c = 0; c < components; c ++)
           ((float*)rasterizer->color)[c] *= gstate->global_alpha_f;
     }
   else
+#endif
   {
-    rasterizer->fragment = ctx_rasterizer_get_fragment_RGBAF (rasterizer);
     rasterizer->comp_op = ctx_RGBAF_porter_duff_generic;
   }
 
-
 #if CTX_INLINED_NORMAL
   if (gstate->compositing_mode == CTX_COMPOSITE_CLEAR)
     rasterizer->comp_op = ctx_RGBAF_clear_normal;
@@ -32128,16 +32133,10 @@ ctx_setup_RGBAF (CtxRasterizer *rasterizer)
             {
               if (((float*)(rasterizer->color))[components-1] == 0.0f)
                 rasterizer->comp_op = CTX_COMPOSITE_SUFFIX(ctx_RGBA8_nop);
-              else if (((float*)(rasterizer->color))[components-1] == 1.0f)
-                rasterizer->comp_op = ctx_RGBAF_source_over_normal_opaque_color;
-              else
-                rasterizer->comp_op = ctx_RGBAF_porter_duff_color_normal;
-              rasterizer->fragment = NULL;
             }
             else
             {
               rasterizer->comp_op = ctx_RGBAF_porter_duff_color_normal;
-              rasterizer->fragment = NULL;
             }
             break;
 #if CTX_GRADIENTS
@@ -32161,7 +32160,7 @@ ctx_setup_RGBAF (CtxRasterizer *rasterizer)
         {
           case CTX_SOURCE_COLOR:
             rasterizer->comp_op = ctx_RGBAF_porter_duff_color;
-            rasterizer->fragment = NULL;
+//          rasterizer->fragment = NULL;
             break;
 #if CTX_GRADIENTS
           case CTX_SOURCE_LINEAR_GRADIENT:
@@ -32192,12 +32191,18 @@ ctx_fragment_linear_gradient_GRAYAF (CtxRasterizer *rasterizer, float x, float y
 {
   float rgba[4];
   CtxSource *g = &rasterizer->state->gstate.source_fill;
+  for (int i = 0 ; i < count; i++)
+  {
   float v = ( ( (g->linear_gradient.dx * x + g->linear_gradient.dy * y) /
                 g->linear_gradient.length) -
               g->linear_gradient.start) * (g->linear_gradient.rdelta);
   ctx_fragment_gradient_1d_RGBAF (rasterizer, v, 1.0, rgba);
   ((float*)out)[0] = ctx_float_color_rgb_to_gray (rasterizer->state, rgba);
   ((float*)out)[1] = rgba[3];
+     out = ((float*)(out)) + 2;
+     x += dx;
+     y += dy;
+  }
 }
 
 static void
@@ -32205,6 +32210,8 @@ ctx_fragment_radial_gradient_GRAYAF (CtxRasterizer *rasterizer, float x, float y
 {
   float rgba[4];
   CtxSource *g = &rasterizer->state->gstate.source_fill;
+  for (int i = 0; i < count; i ++)
+  {
   float v = 0.0f;
   if ((g->radial_gradient.r1-g->radial_gradient.r0) > 0.0f)
     {
@@ -32214,6 +32221,10 @@ ctx_fragment_radial_gradient_GRAYAF (CtxRasterizer *rasterizer, float x, float y
   ctx_fragment_gradient_1d_RGBAF (rasterizer, v, 0.0, rgba);
   ((float*)out)[0] = ctx_float_color_rgb_to_gray (rasterizer->state, rgba);
   ((float*)out)[1] = rgba[3];
+     out = ((float*)(out)) + 2;
+     x += dx;
+     y += dy;
+  }
 }
 #endif
 
@@ -32221,7 +32232,13 @@ static void
 ctx_fragment_color_GRAYAF (CtxRasterizer *rasterizer, float x, float y, void *out, int count, float dx, 
float dy)
 {
   CtxSource *g = &rasterizer->state->gstate.source_fill;
-  ctx_color_get_graya (rasterizer->state, &g->color, (float*)out);
+  for (int i = 0; i < count; i++)
+  {
+     ctx_color_get_graya (rasterizer->state, &g->color, (float*)out);
+     out = ((float*)(out)) + 2;
+     x += dx;
+     y += dy;
+  }
 }
 
 static void ctx_fragment_image_GRAYAF (CtxRasterizer *rasterizer, float x, float y, void *out, int count, 
float dx, float dy)
@@ -32237,9 +32254,12 @@ static void ctx_fragment_image_GRAYAF (CtxRasterizer *rasterizer, float x, float
       case 32: ctx_fragment_image_rgba8_RGBA8 (rasterizer, x, y, rgba, count, dx, dy); break;
       default: ctx_fragment_image_RGBA8 (rasterizer, x, y, rgba, count, dx, dy);       break;
     }
-  for (int c = 0; c < 4; c ++) { rgbaf[c] = ctx_u8_to_float (rgba[c]); }
-  ((float*)out)[0] = ctx_float_color_rgb_to_gray (rasterizer->state, rgbaf);
-  ((float*)out)[1] = rgbaf[3];
+  for (int c = 0; c < 2 * count; c ++) { 
+    rgbaf[c] = ctx_u8_to_float (rgba[c]);
+    ((float*)out)[0] = ctx_float_color_rgb_to_gray (rasterizer->state, rgbaf);
+    ((float*)out)[1] = rgbaf[3];
+    out = ((float*)out) + 2;
+  }
 }
 
 static CtxFragment ctx_rasterizer_get_fragment_GRAYAF (CtxRasterizer *rasterizer)
@@ -32257,11 +32277,11 @@ static CtxFragment ctx_rasterizer_get_fragment_GRAYAF (CtxRasterizer *rasterizer
   return ctx_fragment_color_GRAYAF;
 }
 
-ctx_float_porter_duff(GRAYAF, 2,color,   NULL,                 rasterizer->state->gstate.blend_mode)
+ctx_float_porter_duff(GRAYAF, 2,color,   rasterizer->fragment, rasterizer->state->gstate.blend_mode)
 ctx_float_porter_duff(GRAYAF, 2,generic, rasterizer->fragment, rasterizer->state->gstate.blend_mode)
 
 #if CTX_INLINED_NORMAL
-ctx_float_porter_duff(GRAYAF, 2,color_normal,   NULL,                 CTX_BLEND_NORMAL)
+ctx_float_porter_duff(GRAYAF, 2,color_normal,   rasterizer->fragment, CTX_BLEND_NORMAL)
 ctx_float_porter_duff(GRAYAF, 2,generic_normal, rasterizer->fragment, CTX_BLEND_NORMAL)
 
 static void
@@ -32288,10 +32308,11 @@ ctx_setup_GRAYAF (CtxRasterizer *rasterizer)
 {
   CtxGState *gstate = &rasterizer->state->gstate;
   int components = 2;
+  rasterizer->fragment = ctx_rasterizer_get_fragment_GRAYAF (rasterizer);
   if (gstate->source_fill.type == CTX_SOURCE_COLOR)
     {
       rasterizer->comp_op = ctx_GRAYAF_porter_duff_color;
-      rasterizer->fragment = NULL;
+  //  rasterizer->fragment = NULL;
       ctx_color_get_rgba (rasterizer->state, &gstate->source_fill.color, (float*)rasterizer->color);
       if (gstate->global_alpha_u8 != 255)
         for (int c = 0; c < components; c ++)
@@ -32299,7 +32320,6 @@ ctx_setup_GRAYAF (CtxRasterizer *rasterizer)
     }
   else
   {
-    rasterizer->fragment = ctx_rasterizer_get_fragment_GRAYAF (rasterizer);
     rasterizer->comp_op = ctx_GRAYAF_porter_duff_generic;
   }
 
@@ -32324,16 +32344,18 @@ ctx_setup_GRAYAF (CtxRasterizer *rasterizer)
             {
               if (((float*)rasterizer->color)[components-1] == 0.0f)
                 rasterizer->comp_op = CTX_COMPOSITE_SUFFIX(ctx_RGBA8_nop);
+#if 0
               else if (((float*)rasterizer->color)[components-1] == 0.0f)
                 rasterizer->comp_op = ctx_GRAYAF_source_over_normal_opaque_color;
+#endif
               else
                 rasterizer->comp_op = ctx_GRAYAF_porter_duff_color_normal;
-              rasterizer->fragment = NULL;
+//            rasterizer->fragment = NULL;
             }
             else
             {
               rasterizer->comp_op = ctx_GRAYAF_porter_duff_color_normal;
-              rasterizer->fragment = NULL;
+//            rasterizer->fragment = NULL;
             }
             break;
           default:
@@ -32346,7 +32368,7 @@ ctx_setup_GRAYAF (CtxRasterizer *rasterizer)
         {
           case CTX_SOURCE_COLOR:
             rasterizer->comp_op = ctx_GRAYAF_porter_duff_color;
-            rasterizer->fragment = NULL;
+//          rasterizer->fragment = NULL;
             break;
           default:
             rasterizer->comp_op = ctx_GRAYAF_porter_duff_generic;
@@ -32434,7 +32456,8 @@ static void
 ctx_fragment_other_CMYKAF (CtxRasterizer *rasterizer, float x, float y, void *out, int count, float dx, 
float dy)
 {
   float *cmyka = (float*)out;
-  float rgba[4];
+  float _rgba[4 * count];
+  float *rgba = &_rgba[0];
   CtxGState *gstate = &rasterizer->state->gstate;
   switch (gstate->source_fill.type)
     {
@@ -32456,8 +32479,13 @@ ctx_fragment_other_CMYKAF (CtxRasterizer *rasterizer, float x, float y, void *ou
         rgba[0]=rgba[1]=rgba[2]=rgba[3]=0.0f;
         break;
     }
-  cmyka[4]=rgba[3];
-  ctx_rgb_to_cmyk (rgba[0], rgba[1], rgba[2], &cmyka[0], &cmyka[1], &cmyka[2], &cmyka[3]);
+  for (int i = 0; i < count; i++)
+  {
+    cmyka[4]=rgba[3];
+    ctx_rgb_to_cmyk (rgba[0], rgba[1], rgba[2], &cmyka[0], &cmyka[1], &cmyka[2], &cmyka[3]);
+    cmyka += 5;
+    rgba += 4;
+  }
 }
 
 static void
@@ -32465,12 +32493,17 @@ ctx_fragment_color_CMYKAF (CtxRasterizer *rasterizer, float x, float y, void *ou
 {
   CtxGState *gstate = &rasterizer->state->gstate;
   float *cmyka = (float*)out;
-  ctx_color_get_cmyka (rasterizer->state, &gstate->source_fill.color, cmyka);
-  // RGBW instead of CMYK
-  for (int i = 0; i < 4; i ++)
+  float cmyka_in[5];
+  ctx_color_get_cmyka (rasterizer->state, &gstate->source_fill.color, cmyka_in);
+  for (int i = 0; i < count; i++)
+  {
+    for (int c = 0; c < 4; c ++)
     {
-      cmyka[i] = (1.0f - cmyka[i]);
+      cmyka[c] = (1.0f - cmyka_in[c]);
     }
+    cmyka[4] = cmyka_in[4];
+    cmyka += 5;
+  }
 }
 
 static CtxFragment ctx_rasterizer_get_fragment_CMYKAF (CtxRasterizer *rasterizer)
@@ -32484,13 +32517,13 @@ static CtxFragment ctx_rasterizer_get_fragment_CMYKAF (CtxRasterizer *rasterizer
   return ctx_fragment_other_CMYKAF;
 }
 
-ctx_float_porter_duff (CMYKAF, 5,color,           NULL,                               
rasterizer->state->gstate.blend_mode)
-ctx_float_porter_duff (CMYKAF, 5,generic,         rasterizer->fragment,               
rasterizer->state->gstate.blend_mode)
+ctx_float_porter_duff (CMYKAF, 5,color,           rasterizer->fragment, rasterizer->state->gstate.blend_mode)
+ctx_float_porter_duff (CMYKAF, 5,generic,         rasterizer->fragment, rasterizer->state->gstate.blend_mode)
 
 #if CTX_INLINED_NORMAL
 
-ctx_float_porter_duff (CMYKAF, 5,color_normal,            NULL,                               
CTX_BLEND_NORMAL)
-ctx_float_porter_duff (CMYKAF, 5,generic_normal,          rasterizer->fragment,               
CTX_BLEND_NORMAL)
+ctx_float_porter_duff (CMYKAF, 5,color_normal,            rasterizer->fragment, CTX_BLEND_NORMAL)
+ctx_float_porter_duff (CMYKAF, 5,generic_normal,          rasterizer->fragment, CTX_BLEND_NORMAL)
 
 static void
 ctx_CMYKAF_copy_normal (CTX_COMPOSITE_ARGUMENTS)
@@ -32516,17 +32549,17 @@ ctx_setup_CMYKAF (CtxRasterizer *rasterizer)
 {
   CtxGState *gstate = &rasterizer->state->gstate;
   int components = 5;
+  rasterizer->fragment = ctx_rasterizer_get_fragment_CMYKAF (rasterizer);
   if (gstate->source_fill.type == CTX_SOURCE_COLOR)
     {
       rasterizer->comp_op = ctx_CMYKAF_porter_duff_color;
-      rasterizer->fragment = NULL;
+ //     rasterizer->fragment = NULL;
       ctx_color_get_cmyka (rasterizer->state, &gstate->source_fill.color, (float*)rasterizer->color);
       if (gstate->global_alpha_u8 != 255)
         ((float*)rasterizer->color)[components-1] *= gstate->global_alpha_f;
     }
   else
   {
-    rasterizer->fragment = ctx_rasterizer_get_fragment_CMYKAF (rasterizer);
     rasterizer->comp_op = ctx_CMYKAF_porter_duff_generic;
   }
 
@@ -32552,16 +32585,18 @@ ctx_setup_CMYKAF (CtxRasterizer *rasterizer)
             {
               if (((float*)rasterizer->color)[components-1] == 0.0f)
                 rasterizer->comp_op = CTX_COMPOSITE_SUFFIX(ctx_RGBA8_nop);
+#if 0
               else if (((float*)rasterizer->color)[components-1] == 1.0f)
                 rasterizer->comp_op = ctx_CMYKAF_source_over_normal_opaque_color;
               else
                 rasterizer->comp_op = ctx_CMYKAF_porter_duff_color_normal;
               rasterizer->fragment = NULL;
+#endif
             }
             else
             {
               rasterizer->comp_op = ctx_CMYKAF_porter_duff_color_normal;
-              rasterizer->fragment = NULL;
+   //         rasterizer->fragment = NULL;
             }
             break;
           default:
@@ -32574,7 +32609,7 @@ ctx_setup_CMYKAF (CtxRasterizer *rasterizer)
         {
           case CTX_SOURCE_COLOR:
             rasterizer->comp_op = ctx_CMYKAF_porter_duff_color;
-            rasterizer->fragment = NULL;
+    //      rasterizer->fragment = NULL;
             break;
           default:
             rasterizer->comp_op = ctx_CMYKAF_porter_duff_generic;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]