[babl/wip/rishi/fish-reference-to-double: 2/2] fixup! babl: make conversion to model double more generic



commit 120c635f841c7973e08ef6bd5650312c43ac795f
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Nov 26 15:51:35 2017 +0100

    fixup! babl: make conversion to model double more generic
    
    * Use the correct loop index to get the type of each component of the
      format.
    
    * Restore support for the format having components of different types.
    
    * Set the alpha across the entire plane by using a loop.
    
    * Simplify code by using the pitch and breaking out the casts.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790860

 babl/babl-fish-reference.c |   34 ++++++++++++++++++----------------
 1 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/babl/babl-fish-reference.c b/babl/babl-fish-reference.c
index 3d22cf2..96be9ac 100644
--- a/babl/babl-fish-reference.c
+++ b/babl/babl-fish-reference.c
@@ -171,7 +171,6 @@ convert_to_double (BablFormat      *source_fmt,
     (dst_img->type[0]->bits / 8) * source_fmt->model->components;
   dst_img->stride[0] = 0;
 
-  src_img->data[0]   = (char *)source_buf;
   src_img->type[0]   = (BablType *) babl_type_from_id (BABL_DOUBLE);
   src_img->pitch[0]  = source_fmt->bytes_per_pixel;
   src_img->stride[0] = 0;
@@ -186,38 +185,41 @@ convert_to_double (BablFormat      *source_fmt,
       dst_img->data[0] =
         double_buf + (dst_img->type[0]->bits / 8) * i;
 
-      src_img->type[0] = source_fmt->type[i];
+      src_img->data[0] = (char *)source_buf;
+
       /* j is source position */
       for (j = 0; j < source_fmt->components; j++)
         {
+          src_img->type[0] = source_fmt->type[j];
+
           if (source_fmt->component[j] ==
               source_fmt->model->component[i])
             {
-              src_img->data[0] =
-                (char*)(source_buf) + (src_img->type[0]->bits / 8) * j;
-
               babl_process (assert_conversion_find (src_img->type[0],
                                                     dst_img->type[0]),
                             src_img, dst_img, n);
               found = 1;
               break;
             }
+
+          src_img->data[0] += src_img->type[0]->bits / 8;
         }
 
       if (!found)
-      {
-        if (source_fmt->component[i]->instance.id == BABL_ALPHA)
-          {
-            *(double*)(dst_img->data[0] + (source_fmt->components * dst_img->type[0]->bits/8) * j) = 1.0;
-          }
-        else
         {
-        for (j = 0; j < n; j++)
-          {
-            *(double*)(dst_img->data[0] + (source_fmt->components * dst_img->type[0]->bits/8) * j) = 0.0;
-          }
+          char *dst_ptr = dst_img->data[0];
+          double value;
+
+          value = source_fmt->model->component[i]->instance.id == BABL_ALPHA ? 1.0 : 0.0;
+
+          for (j = 0; j < n; j++)
+            {
+              double *dst_component = (double *) dst_ptr;
+
+              *dst_component = value;
+              dst_ptr += dst_img->pitch[0];
+            }
         }
-      }
     }
   }
   babl_free (src_img);


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