PageRenderTime 17ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 23#ifndef _RESIZE_H_
 24#define _RESIZE_H_
 25
 26#include "FreeImage.h"
 27#include "Utilities.h"
 28#include "Filters.h" 
 29
 30/**
 31  Filter weights table.<br>
 32  This class stores contribution information for an entire line (row or column).
 33*/
 34class CWeightsTable
 35{
 36/** 
 37  Sampled filter weight table.<br>
 38  Contribution information for a single pixel
 39*/
 40typedef struct {
 41	/// Normalized weights of neighboring pixels
 42	double *Weights;
 43	/// Bounds of source pixels window
 44	unsigned Left, Right;   
 45} Contribution;  
 46
 47private:
 48	/// Row (or column) of contribution weights 
 49	Contribution *m_WeightTable;
 50	/// Filter window size (of affecting source pixels) 
 51	unsigned m_WindowSize;
 52	/// Length of line (no. of rows / cols) 
 53	unsigned m_LineLength;
 54
 55public:
 56	/** 
 57	Constructor<br>
 58	Allocate and compute the weights table
 59	@param pFilter Filter used for upsampling or downsampling
 60	@param uDstSize Length (in pixels) of the destination line buffer
 61	@param uSrcSize Length (in pixels) of the source line buffer
 62	*/
 63	CWeightsTable(CGenericFilter *pFilter, unsigned uDstSize, unsigned uSrcSize);
 64
 65	/**
 66	Destructor<br>
 67	Destroy the weights table
 68	*/
 69	~CWeightsTable();
 70
 71	/** Retrieve a filter weight, given source and destination positions
 72	@param dst_pos Pixel position in destination line buffer
 73	@param src_pos Pixel position in source line buffer
 74	@return Returns the filter weight
 75	*/
 76	double getWeight(unsigned dst_pos, unsigned src_pos) {
 77		return m_WeightTable[dst_pos].Weights[src_pos];
 78	}
 79
 80	/** Retrieve left boundary of source line buffer
 81	@param dst_pos Pixel position in destination line buffer
 82	@return Returns the left boundary of source line buffer
 83	*/
 84	unsigned getLeftBoundary(unsigned dst_pos) {
 85		return m_WeightTable[dst_pos].Left;
 86	}
 87
 88	/** Retrieve right boundary of source line buffer
 89	@param dst_pos Pixel position in destination line buffer
 90	@return Returns the right boundary of source line buffer
 91	*/
 92	unsigned getRightBoundary(unsigned dst_pos) {
 93		return m_WeightTable[dst_pos].Right;
 94	}
 95};
 96
 97// ---------------------------------------------
 98
 99/**
100 CResizeEngine<br>
101 This class performs filtered zoom. It scales an image to the desired dimensions with 
102 any of the CGenericFilter derived filter class.<br>
103 It works with 8-, 24- and 32-bit buffers.<br><br>
104
105 <b>References</b> : <br>
106 [1] Paul Heckbert, C code to zoom raster images up or down, with nice filtering. 
107 UC Berkeley, August 1989. [online] http://www-2.cs.cmu.edu/afs/cs.cmu.edu/Web/People/ph/heckbert.html
108 [2] Eran Yariv, Two Pass Scaling using Filters. The Code Project, December 1999. 
109 [online] http://www.codeproject.com/bitmap/2_pass_scaling.asp
110
111*/
112class CResizeEngine
113{
114private:
115	/// Pointer to the FIR / IIR filter
116	CGenericFilter* m_pFilter;
117
118public:
119
120    /// Constructor
121	CResizeEngine(CGenericFilter* filter):m_pFilter(filter) {}
122
123    /// Destructor
124	virtual ~CResizeEngine() {}
125
126    /** Scale an image to the desired dimensions
127	@param src Pointer to the source image
128	@param dst_width Destination image width
129	@param dst_height Destination image height
130	@return Returns the scaled image if successful, returns NULL otherwise
131	*/
132	FIBITMAP* scale(FIBITMAP *src, unsigned dst_width, unsigned dst_height);
133
134private:
135
136    /// Performs horizontal image filtering
137	void horizontalFilter(FIBITMAP *src, unsigned src_width, unsigned src_height, FIBITMAP *dst, unsigned dst_width, unsigned dst_height);
138
139    /// Performs vertical image filtering
140    void verticalFilter(FIBITMAP *src, unsigned src_width, unsigned src_height, FIBITMAP *dst, unsigned dst_width, unsigned dst_height);
141};
142
143
144
145#endif //   _RESIZE_H_