File: LynkeosFourierBuffer.h

package info (click to toggle)
lynkeos.app 3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,740 kB
  • sloc: objc: 40,528; ansic: 811; cpp: 150; sh: 68; makefile: 27
file content (171 lines) | stat: -rw-r--r-- 5,893 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*=============================================================================
** Lynkeos
** $Id$
**-----------------------------------------------------------------------------
**
**  Created by Jean-Etienne LAMIAUD on Aug 5, 2003.
**  Copyright (c) 2003-2023. Jean-Etienne LAMIAUD
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
**
**-----------------------------------------------------------------------------
*/

/*!
 * @header
 * @abstract Definitions related to the Fourier transform
 */
#ifndef __LYNKEOSFOURIERBUFFER_H
#define __LYNKEOSFOURIERBUFFER_H

#include <LynkeosCore/LynkeosImageBuffer.h>

/**
 * \ifnot LynkeosCore
 * \page libraries Libraries needed to compile Lynkeos
 * The Fourier transformations needs FFTW3 library which can be found at 
 * http://www.fftw.org
 * \endif
 */

/*-----------------------------------------------------------------------------
** MACROS
**-----------------------------------------------------------------------------
*/

#define FOR_DIRECT  1      //!< Prepare a buffer for direct transform
#define FOR_INVERSE 2      //!< Prepare a buffer for inverse transform

/*!
 * @abstract Internal method pointer to arithmetically process one line
 */
typedef void(*SpectrumProcessOneLine_t)(LynkeosFourierBuffer *a,
                                        ArithmeticOperand_t *op,
                                        LynkeosFourierBuffer *res,
                                        u_short y );

/*!
 * @abstract Class used to wrap the Fourier transform with FFTW library.
 * @ingroup Processing
 */
@interface LynkeosFourierBuffer : LynkeosImageBuffer
{
@public
   //! The spectrum has only half the image width (complex pixels)
   u_short     _halfw;
   u_short     _spadw;     //!< Spectrum padded width
@private
   u_char      _goal;      //!< The kind of transform that will be performed
   void       *_direct;    //!< FFTW plan for direct transform, if any
   void       *_inverse;   //!< FFTW plan for inverse transform, if any
   BOOL        _isSpectrum; //!< Current state : spatial or frequency
}

/*!
 * @abstract Allocates a new empty buffer
 * @param nPlanes Number of color planes for this image
 * @param w Image pixels width
 * @param h Image pixels height
 * @param goal What kind of transform to prepare, direct, inverse or both.
 * @result The allocated and initialized buffer, ready for FFT.
 */
- (id) initWithNumberOfPlanes:(u_char)nPlanes 
                        width:(u_short)w height:(u_short)h 
                     withGoal:(u_char)goal ;

/*!
 * @abstract Allocates a new empty buffer
 * @param nPlanes Number of color planes for this image
 * @param w Image pixels width
 * @param h Image pixels height
 * @param goal What kind of transform to prepare, direct, inverse or both.
 * @param isSpectrum Whether the initial data is a spectrum
 * @result The allocated and initialized buffer, ready for FFT.
 */
- (id) initWithNumberOfPlanes:(u_char)nPlanes 
                        width:(u_short)w height:(u_short)h 
                     withGoal:(u_char)goal
                   isSpectrum:(BOOL)isSpectrum;

/*!
 * @abstract Tells whether the instance is a spectrum or an image
 * @result YES if the instance is a spectrum
 */
- (BOOL) isSpectrum ;

/*!
 * @abstract Compute the direct transform
 * @result none
 */
- (void) directTransform ;

/*!
 * @abstract Compute the inverse transform, normalize the result and returns
 *   the values extremes
 */
- (void) inverseTransform ;

/*!
 * @abstract Transform the spectrum pixels into their conjugate
 */
- (void) conjugate ;

/*!
 * @abstract Multiplication with conjugate
 * @discussion term shall either have the same number of planes as the receiver
 *    or only one plane. In the latter case, the plane is applied to each planes
 *    of the receiver.
 * @param term other term (shall be a spectrum)
 * @param result where the result is stored, can be one of the terms
 */
- (void) multiplyWithConjugateOf:(LynkeosFourierBuffer*)term
                          result:(LynkeosFourierBuffer*)result ;

/*!
 * @abstract Access to the complex value of a pixel in the spectrum
 * @discussion This method is provided as a macro for speed purpose.
 * @param buf The fourier buffer
 * @param x The X coordinate of the pixel
 * @param y The Y coordinate of the pixel
 * @param c The color plane
 * @ingroup Processing
 * @relates LynkeosFourierBuffer
 */
#define stdColorComplexValue(buf,x,y,c) \
    (((LNKCOMPLEX*)(buf)->_data)[((y)+(c)*(buf)->_padh)*(buf)->_spadw+(x)])

/*!
 * @abstract Allocates a new empty buffer
 * @param nPlanes Number of color planes for this image
 * @param w Image pixels width
 * @param h Image pixels height
 * @param goal What kind of transform to prepare, direct, inverse or both.
 * @result The allocated and initialized buffer, ready for FFT.
 */
+ (LynkeosFourierBuffer*) fourierBufferWithNumberOfPlanes:(u_char)nPlanes 
                                              width:(u_short)w 
                                             height:(u_short)h 
                                           withGoal:(u_char)goal ;

@end

/*!
 * @abstract Base 2 logarithm
 * @param val The source value
 * @result Its logarithm.
 */
extern short log_2( short val );

#endif