app: add GIMP_PRECISION_HALF for 16 bit floating point

and use babl_format_get_palette() to simplify some code.
This commit is contained in:
Michael Natterer 2012-04-26 14:48:37 +02:00
parent a539878bc4
commit 2e7944cad0
10 changed files with 106 additions and 28 deletions

View File

@ -167,6 +167,11 @@ static const GimpRadioActionEntry image_convert_precision_actions[] =
NC_("image-convert-action", "Convert the image to 16 bit unsigned integer"), NC_("image-convert-action", "Convert the image to 16 bit unsigned integer"),
GIMP_PRECISION_U16, GIMP_HELP_IMAGE_CONVERT_U16 }, 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, { "image-convert-float", NULL,
NC_("image-convert-action", "32 bit floating point"), NULL, NC_("image-convert-action", "32 bit floating point"), NULL,
NC_("image-convert-action", "Convert the image to 32 bit floating point"), 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_U8: action = "image-convert-u8"; break;
case GIMP_PRECISION_U16: action = "image-convert-u16"; 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; case GIMP_PRECISION_FLOAT: action = "image-convert-float"; break;
break; break;
} }
@ -306,6 +312,7 @@ image_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("image-convert-u8", image); SET_SENSITIVE ("image-convert-u8", image);
SET_SENSITIVE ("image-convert-u16", image && !is_indexed); 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-convert-float", image && !is_indexed);
SET_SENSITIVE ("image-flip-horizontal", image); SET_SENSITIVE ("image-flip-horizontal", image);

View File

@ -755,6 +755,7 @@ gimp_precision_get_type (void)
{ {
{ GIMP_PRECISION_U8, "GIMP_PRECISION_U8", "u8" }, { GIMP_PRECISION_U8, "GIMP_PRECISION_U8", "u8" },
{ GIMP_PRECISION_U16, "GIMP_PRECISION_U16", "u16" }, { GIMP_PRECISION_U16, "GIMP_PRECISION_U16", "u16" },
{ GIMP_PRECISION_HALF, "GIMP_PRECISION_HALF", "half" },
{ GIMP_PRECISION_FLOAT, "GIMP_PRECISION_FLOAT", "float" }, { GIMP_PRECISION_FLOAT, "GIMP_PRECISION_FLOAT", "float" },
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };
@ -763,6 +764,7 @@ gimp_precision_get_type (void)
{ {
{ GIMP_PRECISION_U8, NC_("precision", "8-bit unsigned integer"), NULL }, { GIMP_PRECISION_U8, NC_("precision", "8-bit unsigned integer"), NULL },
{ GIMP_PRECISION_U16, NC_("precision", "16-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 }, { GIMP_PRECISION_FLOAT, NC_("precision", "32-bit floating point"), NULL },
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };

View File

@ -350,6 +350,7 @@ typedef enum
{ {
GIMP_PRECISION_U8, /*< desc="8-bit unsigned integer" >*/ GIMP_PRECISION_U8, /*< desc="8-bit unsigned integer" >*/
GIMP_PRECISION_U16, /*< desc="16-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" >*/ GIMP_PRECISION_FLOAT /*< desc="32-bit floating point" >*/
} GimpPrecision; } GimpPrecision;

View File

@ -1585,6 +1585,7 @@ gimp_image_get_mask_format (const GimpImage *image)
{ {
case GIMP_PRECISION_U8: return babl_format ("Y u8"); case GIMP_PRECISION_U8: return babl_format ("Y u8");
case GIMP_PRECISION_U16: return babl_format ("Y u16"); 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"); case GIMP_PRECISION_FLOAT: return babl_format ("Y float");
} }

View File

@ -30,30 +30,29 @@
GimpImageType GimpImageType
gimp_babl_format_get_image_type (const Babl *format) gimp_babl_format_get_image_type (const Babl *format)
{ {
const Babl *model;
g_return_val_if_fail (format != NULL, -1); g_return_val_if_fail (format != NULL, -1);
if (format == babl_format ("Y u8") || model = babl_format_get_model (format);
format == babl_format ("Y' u8") ||
format == babl_format ("Y u16") || if (model == babl_model ("Y") ||
format == babl_format ("Y float")) model == babl_model ("Y'"))
{ {
return GIMP_GRAY_IMAGE; return GIMP_GRAY_IMAGE;
} }
else if (format == babl_format ("Y'A u8") || else if (model == babl_model ("YA") ||
format == babl_format ("YA u16") || model == babl_model ("Y'A"))
format == babl_format ("YA float"))
{ {
return GIMP_GRAYA_IMAGE; return GIMP_GRAYA_IMAGE;
} }
else if (format == babl_format ("R'G'B' u8") || else if (model == babl_model ("RGB") ||
format == babl_format ("RGB u16") || model == babl_model ("R'G'B'"))
format == babl_format ("RGB float"))
{ {
return GIMP_RGB_IMAGE; return GIMP_RGB_IMAGE;
} }
else if (format == babl_format ("R'G'B'A u8") || else if (model == babl_model ("RGBA") ||
format == babl_format ("RGBA u16") || model == babl_model ("R'G'B'A"))
format == babl_format ("RGBA float"))
{ {
return GIMP_RGBA_IMAGE; return GIMP_RGBA_IMAGE;
} }

View File

@ -74,6 +74,27 @@ gimp_babl_init (void)
babl_component ("A"), babl_component ("A"),
NULL); 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_format_new ("name", "R float",
babl_model ("RGBA"), babl_model ("RGBA"),
babl_type ("float"), babl_type ("float"),
@ -111,35 +132,43 @@ babl_descriptions[] =
{ {
{ "R'G'B' u8", N_("RGB") }, { "R'G'B' u8", N_("RGB") },
{ "RGB u16", N_("RGB") }, { "RGB u16", N_("RGB") },
{ "RGB half", N_("RGB") },
{ "RGB float", N_("RGB") }, { "RGB float", N_("RGB") },
{ "R'G'B'A u8", N_("RGB-alpha") }, { "R'G'B'A u8", N_("RGB-alpha") },
{ "RGBA u16", N_("RGB-alpha") }, { "RGBA u16", N_("RGB-alpha") },
{ "RGBA half", N_("RGB-alpha") },
{ "RGBA float", N_("RGB-alpha") }, { "RGBA float", N_("RGB-alpha") },
{ "Y' u8", N_("Grayscale") }, { "Y' u8", N_("Grayscale") },
{ "Y u8", N_("Grayscale") }, { "Y u8", N_("Grayscale") },
{ "Y u16", N_("Grayscale") }, { "Y u16", N_("Grayscale") },
{ "Y half", N_("Grayscale") },
{ "Y float", N_("Grayscale") }, { "Y float", N_("Grayscale") },
{ "Y'A u8", N_("Grayscale-alpha") }, { "Y'A u8", N_("Grayscale-alpha") },
{ "YA u16", N_("Grayscale-alpha") }, { "YA u16", N_("Grayscale-alpha") },
{ "YA half", N_("Grayscale-alpha") },
{ "YA float", N_("Grayscale-alpha") }, { "YA float", N_("Grayscale-alpha") },
{ "R' u8", N_("Red component") }, { "R' u8", N_("Red component") },
{ "R u16", N_("Red component") }, { "R u16", N_("Red component") },
{ "R half", N_("Red component") },
{ "R float", N_("Red component") }, { "R float", N_("Red component") },
{ "G' u8", N_("Green component") }, { "G' u8", N_("Green component") },
{ "G u16", N_("Green component") }, { "G u16", N_("Green component") },
{ "G half", N_("Green component") },
{ "G float", N_("Green component") }, { "G float", N_("Green component") },
{ "B' u8", N_("Blue component") }, { "B' u8", N_("Blue component") },
{ "B u16", N_("Blue component") }, { "B u16", N_("Blue component") },
{ "B half", N_("Blue component") },
{ "B float", N_("Blue component") }, { "B float", N_("Blue component") },
{ "A u8", N_("Alpha component") }, { "A u8", N_("Alpha component") },
{ "A u16", N_("Alpha component") }, { "A u16", N_("Alpha component") },
{ "A half", N_("Alpha component") },
{ "A float", N_("Alpha component") }, { "A float", N_("Alpha component") },
{ "A double", N_("Alpha component") } { "A double", N_("Alpha component") }
}; };
@ -187,24 +216,23 @@ gimp_babl_get_description (const Babl *babl)
GimpImageBaseType GimpImageBaseType
gimp_babl_format_get_base_type (const Babl *format) gimp_babl_format_get_base_type (const Babl *format)
{ {
const Babl *model;
g_return_val_if_fail (format != NULL, -1); g_return_val_if_fail (format != NULL, -1);
if (format == babl_format ("Y u8") || model = babl_format_get_model (format);
format == babl_format ("Y' u8") ||
format == babl_format ("Y u16") || if (model == babl_model ("Y") ||
format == babl_format ("Y float") || model == babl_model ("Y'") ||
format == babl_format ("Y'A u8") || model == babl_model ("YA") ||
format == babl_format ("YA u16") || model == babl_model ("Y'A"))
format == babl_format ("YA float"))
{ {
return GIMP_GRAY; return GIMP_GRAY;
} }
else if (format == babl_format ("R'G'B' u8") || else if (model == babl_model ("RGB") ||
format == babl_format ("RGB u16") || model == babl_model ("R'G'B'") ||
format == babl_format ("RGB float") || model == babl_model ("RGBA") ||
format == babl_format ("R'G'B'A u8") || model == babl_model ("R'G'B'A"))
format == babl_format ("RGBA u16") ||
format == babl_format ("RGBA float"))
{ {
return GIMP_RGB; return GIMP_RGB;
} }
@ -229,6 +257,8 @@ gimp_babl_format_get_precision (const Babl *format)
return GIMP_PRECISION_U8; return GIMP_PRECISION_U8;
else if (type == babl_type ("u16")) else if (type == babl_type ("u16"))
return GIMP_PRECISION_U16; return GIMP_PRECISION_U16;
else if (type == babl_type ("half"))
return GIMP_PRECISION_HALF;
else if (type == babl_type ("float")) else if (type == babl_type ("float"))
return GIMP_PRECISION_FLOAT; return GIMP_PRECISION_FLOAT;
@ -257,6 +287,12 @@ gimp_babl_format (GimpImageBaseType base_type,
else else
return babl_format ("RGB u16"); 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: case GIMP_PRECISION_FLOAT:
if (with_alpha) if (with_alpha)
return babl_format ("RGBA float"); return babl_format ("RGBA float");
@ -283,6 +319,12 @@ gimp_babl_format (GimpImageBaseType base_type,
else else
return babl_format ("Y u16"); 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: case GIMP_PRECISION_FLOAT:
if (with_alpha) if (with_alpha)
return babl_format ("YA float"); return babl_format ("YA float");
@ -336,6 +378,18 @@ gimp_babl_component_format (GimpImageBaseType base_type,
} }
break; 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: case GIMP_PRECISION_FLOAT:
switch (index) switch (index)
{ {
@ -376,6 +430,16 @@ gimp_babl_component_format (GimpImageBaseType base_type,
} }
break; 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: case GIMP_PRECISION_FLOAT:
switch (index) switch (index)
{ {

View File

@ -118,6 +118,7 @@
#define GIMP_HELP_IMAGE_CONVERT_INDEXED "gimp-image-convert-indexed" #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_U8 "gimp-image-convert-u8"
#define GIMP_HELP_IMAGE_CONVERT_U16 "gimp-image-convert-u16" #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_CONVERT_FLOAT "gimp-image-convert-float"
#define GIMP_HELP_IMAGE_FLIP_HORIZONTAL "gimp-image-flip-horizontal" #define GIMP_HELP_IMAGE_FLIP_HORIZONTAL "gimp-image-flip-horizontal"
#define GIMP_HELP_IMAGE_FLIP_VERTICAL "gimp-image-flip-vertical" #define GIMP_HELP_IMAGE_FLIP_VERTICAL "gimp-image-flip-vertical"

View File

@ -266,6 +266,7 @@ typedef enum
{ {
GIMP_PRECISION_U8, GIMP_PRECISION_U8,
GIMP_PRECISION_U16, GIMP_PRECISION_U16,
GIMP_PRECISION_HALF,
GIMP_PRECISION_FLOAT GIMP_PRECISION_FLOAT
} GimpPrecision; } GimpPrecision;

View File

@ -323,6 +323,7 @@
<menu action="image-precision-menu" name="Precision"> <menu action="image-precision-menu" name="Precision">
<menuitem action="image-convert-u8" /> <menuitem action="image-convert-u8" />
<menuitem action="image-convert-u16" /> <menuitem action="image-convert-u16" />
<menuitem action="image-convert-half" />
<menuitem action="image-convert-float" /> <menuitem action="image-convert-float" />
<separator /> <separator />
</menu> </menu>

View File

@ -541,10 +541,11 @@ package Gimp::CodeGen::enums;
{ contig => 1, { contig => 1,
header => 'core/core-enums.h', header => 'core/core-enums.h',
symbols => [ qw(GIMP_PRECISION_U8 GIMP_PRECISION_U16 symbols => [ qw(GIMP_PRECISION_U8 GIMP_PRECISION_U16
GIMP_PRECISION_FLOAT) ], GIMP_PRECISION_HALF GIMP_PRECISION_FLOAT) ],
mapping => { GIMP_PRECISION_U8 => '0', mapping => { GIMP_PRECISION_U8 => '0',
GIMP_PRECISION_U16 => '1', GIMP_PRECISION_U16 => '1',
GIMP_PRECISION_FLOAT => '2' } GIMP_PRECISION_HALF => '2',
GIMP_PRECISION_FLOAT => '3' }
}, },
GimpRotationType => GimpRotationType =>
{ contig => 1, { contig => 1,