[babl] babl: add bitmask flags for meta-data about models



commit 695284fa69abbe9c0bde4a3f6ebf5f0418468864
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Nov 26 23:39:08 2018 +0100

    babl: add bitmask flags for meta-data about models
    
    Refactored from new API needed internally for knowing if a model is CMYK based
    or not, this permits adding meta-data that can be quickly figured out in
    possible fast code paths. The API is not complete, and it probably doesn't harm
    to include as many features from different models as possible that fit in a
    bitmask, adding the most important ones first and maintaining the order of the
    enum will ensure API compatibility once it is in a release.

 babl/babl-fish-reference.c |  2 +-
 babl/babl-model.c          | 48 ++++++++++++++++++++++++++++++++++++++++------
 babl/babl-model.h          |  2 +-
 babl/babl.h                | 21 +++++++++++++++++++-
 babl/base/model-cmyk.c     | 12 +++++++++++-
 babl/base/model-gray.c     | 20 +++++++++++++++++++
 babl/base/model-rgb.c      | 22 +++++++++++++++++++++
 babl/base/model-ycbcr.c    |  1 +
 8 files changed, 118 insertions(+), 10 deletions(-)
---
diff --git a/babl/babl-fish-reference.c b/babl/babl-fish-reference.c
index e4f1bc4..b71bf40 100644
--- a/babl/babl-fish-reference.c
+++ b/babl/babl-fish-reference.c
@@ -699,7 +699,7 @@ enum _Kind { KIND_RGB, KIND_CMYK};
 
 static int format_has_cmyk_model (const Babl *format)
 {
-  return format->format.model->is_cmyk;
+  return format->format.model->flags & BABL_MODEL_FLAG_CMYK;
 }
 
 static void
diff --git a/babl/babl-model.c b/babl/babl-model.c
index 4ce2211..7b41303 100644
--- a/babl/babl-model.c
+++ b/babl/babl-model.c
@@ -57,7 +57,7 @@ model_new (const char     *name,
            int             id,
            int             components,
            BablComponent **component,
-           int             is_cmyk)
+           BablModelFlag   flags)
 {
   Babl *babl;
 
@@ -74,7 +74,7 @@ model_new (const char     *name,
   babl->model.space      = space;
   babl->model.data       = NULL;
   babl->model.model      = NULL;
-  babl->model.is_cmyk    = is_cmyk;
+  babl->model.flags      = flags;
   strcpy (babl->instance.name, name);
   memcpy (babl->model.component, component, sizeof (BablComponent *) * components);
 
@@ -116,7 +116,7 @@ babl_model_new (void *first_argument,
   char          *name          = NULL;
   const Babl    *space         = babl_space ("sRGB");
   BablComponent *component [BABL_MAX_COMPONENTS];
-  int            is_cmyk       = 0;
+  BablModelFlag  flags         = 0;
 
   va_start (varg, first_argument);
 
@@ -132,10 +132,41 @@ babl_model_new (void *first_argument,
         {
           assigned_name = va_arg (varg, char *);
         }
-
+      else if (!strcmp (arg, "gray"))
+        {
+          flags |= BABL_MODEL_FLAG_GRAY;
+        }
+      else if (!strcmp (arg, "CIE"))
+        {
+          flags |= BABL_MODEL_FLAG_CIE;
+        }
+      else if (!strcmp (arg, "rgb"))
+        {
+          flags |= BABL_MODEL_FLAG_RGB;
+        }
       else if (!strcmp (arg, "cmyk"))
         {
-          is_cmyk = 1;
+          flags |= BABL_MODEL_FLAG_CMYK;
+        }
+      else if (!strcmp (arg, "inverted"))
+        {
+          flags |= BABL_MODEL_FLAG_INVERTED;
+        }
+      else if (!strcmp (arg, "premultiplied"))
+        {
+          flags |= BABL_MODEL_FLAG_PREMULTIPLIED;
+        }
+      else if (!strcmp (arg, "alpha"))
+        {
+          flags |= BABL_MODEL_FLAG_ALPHA;
+        }
+      else if (!strcmp (arg, "nonlinear"))
+        {
+          flags |= BABL_MODEL_FLAG_NONLINEAR;
+        }
+      else if (!strcmp (arg, "perceptual"))
+        {
+          flags |= BABL_MODEL_FLAG_PERCEPTUAL;
         }
 
       /* if we didn't point to a known string, we assume argument to be babl */
@@ -219,7 +250,7 @@ babl_model_new (void *first_argument,
 
   if (! babl)
     {
-      babl = model_new (name, space, id, components, component, is_cmyk);
+      babl = model_new (name, space, id, components, component, flags);
       babl_db_insert (db, babl);
       construct_double_format (babl);
     }
@@ -428,4 +459,9 @@ babl_model_with_space (const char *name, const Babl *space)
   return babl_remodel_with_space (babl_model (name), space);
 }
 
+BablModelFlag babl_model_get_flags (const Babl *model)
+{
+  if (!model) return 0;
+  return model->model.flags;
+}
 
diff --git a/babl/babl-model.h b/babl/babl-model.h
index 74595a8..62e3c94 100644
--- a/babl/babl-model.h
+++ b/babl/babl-model.h
@@ -32,7 +32,7 @@ typedef struct
   void             *data;    /* user-data, used for palette */
   const Babl       *space;
   void             *model;   /* back pointer to model with sRGB space */
-  int               is_cmyk; /* is an cmyk based model */
+  BablModelFlag     flags;
 } BablModel;
 
 #endif
diff --git a/babl/babl.h b/babl/babl.h
index 1301270..e76a72c 100644
--- a/babl/babl.h
+++ b/babl/babl.h
@@ -283,6 +283,26 @@ int          babl_format_get_bytes_per_pixel   (const Babl *format);
  */
 const Babl * babl_format_get_model             (const Babl *format);
 
+
+
+typedef enum _BablModelFlag BablModelFlag;
+
+enum _BablModelFlag
+{
+  BABL_MODEL_FLAG_OTHER         = 0,
+  BABL_MODEL_FLAG_ALPHA         = 1<<1,
+  BABL_MODEL_FLAG_PREMULTIPLIED = 1<<2,
+  BABL_MODEL_FLAG_CIE           = 1<<3,
+  BABL_MODEL_FLAG_GRAY          = 1<<4,
+  BABL_MODEL_FLAG_RGB           = 1<<5,
+  BABL_MODEL_FLAG_CMYK          = 1<<6,
+  BABL_MODEL_FLAG_INVERTED      = 1<<7,
+  BABL_MODEL_FLAG_NONLINEAR     = 1<<8,
+  BABL_MODEL_FLAG_PERCEPTUAL    = 1<<9,
+};
+
+BablModelFlag babl_model_get_flags (const Babl *model);
+
 /**
  * babl_format_get_n_components:
  *
@@ -584,7 +604,6 @@ babl_space_from_rgbxyz_matrix (const char *name,
  */
 const char * babl_format_get_encoding (const Babl *babl);
 
-
 int babl_space_is_cmyk (const Babl *space);
 
 /* values below this are stored premultiplied with this value,
diff --git a/babl/base/model-cmyk.c b/babl/base/model-cmyk.c
index 6b771a5..a550427 100644
--- a/babl/base/model-cmyk.c
+++ b/babl/base/model-cmyk.c
@@ -26,10 +26,11 @@
  */
 
 #include "config.h"
+
 #include <math.h>
 #include <string.h>
 
-#include "babl.h"
+#include "babl-internal.h"
 #include "babl-base.h"
 #include "base/util.h"
 
@@ -622,6 +623,9 @@ babl_base_model_cmyk (void)
     babl_component ("ka"),
     babl_component ("A"),
     "cmyk",
+    "inverted",
+    "alpha",
+    "premultiplied",
     NULL
   );
 
@@ -633,6 +637,8 @@ babl_base_model_cmyk (void)
     babl_component ("key"),
     babl_component ("A"),
     "cmyk",
+    "inverted",
+    "alpha",
     NULL
   );
   babl_model_new (
@@ -642,6 +648,7 @@ babl_base_model_cmyk (void)
     babl_component ("yellow"),
     babl_component ("key"),
     "cmyk",
+    "inverted",
     NULL
   );
 
@@ -653,6 +660,8 @@ babl_base_model_cmyk (void)
     babl_component ("Ka"),
     babl_component ("A"),
     "cmyk",
+    "alpha",
+    "premultiplied",
     NULL
   );
 
@@ -664,6 +673,7 @@ babl_base_model_cmyk (void)
     babl_component ("Key"),
     babl_component ("A"),
     "cmyk",
+    "alpha",
     NULL
   );
   babl_model_new (
diff --git a/babl/base/model-gray.c b/babl/base/model-gray.c
index 0cae837..ce48731 100644
--- a/babl/base/model-gray.c
+++ b/babl/base/model-gray.c
@@ -79,6 +79,7 @@ models (void)
   babl_model_new (
     "id", BABL_GRAY,
     babl_component_from_id (BABL_GRAY_LINEAR),
+    "gray",
     NULL);
 
 
@@ -86,40 +87,59 @@ models (void)
     "id", BABL_GRAY_ALPHA,
     babl_component_from_id (BABL_GRAY_LINEAR),
     babl_component_from_id (BABL_ALPHA),
+    "gray",
+    "alpha",
     NULL);
 
   babl_model_new (
     "id", BABL_GRAY_ALPHA_PREMULTIPLIED,
     babl_component_from_id (BABL_GRAY_LINEAR_MUL_ALPHA),
     babl_component_from_id (BABL_ALPHA),
+    "gray",
+    "premultiplied",
+    "alpha",
     NULL);
 
   babl_model_new (
     "id", BABL_MODEL_GRAY_NONLINEAR,
     babl_component_from_id (BABL_GRAY_NONLINEAR),
+    "gray",
+    "nonlinear",
     NULL);
 
   babl_model_new (
     "id", BABL_MODEL_GRAY_NONLINEAR_ALPHA,
     babl_component_from_id (BABL_GRAY_NONLINEAR),
     babl_component_from_id (BABL_ALPHA),
+    "gray",
+    "nonlinear",
+    "alpha",
     NULL);
 
   babl_model_new (
     "id", BABL_MODEL_GRAY_NONLINEAR_ALPHA_PREMULTIPLIED,
     babl_component_from_id (BABL_GRAY_NONLINEAR_MUL_ALPHA),
     babl_component_from_id (BABL_ALPHA),
+    "gray",
+    "nonlinear",
+    "premultiplied",
+    "alpha",
     NULL);
 
   babl_model_new (
     "id", BABL_MODEL_GRAY_PERCEPTUAL,
     babl_component_from_id (BABL_GRAY_PERCEPTUAL),
+    "gray",
+    "perceptual",
     NULL);
 
   babl_model_new (
     "id", BABL_MODEL_GRAY_PERCEPTUAL_ALPHA,
     babl_component_from_id (BABL_GRAY_PERCEPTUAL),
     babl_component_from_id (BABL_ALPHA),
+    "gray",
+    "perceptual",
+    "alpha",
     NULL);
 
 }
diff --git a/babl/base/model-rgb.c b/babl/base/model-rgb.c
index 39c8afb..766ed52 100644
--- a/babl/base/model-rgb.c
+++ b/babl/base/model-rgb.c
@@ -159,6 +159,7 @@ models (void)
     babl_component_from_id (BABL_RED),
     babl_component_from_id (BABL_GREEN),
     babl_component_from_id (BABL_BLUE),
+    "rgb",
     NULL);
 
   babl_model_new (
@@ -167,6 +168,9 @@ models (void)
     babl_component_from_id (BABL_GREEN_MUL_ALPHA),
     babl_component_from_id (BABL_BLUE_MUL_ALPHA),
     babl_component_from_id (BABL_ALPHA),
+    "rgb",
+    "premultiplied",
+    "alpha",
     NULL);
 
   babl_model_new (
@@ -174,6 +178,8 @@ models (void)
     babl_component_from_id (BABL_RED_NONLINEAR),
     babl_component_from_id (BABL_GREEN_NONLINEAR),
     babl_component_from_id (BABL_BLUE_NONLINEAR),
+    "rgb",
+    "nonlinear",
     NULL);
 
   babl_model_new (
@@ -181,6 +187,8 @@ models (void)
     babl_component_from_id (BABL_RED_PERCEPTUAL),
     babl_component_from_id (BABL_GREEN_PERCEPTUAL),
     babl_component_from_id (BABL_BLUE_PERCEPTUAL),
+    "rgb",
+    "perceptual",
     NULL);
 
   babl_model_new (
@@ -189,6 +197,9 @@ models (void)
     babl_component_from_id (BABL_GREEN_NONLINEAR),
     babl_component_from_id (BABL_BLUE_NONLINEAR),
     babl_component_from_id (BABL_ALPHA),
+    "rgb",
+    "nonlinear",
+    "alpha",
     NULL);
 
   babl_model_new (
@@ -197,6 +208,9 @@ models (void)
     babl_component_from_id (BABL_GREEN_PERCEPTUAL),
     babl_component_from_id (BABL_BLUE_PERCEPTUAL),
     babl_component_from_id (BABL_ALPHA),
+    "rgb",
+    "perceptual",
+    "alpha",
     NULL);
 
   babl_model_new (
@@ -205,6 +219,10 @@ models (void)
     babl_component_from_id (BABL_GREEN_NONLINEAR_MUL_ALPHA),
     babl_component_from_id (BABL_BLUE_NONLINEAR_MUL_ALPHA),
     babl_component_from_id (BABL_ALPHA),
+    "rgb",
+    "nonlinear",
+    "premultiplied",
+    "alpha",
     NULL);
 
   babl_model_new (
@@ -213,6 +231,10 @@ models (void)
     babl_component_from_id (BABL_GREEN_PERCEPTUAL_MUL_ALPHA),
     babl_component_from_id (BABL_BLUE_PERCEPTUAL_MUL_ALPHA),
     babl_component_from_id (BABL_ALPHA),
+    "rgb",
+    "perceptual",
+    "premultiplied",
+    "alpha",
     NULL);
 }
 
diff --git a/babl/base/model-ycbcr.c b/babl/base/model-ycbcr.c
index 1d6acb7..91749a8 100644
--- a/babl/base/model-ycbcr.c
+++ b/babl/base/model-ycbcr.c
@@ -74,6 +74,7 @@ models (void)
     babl_component_from_id (BABL_CB),
     babl_component_from_id (BABL_CR),
     babl_component_from_id (BABL_ALPHA),
+    "alpha",
     NULL);
 }
 


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