OLD | NEW |
1 diff --git a/third_party/qcms/src/iccread.c b/third_party/qcms/src/iccread.c | 1 diff --git a/third_party/qcms/src/iccread.c b/third_party/qcms/src/iccread.c |
2 index 36b7011..6cec34a 100644 | 2 index 36b7011..208ebee 100644 |
3 --- a/third_party/qcms/src/iccread.c | 3 --- a/third_party/qcms/src/iccread.c |
4 +++ b/third_party/qcms/src/iccread.c | 4 +++ b/third_party/qcms/src/iccread.c |
5 @@ -266,7 +266,7 @@ qcms_bool qcms_profile_is_bogus(qcms_profile *profile) | 5 @@ -266,7 +266,7 @@ qcms_bool qcms_profile_is_bogus(qcms_profile *profile) |
6 if (profile->color_space != RGB_SIGNATURE) | 6 if (profile->color_space != RGB_SIGNATURE) |
7 return false; | 7 return false; |
8 | 8 |
9 - if (profile->A2B0 || profile->B2A0) | 9 - if (profile->A2B0 || profile->B2A0) |
10 + if (qcms_supports_iccv4 && (profile->A2B0 || profile->B2A0)) | 10 + if (qcms_supports_iccv4 && (profile->A2B0 || profile->B2A0)) |
11 return false; | 11 return false; |
12 | 12 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 + | 223 + |
224 channel_offset += tag_len; | 224 channel_offset += tag_len; |
225 // 4 byte aligned | 225 // 4 byte aligned |
226 if ((tag_len % 4) != 0) | 226 if ((tag_len % 4) != 0) |
227 channel_offset += 4 - (tag_len % 4); | 227 channel_offset += 4 - (tag_len % 4); |
228 } | 228 } |
229 - | 229 - |
230 } | 230 } |
231 | 231 |
232 static void mAB_release(struct lutmABType *lut) | 232 static void mAB_release(struct lutmABType *lut) |
233 @@ -657,7 +817,7 @@ static struct lutType *read_tag_lutType(struct mem_source *s
rc, struct tag_index | 233 @@ -540,7 +700,7 @@ static struct lutmABType *read_tag_lutmABType(struct mem_sou
rce *src, struct tag |
| 234 » // We require 3in/out channels since we only support RGB->XYZ (or RGB->L
AB) |
| 235 » // XXX: If we remove this restriction make sure that the number of chann
els |
| 236 » // is less or equal to the maximum number of mAB curves in qcmsint.
h |
| 237 -» // also check for clut_size overflow. |
| 238 +» // also check for clut_size overflow. Also make sure it's != 0 |
| 239 » if (num_in_channels != 3 || num_out_channels != 3) |
| 240 » » return NULL; |
| 241 |
| 242 @@ -570,6 +730,9 @@ static struct lutmABType *read_tag_lutmABType(struct mem_sou
rce *src, struct tag |
| 243 » » // clut_size can not overflow since lg(256^num_in_channels) = 24
bits. |
| 244 » » for (i = 0; i < num_in_channels; i++) { |
| 245 » » » clut_size *= read_u8(src, clut_offset + i); |
| 246 +» » » if (clut_size == 0) { |
| 247 +» » » » invalid_source(src, "bad clut_size"); |
| 248 +» » » } |
| 249 » » } |
| 250 » } else { |
| 251 » » clut_size = 0; |
| 252 @@ -590,6 +753,9 @@ static struct lutmABType *read_tag_lutmABType(struct mem_sou
rce *src, struct tag |
| 253 |
| 254 » for (i = 0; i < num_in_channels; i++) { |
| 255 » » lut->num_grid_points[i] = read_u8(src, clut_offset + i); |
| 256 +» » if (lut->num_grid_points[i] == 0) { |
| 257 +» » » invalid_source(src, "bad grid_points"); |
| 258 +» » } |
| 259 » } |
| 260 |
| 261 » // Reverse the processing of transformation elements for mBA type. |
| 262 @@ -657,7 +823,7 @@ static struct lutType *read_tag_lutType(struct mem_source *s
rc, struct tag_index |
234 uint16_t num_input_table_entries; | 263 uint16_t num_input_table_entries; |
235 uint16_t num_output_table_entries; | 264 uint16_t num_output_table_entries; |
236 uint8_t in_chan, grid_points, out_chan; | 265 uint8_t in_chan, grid_points, out_chan; |
237 - uint32_t clut_offset, output_offset; | 266 - uint32_t clut_offset, output_offset; |
238 + size_t clut_offset, output_offset; | 267 + size_t clut_offset, output_offset; |
239 uint32_t clut_size; | 268 uint32_t clut_size; |
240 size_t entry_size; | 269 size_t entry_size; |
241 struct lutType *lut; | 270 struct lutType *lut; |
242 @@ -979,6 +1139,9 @@ qcms_profile* qcms_profile_sRGB(void) | 271 @@ -672,6 +838,10 @@ static struct lutType *read_tag_lutType(struct mem_source *
src, struct tag_index |
| 272 » } else if (type == LUT16_TYPE) { |
| 273 » » num_input_table_entries = read_u16(src, offset + 48); |
| 274 » » num_output_table_entries = read_u16(src, offset + 50); |
| 275 +» » if (num_input_table_entries == 0 || num_output_table_entries ==
0) { |
| 276 +» » » invalid_source(src, "Bad channel count"); |
| 277 +» » » return NULL; |
| 278 +» » } |
| 279 » » entry_size = 2; |
| 280 » } else { |
| 281 » » assert(0); // the caller checks that this doesn't happen |
| 282 @@ -685,15 +855,18 @@ static struct lutType *read_tag_lutType(struct mem_source
*src, struct tag_index |
| 283 |
| 284 » clut_size = pow(grid_points, in_chan); |
| 285 » if (clut_size > MAX_CLUT_SIZE) { |
| 286 +» » invalid_source(src, "CLUT too large"); |
| 287 » » return NULL; |
| 288 » } |
| 289 |
| 290 » if (in_chan != 3 || out_chan != 3) { |
| 291 +» » invalid_source(src, "CLUT only supports RGB"); |
| 292 » » return NULL; |
| 293 » } |
| 294 |
| 295 » lut = malloc(sizeof(struct lutType) + (num_input_table_entries * in_chan
+ clut_size*out_chan + num_output_table_entries * out_chan)*sizeof(float)); |
| 296 » if (!lut) { |
| 297 +» » invalid_source(src, "CLUT too large"); |
| 298 » » return NULL; |
| 299 » } |
| 300 |
| 301 @@ -704,9 +877,9 @@ static struct lutType *read_tag_lutType(struct mem_source *s
rc, struct tag_index |
| 302 |
| 303 » lut->num_input_table_entries = num_input_table_entries; |
| 304 » lut->num_output_table_entries = num_output_table_entries; |
| 305 -» lut->num_input_channels = read_u8(src, offset + 8); |
| 306 -» lut->num_output_channels = read_u8(src, offset + 9); |
| 307 -» lut->num_clut_grid_points = read_u8(src, offset + 10); |
| 308 +» lut->num_input_channels = in_chan; |
| 309 +» lut->num_output_channels = out_chan; |
| 310 +» lut->num_clut_grid_points = grid_points; |
| 311 » lut->e00 = read_s15Fixed16Number(src, offset+12); |
| 312 » lut->e01 = read_s15Fixed16Number(src, offset+16); |
| 313 » lut->e02 = read_s15Fixed16Number(src, offset+20); |
| 314 @@ -979,6 +1152,9 @@ qcms_profile* qcms_profile_sRGB(void) |
243 return NO_MEM_PROFILE; | 315 return NO_MEM_PROFILE; |
244 | 316 |
245 profile = qcms_profile_create_rgb_with_table(D65, Rec709Primaries, table
, 1024); | 317 profile = qcms_profile_create_rgb_with_table(D65, Rec709Primaries, table
, 1024); |
246 + if (profile) | 318 + if (profile) |
247 + strcpy(profile->description, "sRGB IEC61966-2.1"); | 319 + strcpy(profile->description, "sRGB IEC61966-2.1"); |
248 + | 320 + |
249 free(table); | 321 free(table); |
250 return profile; | 322 return profile; |
251 } | 323 } |
252 @@ -997,6 +1160,9 @@ qcms_profile* qcms_profile_from_memory(const void *mem, siz
e_t size) | 324 @@ -997,6 +1173,9 @@ qcms_profile* qcms_profile_from_memory(const void *mem, siz
e_t size) |
253 source.size = size; | 325 source.size = size; |
254 source.valid = true; | 326 source.valid = true; |
255 | 327 |
256 + if (size < 4) | 328 + if (size < 4) |
257 + return INVALID_PROFILE; | 329 + return INVALID_PROFILE; |
258 + | 330 + |
259 length = read_u32(src, 0); | 331 length = read_u32(src, 0); |
260 if (length <= size) { | 332 if (length <= size) { |
261 // shrink the area that we can read if appropriate | 333 // shrink the area that we can read if appropriate |
262 @@ -1028,6 +1194,15 @@ qcms_profile* qcms_profile_from_memory(const void *mem, s
ize_t size) | 334 @@ -1028,6 +1207,15 @@ qcms_profile* qcms_profile_from_memory(const void *mem, s
ize_t size) |
263 if (!src->valid || !index.tags) | 335 if (!src->valid || !index.tags) |
264 goto invalid_tag_table; | 336 goto invalid_tag_table; |
265 | 337 |
266 + if (!read_tag_descType(profile, src, index, TAG_desc)) | 338 + if (!read_tag_descType(profile, src, index, TAG_desc)) |
267 + goto invalid_tag_table; | 339 + goto invalid_tag_table; |
268 +#if defined(__APPLE__) | 340 +#if defined(__APPLE__) |
269 + if (!read_tag_dscmType(profile, src, index, TAG_dscm)) | 341 + if (!read_tag_dscmType(profile, src, index, TAG_dscm)) |
270 + goto invalid_tag_table; | 342 + goto invalid_tag_table; |
271 + if (!read_tag_mmodType(profile, src, index, TAG_mmod)) | 343 + if (!read_tag_mmodType(profile, src, index, TAG_mmod)) |
272 + goto invalid_tag_table; | 344 + goto invalid_tag_table; |
273 +#endif // __APPLE__ | 345 +#endif // __APPLE__ |
274 + | 346 + |
275 if (find_tag(index, TAG_CHAD)) { | 347 if (find_tag(index, TAG_CHAD)) { |
276 profile->chromaticAdaption = read_tag_s15Fixed16ArrayType(src, i
ndex, TAG_CHAD); | 348 profile->chromaticAdaption = read_tag_s15Fixed16ArrayType(src, i
ndex, TAG_CHAD); |
277 } else { | 349 } else { |
278 @@ -1098,6 +1273,16 @@ invalid_profile: | 350 @@ -1098,6 +1286,16 @@ invalid_profile: |
279 return INVALID_PROFILE; | 351 return INVALID_PROFILE; |
280 } | 352 } |
281 | 353 |
282 +qcms_bool qcms_profile_match(qcms_profile *p1, qcms_profile *p2) | 354 +qcms_bool qcms_profile_match(qcms_profile *p1, qcms_profile *p2) |
283 +{ | 355 +{ |
284 + return memcmp(p1->description, p2->description, sizeof p1->description) ==
0; | 356 + return memcmp(p1->description, p2->description, sizeof p1->description) ==
0; |
285 +} | 357 +} |
286 + | 358 + |
287 +const char* qcms_profile_get_description(qcms_profile *profile) | 359 +const char* qcms_profile_get_description(qcms_profile *profile) |
288 +{ | 360 +{ |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 +void qcms_transform_data_type(qcms_transform *transform, void *src, void *dest,
size_t length, qcms_output_type type) | 1347 +void qcms_transform_data_type(qcms_transform *transform, void *src, void *dest,
size_t length, qcms_output_type type) |
1276 +{ | 1348 +{ |
1277 + static const struct _qcms_format_type output_rgbx = { 0, 2 }; | 1349 + static const struct _qcms_format_type output_rgbx = { 0, 2 }; |
1278 + static const struct _qcms_format_type output_bgrx = { 2, 0 }; | 1350 + static const struct _qcms_format_type output_bgrx = { 2, 0 }; |
1279 + | 1351 + |
1280 + transform->transform_fn(transform, src, dest, length, type == QCMS_OUTPU
T_BGRX ? output_bgrx : output_rgbx); | 1352 + transform->transform_fn(transform, src, dest, length, type == QCMS_OUTPU
T_BGRX ? output_bgrx : output_rgbx); |
1281 } | 1353 } |
1282 | 1354 |
1283 qcms_bool qcms_supports_iccv4; | 1355 qcms_bool qcms_supports_iccv4; |
1284 diff --git a/third_party/qcms/src/transform_util.c b/third_party/qcms/src/transf
orm_util.c | 1356 diff --git a/third_party/qcms/src/transform_util.c b/third_party/qcms/src/transf
orm_util.c |
1285 index e8447e5..f4338b2 100644 | 1357 index e8447e5..f616c3f 100644 |
1286 --- a/third_party/qcms/src/transform_util.c | 1358 --- a/third_party/qcms/src/transform_util.c |
1287 +++ b/third_party/qcms/src/transform_util.c | 1359 +++ b/third_party/qcms/src/transform_util.c |
1288 @@ -36,7 +36,7 @@ | 1360 @@ -36,7 +36,7 @@ |
1289 | 1361 |
1290 /* value must be a value between 0 and 1 */ | 1362 /* value must be a value between 0 and 1 */ |
1291 //XXX: is the above a good restriction to have? | 1363 //XXX: is the above a good restriction to have? |
1292 -float lut_interp_linear(double value, uint16_t *table, int length) | 1364 -float lut_interp_linear(double value, uint16_t *table, int length) |
1293 +float lut_interp_linear(double value, uint16_t *table, size_t length) | 1365 +float lut_interp_linear(double value, uint16_t *table, size_t length) |
1294 { | 1366 { |
1295 int upper, lower; | 1367 int upper, lower; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 } | 1430 } |
1359 } | 1431 } |
1360 - return gamma_table; | 1432 - return gamma_table; |
1361 + | 1433 + |
1362 + validate_gamma_table(gamma_table); | 1434 + validate_gamma_table(gamma_table); |
1363 + | 1435 + |
1364 + return gamma_table; | 1436 + return gamma_table; |
1365 } | 1437 } |
1366 | 1438 |
1367 struct matrix build_colorant_matrix(qcms_profile *p) | 1439 struct matrix build_colorant_matrix(qcms_profile *p) |
1368 @@ -390,7 +408,7 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t
LutTable[], int len | 1440 @@ -295,7 +313,7 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t
LutTable[], int len |
| 1441 |
| 1442 NumZeroes = 0; |
| 1443 while (LutTable[NumZeroes] == 0 && NumZeroes < length-1) |
| 1444 - NumZeroes++; |
| 1445 + NumZeroes++; |
| 1446 |
| 1447 // There are no zeros at the beginning and we are trying to find a zero
, so |
| 1448 // return anything. It seems zero would be the less destructive choice |
| 1449 @@ -305,22 +323,22 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16
_t LutTable[], int len |
| 1450 |
| 1451 NumPoles = 0; |
| 1452 while (LutTable[length-1- NumPoles] == 0xFFFF && NumPoles < length-1) |
| 1453 - NumPoles++; |
| 1454 + NumPoles++; |
| 1455 |
| 1456 // Does the curve belong to this case? |
| 1457 if (NumZeroes > 1 || NumPoles > 1) |
| 1458 - { |
| 1459 + { |
| 1460 int a, b; |
| 1461 |
| 1462 - // Identify if value fall downto 0 or FFFF zone |
| 1463 + // Identify if value fall downto 0 or FFFF zone |
| 1464 if (Value == 0) return 0; |
| 1465 // if (Value == 0xFFFF) return 0xFFFF; |
| 1466 |
| 1467 // else restrict to valid zone |
| 1468 |
| 1469 - a = ((NumZeroes-1) * 0xFFFF) / (length-1); |
| 1470 + a = ((NumZeroes-1) * 0xFFFF) / (length-1); |
| 1471 b = ((length-1 - NumPoles) * 0xFFFF) / (length-1); |
| 1472 - |
| 1473 + |
| 1474 l = a - 1; |
| 1475 r = b + 1; |
| 1476 } |
| 1477 @@ -332,12 +350,12 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16
_t LutTable[], int len |
| 1478 |
| 1479 x = (l + r) / 2; |
| 1480 |
| 1481 -» » res = (int) lut_interp_linear16((uint16_fract_t) (x-1), LutTable
, length); |
| 1482 + res = (int) lut_interp_linear16((uint16_fract_t) (x-1), LutTabl
e, length); |
| 1483 |
| 1484 if (res == Value) { |
| 1485 |
| 1486 - // Found exact match. |
| 1487 - |
| 1488 + // Found exact match. |
| 1489 + |
| 1490 return (uint16_fract_t) (x - 1); |
| 1491 } |
| 1492 |
| 1493 @@ -347,14 +365,14 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16
_t LutTable[], int len |
| 1494 |
| 1495 // Not found, should we interpolate? |
| 1496 |
| 1497 - |
| 1498 + |
| 1499 // Get surrounding nodes |
| 1500 - |
| 1501 + |
| 1502 val2 = (length-1) * ((double) (x - 1) / 65535.0); |
| 1503 |
| 1504 cell0 = (int) floor(val2); |
| 1505 cell1 = (int) ceil(val2); |
| 1506 - |
| 1507 + |
| 1508 if (cell0 == cell1) return (uint16_fract_t) x; |
| 1509 |
| 1510 y0 = LutTable[cell0] ; |
| 1511 @@ -373,8 +391,7 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t
LutTable[], int len |
| 1512 if (f < 0.0) return (uint16_fract_t) 0; |
| 1513 if (f >= 65535.0) return (uint16_fract_t) 0xFFFF; |
| 1514 |
| 1515 - return (uint16_fract_t) floor(f + 0.5); |
| 1516 - |
| 1517 + return (uint16_fract_t) floor(f + 0.5); |
| 1518 } |
| 1519 |
| 1520 /* |
| 1521 @@ -390,7 +407,7 @@ uint16_fract_t lut_inverse_interp16(uint16_t Value, uint16_t
LutTable[], int len |
1369 which has an maximum error of about 9855 (pixel difference of ~38.346) | 1522 which has an maximum error of about 9855 (pixel difference of ~38.346) |
1370 | 1523 |
1371 For now, we punt the decision of output size to the caller. */ | 1524 For now, we punt the decision of output size to the caller. */ |
1372 -static uint16_t *invert_lut(uint16_t *table, int length, int out_length) | 1525 -static uint16_t *invert_lut(uint16_t *table, int length, int out_length) |
1373 +static uint16_t *invert_lut(uint16_t *table, int length, size_t out_length) | 1526 +static uint16_t *invert_lut(uint16_t *table, int length, size_t out_length) |
1374 { | 1527 { |
1375 int i; | 1528 int i; |
1376 /* for now we invert the lut by creating a lut of size out_length | 1529 /* for now we invert the lut by creating a lut of size out_length |
1377 diff --git a/third_party/qcms/src/transform_util.h b/third_party/qcms/src/transf
orm_util.h | 1530 diff --git a/third_party/qcms/src/transform_util.h b/third_party/qcms/src/transf
orm_util.h |
1378 index 8f358a8..de465f4 100644 | 1531 index 8f358a8..de465f4 100644 |
1379 --- a/third_party/qcms/src/transform_util.h | 1532 --- a/third_party/qcms/src/transform_util.h |
1380 +++ b/third_party/qcms/src/transform_util.h | 1533 +++ b/third_party/qcms/src/transform_util.h |
1381 @@ -31,9 +31,9 @@ | 1534 @@ -31,9 +31,9 @@ |
1382 //XXX: could use a bettername | 1535 //XXX: could use a bettername |
1383 typedef uint16_t uint16_fract_t; | 1536 typedef uint16_t uint16_fract_t; |
1384 | 1537 |
1385 -float lut_interp_linear(double value, uint16_t *table, int length); | 1538 -float lut_interp_linear(double value, uint16_t *table, int length); |
1386 -float lut_interp_linear_float(float value, float *table, int length); | 1539 -float lut_interp_linear_float(float value, float *table, int length); |
1387 -uint16_t lut_interp_linear16(uint16_t input_value, uint16_t *table, int length)
; | 1540 -uint16_t lut_interp_linear16(uint16_t input_value, uint16_t *table, int length)
; |
1388 +float lut_interp_linear(double value, uint16_t *table, size_t length); | 1541 +float lut_interp_linear(double value, uint16_t *table, size_t length); |
1389 +float lut_interp_linear_float(float value, float *table, size_t length); | 1542 +float lut_interp_linear_float(float value, float *table, size_t length); |
1390 +uint16_t lut_interp_linear16(uint16_t input_value, uint16_t *table, size_t leng
th); | 1543 +uint16_t lut_interp_linear16(uint16_t input_value, uint16_t *table, size_t leng
th); |
1391 | 1544 |
1392 | 1545 |
1393 static inline float lerp(float a, float b, float t) | 1546 static inline float lerp(float a, float b, float t) |
OLD | NEW |