scImageHandler.dll
 全て クラス 名前空間 関数 変数 列挙値
scMetaImg.h
1 #ifndef _SC_META_IMG_H_
2 #define _SC_META_IMG_H_
3 
4 // C++ の 0 と NULL の混同を避けるためのクラスを定義
5 #include <my_null.h>
6 
8 
12 namespace ns_scMetaImg
13 {
14  enum
15  {
17  RED = 0,
19  GREEN = 1,
21  BLUE = 2,
22  };
23 }
24 
26 
30 typedef struct
31 {
33  unsigned char Red;
35  unsigned char Green;
37  unsigned char Blue;
39  unsigned char Reserved;
41 
43 
50 class scMetaImg
51 {
52 protected:
63  void *buf1d_;
67  void **buf2d_;
71  int width_;
75  int height_;
81  int bit_;
86  int channel_;
95 
99  scMetaImg( const scMetaImg & rhs );
100 // scMetaImg & operator = ( const scMetaImg & rhs ); // 代入演算子
101 // scMetaImg * operator& (){ return this; }; // アドレス演算子
102 // const scMetaImg * operator& () const{ return this; }; // アドレス演算子
103 
107  void * MemCpy__( void *buf1, const void *buf2, int byte_size )
108  {
109  unsigned int *buf1_u32;
110  const unsigned int *buf2_u32;
111  int dword_size;
112  int i;
113 
114  buf1_u32 = static_cast< unsigned int * >( buf1 );
115  buf2_u32 = static_cast< const unsigned int * >( buf2 );
116  dword_size = byte_size / 4;
117  for( i = 0; i < dword_size; i ++ )
118  {
119  *buf1_u32 = *buf2_u32;
120  buf1_u32 ++;
121  buf2_u32 ++;
122  }
123 
124  return buf1;
125  }
126 
127 
128 public:
133  {
134  buf1d_ = my_null; // NULL
135  buf2d_ = my_null; // NULL
136  width_ = 0;
137  height_ = 0;
138  bit_ = 0;
139  channel_ = 0;
140  palette_size_ = 0;
141  ary_palette_ = my_null; // NULL
142  }
143 
148  virtual ‾scMetaImg()
149  {
150  //
151  ::delete [] buf2d_;
152  ::operator delete( buf1d_ );
153  ::delete [] ary_palette_;
154  }
155 
160  scMetaImg & operator = ( const scMetaImg & rhs )
161  {
162  // 自分自身への代入なら、何もしない.
163  if( this == &rhs )
164  {
165  return *this;
166  }
167 
168  // バッファの解放・確保
169  Resize( &rhs );
170 
171  // 画素データのコピー
172  int plane_size;
173  int c;
174  plane_size = width_ * height_ * ( ( bit_ + 7 ) >> 3 );
175  for( c = 0; c < channel_; c ++ )
176  {
177 // std::memcpy( buf2d_[ c ], rhs.buf2d_[ c ], plane_size );
178  MemCpy__( buf2d_[ c ], rhs.buf2d_[ c ], plane_size );
179  }
180 
181  return *this;
182  }
183 
187  int Width() const
188  {
189  return width_;
190  }
191 
195  int Height() const
196  {
197  return height_;
198  }
199 
203  int Bit() const
204  {
205  return bit_;
206  }
207 
211  int Channel() const
212  {
213  return channel_;
214  }
215 
220  {
221  return ary_palette_;
222  }
227  {
228  return ary_palette_;
229  }
230 
234  int PaletteSize() const
235  {
236  return palette_size_;
237  }
238 
255  int Resize( int width, int height, int bit, int channel )
256  {
257  int result = -1;
258  unsigned char *p_addr;
259  int pix_size, plane_size, buf_size;
260  int c;
261 
262  // サイズ等の更新
263  width_ = width;
264  height_ = height;
265  bit_ = bit;
266  channel_ = channel;
267  pix_size = width * height;
268  plane_size = pix_size * ( ( bit + 7 ) >> 3 );
269  buf_size = ( plane_size * channel + 3 ) & ‾3; // 4Byte境界
270 
271  // 作業領域を確保し直す
272  try
273  {
274  if( buf1d_ )
275  {
276  ::operator delete( buf1d_ );
277  }
278  if( buf2d_ )
279  {
280  delete [] buf2d_;
281  }
282 
283  buf1d_ = ::operator new( buf_size );
284  buf2d_ = ::new void*[ channel ];
285  p_addr = static_cast< unsigned char * >( buf1d_ );
286  for( c = 0; c < channel; c ++ )
287  {
288  buf2d_[ c ] = p_addr + c * plane_size;
289  }
290 
291  //
292  // パレット
293  //
294 
295  // 現在のパレットを破棄する。
296  if( ary_palette_ )
297  {
298  ::operator delete( ary_palette_ );
299  ary_palette_ = my_null;
300  palette_size_ = 0;
301  }
302  // チャンネルが1ならパレットを作成。
303  if( channel_ == 1 )
304  {
305  int i;
306  palette_size_ = 1 << bit_;
307  ary_palette_ = static_cast< SC_METAIMG_PALETTE * >( ::operator new( sizeof( SC_METAIMG_PALETTE ) * palette_size_ ) );
308  for( i = 0; i < palette_size_; i ++ )
309  {
310  ary_palette_[ i ].Blue = ary_palette_[ i ].Green = ary_palette_[ i ].Red = static_cast< unsigned char >( 0xFF * i / ( palette_size_ - 1 ) );
311  ary_palette_[ i ].Reserved = 0xFF;
312  }
313  }
314  result = 0;
315  }
316  catch( ... )
317  {
318  ;
319  }
320 
321  return result;
322  }
323 
332  int Resize( const scMetaImg *ref_img )
333  {
334  int result;
335  result = this->Resize( ref_img->Width(), ref_img->Height(), ref_img->Bit(), ref_img->Channel() );
336  if( result == 0 && palette_size_ > 0 )
337  {
338  int i;
339  for( i = 0; i < palette_size_; i ++ )
340  {
341  this->ary_palette_[ i ] = ref_img->ary_palette_[ i ];
342  }
343  }
344  return result;
345  }
346 
351  void * ImgPtr( int index ) const
352  {
353  if( index >= channel_ )
354  {
355  // NULL
356  return my_null;
357  }
358  return buf2d_[ index ];
359  }
360 
365  unsigned char * ImgPtr08( int index ) const
366  {
367  if( index >= channel_ )
368  {
369  // my_null
370  return static_cast< unsigned char * >( 0 );
371  }
372  return static_cast< unsigned char * >( buf2d_[ index ] );
373  }
374 
379  unsigned short * ImgPtr16( int index ) const
380  {
381  if( index >= channel_ ){
382  return my_null;
383  }
384  return static_cast< unsigned short * >( buf2d_[ index ] );
385  }
386 
391  const unsigned char * CstImgPtr08( int index ) const
392  {
393  if( index >= channel_ ){
394  return my_null;
395  }
396  return static_cast< const unsigned char * >( buf2d_[ index ] );
397  }
398 
403  const unsigned short * CstImgPtr16( int index ) const
404  {
405  if( index >= channel_ ){
406  return my_null;
407  }
408  return static_cast< const unsigned short * >( buf2d_[ index ] );
409  }
410 
414  unsigned char ** ImgPtr08_2d() const
415  {
416  return reinterpret_cast< unsigned char ** >( buf2d_ );
417  }
418 
422  unsigned short ** ImgPtr16_2d() const
423  {
424  return reinterpret_cast< unsigned short ** >( buf2d_ );
425  }
426 
430  const unsigned char ** CstImgPtr08_2d() const
431  {
432  return const_cast< const unsigned char ** >( reinterpret_cast< unsigned char ** >( buf2d_ ) );
433  }
434 
438  const unsigned short ** CstImgPtr16_2d() const
439  {
440  return const_cast< const unsigned short ** >( reinterpret_cast< unsigned short ** >( buf2d_ ) );
441  }
442 
443 };
444 
445 #endif //
const unsigned short ** CstImgPtr16_2d() const
Definition: scMetaImg.h:438
void * buf1d_
Definition: scMetaImg.h:63
unsigned char Green
パレット情報の緑成分
Definition: scMetaImg.h:35
Blue Channel = 2.
Definition: scMetaImg.h:21
int channel_
Definition: scMetaImg.h:86
抽象画像データを扱うためのクラス
Definition: scMetaImg.h:50
int Width() const
Definition: scMetaImg.h:187
SC_METAIMG_PALETTE * Palette()
Definition: scMetaImg.h:219
unsigned char Red
パレット情報の赤成分
Definition: scMetaImg.h:33
void ** buf2d_
Definition: scMetaImg.h:67
int Bit() const
Definition: scMetaImg.h:203
void * ImgPtr(int index) const
Definition: scMetaImg.h:351
virtual ‾scMetaImg()
Definition: scMetaImg.h:148
SC_METAIMG_PALETTE * ary_palette_
Definition: scMetaImg.h:90
int Resize(int width, int height, int bit, int channel)
Definition: scMetaImg.h:255
int height_
Definition: scMetaImg.h:75
scMetaImg()
Definition: scMetaImg.h:132
unsigned short * ImgPtr16(int index) const
Definition: scMetaImg.h:379
int Height() const
Definition: scMetaImg.h:195
const SC_METAIMG_PALETTE * CstPalette() const
Definition: scMetaImg.h:226
const unsigned char * CstImgPtr08(int index) const
Definition: scMetaImg.h:391
const unsigned short * CstImgPtr16(int index) const
Definition: scMetaImg.h:403
unsigned short ** ImgPtr16_2d() const
Definition: scMetaImg.h:422
const unsigned char ** CstImgPtr08_2d() const
Definition: scMetaImg.h:430
unsigned char Reserved
パレット情報の未使用領域
Definition: scMetaImg.h:39
パレットを扱うための構造体
Definition: scMetaImg.h:30
scMetaImg & operator=(const scMetaImg &rhs)
Definition: scMetaImg.h:160
int bit_
Definition: scMetaImg.h:81
int palette_size_
Definition: scMetaImg.h:94
int PaletteSize() const
Definition: scMetaImg.h:234
int Channel() const
Definition: scMetaImg.h:211
int Resize(const scMetaImg *ref_img)
Definition: scMetaImg.h:332
int width_
Definition: scMetaImg.h:71
unsigned char ** ImgPtr08_2d() const
Definition: scMetaImg.h:414
unsigned char Blue
パレット情報の青成分
Definition: scMetaImg.h:37
unsigned char * ImgPtr08(int index) const
Definition: scMetaImg.h:365
void * MemCpy__(void *buf1, const void *buf2, int byte_size)
Definition: scMetaImg.h:107
Red Channel = 0.
Definition: scMetaImg.h:17
Green Channel = 1.
Definition: scMetaImg.h:19