WIL説明書(C++)  3.0.0
FvConversionTemplate.h
[詳解]
1 // $Revision: 1.1 $
2 /*
3  @file FvConversionTemplate.h
4  @brief image convert template functions
5  @author FAST Corporation
6 */
7 
8 
9 #ifndef _FVCONVERSIONTEMPLATE_H_INCLUDED_
10 #define _FVCONVERSIONTEMPLATE_H_INCLUDED_
11 
12 #include "FvMacros.h"
13 #include "FvDefs.h"
14 #include "Math/FvMathTemplate.h"
15 
16 namespace FVCL
17 {
18 namespace Conversion
19 {
20 
21 template<class TD, class TS> bool BinToAny( TD* dst, const TS* src, UINT start, UINT end, const TD& low, const TD& high )
22 {
23  if( dst == NULL ) return false;
24  if( src == NULL ) return false;
25 
26  UINT bits = sizeof(TS) * 8;
27  for( UINT xpos=start ; xpos<=end ; xpos++ )
28  {
29  const TS* src_adrs = src + (xpos/bits);
30  UINT bit = xpos % bits;
31  INT shift = (INT)(bits - bit - 1);
32  TS mask;
33  Math::BitShiftL( &mask, (TS)0x1, shift );
34  *dst = ((*src_adrs) & mask) ? high : low;
35  dst++;
36  }
37  return true;
38 }
39 
40 template<class TD, class TS> bool GrayToGray( TD* dst, INT dst_depth, TS* src, INT src_depth, UINT pixels )
41 {
42  if( dst == NULL ) return false;
43  if( src == NULL ) return false;
44 
45  INT shift = src_depth - dst_depth;
46  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
47  {
48  Math::BitShiftR( dst, (*src), shift );
49  dst++;
50  src++;
51  }
52  return true;
53 }
54 
55 template<class TD, class TS> bool GrayToRGB( TD* dst, INT dst_depth, TS* src, INT src_depth, UINT pixels, const TD* initval=NULL )
56 {
57  if( dst == NULL ) return false;
58  if( src == NULL ) return false;
59 
60  INT shift = src_depth - dst_depth;
61  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
62  {
63  UINT D;
64  Math::BitShiftR( &D, *src, shift );
65  if( initval ) *dst = *initval;
66  dst->R = D;
67  dst->G = D;
68  dst->B = D;
69  dst++;
70  src++;
71  }
72  return true;
73 }
74 
75 template<class TD, class TS> bool RGBToGray( TD* dst, INT dst_depth, TS* src, INT src_depth, UINT pixels, DOUBLE dbR=0.299, DOUBLE dbG=0.587, DOUBLE dbB=0.114 )
76 {
77  if( dst == NULL ) return false;
78  if( src == NULL ) return false;
79 
80  INT shift = src_depth - dst_depth;
81  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
82  {
83  TD R, G, B;
84  Math::BitShiftR( &R, src->R, shift );
85  Math::BitShiftR( &G, src->G, shift );
86  Math::BitShiftR( &B, src->B, shift );
87  *dst = (TD)(R*dbR + G*dbG + B*dbB);
88  dst++;
89  src++;
90  }
91  return true;
92 }
93 
94 template<class TD, class TS> bool RGBToGray( TD* dst, INT dst_depth, TS* srcR, TS* srcG, TS* srcB, INT src_depth, UINT pixels, DOUBLE dbR=0.299, DOUBLE dbG=0.587, DOUBLE dbB=0.114 )
95 {
96  if( dst == NULL ) return false;
97  if( srcR == NULL ) return false;
98  if( srcG == NULL ) return false;
99  if( srcB == NULL ) return false;
100 
101  INT shift = src_depth - dst_depth;
102  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
103  {
104  TD R, G, B;
105  Math::BitShiftR( &R, *srcR, shift );
106  Math::BitShiftR( &G, *srcG, shift );
107  Math::BitShiftR( &B, *srcB, shift );
108  *dst = (TD)(R*dbR + G*dbG + B*dbB);
109  dst++;
110  srcR++;
111  srcG++;
112  srcB++;
113  }
114  return true;
115 }
116 
117 template<class TD, class TS> bool RGBToRGB( TD* dst, INT dst_depth, TS* src, INT src_depth, UINT pixels, const TD* initval=NULL )
118 {
119  if( dst == NULL ) return false;
120  if( src == NULL ) return false;
121 
122  INT shift = src_depth - dst_depth;
123  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
124  {
125  UINT R, G, B;
126  Math::BitShiftR( &R, src->R, shift );
127  Math::BitShiftR( &G, src->G, shift );
128  Math::BitShiftR( &B, src->B, shift );
129  if( initval ) *dst = *initval;
130  dst->R = R;
131  dst->G = G;
132  dst->B = B;
133  dst++;
134  src++;
135  }
136  return true;
137 }
138 
139 template<class TD, class TS> bool PackRGB( TD* dst, INT dst_depth, TS* srcR, TS* srcG, TS* srcB, INT src_depth, UINT pixels, const TD* initval=NULL )
140 {
141  if( dst == NULL ) return false;
142  if( srcR == NULL ) return false;
143  if( srcG == NULL ) return false;
144  if( srcB == NULL ) return false;
145 
146  INT shift = src_depth - dst_depth;
147  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
148  {
149  UINT R, G, B;
150  Math::BitShiftR( &R, *(srcR+xpos), shift );
151  Math::BitShiftR( &G, *(srcG+xpos), shift );
152  Math::BitShiftR( &B, *(srcB+xpos), shift );
153  if( initval ) *dst = *initval;
154  dst->R = R;
155  dst->G = G;
156  dst->B = B;
157  dst++;
158  }
159  return true;
160 }
161 
162 template<class TD, class TS> bool UnpackRGB( TD* dstR, TD* dstG, TD* dstB, INT dst_depth, TS* src, INT src_depth, UINT pixels )
163 {
164  if( src == NULL ) return false;
165  if( dstR == NULL ) return false;
166  if( dstG == NULL ) return false;
167  if( dstB == NULL ) return false;
168 
169  TS* srcR = src;
170  TS* srcG = src;
171  TS* srcB = src;
172 
173  INT shift = src_depth - dst_depth;
174  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
175  {
176  Math::BitShiftR( dstR, srcR->R, shift );
177  srcR++;
178  dstR++;
179  }
180  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
181  {
182  Math::BitShiftR( dstG, srcG->G, shift );
183  srcG++;
184  dstG++;
185  }
186  for( UINT xpos=0 ; xpos<pixels ; xpos++ )
187  {
188  Math::BitShiftR( dstB, srcB->B, shift );
189  srcB++;
190  dstB++;
191  }
192  return true;
193 }
194 
195 } // Conversion
196 } // FVCL
197 
198 #endif // _FVCONVERSIONTEMPLATE_H_INCLUDED_
bool BinToAny(TD *dst, const TS *src, UINT start, UINT end, const TD &low, const TD &high)
2値画像の変換
Definition: FvConversionTemplate.h:21
FVCLのネームスペース
Definition: EVCbasicDeclare.txt:9
int INT
整数型(32ビット)
Definition: FvDefs.h:36
void BitShiftL(TD *dst, TS src, INT shift)
ビットシフト(左)
Definition: FvMathTemplate.h:39
マクロ定義
double DOUBLE
倍精度浮動小数点型(64ビット)
Definition: FvDefs.h:62
bool UnpackRGB(TD *dstR, TD *dstG, TD *dstB, INT dst_depth, TS *src, INT src_depth, UINT pixels)
RGBデータのチャネル分割
Definition: FvConversionTemplate.h:162
bool GrayToRGB(TD *dst, INT dst_depth, TS *src, INT src_depth, UINT pixels, const TD *initval=NULL)
濃淡画像の変換
Definition: FvConversionTemplate.h:55
bool PackRGB(TD *dst, INT dst_depth, TS *srcR, TS *srcG, TS *srcB, INT src_depth, UINT pixels, const TD *initval=NULL)
チャネル分割されたデータのパッキング
Definition: FvConversionTemplate.h:139
bool GrayToGray(TD *dst, INT dst_depth, TS *src, INT src_depth, UINT pixels)
濃淡画像の変換
Definition: FvConversionTemplate.h:40
unsigned int UINT
整数型(32ビット)[符号なし]
Definition: FvDefs.h:37
数値演算系テンプレート関数
bool RGBToRGB(TD *dst, INT dst_depth, TS *src, INT src_depth, UINT pixels, const TD *initval=NULL)
カラー画像の変換
Definition: FvConversionTemplate.h:117
変数型と定数の定義
bool RGBToGray(TD *dst, INT dst_depth, TS *src, INT src_depth, UINT pixels, DOUBLE dbR=0.299, DOUBLE dbG=0.587, DOUBLE dbB=0.114)
カラー画像の変換
Definition: FvConversionTemplate.h:75
void BitShiftR(TD *dst, TS src, INT shift)
ビットシフト(右)
Definition: FvMathTemplate.h:33

Documentation copyright © 2007 FAST Corporation. [B-001864]
Generated on 2023年11月02日(木) 10時12分53秒 for WIL説明書(C++) by doxygen 1.8.11