OLD | NEW |
1 // qcms | 1 // qcms |
2 // Copyright (C) 2009 Mozilla Foundation | 2 // Copyright (C) 2009 Mozilla Foundation |
3 // | 3 // |
4 // Permission is hereby granted, free of charge, to any person obtaining | 4 // Permission is hereby granted, free of charge, to any person obtaining |
5 // a copy of this software and associated documentation files (the "Software"), | 5 // a copy of this software and associated documentation files (the "Software"), |
6 // to deal in the Software without restriction, including without limitation | 6 // to deal in the Software without restriction, including without limitation |
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, | 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e | 8 // and/or sell copies of the Software, and to permit persons to whom the Softwar
e |
9 // is furnished to do so, subject to the following conditions: | 9 // is furnished to do so, subject to the following conditions: |
10 // | 10 // |
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 return output; | 593 return output; |
594 } | 594 } |
595 | 595 |
596 void build_output_lut(struct curveType *trc, | 596 void build_output_lut(struct curveType *trc, |
597 uint16_t **output_gamma_lut, size_t *output_gamma_lut_length) | 597 uint16_t **output_gamma_lut, size_t *output_gamma_lut_length) |
598 { | 598 { |
599 if (trc->type == PARAMETRIC_CURVE_TYPE) { | 599 if (trc->type == PARAMETRIC_CURVE_TYPE) { |
600 float gamma_table[256]; | 600 float gamma_table[256]; |
601 uint16_t i; | 601 uint16_t i; |
602 uint16_t *output = malloc(sizeof(uint16_t)*256); | 602 uint16_t *output = malloc(sizeof(uint16_t)*256); |
| 603 uint16_t *inverted; |
| 604 int inverted_size = 256; |
603 | 605 |
604 if (!output) { | 606 if (!output) { |
605 *output_gamma_lut = NULL; | 607 *output_gamma_lut = NULL; |
606 return; | 608 return; |
607 } | 609 } |
608 | 610 |
609 compute_curve_gamma_table_type_parametric(gamma_table, trc->para
meter, trc->count); | 611 compute_curve_gamma_table_type_parametric(gamma_table, trc->para
meter, trc->count); |
610 *output_gamma_lut_length = 256; | 612 |
611 for(i = 0; i < 256; i++) { | 613 for(i = 0; i < 256; i++) { |
612 output[i] = (uint16_t)(gamma_table[i] * 65535); | 614 output[i] = (uint16_t)(gamma_table[i] * 65535); |
613 } | 615 } |
614 *output_gamma_lut = output; | 616 |
| 617 //XXX: the choice of a minimum of 256 here is not backed by any
theory, |
| 618 // measurement or data, however it is what lcms uses. |
| 619 // the maximum number we would need is 65535 because that's
the |
| 620 // accuracy used for computing the pre cache table |
| 621 if (inverted_size < 256) |
| 622 inverted_size = 256; |
| 623 |
| 624 inverted = invert_lut(output, 256, inverted_size); |
| 625 if (!inverted) |
| 626 return; |
| 627 *output_gamma_lut = inverted; |
| 628 *output_gamma_lut_length = inverted_size; |
| 629 free(output); |
615 } else { | 630 } else { |
616 if (trc->count == 0) { | 631 if (trc->count == 0) { |
617 *output_gamma_lut = build_linear_table(4096); | 632 *output_gamma_lut = build_linear_table(4096); |
618 *output_gamma_lut_length = 4096; | 633 *output_gamma_lut_length = 4096; |
619 } else if (trc->count == 1) { | 634 } else if (trc->count == 1) { |
620 float gamma = 1./u8Fixed8Number_to_float(trc->data[0]); | 635 float gamma = 1./u8Fixed8Number_to_float(trc->data[0]); |
621 *output_gamma_lut = build_pow_table(gamma, 4096); | 636 *output_gamma_lut = build_pow_table(gamma, 4096); |
622 *output_gamma_lut_length = 4096; | 637 *output_gamma_lut_length = 4096; |
623 } else { | 638 } else { |
624 //XXX: the choice of a minimum of 256 here is not backed
by any theory, | 639 //XXX: the choice of a minimum of 256 here is not backed
by any theory, |
625 // measurement or data, however it is what lcms uses
. | 640 // measurement or data, however it is what lcms uses
. |
626 *output_gamma_lut_length = trc->count; | 641 *output_gamma_lut_length = trc->count; |
627 if (*output_gamma_lut_length < 256) | 642 if (*output_gamma_lut_length < 256) |
628 *output_gamma_lut_length = 256; | 643 *output_gamma_lut_length = 256; |
629 | 644 |
630 *output_gamma_lut = invert_lut(trc->data, trc->count, *o
utput_gamma_lut_length); | 645 *output_gamma_lut = invert_lut(trc->data, trc->count, *o
utput_gamma_lut_length); |
631 } | 646 } |
632 } | 647 } |
633 | 648 |
634 } | 649 } |
OLD | NEW |