/src/FreeImage/Source/FreeImageToolkit/Resize.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 145 lines · 41 code · 21 blank · 83 comment · 0 complexity · 3bc6741e9c037256f197b82d8cc7f057 MD5 · raw file

  1. // ==========================================================
  2. // Upsampling / downsampling classes
  3. //
  4. // Design and implementation by
  5. // - Hervé Drolon (drolon@infonie.fr)
  6. // - Detlev Vendt (detlev.vendt@brillit.de)
  7. //
  8. // This file is part of FreeImage 3
  9. //
  10. // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  11. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  12. // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  13. // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  14. // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  15. // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  16. // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  17. // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  18. // THIS DISCLAIMER.
  19. //
  20. // Use at your own risk!
  21. // ==========================================================
  22. #ifndef _RESIZE_H_
  23. #define _RESIZE_H_
  24. #include "FreeImage.h"
  25. #include "Utilities.h"
  26. #include "Filters.h"
  27. /**
  28. Filter weights table.<br>
  29. This class stores contribution information for an entire line (row or column).
  30. */
  31. class CWeightsTable
  32. {
  33. /**
  34. Sampled filter weight table.<br>
  35. Contribution information for a single pixel
  36. */
  37. typedef struct {
  38. /// Normalized weights of neighboring pixels
  39. double *Weights;
  40. /// Bounds of source pixels window
  41. unsigned Left, Right;
  42. } Contribution;
  43. private:
  44. /// Row (or column) of contribution weights
  45. Contribution *m_WeightTable;
  46. /// Filter window size (of affecting source pixels)
  47. unsigned m_WindowSize;
  48. /// Length of line (no. of rows / cols)
  49. unsigned m_LineLength;
  50. public:
  51. /**
  52. Constructor<br>
  53. Allocate and compute the weights table
  54. @param pFilter Filter used for upsampling or downsampling
  55. @param uDstSize Length (in pixels) of the destination line buffer
  56. @param uSrcSize Length (in pixels) of the source line buffer
  57. */
  58. CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize);
  59. /**
  60. Destructor<br>
  61. Destroy the weights table
  62. */
  63. ~CWeightsTable();
  64. /** Retrieve a filter weight, given source and destination positions
  65. @param dst_pos Pixel position in destination line buffer
  66. @param src_pos Pixel position in source line buffer
  67. @return Returns the filter weight
  68. */
  69. double getWeight(unsigned dst_pos, unsigned src_pos) {
  70. return m_WeightTable[dst_pos].Weights[src_pos];
  71. }
  72. /** Retrieve left boundary of source line buffer
  73. @param dst_pos Pixel position in destination line buffer
  74. @return Returns the left boundary of source line buffer
  75. */
  76. unsigned getLeftBoundary(unsigned dst_pos) {
  77. return m_WeightTable[dst_pos].Left;
  78. }
  79. /** Retrieve right boundary of source line buffer
  80. @param dst_pos Pixel position in destination line buffer
  81. @return Returns the right boundary of source line buffer
  82. */
  83. unsigned getRightBoundary(unsigned dst_pos) {
  84. return m_WeightTable[dst_pos].Right;
  85. }
  86. };
  87. // ---------------------------------------------
  88. /**
  89. CResizeEngine<br>
  90. This class performs filtered zoom. It scales an image to the desired dimensions with
  91. any of the CGenericFilter derived filter class.<br>
  92. It works with 8-, 24- and 32-bit buffers.<br><br>
  93. <b>References</b> : <br>
  94. [1] Paul Heckbert, C code to zoom raster images up or down, with nice filtering.
  95. UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html
  96. [2] Eran Yariv, Two Pass Scaling using Filters. The Code Project, December 1999.
  97. [online] http://www.codeproject.com/bitmap/2_pass_scaling.asp
  98. */
  99. class CResizeEngine
  100. {
  101. private:
  102. /// Pointer to the FIR / IIR filter
  103. CGenericFilter* m_pFilter;
  104. public:
  105. /// Constructor
  106. CResizeEngine(CGenericFilter* filter):m_pFilter(filter) {}
  107. /// Destructor
  108. virtual ~CResizeEngine() {}
  109. /** Scale an image to the desired dimensions
  110. @param src Pointer to the source image
  111. @param dst_width Destination image width
  112. @param dst_height Destination image height
  113. @return Returns the scaled image if successful, returns NULL otherwise
  114. */
  115. FIBITMAP* scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height);
  116. private:
  117. /// Performs horizontal image filtering
  118. void horizontalFilter(FIBITMAP *src, unsigned src_width, unsigned src_height, FIBITMAP *dst, unsigned dst_width, unsigned dst_height);
  119. /// Performs vertical image filtering
  120. void verticalFilter(FIBITMAP *src, unsigned src_width, unsigned src_height, FIBITMAP *dst, unsigned dst_width, unsigned dst_height);
  121. };
  122. #endif // _RESIZE_H_