interpolate.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Various interpolators.
  2. *
  3. * J.Cupitt, 15/10/08
  4. */
  5. /*
  6. This file is part of VIPS.
  7. VIPS is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU Lesser General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. 02110-1301 USA
  19. */
  20. /*
  21. These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
  22. */
  23. #ifndef VIPS_INTERPOLATE_H
  24. #define VIPS_INTERPOLATE_H
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif /*__cplusplus*/
  28. #define VIPS_TYPE_INTERPOLATE (vips_interpolate_get_type())
  29. #define VIPS_INTERPOLATE( obj ) \
  30. (G_TYPE_CHECK_INSTANCE_CAST( (obj), \
  31. VIPS_TYPE_INTERPOLATE, VipsInterpolate ))
  32. #define VIPS_INTERPOLATE_CLASS( klass ) \
  33. (G_TYPE_CHECK_CLASS_CAST( (klass), \
  34. VIPS_TYPE_INTERPOLATE, VipsInterpolateClass))
  35. #define VIPS_IS_INTERPOLATE( obj ) \
  36. (G_TYPE_CHECK_INSTANCE_TYPE( (obj), VIPS_TYPE_INTERPOLATE ))
  37. #define VIPS_IS_INTERPOLATE_CLASS( klass ) \
  38. (G_TYPE_CHECK_CLASS_TYPE( (klass), VIPS_TYPE_INTERPOLATE ))
  39. #define VIPS_INTERPOLATE_GET_CLASS( obj ) \
  40. (G_TYPE_INSTANCE_GET_CLASS( (obj), \
  41. VIPS_TYPE_INTERPOLATE, VipsInterpolateClass ))
  42. typedef struct _VipsInterpolate {
  43. VipsObject parent_object;
  44. } VipsInterpolate;
  45. /* An interpolation function. This is a class method, but we have a lookup
  46. * function for it to speed up dispatch. Write to the memory at "out",
  47. * interpolate the value at position (x, y) in "in".
  48. */
  49. typedef void (*VipsInterpolateMethod)( VipsInterpolate *interpolate,
  50. void *out, VipsRegion *in, double x, double y );
  51. typedef struct _VipsInterpolateClass {
  52. VipsObjectClass parent_class;
  53. /* Write to pixel out(x,y), interpolating from in(x,y). The caller has
  54. * to set the regions up.
  55. */
  56. VipsInterpolateMethod interpolate;
  57. /* This interpolator needs a window this many pixels across and down.
  58. */
  59. int (*get_window_size)( VipsInterpolate *interpolate );
  60. /* Or just set this if you want a constant.
  61. */
  62. int window_size;
  63. /* Stencils are offset by this much. Default to window_size / 2 - 1
  64. * (centering) if get_window_offset is NULL and window_offset is -1.
  65. */
  66. int (*get_window_offset)( VipsInterpolate *interpolate );
  67. int window_offset;
  68. } VipsInterpolateClass;
  69. /* Don't put spaces around void here, it breaks gtk-doc.
  70. */
  71. GType vips_interpolate_get_type(void);
  72. void vips_interpolate( VipsInterpolate *interpolate,
  73. void *out, VipsRegion *in, double x, double y );
  74. VipsInterpolateMethod vips_interpolate_get_method( VipsInterpolate *interpolate );
  75. int vips_interpolate_get_window_size( VipsInterpolate *interpolate );
  76. int vips_interpolate_get_window_offset( VipsInterpolate *interpolate );
  77. /* How many bits of precision we keep for transformations, ie. how many
  78. * pre-computed matricies we have.
  79. */
  80. #define VIPS_TRANSFORM_SHIFT (6)
  81. #define VIPS_TRANSFORM_SCALE (1 << VIPS_TRANSFORM_SHIFT)
  82. /* How many bits of precision we keep for interpolation, ie. where the decimal
  83. * is in the fixed-point tables. For 16-bit pixels, we need 16 bits for the
  84. * data and 4 bits to add 16 values together. That leaves 12 bits for the
  85. * fractional part.
  86. */
  87. #define VIPS_INTERPOLATE_SHIFT (12)
  88. #define VIPS_INTERPOLATE_SCALE (1 << VIPS_INTERPOLATE_SHIFT)
  89. /* Convenience: return static interpolators, no need to unref.
  90. */
  91. VipsInterpolate *vips_interpolate_nearest_static( void );
  92. VipsInterpolate *vips_interpolate_bilinear_static( void );
  93. /* Convenience: make an interpolator from a nickname. g_object_unref() when
  94. * you're done with it.
  95. */
  96. VipsInterpolate *vips_interpolate_new( const char *nickname );
  97. #ifdef __cplusplus
  98. }
  99. #endif /*__cplusplus*/
  100. #endif /*VIPS_INTERPOLATE_H*/