Extract tag type and include it in returned type struct
Bug:
Change-Id: Ie60184dc58bf8c3abd9a4b229bcf68f7f47ca46a
diff --git a/iccdump.c b/iccdump.c
index 8b8af16..3aa022f 100644
--- a/iccdump.c
+++ b/iccdump.c
@@ -18,9 +18,18 @@
exit(1);
}
+static void signature_to_string(uint32_t sig, char* str) {
+ str[0] = (sig >> 24) & 0xFF;
+ str[1] = (sig >> 16) & 0xFF;
+ str[2] = (sig >> 8) & 0xFF;
+ str[3] = (sig >> 0) & 0xFF;
+ str[4] = 0;
+}
+
static void dump_sig_field(const char* name, uint32_t val) {
- printf("%20s : 0x%08X : '%c%c%c%c'\n",
- name, val, val >> 24, (val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF);
+ char valStr[5];
+ signature_to_string(val, valStr);
+ printf("%20s : 0x%08X : '%s'\n", name, val, valStr);
}
int main(int argc, char** argv) {
@@ -74,15 +83,20 @@
printf("%20s : : %f\n", "Illuminant Y", profile.illuminant_Y);
printf("%20s : : %f\n", "Illuminant Z", profile.illuminant_Z);
dump_sig_field("Creator", profile.creator);
+ printf("%20s : 0x%08X : %u\n", "Tag count", profile.tag_count, profile.tag_count);
printf("\n");
- printf("%20s : 0x%08X : %u\n", "Tag count", profile.tag_count, profile.tag_count);
+ printf(" Tag : Type : Size\n");
+ printf(" ------ : ------ : ------\n");
for (uint32_t i = 0; i < profile.tag_count; ++i) {
skcms_ICCTag tag;
skcms_ICCProfile_getTagByIndex(&profile, i, &tag);
- dump_sig_field("Signature", tag.signature);
- printf("%20s : 0x%08X : %u\n", "Size", tag.size, tag.size);
+ char tagSig[5];
+ char typeSig[5];
+ signature_to_string(tag.signature, tagSig);
+ signature_to_string(tag.type, typeSig);
+ printf(" '%s' : '%s' : %6u\n", tagSig, typeSig, tag.size);
}
return 0;
diff --git a/skcms.h b/skcms.h
index a149721..87e13d1 100644
--- a/skcms.h
+++ b/skcms.h
@@ -87,6 +87,7 @@
typedef struct {
uint32_t signature;
+ uint32_t type;
uint32_t size;
const void* buf;
} skcms_ICCTag;
diff --git a/src/ICCProfile.c b/src/ICCProfile.c
index 316c973..2cb4c58 100644
--- a/src/ICCProfile.c
+++ b/src/ICCProfile.c
@@ -78,7 +78,7 @@
uint8_t size [4];
} skcms_ICCTag_Layout;
-static const skcms_ICCTag_Layout* skcms_ICCProfile_getTagTable(const skcms_ICCProfile* profile) {
+static const skcms_ICCTag_Layout* get_tag_table(const skcms_ICCProfile* profile) {
return (const skcms_ICCTag_Layout*)(profile->buffer + sizeof(skcms_ICCHeader));
}
@@ -138,7 +138,7 @@
}
// Validate that all tag entries have sane offset + size
- const skcms_ICCTag_Layout* tags = skcms_ICCProfile_getTagTable(profile);
+ const skcms_ICCTag_Layout* tags = get_tag_table(profile);
for (uint32_t i = 0; i < profile->tag_count; ++i) {
uint32_t tag_offset = read_big_u32(tags[i].offset);
uint32_t tag_size = read_big_u32(tags[i].size);
@@ -170,22 +170,24 @@
skcms_ICCTag* tag) {
if (!profile || !profile->buffer || !tag) { return; }
if (index > profile->tag_count) { return; }
- const skcms_ICCTag_Layout* tags = skcms_ICCProfile_getTagTable(profile);
+ const skcms_ICCTag_Layout* tags = get_tag_table(profile);
tag->signature = read_big_u32(tags[index].signature);
tag->size = read_big_u32(tags[index].size);
tag->buf = read_big_u32(tags[index].offset) + profile->buffer;
+ tag->type = read_big_u32((const uint8_t*)tag->buf);
}
bool skcms_ICCProfile_getTagBySignature(const skcms_ICCProfile* profile,
uint32_t signature,
skcms_ICCTag* tag) {
if (!profile || !profile->buffer || !tag) { return false; }
- const skcms_ICCTag_Layout* tags = skcms_ICCProfile_getTagTable(profile);
+ const skcms_ICCTag_Layout* tags = get_tag_table(profile);
for (uint32_t i = 0; i < profile->tag_count; ++i) {
if (read_big_u32(tags[i].signature) == signature) {
tag->signature = signature;
tag->size = read_big_u32(tags[i].size);
tag->buf = read_big_u32(tags[i].offset) + profile->buffer;
+ tag->type = read_big_u32((const uint8_t*)tag->buf);
return true;
}
}