[babl] babl: use an existing const char ptr for encoding in format
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] babl: use an existing const char ptr for encoding in format
- Date: Fri, 20 Jul 2018 14:48:50 +0000 (UTC)
commit cda014b14f64783b6df3880e6be2f66f8dabdc7a
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Jul 20 16:27:55 2018 +0200
babl: use an existing const char ptr for encoding in format
babl/babl-format.c | 38 ++++++++++++--------------------------
babl/babl-format.h | 1 +
babl/babl.h | 2 +-
3 files changed, 14 insertions(+), 27 deletions(-)
---
diff --git a/babl/babl-format.c b/babl/babl-format.c
index 51e5458..7b81cae 100644
--- a/babl/babl-format.c
+++ b/babl/babl-format.c
@@ -143,11 +143,12 @@ format_new_from_format_with_space (const Babl *format, const Babl *space)
ret = format_new (new_name,
0,
- format->format.planar, format->format.components,
+ format->format.planar, format->format.components,
(void*)babl_remodel_with_space (BABL(format->format.model), space),
space,
format->format.component, format->format.sampling, (void*)format->format.type);
+ ret->format.encoding = babl_get_name(format);
babl_db_insert (db, (void*)ret);
return ret;
}
@@ -713,38 +714,23 @@ BABL_CLASS_IMPLEMENT (format)
const char *
babl_format_get_encoding (const Babl *babl)
{
- static char ret[256];
- const char *name = babl_get_name (babl);
- strcpy (&ret[0], name);
- if (babl_format_get_space (babl) != babl_space ("sRGB"))
- {
-
- if (strstr (ret, "-space"))
- *strstr (ret, "-space") = '\0';
-
- name = &ret[0];
- }
- return name;
+ if (!babl) return NULL;
+ if (babl->format.encoding) return babl->format.encoding;
+ return babl_get_name (babl);
}
const Babl *
-babl_format_with_space (const char *name, const Babl *space)
+babl_format_with_space (const char *encoding, const Babl *space)
{
- char tmpname[256]="";
- const Babl *example_format = (void*) name;
- if (!name) return NULL;
+ const Babl *example_format = (void*) encoding;
+ if (!encoding) return NULL;
if (BABL_IS_BABL (example_format))
{
- name = babl_get_name (example_format);
+ encoding = babl_get_name (example_format);
if (babl_format_get_space (example_format) != babl_space ("sRGB"))
{
- strcpy (&tmpname[0], name);
-
- if (strstr (tmpname, "-space"))
- *strstr (tmpname, "-space") = '\0';
-
- name = &tmpname[0];
+ encoding = babl_format_get_encoding (example_format);
}
}
@@ -764,9 +750,9 @@ babl_format_with_space (const char *name, const Babl *space)
return NULL;
}
if (space == babl_space("sRGB"))
- return babl_format (name);
+ return babl_format (encoding);
- return format_new_from_format_with_space (babl_format (name), space);
+ return format_new_from_format_with_space (babl_format (encoding), space);
}
int
diff --git a/babl/babl-format.h b/babl/babl-format.h
index ddf7861..b3a4643 100644
--- a/babl/babl-format.h
+++ b/babl/babl-format.h
@@ -43,6 +43,7 @@ typedef struct
for conversion paths */
int format_n; /* whether the format is a format_n type or not */
int palette;
+ const char *encoding;
} BablFormat;
#endif
diff --git a/babl/babl.h b/babl/babl.h
index 12b09c1..e0fd9e5 100644
--- a/babl/babl.h
+++ b/babl/babl.h
@@ -181,7 +181,7 @@ int babl_format_exists (const char *name);
* the unsuffixed version is used. If a format is passed in as space
* the space of the format is used.
*/
-const Babl * babl_format_with_space (const char *name, const Babl *space);
+const Babl * babl_format_with_space (const char *encoding, const Babl *space);
const Babl *
babl_model_with_space (const char *name, const Babl *space);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]