[gimp] app: add GIMP_PRECISION_HALF for 16 bit floating point



commit 2e7944cad0e646f9f657f463cb6ff86ce0b1bbf2
Author: Michael Natterer <mitch gimp org>
Date:   Thu Apr 26 14:48:37 2012 +0200

    app: add GIMP_PRECISION_HALF for 16 bit floating point
    
    and use babl_format_get_palette() to simplify some code.

 app/actions/image-actions.c |    7 +++
 app/core/core-enums.c       |    2 +
 app/core/core-enums.h       |    1 +
 app/core/gimpimage.c        |    1 +
 app/gegl/gimp-babl-compat.c |   25 ++++++------
 app/gegl/gimp-babl.c        |   90 ++++++++++++++++++++++++++++++++++++------
 app/widgets/gimphelp-ids.h  |    1 +
 libgimp/gimpenums.h         |    1 +
 menus/image-menu.xml.in     |    1 +
 tools/pdbgen/enums.pl       |    5 +-
 10 files changed, 106 insertions(+), 28 deletions(-)
---
diff --git a/app/actions/image-actions.c b/app/actions/image-actions.c
index 65c2e33..b7ec8e6 100644
--- a/app/actions/image-actions.c
+++ b/app/actions/image-actions.c
@@ -167,6 +167,11 @@ static const GimpRadioActionEntry image_convert_precision_actions[] =
     NC_("image-convert-action", "Convert the image to 16 bit unsigned integer"),
     GIMP_PRECISION_U16, GIMP_HELP_IMAGE_CONVERT_U16 },
 
+  { "image-convert-half", NULL,
+    NC_("image-convert-action", "16 bit floating point"), NULL,
+    NC_("image-convert-action", "Convert the image to 16 bit floating point"),
+    GIMP_PRECISION_HALF, GIMP_HELP_IMAGE_CONVERT_HALF },
+
   { "image-convert-float", NULL,
     NC_("image-convert-action", "32 bit floating point"), NULL,
     NC_("image-convert-action", "Convert the image to 32 bit floating point"),
@@ -280,6 +285,7 @@ image_actions_update (GimpActionGroup *group,
         {
         case GIMP_PRECISION_U8:    action = "image-convert-u8";    break;
         case GIMP_PRECISION_U16:   action = "image-convert-u16";   break;
+        case GIMP_PRECISION_HALF:  action = "image-convert-half";  break;
         case GIMP_PRECISION_FLOAT: action = "image-convert-float"; break;
           break;
         }
@@ -306,6 +312,7 @@ image_actions_update (GimpActionGroup *group,
 
   SET_SENSITIVE ("image-convert-u8",    image);
   SET_SENSITIVE ("image-convert-u16",   image && !is_indexed);
+  SET_SENSITIVE ("image-convert-half",  image && !is_indexed);
   SET_SENSITIVE ("image-convert-float", image && !is_indexed);
 
   SET_SENSITIVE ("image-flip-horizontal", image);
diff --git a/app/core/core-enums.c b/app/core/core-enums.c
index e787d68..83335fb 100644
--- a/app/core/core-enums.c
+++ b/app/core/core-enums.c
@@ -755,6 +755,7 @@ gimp_precision_get_type (void)
   {
     { GIMP_PRECISION_U8, "GIMP_PRECISION_U8", "u8" },
     { GIMP_PRECISION_U16, "GIMP_PRECISION_U16", "u16" },
+    { GIMP_PRECISION_HALF, "GIMP_PRECISION_HALF", "half" },
     { GIMP_PRECISION_FLOAT, "GIMP_PRECISION_FLOAT", "float" },
     { 0, NULL, NULL }
   };
@@ -763,6 +764,7 @@ gimp_precision_get_type (void)
   {
     { GIMP_PRECISION_U8, NC_("precision", "8-bit unsigned integer"), NULL },
     { GIMP_PRECISION_U16, NC_("precision", "16-bit unsigned integer"), NULL },
+    { GIMP_PRECISION_HALF, NC_("precision", "16-bit floating point"), NULL },
     { GIMP_PRECISION_FLOAT, NC_("precision", "32-bit floating point"), NULL },
     { 0, NULL, NULL }
   };
diff --git a/app/core/core-enums.h b/app/core/core-enums.h
index fbca549..a46c2e8 100644
--- a/app/core/core-enums.h
+++ b/app/core/core-enums.h
@@ -350,6 +350,7 @@ typedef enum
 {
   GIMP_PRECISION_U8,    /*< desc="8-bit unsigned integer"  >*/
   GIMP_PRECISION_U16,   /*< desc="16-bit unsigned integer" >*/
+  GIMP_PRECISION_HALF,  /*< desc="16-bit floating point"   >*/
   GIMP_PRECISION_FLOAT  /*< desc="32-bit floating point"   >*/
 } GimpPrecision;
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index a1e05cd..38c4da3 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1585,6 +1585,7 @@ gimp_image_get_mask_format (const GimpImage *image)
     {
     case GIMP_PRECISION_U8:    return babl_format ("Y u8");
     case GIMP_PRECISION_U16:   return babl_format ("Y u16");
+    case GIMP_PRECISION_HALF:  return babl_format ("Y half");
     case GIMP_PRECISION_FLOAT: return babl_format ("Y float");
     }
 
diff --git a/app/gegl/gimp-babl-compat.c b/app/gegl/gimp-babl-compat.c
index 353233d..ebb794a 100644
--- a/app/gegl/gimp-babl-compat.c
+++ b/app/gegl/gimp-babl-compat.c
@@ -30,30 +30,29 @@
 GimpImageType
 gimp_babl_format_get_image_type (const Babl *format)
 {
+  const Babl *model;
+
   g_return_val_if_fail (format != NULL, -1);
 
-  if (format == babl_format ("Y u8")   ||
-      format == babl_format ("Y' u8")  ||
-      format == babl_format ("Y u16")  ||
-      format == babl_format ("Y float"))
+  model = babl_format_get_model (format);
+
+  if (model == babl_model ("Y") ||
+      model == babl_model ("Y'"))
     {
       return GIMP_GRAY_IMAGE;
     }
-  else if (format == babl_format ("Y'A u8")  ||
-           format == babl_format ("YA u16")  ||
-           format == babl_format ("YA float"))
+  else if (model == babl_model ("YA") ||
+           model == babl_model ("Y'A"))
     {
       return GIMP_GRAYA_IMAGE;
     }
-  else if (format == babl_format ("R'G'B' u8") ||
-           format == babl_format ("RGB u16")   ||
-           format == babl_format ("RGB float"))
+  else if (model == babl_model ("RGB") ||
+           model == babl_model ("R'G'B'"))
     {
       return GIMP_RGB_IMAGE;
     }
-  else if (format == babl_format ("R'G'B'A u8") ||
-           format == babl_format ("RGBA u16")   ||
-           format == babl_format ("RGBA float"))
+  else if (model == babl_model ("RGBA") ||
+           model == babl_model ("R'G'B'A"))
     {
       return GIMP_RGBA_IMAGE;
     }
diff --git a/app/gegl/gimp-babl.c b/app/gegl/gimp-babl.c
index 6b86967..6aa4f31 100644
--- a/app/gegl/gimp-babl.c
+++ b/app/gegl/gimp-babl.c
@@ -74,6 +74,27 @@ gimp_babl_init (void)
                    babl_component ("A"),
                    NULL);
 
+  babl_format_new ("name", "R half",
+                   babl_model ("RGBA"),
+                   babl_type ("half"),
+                   babl_component ("R"),
+                   NULL);
+  babl_format_new ("name", "G half",
+                   babl_model ("RGBA"),
+                   babl_type ("half"),
+                   babl_component ("G"),
+                   NULL);
+  babl_format_new ("name", "B half",
+                   babl_model ("RGBA"),
+                   babl_type ("half"),
+                   babl_component ("B"),
+                   NULL);
+  babl_format_new ("name", "A half",
+                   babl_model ("RGBA"),
+                   babl_type ("half"),
+                   babl_component ("A"),
+                   NULL);
+
   babl_format_new ("name", "R float",
                    babl_model ("RGBA"),
                    babl_type ("float"),
@@ -111,35 +132,43 @@ babl_descriptions[] =
 {
   { "R'G'B' u8",  N_("RGB") },
   { "RGB u16",    N_("RGB") },
+  { "RGB half",   N_("RGB") },
   { "RGB float",  N_("RGB") },
 
   { "R'G'B'A u8", N_("RGB-alpha") },
   { "RGBA u16",   N_("RGB-alpha") },
+  { "RGBA half",  N_("RGB-alpha") },
   { "RGBA float", N_("RGB-alpha") },
 
   { "Y' u8",      N_("Grayscale") },
   { "Y u8",       N_("Grayscale") },
   { "Y u16",      N_("Grayscale") },
+  { "Y half",     N_("Grayscale") },
   { "Y float",    N_("Grayscale") },
 
   { "Y'A u8",     N_("Grayscale-alpha") },
   { "YA u16",     N_("Grayscale-alpha") },
+  { "YA half",    N_("Grayscale-alpha") },
   { "YA float",   N_("Grayscale-alpha") },
 
   { "R' u8",      N_("Red component") },
   { "R u16",      N_("Red component") },
+  { "R half",     N_("Red component") },
   { "R float",    N_("Red component") },
 
   { "G' u8",      N_("Green component") },
   { "G u16",      N_("Green component") },
+  { "G half",     N_("Green component") },
   { "G float",    N_("Green component") },
 
   { "B' u8",      N_("Blue component") },
   { "B u16",      N_("Blue component") },
+  { "B half",     N_("Blue component") },
   { "B float",    N_("Blue component") },
 
   { "A u8",       N_("Alpha component") },
   { "A u16",      N_("Alpha component") },
+  { "A half",     N_("Alpha component") },
   { "A float",    N_("Alpha component") },
   { "A double",   N_("Alpha component") }
 };
@@ -187,24 +216,23 @@ gimp_babl_get_description (const Babl *babl)
 GimpImageBaseType
 gimp_babl_format_get_base_type (const Babl *format)
 {
+  const Babl *model;
+
   g_return_val_if_fail (format != NULL, -1);
 
-  if (format == babl_format ("Y u8")    ||
-      format == babl_format ("Y' u8")   ||
-      format == babl_format ("Y u16")   ||
-      format == babl_format ("Y float") ||
-      format == babl_format ("Y'A u8")  ||
-      format == babl_format ("YA u16")  ||
-      format == babl_format ("YA float"))
+  model = babl_format_get_model (format);
+
+  if (model == babl_model ("Y")  ||
+      model == babl_model ("Y'") ||
+      model == babl_model ("YA") ||
+      model == babl_model ("Y'A"))
     {
       return GIMP_GRAY;
     }
-  else if (format == babl_format ("R'G'B' u8")  ||
-           format == babl_format ("RGB u16")    ||
-           format == babl_format ("RGB float")  ||
-           format == babl_format ("R'G'B'A u8") ||
-           format == babl_format ("RGBA u16")   ||
-           format == babl_format ("RGBA float"))
+  else if (model == babl_model ("RGB")    ||
+           model == babl_model ("R'G'B'") ||
+           model == babl_model ("RGBA")   ||
+           model == babl_model ("R'G'B'A"))
     {
       return GIMP_RGB;
     }
@@ -229,6 +257,8 @@ gimp_babl_format_get_precision (const Babl *format)
     return GIMP_PRECISION_U8;
   else if (type == babl_type ("u16"))
     return GIMP_PRECISION_U16;
+  else if (type == babl_type ("half"))
+    return GIMP_PRECISION_HALF;
   else if (type == babl_type ("float"))
     return GIMP_PRECISION_FLOAT;
 
@@ -257,6 +287,12 @@ gimp_babl_format (GimpImageBaseType  base_type,
           else
             return babl_format ("RGB u16");
 
+        case GIMP_PRECISION_HALF:
+          if (with_alpha)
+            return babl_format ("RGBA half");
+          else
+            return babl_format ("RGB half");
+
         case GIMP_PRECISION_FLOAT:
           if (with_alpha)
             return babl_format ("RGBA float");
@@ -283,6 +319,12 @@ gimp_babl_format (GimpImageBaseType  base_type,
           else
             return babl_format ("Y u16");
 
+        case GIMP_PRECISION_HALF:
+          if (with_alpha)
+            return babl_format ("YA half");
+          else
+            return babl_format ("Y half");
+
         case GIMP_PRECISION_FLOAT:
           if (with_alpha)
             return babl_format ("YA float");
@@ -336,6 +378,18 @@ gimp_babl_component_format (GimpImageBaseType base_type,
             }
           break;
 
+        case GIMP_PRECISION_HALF:
+          switch (index)
+            {
+            case 0: return babl_format ("R half");
+            case 1: return babl_format ("G half");
+            case 2: return babl_format ("B half");
+            case 3: return babl_format ("A half");
+            default:
+              break;
+            }
+          break;
+
         case GIMP_PRECISION_FLOAT:
           switch (index)
             {
@@ -376,6 +430,16 @@ gimp_babl_component_format (GimpImageBaseType base_type,
             }
           break;
 
+        case GIMP_PRECISION_HALF:
+          switch (index)
+            {
+            case 0: return babl_format ("Y half");
+            case 1: return babl_format ("A half");
+            default:
+              break;
+            }
+          break;
+
         case GIMP_PRECISION_FLOAT:
           switch (index)
             {
diff --git a/app/widgets/gimphelp-ids.h b/app/widgets/gimphelp-ids.h
index d5019c8..293d526 100644
--- a/app/widgets/gimphelp-ids.h
+++ b/app/widgets/gimphelp-ids.h
@@ -118,6 +118,7 @@
 #define GIMP_HELP_IMAGE_CONVERT_INDEXED           "gimp-image-convert-indexed"
 #define GIMP_HELP_IMAGE_CONVERT_U8                "gimp-image-convert-u8"
 #define GIMP_HELP_IMAGE_CONVERT_U16               "gimp-image-convert-u16"
+#define GIMP_HELP_IMAGE_CONVERT_HALF              "gimp-image-convert-half"
 #define GIMP_HELP_IMAGE_CONVERT_FLOAT             "gimp-image-convert-float"
 #define GIMP_HELP_IMAGE_FLIP_HORIZONTAL           "gimp-image-flip-horizontal"
 #define GIMP_HELP_IMAGE_FLIP_VERTICAL             "gimp-image-flip-vertical"
diff --git a/libgimp/gimpenums.h b/libgimp/gimpenums.h
index 508cb6e..c338a7c 100644
--- a/libgimp/gimpenums.h
+++ b/libgimp/gimpenums.h
@@ -266,6 +266,7 @@ typedef enum
 {
   GIMP_PRECISION_U8,
   GIMP_PRECISION_U16,
+  GIMP_PRECISION_HALF,
   GIMP_PRECISION_FLOAT
 } GimpPrecision;
 
diff --git a/menus/image-menu.xml.in b/menus/image-menu.xml.in
index 131a08a..101742b 100644
--- a/menus/image-menu.xml.in
+++ b/menus/image-menu.xml.in
@@ -323,6 +323,7 @@
       <menu action="image-precision-menu" name="Precision">
         <menuitem action="image-convert-u8" />
         <menuitem action="image-convert-u16" />
+        <menuitem action="image-convert-half" />
         <menuitem action="image-convert-float" />
         <separator />
       </menu>
diff --git a/tools/pdbgen/enums.pl b/tools/pdbgen/enums.pl
index 3f19a65..1936163 100644
--- a/tools/pdbgen/enums.pl
+++ b/tools/pdbgen/enums.pl
@@ -541,10 +541,11 @@ package Gimp::CodeGen::enums;
 	{ contig => 1,
 	  header => 'core/core-enums.h',
 	  symbols => [ qw(GIMP_PRECISION_U8 GIMP_PRECISION_U16
-			  GIMP_PRECISION_FLOAT) ],
+			  GIMP_PRECISION_HALF GIMP_PRECISION_FLOAT) ],
 	  mapping => { GIMP_PRECISION_U8 => '0',
 		       GIMP_PRECISION_U16 => '1',
-		       GIMP_PRECISION_FLOAT => '2' }
+		       GIMP_PRECISION_HALF => '2',
+		       GIMP_PRECISION_FLOAT => '3' }
 	},
     GimpRotationType =>
 	{ contig => 1,



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