jas_cm.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * Copyright (c) 2002-2003 Michael David Adams.
  3. * All rights reserved.
  4. */
  5. /* __START_OF_JASPER_LICENSE__
  6. *
  7. * JasPer License Version 2.0
  8. *
  9. * Copyright (c) 2001-2006 Michael David Adams
  10. * Copyright (c) 1999-2000 Image Power, Inc.
  11. * Copyright (c) 1999-2000 The University of British Columbia
  12. *
  13. * All rights reserved.
  14. *
  15. * Permission is hereby granted, free of charge, to any person (the
  16. * "User") obtaining a copy of this software and associated documentation
  17. * files (the "Software"), to deal in the Software without restriction,
  18. * including without limitation the rights to use, copy, modify, merge,
  19. * publish, distribute, and/or sell copies of the Software, and to permit
  20. * persons to whom the Software is furnished to do so, subject to the
  21. * following conditions:
  22. *
  23. * 1. The above copyright notices and this permission notice (which
  24. * includes the disclaimer below) shall be included in all copies or
  25. * substantial portions of the Software.
  26. *
  27. * 2. The name of a copyright holder shall not be used to endorse or
  28. * promote products derived from the Software without specific prior
  29. * written permission.
  30. *
  31. * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
  32. * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  33. * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
  34. * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  35. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  36. * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
  37. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
  38. * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
  39. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  40. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  41. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
  42. * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
  43. * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
  44. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
  45. * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
  46. * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
  47. * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
  48. * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
  49. * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
  50. * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
  51. * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
  52. * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
  53. * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
  54. * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
  55. * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
  56. * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
  57. *
  58. * __END_OF_JASPER_LICENSE__
  59. */
  60. /*
  61. * Color Management
  62. *
  63. * $Id: jas_cm.h,v 1.2 2008-05-26 09:41:51 vp153 Exp $
  64. */
  65. #ifndef JAS_CM_H
  66. #define JAS_CM_H
  67. #include <jasper/jas_config.h>
  68. #include <jasper/jas_icc.h>
  69. #ifdef __cplusplus
  70. extern "C" {
  71. #endif
  72. typedef int jas_clrspc_t;
  73. /* transform operations */
  74. #define JAS_CMXFORM_OP_FWD 0
  75. #define JAS_CMXFORM_OP_REV 1
  76. #define JAS_CMXFORM_OP_PROOF 2
  77. #define JAS_CMXFORM_OP_GAMUT 3
  78. /* rendering intents */
  79. #define JAS_CMXFORM_INTENT_PER 0
  80. #define JAS_CMXFORM_INTENT_RELCLR 1
  81. #define JAS_CMXFORM_INTENT_ABSCLR 2
  82. #define JAS_CMXFORM_INTENT_SAT 3
  83. #define JAS_CMXFORM_NUMINTENTS 4
  84. #define JAS_CMXFORM_OPTM_SPEED 0
  85. #define JAS_CMXFORM_OPTM_SIZE 1
  86. #define JAS_CMXFORM_OPTM_ACC 2
  87. #define jas_clrspc_create(fam, mbr) (((fam) << 8) | (mbr))
  88. #define jas_clrspc_fam(clrspc) ((clrspc) >> 8)
  89. #define jas_clrspc_mbr(clrspc) ((clrspc) & 0xff)
  90. #define jas_clrspc_isgeneric(clrspc) (!jas_clrspc_mbr(clrspc))
  91. #define jas_clrspc_isunknown(clrspc) ((clrspc) & JAS_CLRSPC_UNKNOWNMASK)
  92. #define JAS_CLRSPC_UNKNOWNMASK 0x4000
  93. /* color space families */
  94. #define JAS_CLRSPC_FAM_UNKNOWN 0
  95. #define JAS_CLRSPC_FAM_XYZ 1
  96. #define JAS_CLRSPC_FAM_LAB 2
  97. #define JAS_CLRSPC_FAM_GRAY 3
  98. #define JAS_CLRSPC_FAM_RGB 4
  99. #define JAS_CLRSPC_FAM_YCBCR 5
  100. /* specific color spaces */
  101. #define JAS_CLRSPC_UNKNOWN JAS_CLRSPC_UNKNOWNMASK
  102. #define JAS_CLRSPC_CIEXYZ jas_clrspc_create(JAS_CLRSPC_FAM_XYZ, 1)
  103. #define JAS_CLRSPC_CIELAB jas_clrspc_create(JAS_CLRSPC_FAM_LAB, 1)
  104. #define JAS_CLRSPC_SGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 1)
  105. #define JAS_CLRSPC_SRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 1)
  106. #define JAS_CLRSPC_SYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 1)
  107. /* generic color spaces */
  108. #define JAS_CLRSPC_GENRGB jas_clrspc_create(JAS_CLRSPC_FAM_RGB, 0)
  109. #define JAS_CLRSPC_GENGRAY jas_clrspc_create(JAS_CLRSPC_FAM_GRAY, 0)
  110. #define JAS_CLRSPC_GENYCBCR jas_clrspc_create(JAS_CLRSPC_FAM_YCBCR, 0)
  111. #define JAS_CLRSPC_CHANIND_YCBCR_Y 0
  112. #define JAS_CLRSPC_CHANIND_YCBCR_CB 1
  113. #define JAS_CLRSPC_CHANIND_YCBCR_CR 2
  114. #define JAS_CLRSPC_CHANIND_RGB_R 0
  115. #define JAS_CLRSPC_CHANIND_RGB_G 1
  116. #define JAS_CLRSPC_CHANIND_RGB_B 2
  117. #define JAS_CLRSPC_CHANIND_GRAY_Y 0
  118. typedef double jas_cmreal_t;
  119. struct jas_cmpxform_s;
  120. typedef struct {
  121. long *buf;
  122. int prec;
  123. int sgnd;
  124. int width;
  125. int height;
  126. } jas_cmcmptfmt_t;
  127. typedef struct {
  128. int numcmpts;
  129. jas_cmcmptfmt_t *cmptfmts;
  130. } jas_cmpixmap_t;
  131. typedef struct {
  132. void (*destroy)(struct jas_cmpxform_s *pxform);
  133. int (*apply)(struct jas_cmpxform_s *pxform, jas_cmreal_t *in, jas_cmreal_t *out, int cnt);
  134. void (*dump)(struct jas_cmpxform_s *pxform);
  135. } jas_cmpxformops_t;
  136. typedef struct {
  137. jas_cmreal_t *data;
  138. int size;
  139. } jas_cmshapmatlut_t;
  140. typedef struct {
  141. int mono;
  142. int order;
  143. int useluts;
  144. int usemat;
  145. jas_cmshapmatlut_t luts[3];
  146. jas_cmreal_t mat[3][4];
  147. } jas_cmshapmat_t;
  148. typedef struct {
  149. int order;
  150. } jas_cmshaplut_t;
  151. typedef struct {
  152. int inclrspc;
  153. int outclrspc;
  154. } jas_cmclrspcconv_t;
  155. #define jas_align_t double
  156. typedef struct jas_cmpxform_s {
  157. int refcnt;
  158. jas_cmpxformops_t *ops;
  159. int numinchans;
  160. int numoutchans;
  161. union {
  162. jas_align_t dummy;
  163. jas_cmshapmat_t shapmat;
  164. jas_cmshaplut_t shaplut;
  165. jas_cmclrspcconv_t clrspcconv;
  166. } data;
  167. } jas_cmpxform_t;
  168. typedef struct {
  169. int numpxforms;
  170. int maxpxforms;
  171. jas_cmpxform_t **pxforms;
  172. } jas_cmpxformseq_t;
  173. typedef struct {
  174. int numinchans;
  175. int numoutchans;
  176. jas_cmpxformseq_t *pxformseq;
  177. } jas_cmxform_t;
  178. #define JAS_CMPROF_TYPE_DEV 1
  179. #define JAS_CMPROF_TYPE_CLRSPC 2
  180. #define JAS_CMPROF_NUMPXFORMSEQS 13
  181. typedef struct {
  182. int clrspc;
  183. int numchans;
  184. int refclrspc;
  185. int numrefchans;
  186. jas_iccprof_t *iccprof;
  187. jas_cmpxformseq_t *pxformseqs[JAS_CMPROF_NUMPXFORMSEQS];
  188. } jas_cmprof_t;
  189. /* Create a profile. */
  190. /* Destroy a profile. */
  191. void jas_cmprof_destroy(jas_cmprof_t *prof);
  192. #if 0
  193. typedef int_fast32_t jas_cmattrname_t;
  194. typedef int_fast32_t jas_cmattrval_t;
  195. typedef int_fast32_t jas_cmattrtype_t;
  196. /* Load a profile. */
  197. int jas_cmprof_load(jas_cmprof_t *prof, jas_stream_t *in, int fmt);
  198. /* Save a profile. */
  199. int jas_cmprof_save(jas_cmprof_t *prof, jas_stream_t *out, int fmt);
  200. /* Set an attribute of a profile. */
  201. int jas_cm_prof_setattr(jas_cm_prof_t *prof, jas_cm_attrname_t name, void *val);
  202. /* Get an attribute of a profile. */
  203. void *jas_cm_prof_getattr(jas_cm_prof_t *prof, jas_cm_attrname_t name);
  204. #endif
  205. jas_cmxform_t *jas_cmxform_create(jas_cmprof_t *inprof, jas_cmprof_t *outprof,
  206. jas_cmprof_t *proofprof, int op, int intent, int optimize);
  207. void jas_cmxform_destroy(jas_cmxform_t *xform);
  208. /* Apply a transform to data. */
  209. int jas_cmxform_apply(jas_cmxform_t *xform, jas_cmpixmap_t *in,
  210. jas_cmpixmap_t *out);
  211. int jas_cxform_optimize(jas_cmxform_t *xform, int optimize);
  212. int jas_clrspc_numchans(int clrspc);
  213. jas_cmprof_t *jas_cmprof_createfromiccprof(jas_iccprof_t *iccprof);
  214. jas_cmprof_t *jas_cmprof_createfromclrspc(int clrspc);
  215. jas_iccprof_t *jas_iccprof_createfromcmprof(jas_cmprof_t *prof);
  216. #define jas_cmprof_clrspc(prof) ((prof)->clrspc)
  217. jas_cmprof_t *jas_cmprof_copy(jas_cmprof_t *prof);
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. #endif