SDXFrameWork  0.09
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
ImagePack.h
1 #pragma once//©SDXFramework http://sourceforge.jp/projects/dxframework/
2 #include<Multimedia/SDX.h>
3 #include<Multimedia/Image.h>
4 
5 namespace SDX
6 {
9 class ImagePack
10 {
11 protected:
12  std::vector<Image*> images;
13  int widthMax;
14  int heightMax;
15 public:
16  ImagePack():
17  widthMax( 0 ),
18  heightMax( 0 )
19  {}
20 
22  ImagePack( const char *ファイル名 , int 総コマ数 , int コマ割り横,int コマ割り縦)
23  {
24  ImagePack::Load(ファイル名,総コマ数 , コマ割り横, コマ割り縦 );
25  }
26 
34  bool Load(const char *ファイル名 , int 総コマ数,int コマ割り横, int コマ割り縦 )
35  {
36  int x = 0, y = 0, count = 0;
37  Image image(ファイル名);
38 
39  const int width = image.GetWidth() / コマ割り横;
40  const int height = image.GetHeight() / コマ割り縦;
41 
42  for (int a = 0; a < コマ割り縦; ++a)
43  {
44  x = 0;
45  for (int b = 0; b < コマ割り横; ++b)
46  {
47  if (count >= 総コマ数) break;
48  this->Add(new Image(image, x, y, width, height));
49  x += width;
50  count++;
51  }
52  y += height;
53  }
54 
55  return true;
56  }
57 
61  bool Load(const char *ファイル名 , const char *拡張子 , int 総コマ数 , const char* 書式 = "%03d.")
62  {
63  for(int a=0 ; a<総コマ数 ; ++a)
64  {
65  char fileBuf[8];
66  sprintf_s( fileBuf , 8 , 書式 , a );
67 
68  std::string fileName = ファイル名;
69  fileName += fileBuf;
70  fileName += 拡張子;
71 
72  this->Add( new Image( fileName.c_str() ) );
73  }
74  return true;
75  }
76 
78  void Add(Image *追加イメージ)
79  {
80  images.push_back( 追加イメージ );
81  this->widthMax = std::max( this->widthMax , 追加イメージ->GetWidth() );
82  this->heightMax = std::max( this->heightMax, 追加イメージ->GetHeight());
83  }
84  void Add(const char *ファイル名)
85  {
86  Add( new Image( ファイル名 ) );
87  }
88 
90  virtual void Release()
91  {
92  for( auto it : images)
93  {
94  it->Release();
95  }
96 
97  images.clear();
98  }
99 
101  int GetSize() const
102  {
103  return (int)images.size();
104  }
105 
107  int GetWidth() const
108  {
109  return this->widthMax;
110  }
111 
113  int GetHeight() const
114  {
115  return this->heightMax;
116  }
117 
118  Image* operator[](int index)
119  {
120  return images[index];
121  }
122 
123  Image* operator[](int index) const
124  {
125  return images[index];
126  }
127 
128 };
129 }
virtual void Release()
Imageをメモリから開放.
Definition: ImagePack.h:90
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:107
bool Load(const char *ファイル名, const char *拡張子, int 総コマ数, const char *書式="%03d.")
連番ファイルを一括して読み込む.
Definition: ImagePack.h:61
画像データを表すクラス.
Definition: Image.h:38
bool Load(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:34
int GetHeight() const
高さを取得.
Definition: Image.h:248
int GetWidth() const
幅を取得.
Definition: Image.h:242
int GetSize() const
要素数を取得.
Definition: ImagePack.h:101
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:113
ImagePack(const char *ファイル名, int 総コマ数, int コマ割り横, int コマ割り縦)
1つの画像を分割して読み込む.
Definition: ImagePack.h:22
複数のImageをまとめるクラス.
Definition: ImagePack.h:9
void Add(Image *追加イメージ)
Imageを末尾に追加.
Definition: ImagePack.h:78