[babl] babl: add babl_new_palette_with_space



commit a643868c23b15bd6ec105618ce6503d7f96f762f
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Dec 6 17:09:47 2018 +0100

    babl: add babl_new_palette_with_space
    
    Handling of space in palettes is still incomplete.

 babl/babl-palette.c | 36 +++++++++++++++++++++++-------------
 babl/babl.h         | 14 ++++++++++++++
 2 files changed, 37 insertions(+), 13 deletions(-)
---
diff --git a/babl/babl-palette.c b/babl/babl-palette.c
index 205573f..a53f654 100644
--- a/babl/babl-palette.c
+++ b/babl/babl-palette.c
@@ -239,7 +239,7 @@ babl_palette_lookup (BablPalette         *pal,
     }
 }
 
-static BablPalette *make_pal (const Babl *format, const void *data, int count)
+static BablPalette *make_pal (const Babl *pal_space, const Babl *format, const void *data, int count)
 {
   BablPalette *pal = NULL;
   int bpp = babl_format_get_bytes_per_pixel (format);
@@ -258,9 +258,9 @@ static BablPalette *make_pal (const Babl *format, const void *data, int count)
 
   memcpy (pal->data, data, bpp * count);
 
-  babl_process (babl_fish (format, babl_format ("RGBA double")),
+  babl_process (babl_fish (format, babl_format_with_space ("RGBA double", pal_space)),
                 data, pal->data_double, count);
-  babl_process (babl_fish (format, babl_format ("R'G'B'A u8")),
+  babl_process (babl_fish (format, babl_format_with_space ("R'G'B'A u8", pal_space)),
                 data, pal->data_u8, count);
 
   babl_palette_init_radii (pal);
@@ -711,12 +711,11 @@ babl_format_is_palette (const Babl *format)
   return 0;
 }
 
-/* should return the BablModel, permitting to fetch
- * other formats out of it?
- */
-const Babl *babl_new_palette (const char  *name,
-                              const Babl **format_u8,
-                              const Babl **format_u8_with_alpha)
+
+const Babl *babl_new_palette_with_space (const char  *name,
+                                         const Babl  *space,
+                                         const Babl **format_u8,
+                                         const Babl **format_u8_with_alpha)
 {
   const Babl *model;
   const Babl *model_no_alpha;
@@ -736,7 +735,7 @@ const Babl *babl_new_palette (const char  *name,
     }
   else
     {
-      strcpy (cname, name);
+      snprintf (cname, sizeof (cname), "%s-%p", name, space);
       name = cname;
 
       if ((model = babl_db_exist_by_name (babl_model_db (), name)))
@@ -764,11 +763,11 @@ const Babl *babl_new_palette (const char  *name,
   cname[0] = 'v';
   model_no_alpha = babl_model_new ("name", name, component, NULL);
   cname[0] = '\\';
-  f_pal_a_u8 = (void*) babl_format_new ("name", name, model,
+  f_pal_a_u8 = (void*) babl_format_new ("name", name, model, space,
                                 babl_type ("u8"),
                                 component, alpha, NULL);
   cname[0] = ')';
-  f_pal_u8  = (void*) babl_format_new ("name", name, model_no_alpha,
+  f_pal_u8  = (void*) babl_format_new ("name", name, model_no_alpha, space,
                                babl_type ("u8"),
                                component, NULL);
 
@@ -867,6 +866,17 @@ const Babl *babl_new_palette (const char  *name,
   return model;
 }
 
+/* should return the BablModel, permitting to fetch
+ * other formats out of it?
+ */
+const Babl *babl_new_palette (const char  *name,
+                              const Babl **format_u8,
+                              const Babl **format_u8_with_alpha)
+{
+  return babl_new_palette_with_space (name, babl_space("sRGB"),
+                                      format_u8, format_u8_with_alpha);
+}
+
 void
 babl_palette_set_palette (const Babl *babl,
                           const Babl *format,
@@ -887,7 +897,7 @@ babl_palette_set_palette (const Babl *babl,
 
   if (count > 0)
     {
-      *palptr = make_pal (format, data, count);
+      *palptr = make_pal (babl_format_get_space (babl), format, data, count);
     }
   else
     {
diff --git a/babl/babl.h b/babl/babl.h
index b02b1c0..2cb1a46 100644
--- a/babl/babl.h
+++ b/babl/babl.h
@@ -451,6 +451,20 @@ const Babl *babl_new_palette (const char  *name,
                               const Babl **format_u8,
                               const Babl **format_u8_with_alpha);
 
+/**
+ * babl_new_palette_with_space:
+ *
+ * create a new palette based format, name is optional pass in NULL to get
+ * an anonymous format. If you pass in with_alpha the format also gets
+ * an 8bit alpha channel. Returns the BablModel of the color model. If
+ * you pass in the same name the previous formats will be provided
+ * again.
+ */
+const Babl *babl_new_palette_with_space (const char  *name,
+                                         const Babl  *space,
+                                         const Babl **format_u8,
+                                         const Babl **format_u8_with_alpha);
+
 /**
  * babl_format_is_palette:
  *


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