scfparam.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 1998 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: scfparam.c,v 1.2 2000/09/19 19:00:49 lpd Exp $ */
  16. /* CCITTFax filter parameter setting and reading */
  17. #include "std.h"
  18. #include "gserror.h"
  19. #include "gserrors.h"
  20. #include "gstypes.h"
  21. #include "gsmemory.h"
  22. #include "gsparam.h"
  23. #include "scommon.h"
  24. #include "scf.h" /* for cfe_max_width */
  25. #include "scfx.h"
  26. /* Define the CCITTFax parameters. */
  27. private const gs_param_item_t s_CF_param_items[] =
  28. {
  29. #define cfp(key, type, memb) { key, type, offset_of(stream_CF_state, memb) }
  30. cfp("Uncompressed", gs_param_type_bool, Uncompressed),
  31. cfp("K", gs_param_type_int, K),
  32. cfp("EndOfLine", gs_param_type_bool, EndOfLine),
  33. cfp("EncodedByteAlign", gs_param_type_bool, EncodedByteAlign),
  34. cfp("Columns", gs_param_type_int, Columns),
  35. cfp("Rows", gs_param_type_int, Rows),
  36. cfp("EndOfBlock", gs_param_type_bool, EndOfBlock),
  37. cfp("BlackIs1", gs_param_type_bool, BlackIs1),
  38. cfp("DamagedRowsBeforeError", gs_param_type_int, DamagedRowsBeforeError),
  39. cfp("FirstBitLowOrder", gs_param_type_bool, FirstBitLowOrder),
  40. cfp("DecodedByteAlign", gs_param_type_int, DecodedByteAlign),
  41. #undef cfp
  42. gs_param_item_end
  43. };
  44. /* Define a limit on the Rows parameter, close to max_int. */
  45. #define cf_max_height 32000
  46. /* Get non-default CCITTFax filter parameters. */
  47. stream_state_proc_get_params(s_CF_get_params, stream_CF_state); /* check */
  48. int
  49. s_CF_get_params(gs_param_list * plist, const stream_CF_state * ss, bool all)
  50. {
  51. stream_CF_state cfs_defaults;
  52. const stream_CF_state *defaults;
  53. if (all)
  54. defaults = 0;
  55. else {
  56. s_CF_set_defaults_inline(&cfs_defaults);
  57. defaults = &cfs_defaults;
  58. }
  59. return gs_param_write_items(plist, ss, defaults, s_CF_param_items);
  60. }
  61. /* Put CCITTFax filter parameters. */
  62. stream_state_proc_put_params(s_CF_put_params, stream_CF_state); /* check */
  63. int
  64. s_CF_put_params(gs_param_list * plist, stream_CF_state * ss)
  65. {
  66. stream_CF_state state;
  67. int code;
  68. state = *ss;
  69. code = gs_param_read_items(plist, (void *)&state, s_CF_param_items);
  70. if (code >= 0 &&
  71. (state.K < -cf_max_height || state.K > cf_max_height ||
  72. state.Columns < 0 || state.Columns > cfe_max_width ||
  73. state.Rows < 0 || state.Rows > cf_max_height ||
  74. state.DamagedRowsBeforeError < 0 ||
  75. state.DamagedRowsBeforeError > cf_max_height ||
  76. state.DecodedByteAlign < 1 || state.DecodedByteAlign > 16 ||
  77. (state.DecodedByteAlign & (state.DecodedByteAlign - 1)) != 0)
  78. )
  79. code = gs_note_error(gs_error_rangecheck);
  80. if (code >= 0)
  81. *ss = state;
  82. return code;
  83. }