gdevdcrd.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* Copyright (C) 1999 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gdevdcrd.c,v 1.6 2004/08/04 19:36:12 stefan Exp $ */
  14. /* Create a sample device CRD */
  15. #include "math_.h"
  16. #include "memory_.h"
  17. #include "string_.h"
  18. #include "gx.h"
  19. #include "gserrors.h"
  20. #include "gsparam.h"
  21. #include "gscspace.h" /* for gscie.h */
  22. #include "gscrd.h"
  23. #include "gscrdp.h"
  24. #include "gxdevcli.h"
  25. #include "gdevdcrd.h"
  26. /*
  27. * The parameters in this driver CRD are the default PostScript values,
  28. * except for the optional 'dented' procedures.
  29. */
  30. #define DENT(v, f)\
  31. (v <= 0.5 ? v * f : (v - 0.5) * (1 - (0.5 * f)) / 0.5 + 0.5 * f)
  32. private const gs_vector3 bit_WhitePoint = {(float)0.9505, 1, (float)1.0890};
  33. private const gs_range3 bit_RangePQR = {
  34. {{0, (float)0.9505}, {0, 1}, {0, (float)1.0890}}
  35. };
  36. private const float dent_PQR = 1.0;
  37. private int
  38. bit_TransformPQR_proc(int index, floatp in, const gs_cie_wbsd * pwbsd,
  39. gs_cie_render * pcrd, float *out)
  40. {
  41. *out = DENT(in, dent_PQR);
  42. return 0;
  43. }
  44. private const gs_cie_transform_proc3 bit_TransformPQR = {
  45. bit_TransformPQR_proc, "bitTPQRDefault", {0, 0}, 0
  46. };
  47. private const float dent_LMN = 1.0;
  48. private float
  49. bit_EncodeLMN_proc(floatp in, const gs_cie_render * pcrd)
  50. {
  51. return DENT(in, dent_LMN);
  52. }
  53. private const gs_cie_render_proc3 bit_EncodeLMN = { /* dummy */
  54. {bit_EncodeLMN_proc, bit_EncodeLMN_proc, bit_EncodeLMN_proc}
  55. };
  56. private const gs_range3 bit_RangeLMN = {
  57. {{0, (float)0.9505}, {0, 1}, {0, (float)1.0890}}
  58. };
  59. private const gs_matrix3 bit_MatrixABC = {
  60. {(float) 3.24063, (float)-0.96893, (float) 0.05571},
  61. {(float)-1.53721, (float) 1.87576, (float)-0.20402},
  62. {(float)-0.49863, (float) 0.04152, (float) 1.05700}
  63. };
  64. private float
  65. bit_EncodeABC_proc(floatp in, const gs_cie_render * pcrd)
  66. {
  67. return pow(max(in, 0.0), 0.45);
  68. }
  69. private const gs_cie_render_proc3 bit_EncodeABC = {
  70. {bit_EncodeABC_proc, bit_EncodeABC_proc, bit_EncodeABC_proc}
  71. };
  72. /* These RenderTables are no-ops. */
  73. private const byte bit_rtt0[2*2*3] = {
  74. /*0,0,0*/ 0,0,0,
  75. /*0,0,1*/ 0,0,255,
  76. /*0,1,0*/ 0,255,0,
  77. /*0,1,1*/ 0,255,255
  78. };
  79. private const byte bit_rtt1[2*2*3] = {
  80. /*1,0,0*/ 255,0,0,
  81. /*1,0,1*/ 255,0,255,
  82. /*1,1,0*/ 255,255,0,
  83. /*1,1,1*/ 255,255,255
  84. };
  85. private const gs_const_string bit_rt_data[2] = {
  86. {bit_rtt0, 2*2*3}, {bit_rtt1, 2*2*3}
  87. };
  88. private frac
  89. bit_rt_proc(byte in, const gs_cie_render *pcrd)
  90. {
  91. return frac_1 * in / 255;
  92. }
  93. private const gs_cie_render_table_t bit_RenderTable = { /* dummy */
  94. {3, {2, 2, 2}, 3, bit_rt_data},
  95. {{bit_rt_proc, bit_rt_proc, bit_rt_proc}}
  96. };
  97. /*
  98. * Implement get_params for a sample device CRD. A useful convention,
  99. * for devices that can provide more than one CRD, is to have a settable
  100. * parameter CRDName, which gives the name of the CRD in use. This sample
  101. * code provides a constant CRDName: making it settable is left as an
  102. * exercise to the reader.
  103. */
  104. int
  105. sample_device_crd_get_params(gx_device *pdev, gs_param_list *plist,
  106. const char *crd_param_name)
  107. {
  108. int ecode = 0;
  109. if (param_requested(plist, "CRDName") > 0) {
  110. gs_param_string cns;
  111. int code;
  112. cns.data = (const byte *)crd_param_name;
  113. cns.size = strlen(crd_param_name);
  114. cns.persistent = true;
  115. code = param_write_string(plist, "CRDName", &cns);
  116. if (code < 0)
  117. ecode = code;
  118. }
  119. if (param_requested(plist, crd_param_name) > 0) {
  120. gs_cie_render *pcrd;
  121. int code = gs_cie_render1_build(&pcrd, pdev->memory,
  122. "sample_device_crd_get_params");
  123. if (code >= 0) {
  124. gs_cie_transform_proc3 tpqr;
  125. tpqr = bit_TransformPQR;
  126. tpqr.driver_name = pdev->dname;
  127. code = gs_cie_render1_initialize(pdev->memory, pcrd, NULL,
  128. &bit_WhitePoint, NULL /*BlackPoint*/,
  129. NULL /*MatrixPQR*/, &bit_RangePQR, &tpqr,
  130. NULL /*MatrixLMN*/, &bit_EncodeLMN, &bit_RangeLMN,
  131. &bit_MatrixABC, &bit_EncodeABC, NULL /*RangeABC*/,
  132. &bit_RenderTable);
  133. if (code >= 0) {
  134. code = param_write_cie_render1(plist, crd_param_name, pcrd,
  135. pdev->memory);
  136. }
  137. rc_decrement(pcrd, "sample_device_crd_get_params"); /* release */
  138. }
  139. if (code < 0)
  140. ecode = code;
  141. }
  142. if (param_requested(plist, bit_TransformPQR.proc_name) > 0) {
  143. /*
  144. * We definitely do not recommend the following use of a static
  145. * to hold the address: this is a shortcut.
  146. */
  147. gs_cie_transform_proc my_proc = bit_TransformPQR_proc;
  148. byte *my_addr = gs_alloc_string(pdev->memory, sizeof(my_proc),
  149. "sd_crd_get_params(proc)");
  150. int code;
  151. if (my_addr == 0)
  152. code = gs_note_error(gs_error_VMerror);
  153. else {
  154. gs_param_string as;
  155. memcpy(my_addr, &my_proc, sizeof(my_proc));
  156. as.data = my_addr;
  157. as.size = sizeof(my_proc);
  158. as.persistent = true;
  159. code = param_write_string(plist, bit_TransformPQR.proc_name, &as);
  160. }
  161. if (code < 0)
  162. ecode = code;
  163. }
  164. return ecode;
  165. }