babl: add bitmask flags for meta-data about models
authorØyvind Kolås <pippin@gimp.org>
Mon, 26 Nov 2018 22:39:08 +0000 (23:39 +0100)
committerØyvind Kolås <pippin@gimp.org>
Mon, 26 Nov 2018 23:15:40 +0000 (00:15 +0100)
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
babl/babl-model.c
babl/babl-model.h
babl/babl.h
babl/base/model-cmyk.c
babl/base/model-gray.c
babl/base/model-rgb.c
babl/base/model-ycbcr.c

index e4f1bc4ae912a7f0e42d600c39a0ae9f39f14a13..b71bf40b2119e5e3aa6be019b949ded5742192c4 100644 (file)
@@ -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
index 4ce2211ccf4dad0277683ac97e5b01c5a67ec6e2..7b413037da0298efbf5e35d8f2d41da857521826 100644 (file)
@@ -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;
+}
 
index 74595a8267de29d745eb996dfa4f30777755172a..62e3c945b5325b272f8447ff5f99c3f057dca04f 100644 (file)
@@ -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
index 13012704dc1c464eb52e37048c864f54ebe88533..e76a72c8816d0a4d7958e29e622624d733e135af 100644 (file)
@@ -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,
index 6b771a541891b1de873770cdd05e5a05593a96ec..a550427540ba05feb20c04a404d5e5deedd3a6c7 100644 (file)
  */
 
 #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 (
index 0cae83787d1eae8bddf05e33a6bae270b5634f10..ce4873112a51e6f513582c8500416f64c55fcee6 100644 (file)
@@ -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);
 
 }
index 39c8afb872300fa7437247c93f98608e87346fd6..766ed528c71b8bf7c591fdd0f8866479c8204439 100644 (file)
@@ -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);
 }
 
index 1d6acb7e7e30695681e0fe1aaa2afeac1fa37d1b..91749a876d9e209507bef2c0db05d9c29d84a59e 100644 (file)
@@ -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);
 }