From b6624b457c5fd667a38f9034d4274e519d95dac4 Mon Sep 17 00:00:00 2001 From: noel Date: Wed, 21 Jan 2015 06:44:30 -0800 Subject: [PATCH] [APPLE port] Use en-localized profile description names Apple machines automatically configure their display profiles by reading EDID color profile data from display device ROM, but the profile created is given a generic description: 'Display'. The specific display name is stored in the profile's 'dscm' tag, which contains MLUC (multi-localized unicode) data records, with format described in ICC specification, Sect. 10.13 [1]. Examples of specific display names are: 'Color LCD', 'Dell U2410'. Add a reader of the specific display name present in the 'dscm', and store the data in the QCMS profile description. The language 'en' MLUC is used regardless of locale, and stored with a prefix to identify the data source (dscm:). Since MLUC description data is Unicode, convert any 0 data bytes to ASCII dots when saving them to the profile description so the result is a printable ASCII string. [1] http://www.color.org/specification/ICC1v43_2010-12.pdf TBR=darin@chromium.org BUG=401971 Review URL: https://codereview.chromium.org/852973002 Cr-Commit-Position: refs/heads/master@{#312383} --- third_party/qcms/README.chromium | 2 ++ third_party/qcms/src/iccread.c | 65 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/third_party/qcms/README.chromium b/third_party/qcms/README.chromium index cdf291d0cfad..8ad0d7e7293c 100644 --- a/third_party/qcms/README.chromium +++ b/third_party/qcms/README.chromium @@ -45,5 +45,7 @@ google.patch contains the following modifications. Apply with - https://code.google.com/p/chromium/issues/detail?id=401971 - Convert MLUC profile description embedded nulls to '.' - https://code.google.com/p/chromium/issues/detail?id=401971 + - [APPLE port] Use en-localized profile description names + - https://code.google.com/p/chromium/issues/detail?id=401971 To regenerate google.patch: git diff b8456f38 src > google.patch diff --git a/third_party/qcms/src/iccread.c b/third_party/qcms/src/iccread.c index 7790c07f490e..2e86aa814b8b 100644 --- a/third_party/qcms/src/iccread.c +++ b/third_party/qcms/src/iccread.c @@ -403,6 +403,67 @@ invalid_desc_tag: return false; } +#if defined(__APPLE__) + +#define TAG_dscm 0x6473636D // 'dscm' + +// Use dscm tag to change profile description "Display" to its more specific en-localized monitor name, if any. +static bool read_tag_dscmType(qcms_profile *profile, struct mem_source *src, struct tag_index index, uint32_t tag_id) +{ + if (strcmp(profile->description, "Display") != 0) + return true; + + struct tag *tag = find_tag(index, tag_id); + if (tag) { + uint32_t offset = tag->offset; + uint32_t type = read_u32(src, offset); + uint32_t records = read_u32(src, offset+8); + + if (!src->valid || !records || type != MLUC_TYPE) + goto invalid_dscm_tag; + if (read_u32(src, offset+12) != 12) // MLUC record size: bytes + goto invalid_dscm_tag; + + for (uint32_t i = 0; i < records; ++i) { + const uint32_t limit = sizeof profile->description; + const uint16_t isoen = 0x656E; // ISO-3166-1 language 'en' + + uint16_t language = read_u16(src, offset + 16 + (i * 12) + 0); + uint32_t length = read_u32(src, offset + 16 + (i * 12) + 4); + uint32_t description_offset = read_u32(src, offset + 16 + (i * 12) + 8); + + if (!src->valid || !length || (length & 1)) + goto invalid_dscm_tag; + if (language != isoen) + continue; + + // Use a prefix to identify the display description source + strcpy(profile->description, "dscm:"); + length += 5; + + if (length >= limit) + length = limit - 1; + for (uint32_t j = 5; j < length; ++j) { + uint8_t value = read_u8(src, offset + description_offset + j - 5); + if (!src->valid) + goto invalid_dscm_tag; + profile->description[j] = value ? value : '.'; + } + profile->description[length] = 0; + break; + } + } + + if (src->valid) + return true; + +invalid_dscm_tag: + invalid_source(src, "invalid dscm tag"); + return false; +} + +#endif // __APPLE__ + #define XYZ_TYPE 0x58595a20 // 'XYZ ' #define CURVE_TYPE 0x63757276 // 'curv' #define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para' @@ -1099,6 +1160,10 @@ qcms_profile* qcms_profile_from_memory(const void *mem, size_t size) if (!read_tag_descType(profile, src, index, TAG_desc)) goto invalid_tag_table; +#if defined(__APPLE__) + if (!read_tag_dscmType(profile, src, index, TAG_dscm)) + goto invalid_tag_table; +#endif // __APPLE__ if (find_tag(index, TAG_CHAD)) { profile->chromaticAdaption = read_tag_s15Fixed16ArrayType(src, index, TAG_CHAD); -- 2.11.4.GIT