Author: abrander
Date: 2010-04-04 17:44:22 +0200 (Sun, 04 Apr 2010)
New Revision: 3330
Modified:
trunk/librawstudio/rs-icc-profile.c
trunk/librawstudio/rs-icc-profile.h
Log:
Added reading of profile description.
Modified: trunk/librawstudio/rs-icc-profile.c
===================================================================
--- trunk/librawstudio/rs-icc-profile.c 2010-04-04 13:56:13 UTC (rev 3329)
+++ trunk/librawstudio/rs-icc-profile.c 2010-04-04 15:44:22 UTC (rev 3330)
@@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA.
*/
+#include <string.h>
#include <sys/stat.h>
#ifdef WIN32
#include <Winsock2.h> /* ntohl() */
@@ -36,6 +37,7 @@
gsize map_length;
RSIccProfile_ColorSpace colorspace;
RSIccProfile_Class profile_class;
+ gchar *description;
};
G_DEFINE_TYPE (RSIccProfile, rs_icc_profile, G_TYPE_OBJECT)
@@ -118,7 +120,8 @@
PROP_0,
PROP_FILENAME,
PROP_COLORSPACE,
- PROP_CLASS
+ PROP_CLASS,
+ PROP_DESCRIPTION,
};
static void
@@ -130,6 +133,7 @@
{
g_free(profile->filename);
g_free(profile->map);
+ g_free(profile->description);
profile->dispose_has_run = TRUE;
}
@@ -167,6 +171,11 @@
"profile-class", "profile-class", "Profile class",
RS_TYPE_ICC_PROFILE_CLASS, RS_ICC_PROFILE_UNDEFINED,
G_PARAM_READABLE));
+ g_object_class_install_property(object_class,
+ PROP_DESCRIPTION, g_param_spec_string(
+ "description", "Description", "Profile description",
+ "", G_PARAM_READABLE));
+
object_class->dispose = dispose;
object_class->finalize = finalize;
}
@@ -187,6 +196,9 @@
case PROP_CLASS:
g_value_set_enum(value, profile->profile_class);
break;
+ case PROP_DESCRIPTION:
+ g_value_set_string(value, profile->description);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
pspec);
}
@@ -249,6 +261,33 @@
return ret;
}
+/* Macro for reading unsigned integers from ICC profiles */
+#define _GUINT(map, offset) (ntohl(*((guint *)(&map[offset]))))
+static gchar *
+read_desc(RSIccProfile *profile, guint offset)
+{
+ gchar *ret = NULL;
+ gchar type[5];
+ type[4] = '\0';
+
+ if (offset > (profile->map_length-14))
+ return ret;
+
+ g_memmove(type, profile->map+offset, 4);
+
+ if (!g_str_equal(type, "desc"))
+ return ret;
+
+ guint count = _GUINT(profile->map, offset + 8);
+ if ((count < 1000) && (offset+12+count) <= profile->map_length)
+ {
+ ret = g_new0(gchar, count + 1);
+ g_memmove(ret, profile->map + offset + 12, count);
+ }
+
+ return ret;
+}
+
static gboolean
read_from_memory(RSIccProfile *profile, gchar *map, gsize map_length, gboolean
copy)
{
@@ -262,14 +301,42 @@
profile->map_length = map_length;
- /* Macro for reading unsigned integers from ICC profiles */
-#define _GUINT(map, offset) (ntohl(*((guint *)(&map[offset]))))
profile->colorspace = _GUINT(profile->map, 16);
profile->profile_class = _GUINT(profile->map, 12);
-#undef _GUINT
+ guint i, n_tags = _GUINT(profile->map, 128);
+
+ /* We don't believe this */
+ if (n_tags > 100)
+ n_tags = 0;
+
+ guint offset = 132;
+ gchar tag[5];
+ gchar tag_type[5];
+ guint tag_offset;
+ guint tag_size;
+
+ tag[4] = '\0';
+ tag_type[4] = '\0';
+ for(i=0;i<n_tags;i++)
+ {
+ offset = 128 + 4 + i*12;
+ if (offset > map_length-12)
+ break;
+
+ g_memmove(tag, profile->map+offset, 4);
+ tag_offset = _GUINT(profile->map, offset+4);
+ tag_size = _GUINT(profile->map, offset+8);
+
+ g_memmove(tag_type, profile->map+tag_offset, 4);
+
+ if (g_str_equal("desc", tag))
+ profile->description = read_desc(profile, tag_offset);
+ }
+
return ret;
}
+#undef _GUINT
/**
* Construct new RSIccProfile from an ICC profile on disk
@@ -335,3 +402,11 @@
return ret;
}
+
+const gchar *
+rs_icc_profile_get_description(const RSIccProfile *profile)
+{
+ g_assert(RS_IS_ICC_PROFILE(profile));
+
+ return profile->description;
+}
\ No newline at end of file
Modified: trunk/librawstudio/rs-icc-profile.h
===================================================================
--- trunk/librawstudio/rs-icc-profile.h 2010-04-04 13:56:13 UTC (rev 3329)
+++ trunk/librawstudio/rs-icc-profile.h 2010-04-04 15:44:22 UTC (rev 3330)
@@ -108,6 +108,9 @@
gboolean
rs_icc_profile_get_data(const RSIccProfile *icc, gchar **data, gsize *length);
+const gchar *
+rs_icc_profile_get_description(const RSIccProfile *profile);
+
G_END_DECLS
#endif /* RS_ICC_PROFILE_H */
_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit