From 82777a5dbcf0d6aeaba0a3204c580d58be6ea273 Mon Sep 17 00:00:00 2001
From: Richard Hughes <richard@hughsie.com>
Date: Wed, 20 Mar 2013 14:36:43 +0000
Subject: [PATCH] Add some helpers to get the size and contents of a cmsMLU
 object

---
 include/lcms2.h |  5 +++++
 src/cmsnamed.c  | 24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/lcms2.h b/include/lcms2.h
index bafe775..388834e 100644
--- a/include/lcms2.h
+++ b/include/lcms2.h
@@ -1245,6 +1245,11 @@ CMSAPI cmsUInt32Number   CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu,
 CMSAPI cmsBool           CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
                                                          const char LanguageCode[3], const char CountryCode[3],
                                                          char ObtainedLanguage[3], char ObtainedCountry[3]);
+CMSAPI cmsUInt32Number   CMSEXPORT cmsMLUgetSize(const cmsMLU* mlu);
+CMSAPI cmsBool           CMSEXPORT cmsMLUgetTranslationCodes(const cmsMLU* mlu,
+                                                             cmsUInt32Number idx,
+                                                             char LanguageCode[3],
+                                                             char CountryCode[3]);
 
 // Undercolorremoval & black generation -------------------------------------------------------------------------------------
 
diff --git a/src/cmsnamed.c b/src/cmsnamed.c
index 6bcb994..5d810a0 100644
--- a/src/cmsnamed.c
+++ b/src/cmsnamed.c
@@ -445,6 +445,30 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu,
     return TRUE;
 }
 
+// Get the number of translations in the MLU object
+CMSAPI cmsUInt32Number CMSEXPORT cmsMLUgetSize(const cmsMLU* mlu)
+{
+    if (mlu == NULL) return 0;
+    return mlu->UsedEntries;
+}
+
+// Get the language and country codes for a specific MLU index
+CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslationCodes(const cmsMLU* mlu,
+                                                   cmsUInt32Number idx,
+                                                   char LanguageCode[3],
+                                                   char CountryCode[3])
+{
+    _cmsMLUentry *entry;
+
+    if (mlu == NULL) return FALSE;
+    if (idx + 1 > mlu->UsedEntries) return FALSE;
+
+    entry = &mlu->Entries[idx];
+    *(cmsUInt16Number *)LanguageCode = _cmsAdjustEndianess16(entry->Language);
+    *(cmsUInt16Number *)CountryCode  = _cmsAdjustEndianess16(entry->Country);
+
+    return TRUE;
+}
 
 // Named color lists --------------------------------------------------------------------------------------------
 
-- 
1.8.1.4

