Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/qcms/src/iccread.c

Issue 885443002: Roll Chrome into Mojo. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebase to ToT mojo Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/qcms/README.chromium ('k') | tools/android/asan/asan_device_setup.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* vim: set ts=8 sw=8 noexpandtab: */ 1 /* vim: set ts=8 sw=8 noexpandtab: */
2 // qcms 2 // qcms
3 // Copyright (C) 2009 Mozilla Foundation 3 // Copyright (C) 2009 Mozilla Foundation
4 // Copyright (C) 1998-2007 Marti Maria 4 // Copyright (C) 1998-2007 Marti Maria
5 // 5 //
6 // Permission is hereby granted, free of charge, to any person obtaining 6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the "Software"), 7 // a copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation 8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e 10 // and/or sell copies of the Software, and to permit persons to whom the Softwar e
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 for (i = 0; i < index.count; i++) { 349 for (i = 0; i < index.count; i++) {
350 if (index.tags[i].signature == tag_id) { 350 if (index.tags[i].signature == tag_id) {
351 return &index.tags[i]; 351 return &index.tags[i];
352 } 352 }
353 } 353 }
354 return tag; 354 return tag;
355 } 355 }
356 356
357 #define DESC_TYPE 0x64657363 // 'desc' 357 #define DESC_TYPE 0x64657363 // 'desc'
358 #define MLUC_TYPE 0x6d6c7563 // 'mluc' 358 #define MLUC_TYPE 0x6d6c7563 // 'mluc'
359 #define MMOD_TYPE 0x6D6D6F64 // 'mmod'
359 360
360 static bool read_tag_descType(qcms_profile *profile, struct mem_source *src, str uct tag_index index, uint32_t tag_id) 361 static bool read_tag_descType(qcms_profile *profile, struct mem_source *src, str uct tag_index index, uint32_t tag_id)
361 { 362 {
362 struct tag *tag = find_tag(index, tag_id); 363 struct tag *tag = find_tag(index, tag_id);
363 if (tag) { 364 if (tag) {
364 const uint32_t limit = sizeof profile->description; 365 const uint32_t limit = sizeof profile->description;
365 uint32_t offset = tag->offset; 366 uint32_t offset = tag->offset;
366 uint32_t type = read_u32(src, offset); 367 uint32_t type = read_u32(src, offset);
367 uint32_t length = read_u32(src, offset+8); 368 uint32_t length = read_u32(src, offset+8);
368 » » uint32_t i, description; 369 » » uint32_t i, description_offset;
369 bool mluc = false; 370 bool mluc = false;
370 if (length && type == MLUC_TYPE) { 371 if (length && type == MLUC_TYPE) {
371 length = read_u32(src, offset+20); 372 length = read_u32(src, offset+20);
372 if (!length || (length & 1) || (read_u32(src, offset+12) != 12)) 373 if (!length || (length & 1) || (read_u32(src, offset+12) != 12))
373 goto invalid_desc_tag; 374 goto invalid_desc_tag;
374 » » » description = offset + read_u32(src, offset+24); 375 » » » description_offset = offset + read_u32(src, offset+24);
375 if (!src->valid) 376 if (!src->valid)
376 goto invalid_desc_tag; 377 goto invalid_desc_tag;
377 mluc = true; 378 mluc = true;
378 } else if (length && type == DESC_TYPE) { 379 } else if (length && type == DESC_TYPE) {
379 » » » description = offset + 12; 380 » » » description_offset = offset + 12;
380 } else { 381 } else {
381 goto invalid_desc_tag; 382 goto invalid_desc_tag;
382 } 383 }
383 if (length >= limit) 384 if (length >= limit)
384 length = limit - 1; 385 length = limit - 1;
385 for (i = 0; i < length; ++i) { 386 for (i = 0; i < length; ++i) {
386 » » » uint8_t value = read_u8(src, description+i); 387 » » » uint8_t value = read_u8(src, description_offset + i);
387 if (!src->valid) 388 if (!src->valid)
388 goto invalid_desc_tag; 389 goto invalid_desc_tag;
389 if (mluc && !value) 390 if (mluc && !value)
390 value = '.'; 391 value = '.';
391 profile->description[i] = value; 392 profile->description[i] = value;
392 } 393 }
393 profile->description[length] = 0; 394 profile->description[length] = 0;
394 } else { 395 } else {
395 goto invalid_desc_tag; 396 goto invalid_desc_tag;
396 } 397 }
397 398
398 if (src->valid) 399 if (src->valid)
399 return true; 400 return true;
400 401
401 invalid_desc_tag: 402 invalid_desc_tag:
402 invalid_source(src, "invalid description"); 403 invalid_source(src, "invalid description");
403 return false; 404 return false;
404 } 405 }
405 406
406 #if defined(__APPLE__) 407 #if defined(__APPLE__)
407 408
409 // Use the dscm tag to change profile description "Display" to its more specific en-localized monitor name, if any.
410
408 #define TAG_dscm 0x6473636D // 'dscm' 411 #define TAG_dscm 0x6473636D // 'dscm'
409 412
410 // Use dscm tag to change profile description "Display" to its more specific en- localized monitor name, if any.
411 static bool read_tag_dscmType(qcms_profile *profile, struct mem_source *src, str uct tag_index index, uint32_t tag_id) 413 static bool read_tag_dscmType(qcms_profile *profile, struct mem_source *src, str uct tag_index index, uint32_t tag_id)
412 { 414 {
413 if (strcmp(profile->description, "Display") != 0) 415 if (strcmp(profile->description, "Display") != 0)
414 return true; 416 return true;
415 417
416 struct tag *tag = find_tag(index, tag_id); 418 struct tag *tag = find_tag(index, tag_id);
417 if (tag) { 419 if (tag) {
418 uint32_t offset = tag->offset; 420 uint32_t offset = tag->offset;
419 uint32_t type = read_u32(src, offset); 421 uint32_t type = read_u32(src, offset);
420 uint32_t records = read_u32(src, offset+8); 422 uint32_t records = read_u32(src, offset+8);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 457 }
456 458
457 if (src->valid) 459 if (src->valid)
458 return true; 460 return true;
459 461
460 invalid_dscm_tag: 462 invalid_dscm_tag:
461 invalid_source(src, "invalid dscm tag"); 463 invalid_source(src, "invalid dscm tag");
462 return false; 464 return false;
463 } 465 }
464 466
467 // Use the mmod tag to change profile description "Display" to its specific mmod maker model data, if any.
468
469 #define TAG_mmod 0x6D6D6F64 // 'mmod'
470
471 static bool read_tag_mmodType(qcms_profile *profile, struct mem_source *src, str uct tag_index index, uint32_t tag_id)
472 {
473 if (strcmp(profile->description, "Display") != 0)
474 return true;
475
476 struct tag *tag = find_tag(index, tag_id);
477 if (tag) {
478 const uint8_t length = 4 * 4; // Four 4-byte fields: 'mmod', 0, maker, model.
479
480 uint32_t offset = tag->offset;
481 if (tag->size < 40 || read_u32(src, offset) != MMOD_TYPE)
482 goto invalid_mmod_tag;
483
484 for (uint8_t i = 0; i < length; ++i) {
485 uint8_t value = read_u8(src, offset + i);
486 if (!src->valid)
487 goto invalid_mmod_tag;
488 profile->description[i] = value ? value : '.';
489 }
490 profile->description[length] = 0;
491 }
492
493 if (src->valid)
494 return true;
495
496 invalid_mmod_tag:
497 invalid_source(src, "invalid mmod tag");
498 return false;
499 }
500
465 #endif // __APPLE__ 501 #endif // __APPLE__
466 502
467 #define XYZ_TYPE 0x58595a20 // 'XYZ ' 503 #define XYZ_TYPE 0x58595a20 // 'XYZ '
468 #define CURVE_TYPE 0x63757276 // 'curv' 504 #define CURVE_TYPE 0x63757276 // 'curv'
469 #define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para' 505 #define PARAMETRIC_CURVE_TYPE 0x70617261 // 'para'
470 #define LUT16_TYPE 0x6d667432 // 'mft2' 506 #define LUT16_TYPE 0x6d667432 // 'mft2'
471 #define LUT8_TYPE 0x6d667431 // 'mft1' 507 #define LUT8_TYPE 0x6d667431 // 'mft1'
472 #define LUT_MAB_TYPE 0x6d414220 // 'mAB ' 508 #define LUT_MAB_TYPE 0x6d414220 // 'mAB '
473 #define LUT_MBA_TYPE 0x6d424120 // 'mBA ' 509 #define LUT_MBA_TYPE 0x6d424120 // 'mBA '
474 #define CHROMATIC_TYPE 0x73663332 // 'sf32' 510 #define CHROMATIC_TYPE 0x73663332 // 'sf32'
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 1192
1157 index = read_tag_table(profile, src); 1193 index = read_tag_table(profile, src);
1158 if (!src->valid || !index.tags) 1194 if (!src->valid || !index.tags)
1159 goto invalid_tag_table; 1195 goto invalid_tag_table;
1160 1196
1161 if (!read_tag_descType(profile, src, index, TAG_desc)) 1197 if (!read_tag_descType(profile, src, index, TAG_desc))
1162 goto invalid_tag_table; 1198 goto invalid_tag_table;
1163 #if defined(__APPLE__) 1199 #if defined(__APPLE__)
1164 if (!read_tag_dscmType(profile, src, index, TAG_dscm)) 1200 if (!read_tag_dscmType(profile, src, index, TAG_dscm))
1165 goto invalid_tag_table; 1201 goto invalid_tag_table;
1202 if (!read_tag_mmodType(profile, src, index, TAG_mmod))
1203 goto invalid_tag_table;
1166 #endif // __APPLE__ 1204 #endif // __APPLE__
1167 1205
1168 if (find_tag(index, TAG_CHAD)) { 1206 if (find_tag(index, TAG_CHAD)) {
1169 profile->chromaticAdaption = read_tag_s15Fixed16ArrayType(src, i ndex, TAG_CHAD); 1207 profile->chromaticAdaption = read_tag_s15Fixed16ArrayType(src, i ndex, TAG_CHAD);
1170 } else { 1208 } else {
1171 profile->chromaticAdaption.invalid = true; //Signal the data is not present 1209 profile->chromaticAdaption.invalid = true; //Signal the data is not present
1172 } 1210 }
1173 1211
1174 if (profile->class == DISPLAY_DEVICE_PROFILE || profile->class == INPUT_ DEVICE_PROFILE || 1212 if (profile->class == DISPLAY_DEVICE_PROFILE || profile->class == INPUT_ DEVICE_PROFILE ||
1175 profile->class == OUTPUT_DEVICE_PROFILE || profile->class == COLOR_ SPACE_PROFILE) { 1213 profile->class == OUTPUT_DEVICE_PROFILE || profile->class == COLOR_ SPACE_PROFILE) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 { 1380 {
1343 qcms_profile *profile = NULL; 1381 qcms_profile *profile = NULL;
1344 FILE *file = _wfopen(path, L"rb"); 1382 FILE *file = _wfopen(path, L"rb");
1345 if (file) { 1383 if (file) {
1346 profile = qcms_profile_from_file(file); 1384 profile = qcms_profile_from_file(file);
1347 fclose(file); 1385 fclose(file);
1348 } 1386 }
1349 return profile; 1387 return profile;
1350 } 1388 }
1351 #endif 1389 #endif
OLDNEW
« no previous file with comments | « third_party/qcms/README.chromium ('k') | tools/android/asan/asan_device_setup.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698