gsfuncv.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (C) 2000 Aladdin Enterprises. All rights reserved.
  2. This file is part of AFPL Ghostscript.
  3. AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  4. distributor accepts any responsibility for the consequences of using it, or
  5. for whether it serves any particular purpose or works at all, unless he or
  6. she says so in writing. Refer to the Aladdin Free Public License (the
  7. "License") for full details.
  8. Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. in a plain ASCII text file named PUBLIC. The License grants you the right
  10. to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. conditions described in the License. Among other things, the License
  12. requires that the copyright notice and this notice be preserved on all
  13. copies.
  14. */
  15. /*$Id: gsfuncv.c,v 1.2 2000/09/19 19:00:28 lpd Exp $ */
  16. /* "Vanilla" Function support */
  17. #include "gx.h"
  18. #include "gserrors.h"
  19. #include "gsfuncv.h"
  20. #include "gsparam.h"
  21. #include "gxfunc.h"
  22. /* GC descriptor */
  23. private_st_function_Va();
  24. /*
  25. * Test whether a Vanilla function is monotonic. (This information is
  26. * provided at function definition time.)
  27. */
  28. private int
  29. fn_Va_is_monotonic(const gs_function_t * pfn_common,
  30. const float *lower, const float *upper,
  31. gs_function_effort_t effort)
  32. {
  33. const gs_function_Va_t *const pfn =
  34. (const gs_function_Va_t *)pfn_common;
  35. return pfn->params.is_monotonic;
  36. }
  37. /* Free the parameters of a Vanilla function. */
  38. void
  39. gs_function_Va_free_params(gs_function_Va_params_t * params,
  40. gs_memory_t * mem)
  41. {
  42. gs_free_object(mem, params->eval_data, "eval_data");
  43. fn_common_free_params((gs_function_params_t *) params, mem);
  44. }
  45. /* Allocate and initialize a Vanilla function. */
  46. int
  47. gs_function_Va_init(gs_function_t ** ppfn,
  48. const gs_function_Va_params_t * params,
  49. gs_memory_t * mem)
  50. {
  51. static const gs_function_head_t function_Va_head = {
  52. function_type_Vanilla,
  53. {
  54. NULL, /* filled in from params */
  55. (fn_is_monotonic_proc_t) fn_Va_is_monotonic,
  56. gs_function_get_info_default,
  57. fn_common_get_params, /****** WHAT TO DO ABOUT THIS? ******/
  58. (fn_free_params_proc_t) gs_function_Va_free_params,
  59. fn_common_free
  60. }
  61. };
  62. int code;
  63. *ppfn = 0; /* in case of error */
  64. code = fn_check_mnDR((const gs_function_params_t *)params, 1, params->n);
  65. if (code < 0)
  66. return code;
  67. {
  68. gs_function_Va_t *pfn =
  69. gs_alloc_struct(mem, gs_function_Va_t, &st_function_Va,
  70. "gs_function_Va_init");
  71. if (pfn == 0)
  72. return_error(gs_error_VMerror);
  73. pfn->params = *params;
  74. pfn->head = function_Va_head;
  75. pfn->head.procs.evaluate = params->eval_proc;
  76. pfn->head.is_monotonic = params->is_monotonic;
  77. *ppfn = (gs_function_t *) pfn;
  78. }
  79. return 0;
  80. }