color-imp.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (C) 2004-2021 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. #ifndef FITZ_COLOR_IMP_H
  23. #define FITZ_COLOR_IMP_H
  24. #include "mupdf/fitz.h"
  25. typedef struct fz_color_converter fz_color_converter;
  26. /* Color management engine */
  27. #if FZ_ENABLE_ICC
  28. /*
  29. Create ICC profile from PDF calGray and calRGB definitions
  30. */
  31. fz_buffer *fz_new_icc_data_from_cal(fz_context *ctx, float wp[3], float bp[3], float *gamma, float matrix[9], int n);
  32. /*
  33. Opaque type for a link (transform) generated between ICC
  34. profiles.
  35. */
  36. typedef struct fz_icc_link fz_icc_link;
  37. void fz_new_icc_context(fz_context *ctx);
  38. void fz_drop_icc_context(fz_context *ctx);
  39. fz_icc_profile *fz_new_icc_profile(fz_context *ctx, unsigned char *data, size_t size);
  40. void fz_drop_icc_profile(fz_context *ctx, fz_icc_profile *profile);
  41. void fz_icc_profile_name(fz_context *ctx, fz_icc_profile *profile, char *name, size_t size);
  42. int fz_icc_profile_components(fz_context *ctx, fz_icc_profile *profile);
  43. int fz_icc_profile_is_lab(fz_context *ctx, fz_icc_profile *profile);
  44. fz_icc_link *fz_new_icc_link(fz_context *ctx,
  45. fz_colorspace *src, int src_extras,
  46. fz_colorspace *dst, int dst_extras,
  47. fz_colorspace *prf,
  48. fz_color_params color_params,
  49. int format,
  50. int copy_spots,
  51. int premult);
  52. void fz_drop_icc_link_imp(fz_context *ctx, fz_storable *link);
  53. void fz_drop_icc_link(fz_context *ctx, fz_icc_link *link);
  54. fz_icc_link *fz_find_icc_link(fz_context *ctx,
  55. fz_colorspace *src, int src_extras,
  56. fz_colorspace *dst, int dst_extras,
  57. fz_colorspace *prf,
  58. fz_color_params color_params,
  59. int format,
  60. int copy_spots,
  61. int premult);
  62. void fz_icc_transform_color(fz_context *ctx, fz_color_converter *cc, const float *src, float *dst);
  63. void fz_icc_transform_pixmap(fz_context *ctx, fz_icc_link *link, const fz_pixmap *src, fz_pixmap *dst, int copy_spots);
  64. #endif
  65. typedef void (fz_color_convert_fn)(fz_context *ctx, fz_color_converter *cc, const float *src, float *dst);
  66. struct fz_color_converter
  67. {
  68. fz_color_convert_fn *convert;
  69. fz_color_convert_fn *convert_via;
  70. fz_colorspace *ds;
  71. fz_separations *dseps;
  72. int dst_n;
  73. fz_colorspace *ss;
  74. fz_colorspace *ss_via;
  75. void *opaque;
  76. #if FZ_ENABLE_ICC
  77. fz_icc_link *link;
  78. #endif
  79. };
  80. struct fz_colorspace_context
  81. {
  82. int ctx_refs;
  83. fz_colorspace *gray, *rgb, *bgr, *cmyk, *lab;
  84. #if FZ_ENABLE_ICC
  85. void *icc_instance;
  86. #endif
  87. };
  88. void fz_drop_colorspace_store_key(fz_context *ctx, fz_colorspace *cs);
  89. fz_colorspace *fz_keep_colorspace_store_key(fz_context *ctx, fz_colorspace *cs);
  90. void fz_init_cached_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ss, fz_colorspace *ds, fz_separations *seps, fz_colorspace *is, fz_color_params params);
  91. void fz_fin_cached_color_converter(fz_context *ctx, fz_color_converter *cc);
  92. fz_color_convert_fn *fz_lookup_fast_color_converter(fz_context *ctx, fz_colorspace *ss, fz_colorspace *ds);
  93. void fz_find_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ss, fz_colorspace *ds, fz_separations *seps, fz_colorspace *is, fz_color_params params);
  94. void fz_drop_color_converter(fz_context *ctx, fz_color_converter *cc);
  95. /*
  96. Color convert a pixmap. The passing of default_cs is needed due
  97. to the base cs of the image possibly needing to be treated as
  98. being in one of the page default color spaces.
  99. */
  100. void fz_convert_pixmap_samples(fz_context *ctx, const fz_pixmap *src, fz_pixmap *dst, fz_colorspace *prf, const fz_default_colorspaces *default_cs, fz_color_params color_params, int copy_spots);
  101. void fz_fast_any_to_alpha(fz_context *ctx, const fz_pixmap *src, fz_pixmap *dst, int copy_spots);
  102. void fz_convert_fast_pixmap_samples(fz_context *ctx, const fz_pixmap *src, fz_pixmap *dst, int copy_spots);
  103. void fz_convert_slow_pixmap_samples(fz_context *ctx, const fz_pixmap *src, fz_pixmap *dst, fz_colorspace *prf, fz_color_params params, int copy_spots);
  104. /**
  105. Attempt to init a color converter to work by copying separation values.
  106. */
  107. int
  108. fz_init_separation_copy_color_converter(fz_context *ctx, fz_color_converter *cc, fz_colorspace *ss, fz_colorspace *ds, fz_separations *dseps, fz_colorspace *is, fz_color_params params);
  109. #endif