26 #include "DeInterlace.hh"
28 #include <Base/Common/BIASpragma.hh>
29 #include <Base/Image/ImageConvert.hh>
38 template <
class InputStorageType,
class OutputStorageType>
47 template <
class InputStorageType,
class OutputStorageType>
50 :
FilterNToN<InputStorageType, OutputStorageType>(),
51 bUseEvenLines_(other.bUseEvenLines_),
52 bDoDownSamplingByTwo_(other.bDoDownSamplingByTwo_),
53 eDeInterlaceType_(other.eDeInterlaceType_)
57 template <
class InputStorageType,
class OutputStorageType>
63 template <
class InputStorageType,
class OutputStorageType>
67 BIASCDOUT(D_FILTERBASE_CALLSTACK,
"DeInterlace::Filter\n");
70 register double sum=0.0;
71 const InputStorageType **psrc;
72 OutputStorageType **pdst;
74 register const int width = src.
GetWidth();
75 register const int height= src.
GetHeight();
78 if(!bDoDownSamplingByTwo_){
91 for(
int i=0;i<height;i++){
93 if ( (i % 2) == 0)line = i;
95 for(
int j=0;j<width;j++){
96 for(
int c=0;c<cc;c++){
97 pdst[i][j*cc+c] = (OutputStorageType)psrc[line][j*cc+c];
105 for(
int i=1;i<height-1;i++){
107 if ( (i % 2) == 0)line = i+1;
109 for(
int j=0;j<width;j++){
110 for(
int c=0;c<cc;c++){
111 pdst[i][j*cc+c] = (OutputStorageType)psrc[line][j*cc+c];
135 for(
int i=0;i<height/2;i++){
136 for(
int j=0;j<width/2;j++){
137 jtwo = 2*j; itwo = 2*i;
139 for(
int c=0;c<cc;c++){
141 switch(eDeInterlaceType_)
145 sum = (psrc[itwo][0*cc+c]+psrc[itwo][1*cc+c])/2;
146 else if(j==(width/2)-1)
147 sum = (psrc[itwo][(jtwo-1)*cc+c]+psrc[itwo][jtwo*cc+c])/2;
149 sum = double( (psrc[itwo][(jtwo-1)*cc+c] + psrc[itwo][jtwo*cc+c]*2 + psrc[itwo][(jtwo+1)*cc+c])/4 );
153 sum = (psrc[itwo][0*cc+c]+psrc[itwo][1*cc+c])/2;
155 sum = (psrc[itwo][(jtwo-1)*cc+c]+psrc[itwo][jtwo*cc+c])/2;
158 pdst[i][j*cc+c] = (OutputStorageType)sum;
168 for(
int i=1;i<height/2;i++)
169 for(
int j=0;j<width/2;j++){
170 jtwo = 2*j; itwo = (2*i)-1;
172 for(
int c=0;c<cc;c++){
174 switch(eDeInterlaceType_)
178 sum = (psrc[itwo][0*cc+c]+psrc[itwo][1*cc+c])/2;
179 else if(j==(width/2)-1)
180 sum = (psrc[itwo][(jtwo-1)*cc+c]+psrc[itwo][jtwo*cc+c])/2;
182 sum = (psrc[itwo][(jtwo-1)*cc+c] + psrc[itwo][jtwo*cc+c]*2 + psrc[itwo][(jtwo+1)*cc+c])/4;
186 sum = (psrc[itwo][0*cc+c]+psrc[itwo][1*cc+c])/2;
188 sum = (psrc[itwo][(jtwo-1)*cc+c]+psrc[itwo][jtwo*cc+c])/2;
191 pdst[i][j*cc+c] = (OutputStorageType)sum;
199 template <
class InputStorageType,
class OutputStorageType>
203 BIASERR(
"Unimplemented interface, calling generic Filter");
204 return Filter(src, dst);
207 template <
class InputStorageType,
class OutputStorageType>
211 BIASERR(
"Unimplemented interface, calling generic Filter");
212 return Filter(src, dst);
216 template <
class InputStorageType,
class OutputStorageType>
259 Filter(green, greenG);
266 for (
int i =0; i < width; i++) {
267 for (
int j=0; j < height; j++) {
280 template <
class InputStorageType,
class OutputStorageType>
284 bUseEvenLines_ = bEvenLines;
287 template <
class InputStorageType,
class OutputStorageType>
291 eDeInterlaceType_ = type;
295 template <
class InputStorageType,
class OutputStorageType>
299 bDoDownSamplingByTwo_ = bDoDownSamplingByTwo;
306 #define FILTER_INSTANTIATION_CLASS DeInterlace
308 #include "Filterinst.hh"
void Release()
reimplemented from ImageBase
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
averages over a region with constant weights
bool IsInterleaved() const
BIAS_DEINTERLACE_TYPE
the type of deinterlacing: BIAS_DI_121 : calculate new pixel from old neighbouring pixels with new = ...
bool bDoDownSamplingByTwo_
unsigned int GetWidth() const
StorageType PixelValue(const unsigned int x, const unsigned int y, const unsigned short int channel=0) const
Returns value of pixel at specific position, using specific channel as offset.
Deinterlacer filter for images.
int GetChannel(const ImageBase &source, const unsigned int channel)
copies one specific channel from source to Image can only be called from an planar image...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
base class for simple n->n filter implementations
void SetUseEvenLines(bool bEvenLines=true)
Set if the even or odd lines in the images should be used.
unsigned int GetHeight() const
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
only calls filter, for consistency of params
void SetPixel(const StorageType &value, const unsigned int &x, const unsigned int &y, const unsigned short int channel=0)
Set the value of a given pixel (x,y) in channel to value.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
void SetDownSamplingByTwo(bool bDoDownSamplingByTwo=true)
Set the downsampling factor while filter.
enum EColorModel GetColorModel() const
void SetDeInterlaceType(BIAS_DEINTERLACE_TYPE type)
Set the Type of deinterlacing e.g.
BIAS_DEINTERLACE_TYPE eDeInterlaceType_
static int Convert(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false)
main general conversion function, calls desired specialized functions, always initializes the destIma...
enum EStorageType GetStorageType() const
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
only calls filter, for consistency of params
virtual int FilterColorImg(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
applies deinterlacing to each channel sperately
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase