qcmsint.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // qcms
  2. // Copyright (C) 2009 Mozilla Foundation
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the "Software"),
  6. // to deal in the Software without restriction, including without limitation
  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 Software
  9. // is furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  16. // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  18. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. #include "qcms.h"
  22. #include "qcmstypes.h"
  23. /* used as a lookup table for the output transformation.
  24. * we refcount them so we only need to have one around per output
  25. * profile, instead of duplicating them per transform */
  26. struct precache_output
  27. {
  28. int ref_count;
  29. /* We previously used a count of 65536 here but that seems like more
  30. * precision than we actually need. By reducing the size we can
  31. * improve startup performance and reduce memory usage. ColorSync on
  32. * 10.5 uses 4097 which is perhaps because they use a fixed point
  33. * representation where 1. is represented by 0x1000. */
  34. #define PRECACHE_OUTPUT_SIZE 8192
  35. #define PRECACHE_OUTPUT_MAX (PRECACHE_OUTPUT_SIZE-1)
  36. uint8_t data[PRECACHE_OUTPUT_SIZE];
  37. };
  38. #ifdef _MSC_VER
  39. #define ALIGN __declspec(align(16))
  40. #else
  41. #define ALIGN __attribute__(( aligned (16) ))
  42. #endif
  43. struct _qcms_transform {
  44. float ALIGN matrix[3][4];
  45. float *input_gamma_table_r;
  46. float *input_gamma_table_g;
  47. float *input_gamma_table_b;
  48. float *input_gamma_table_gray;
  49. float out_gamma_r;
  50. float out_gamma_g;
  51. float out_gamma_b;
  52. float out_gamma_gray;
  53. uint16_t *output_gamma_lut_r;
  54. uint16_t *output_gamma_lut_g;
  55. uint16_t *output_gamma_lut_b;
  56. uint16_t *output_gamma_lut_gray;
  57. size_t output_gamma_lut_r_length;
  58. size_t output_gamma_lut_g_length;
  59. size_t output_gamma_lut_b_length;
  60. size_t output_gamma_lut_gray_length;
  61. struct precache_output *output_table_r;
  62. struct precache_output *output_table_g;
  63. struct precache_output *output_table_b;
  64. void (*transform_fn)(struct _qcms_transform *transform, unsigned char *src, unsigned char *dest, size_t length);
  65. };
  66. typedef int32_t s15Fixed16Number;
  67. typedef uint16_t uInt16Number;
  68. struct XYZNumber {
  69. s15Fixed16Number X;
  70. s15Fixed16Number Y;
  71. s15Fixed16Number Z;
  72. };
  73. struct curveType {
  74. uint32_t count;
  75. uInt16Number data[];
  76. };
  77. struct lutType {
  78. uint8_t num_input_channels;
  79. uint8_t num_output_channels;
  80. uint8_t num_clut_grid_points;
  81. s15Fixed16Number e00;
  82. s15Fixed16Number e01;
  83. s15Fixed16Number e02;
  84. s15Fixed16Number e10;
  85. s15Fixed16Number e11;
  86. s15Fixed16Number e12;
  87. s15Fixed16Number e20;
  88. s15Fixed16Number e21;
  89. s15Fixed16Number e22;
  90. uint16_t num_input_table_entries;
  91. uint16_t num_output_table_entries;
  92. uint16_t *input_table;
  93. uint16_t *clut_table;
  94. uint16_t *output_table;
  95. };
  96. #if 0
  97. /* this is from an intial idea of having the struct correspond to the data in
  98. * the file. I decided that it wasn't a good idea.
  99. */
  100. struct tag_value {
  101. uint32_t type;
  102. union {
  103. struct {
  104. uint32_t reserved;
  105. struct {
  106. s15Fixed16Number X;
  107. s15Fixed16Number Y;
  108. s15Fixed16Number Z;
  109. } XYZNumber;
  110. } XYZType;
  111. };
  112. }; // I guess we need to pack this?
  113. #endif
  114. #define RGB_SIGNATURE 0x52474220
  115. #define GRAY_SIGNATURE 0x47524159
  116. struct _qcms_profile {
  117. uint32_t class;
  118. uint32_t color_space;
  119. qcms_intent rendering_intent;
  120. struct XYZNumber redColorant;
  121. struct XYZNumber blueColorant;
  122. struct XYZNumber greenColorant;
  123. struct curveType *redTRC;
  124. struct curveType *blueTRC;
  125. struct curveType *greenTRC;
  126. struct curveType *grayTRC;
  127. struct lutType *A2B0;
  128. struct precache_output *output_table_r;
  129. struct precache_output *output_table_g;
  130. struct precache_output *output_table_b;
  131. };
  132. #ifdef _MSC_VER
  133. #define inline _inline
  134. #endif
  135. /* produces the nearest float to 'a' with a maximum error
  136. * of 1/1024 which happens for large values like 0x40000040 */
  137. static inline float s15Fixed16Number_to_float(s15Fixed16Number a)
  138. {
  139. return ((int32_t)a)/65536.f;
  140. }
  141. static inline s15Fixed16Number double_to_s15Fixed16Number(double v)
  142. {
  143. return (int32_t)(v*65536);
  144. }
  145. void precache_release(struct precache_output *p);
  146. qcms_bool set_rgb_colorants(qcms_profile *profile, qcms_CIE_xyY white_point, qcms_CIE_xyYTRIPLE primaries);
  147. void qcms_transform_data_rgb_out_lut_sse2(qcms_transform *transform,
  148. unsigned char *src,
  149. unsigned char *dest,
  150. size_t length);
  151. void qcms_transform_data_rgba_out_lut_sse2(qcms_transform *transform,
  152. unsigned char *src,
  153. unsigned char *dest,
  154. size_t length);
  155. void qcms_transform_data_rgb_out_lut_sse1(qcms_transform *transform,
  156. unsigned char *src,
  157. unsigned char *dest,
  158. size_t length);
  159. void qcms_transform_data_rgba_out_lut_sse1(qcms_transform *transform,
  160. unsigned char *src,
  161. unsigned char *dest,
  162. size_t length);