1
0

zfunc0.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Copyright (C) 1997, 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: zfunc0.c,v 1.3.6.1 2002/01/17 02:59:35 dancoby Exp $ */
  16. /* PostScript language interface to FunctionType 0 (Sampled) Functions */
  17. #include "memory_.h"
  18. #include "ghost.h"
  19. #include "oper.h"
  20. #include "gsdsrc.h"
  21. #include "gsfunc.h"
  22. #include "gsfunc0.h"
  23. #include "stream.h" /* for files.h */
  24. #include "files.h"
  25. #include "ialloc.h"
  26. #include "idict.h"
  27. #include "idparam.h"
  28. #include "ifunc.h"
  29. /* Check prototype */
  30. build_function_proc(gs_build_function_0);
  31. /* Finish building a FunctionType 0 (Sampled) function. */
  32. int
  33. gs_build_function_0(i_ctx_t *i_ctx_p, const ref *op, const gs_function_params_t * mnDR,
  34. int depth, gs_function_t ** ppfn, gs_memory_t *mem)
  35. {
  36. gs_function_Sd_params_t params;
  37. ref *pDataSource;
  38. int code;
  39. *(gs_function_params_t *) & params = *mnDR;
  40. params.Encode = 0;
  41. params.Decode = 0;
  42. params.Size = 0;
  43. if ((code = dict_find_string(op, "DataSource", &pDataSource)) <= 0)
  44. return (code < 0 ? code : gs_note_error(e_rangecheck));
  45. switch (r_type(pDataSource)) {
  46. case t_string:
  47. data_source_init_string2(&params.DataSource,
  48. pDataSource->value.const_bytes,
  49. r_size(pDataSource));
  50. break;
  51. case t_file: {
  52. stream *s;
  53. check_read_known_file_else(s, pDataSource, return_error,
  54. return_error(e_invalidfileaccess));
  55. if (!(s->modes & s_mode_seek))
  56. return_error(e_ioerror);
  57. data_source_init_stream(&params.DataSource, s);
  58. break;
  59. }
  60. default:
  61. return_error(e_rangecheck);
  62. }
  63. if ((code = dict_int_param(op, "Order", 1, 3, 1, &params.Order)) < 0 ||
  64. (code = dict_int_param(op, "BitsPerSample", 1, 32, 0,
  65. &params.BitsPerSample)) < 0 ||
  66. ((code = fn_build_float_array(op, "Encode", false, true, &params.Encode, mem)) != 2 * params.m && (code != 0 || params.Encode != 0)) ||
  67. ((code = fn_build_float_array(op, "Decode", false, true, &params.Decode, mem)) != 2 * params.n && (code != 0 || params.Decode != 0))
  68. ) {
  69. goto fail;
  70. } {
  71. int *ptr = (int *)
  72. gs_alloc_byte_array(mem, params.m, sizeof(int), "Size");
  73. if (ptr == 0) {
  74. code = gs_note_error(e_VMerror);
  75. goto fail;
  76. }
  77. params.Size = ptr;
  78. code = dict_ints_param(op, "Size", params.m, ptr);
  79. if (code != params.m)
  80. goto fail;
  81. }
  82. code = gs_function_Sd_init(ppfn, &params, mem);
  83. if (code >= 0)
  84. return 0;
  85. fail:
  86. gs_function_Sd_free_params(&params, mem);
  87. return (code < 0 ? code : gs_note_error(e_rangecheck));
  88. }