home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / UsingPDF / GhostScript / source / gs5.10 / zfunc0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-01  |  3.3 KB  |  104 lines

  1. /* Copyright (C) 1997 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zfunc0.c */
  20. /* PostScript language interface to FunctionType 0 (Sampled) Functions */
  21. #include "memory_.h"
  22. #include "ghost.h"
  23. #include "errors.h"
  24. #include "oper.h"
  25. #include "gsdsrc.h"
  26. #include "gsfunc.h"
  27. #include "gsfunc0.h"
  28. #include "stream.h"        /* for files.h */
  29. #include "files.h"
  30. #include "ialloc.h"
  31. #include "idict.h"
  32. #include "idparam.h"
  33. #include "ifunc.h"
  34.  
  35. /* Initialization */
  36. private build_function_proc(build_function_0);
  37. int
  38. zfunc0_init(gs_memory_t *mem)
  39. {    build_function_procs[0] = build_function_0;
  40.     return 0;
  41. }
  42.  
  43. BEGIN_OP_DEFS(zfunc0_op_defs) {
  44. END_OP_DEFS(zfunc0_init) }
  45.  
  46. /* Finish building a FunctionType 0 (Sampled) function. */
  47. private int
  48. build_function_0(const_os_ptr op, const gs_function_params_t *mnDR, int depth,
  49.   gs_function_t **ppfn)
  50. {    gs_function_Sd_params_t params;
  51.     ref *pDataSource;
  52.     int code;
  53.  
  54.     *(gs_function_params_t *)¶ms = *mnDR;
  55.     params.Encode = 0;
  56.     params.Decode = 0;
  57.     params.Size = 0;
  58.     if ( (code = dict_find_string(op, "DataSource", &pDataSource)) <= 0 )
  59.       return(code < 0 ? code : gs_note_error(e_rangecheck));
  60.     switch ( r_type(pDataSource) ) {
  61.       case t_string:
  62.         data_source_init_string2(¶ms.DataSource,
  63.                      pDataSource->value.const_bytes,
  64.                      r_size(pDataSource));
  65.         break;
  66.       case t_file:
  67.         { stream *s;
  68.  
  69.           check_read_known_file_else(s, pDataSource, return_error,
  70.                      return_error(e_invalidfileaccess));
  71.           if ( !(s->modes & s_mode_seek) )
  72.         return_error(e_ioerror);
  73.           data_source_init_stream(¶ms.DataSource, s);
  74.         }
  75.         break;
  76.       default:
  77.         return_error(e_rangecheck);
  78.     }
  79.     if ( (code = dict_int_param(op, "Order", 1, 3, 1, ¶ms.Order)) < 0 ||
  80.          (code = dict_int_param(op, "BitsPerSample", 1, 32, 0,
  81.                     ¶ms.BitsPerSample)) < 0 ||
  82.          ((code = fn_build_float_array(op, "Encode", false, true, ¶ms.Encode)) != 2 * params.m && (code != 0 || params.Encode != 0)) ||
  83.          ((code = fn_build_float_array(op, "Decode", false, true, ¶ms.Decode)) != 2 * params.n && (code != 0 || params.Decode != 0))
  84.        ) {
  85.       goto fail;
  86.     }
  87.     { int *ptr = (int *)ialloc_byte_array(params.m, sizeof(int), "Size");
  88.  
  89.       if ( ptr == 0 ) {
  90.         code = gs_note_error(e_VMerror);
  91.         goto fail;
  92.       }
  93.       params.Size = ptr;
  94.       code = dict_int_array_param(op, "Size", params.m, ptr);
  95.       if ( code != params.m )
  96.         goto fail;
  97.     }
  98.     code = gs_function_Sd_init(ppfn, ¶ms, imemory);
  99.     if ( code >= 0 )
  100.       return 0;
  101. fail:    gs_function_Sd_free_params(¶ms, imemory);
  102.     return(code < 0 ? code : gs_note_error(e_rangecheck));
  103. }
  104.