gxmatrix.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 1989, 2000 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: gxmatrix.h,v 1.10 2004/08/31 13:49:33 igor Exp $ */
  14. /* Internal matrix routines for Ghostscript library */
  15. #ifndef gxmatrix_INCLUDED
  16. # define gxmatrix_INCLUDED
  17. #include "gsmatrix.h"
  18. /* The following switch is for developmenty purpose only.
  19. PRECISE_CURRENTPOINT 0 must not go to production due to no clamping. */
  20. #define PRECISE_CURRENTPOINT 1 /* Old code compatible with dropped clamping = 0, new code = 1 */
  21. /*
  22. * Define a matrix with a cached fixed-point copy of the translation.
  23. * This is only used by a few routines in gscoord.c; they are responsible
  24. * for ensuring the validity of the cache. Note that the floating point
  25. * tx/ty values may be too large to fit in a fixed values; txy_fixed_valid
  26. * is false if this is the case, and true otherwise.
  27. */
  28. struct gs_matrix_fixed_s {
  29. _matrix_body;
  30. fixed tx_fixed, ty_fixed;
  31. bool txy_fixed_valid;
  32. };
  33. #ifndef gs_matrix_fixed_DEFINED
  34. #define gs_matrix_fixed_DEFINED
  35. typedef struct gs_matrix_fixed_s gs_matrix_fixed;
  36. #endif
  37. /* Make a gs_matrix_fixed from a gs_matrix. */
  38. int gs_matrix_fixed_from_matrix(gs_matrix_fixed *, const gs_matrix *);
  39. /* Coordinate transformations to fixed point. */
  40. int gs_point_transform2fixed(const gs_matrix_fixed *, floatp, floatp,
  41. gs_fixed_point *);
  42. int gs_distance_transform2fixed(const gs_matrix_fixed *, floatp, floatp,
  43. gs_fixed_point *);
  44. #if PRECISE_CURRENTPOINT
  45. int gs_point_transform2fixed_rounding(const gs_matrix_fixed * pmat,
  46. floatp x, floatp y, gs_fixed_point * ppt);
  47. #endif
  48. /*
  49. * Define the fixed-point coefficient structure for avoiding
  50. * floating point in coordinate transformations.
  51. * Currently this is used only by the Type 1 font interpreter.
  52. * The setup is in gscoord.c.
  53. */
  54. typedef struct {
  55. long xx, xy, yx, yy;
  56. int skewed;
  57. int shift; /* see m_fixed */
  58. int max_bits; /* max bits of coefficient */
  59. fixed round; /* ditto */
  60. } fixed_coeff;
  61. /*
  62. * Multiply a fixed point value by a coefficient. The coefficient has two
  63. * parts: a value (long) and a shift factor (int), The result is (fixed *
  64. * coef_value + round_value) >> (shift + _fixed_shift)) where the shift
  65. * factor and the round value are picked from the fixed_coeff structure, and
  66. * the coefficient value (from one of the coeff1 members) is passed
  67. * explicitly. The last parameter specifies the number of bits available to
  68. * prevent overflow for integer arithmetic. (This is a very custom
  69. * routine.) The intermediate value may exceed the size of a long integer.
  70. */
  71. fixed fixed_coeff_mult(fixed, long, const fixed_coeff *, int);
  72. /*
  73. * Multiply a fixed whose integer part usually does not exceed max_bits
  74. * in magnitude by a coefficient from a fixed_coeff.
  75. * We can use a faster algorithm if the fixed is an integer within
  76. * a range that doesn't cause the multiplication to overflow an int.
  77. */
  78. #define m_fixed(v, c, fc, maxb)\
  79. (((v) + (fixed_1 << (maxb - 1))) &\
  80. ((-fixed_1 << maxb) | _fixed_fraction_v) ? /* out of range, or has fraction */\
  81. fixed_coeff_mult((v), (fc).c, &(fc), maxb) : \
  82. arith_rshift(fixed2int_var(v) * (fc).c + (fc).round, (fc).shift))
  83. #endif /* gxmatrix_INCLUDED */