[babl/wip/Jehan/babl-cli-tool] bin: add a --brief/-b option.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl/wip/Jehan/babl-cli-tool] bin: add a --brief/-b option.
- Date: Fri, 22 Jul 2022 09:39:28 +0000 (UTC)
commit ed1a45a230dc973325b39e45deb0a0c235010dc3
Author: Jehan <jehan girinstud io>
Date: Fri Jul 22 11:35:58 2022 +0200
bin: add a --brief/-b option.
This will output the result as int or float values (depending on output
format), separated by space.
It would allow to use the output of this script for testing conversion
(with expected output), and can also be used for chaining calls, making
this a re-entrant CLI tool.
bin/babl.c | 48 ++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 40 insertions(+), 8 deletions(-)
---
diff --git a/bin/babl.c b/bin/babl.c
index 607d10b44..68f97b081 100644
--- a/bin/babl.c
+++ b/bin/babl.c
@@ -46,6 +46,7 @@ main (int argc,
int set_to = 0;
int set_from_profile = 0;
int set_to_profile = 0;
+ int brief_output = 0;
int options_ended = 0;
int n_components;
int data_index;
@@ -135,6 +136,11 @@ main (int argc,
{
set_to_profile = 1;
}
+ else if (strcmp (argv[i], "--brief") == 0 ||
+ strcmp (argv[i], "-b") == 0)
+ {
+ brief_output = 1;
+ }
}
from_format = babl_format_with_space (from, from_space);
@@ -202,6 +208,11 @@ main (int argc,
{
set_to_profile = 1;
}
+ else if (strcmp (argv[i], "--brief") == 0 ||
+ strcmp (argv[i], "-b") == 0)
+ {
+ /* Pass. */
+ }
else
{
fprintf (stderr, "babl: unknown option: %s\n", argv[i]);
@@ -304,7 +315,9 @@ main (int argc,
n_components = babl_format_get_n_components (to_format);
data_index = 0;
- printf ("Conversion as \"%s\":\n", babl_get_name (to_format));
+ if (! brief_output)
+ printf ("Conversion as \"%s\":\n", babl_get_name (to_format));
+
for (c = 0; c < n_components; c++)
{
const Babl *arg_type = NULL;
@@ -317,7 +330,10 @@ main (int argc,
data_index += 4;
- printf ("- %f\n", value);
+ if (brief_output)
+ printf ("%s%f", c > 0 ? " ":"", value);
+ else
+ printf ("- %f\n", value);
}
else if (strcmp (babl_get_name (arg_type), "u8") == 0)
{
@@ -325,7 +341,10 @@ main (int argc,
data_index += 1;
- printf ("- %d\n", value);
+ if (brief_output)
+ printf ("%s%d", c > 0 ? " ":"", value);
+ else
+ printf ("- %d\n", value);
}
else if (strcmp (babl_get_name (arg_type), "u16") == 0)
{
@@ -333,7 +352,10 @@ main (int argc,
data_index += 2;
- printf ("- %d\n", value);
+ if (brief_output)
+ printf ("%s%d", c > 0 ? " ":"", value);
+ else
+ printf ("- %d\n", value);
}
else if (strcmp (babl_get_name (arg_type), "u32") == 0)
{
@@ -341,7 +363,10 @@ main (int argc,
data_index += 4;
- printf ("- %d\n", value);
+ if (brief_output)
+ printf ("%s%d", c > 0 ? " ":"", value);
+ else
+ printf ("- %d\n", value);
}
else
{
@@ -404,7 +429,8 @@ static void
babl_cli_print_usage (FILE *stream)
{
fprintf (stream,
- "usage: babl [options] [c1 ..]\n"
+ "Usage: babl [options] [c1 ..]\n"
+ "Convert color data from a specific Babl format and space to another.\n"
"\n"
" Options:\n"
" -h, --help this help information\n"
@@ -417,6 +443,12 @@ babl_cli_print_usage (FILE *stream)
"\n"
" -o, --output-profile output profile\n"
"\n"
- "All parameters following -- are considered components values.\n"
- "The tool expects exactly the number of components expected by your input format.\n");
+ " -b, --brief brief output\n"
+ " it can be re-entered as input for chain conversions\n"
+ "\n"
+ "All parameters following -- are considered components values. "
+ "This is useful to input negative components.\n\n"
+ "The tool expects exactly the number of components expected by your input format.\n\n"
+ "The default input and output formats are \"R'G'B' float\" and default space is "
+ "sRGB for RGB formats, or the naive CMYK space for CMYK formats.\n");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]