LIBPOLYMNIA
ibuf.h
[詳解]
1 /**********************************************************************//*
11  * (c) 2002-2018 oZ/acy. ALL RIGHTS RESERVED.
12  */
13 #ifndef INC_POLYMNIA_IMAGEBUFFER_H___
14 #define INC_POLYMNIA_IMAGEBUFFER_H___
15 
16 #include <boost/utility.hpp>
17 #include <themis/except.h>
18 
19 
20 namespace polymnia
21 {
22 
23 template<class C_> class ImageBuffer;
24 
28 struct Point
29 {
30  int x;
31  int y;
32 
33  Point() = default;
34  constexpr Point(int xx, int yy) : x(xx), y(yy) {}
35 };
36 
37 
41 struct Rect
42 {
43  int x1;
44  int y1;
45  int x2;
46  int y2;
47 
48  Rect() = default;
49  constexpr Rect(int x, int y, int xx, int yy)
50  : x1(x), y1(y), x2(xx), y2(yy)
51  {}
52 };
53 
54 
58 class RangeOverException : public themis::EmptyException
59 {
60 public:
61  const char* what() const noexcept
62  {
63  static const char rstr[] = "polymnia::RangeOverException";
64  return rstr;
65  }
66 };
67 
68 }//end of namespace polymnia
69 
70 
71 
72 
73 /*-----------------------------------------------------*/
76 template<class C_>
77 class polymnia::ImageBuffer : boost::noncopyable
78 {
79 public:
80  typedef C_ ColorType;
81 
82  //-------------------------------------
83  // class Effecter
84  // 畫像効果追加用の抽象基底クラス
85  //-------------------------------------
86  //class Effecter
87  //{
88  //public:
89  // Effecter() {}
90  // virtual ~Effecter() {}
91  //
92  // virtual void operator() (
93  // C_* buf, const C_* src, int w, int h, int offset) const =0;
94  //};
95 
96 //private:
97 // typedef polymnia::ImageBuffer<C_>& Ref_;
98 // typedef const polymnia::ImageBuffer<C_>& CR_;
99  //typedef const polymnia::ImageBuffer<C_>* CP_;
100 
101 
102 protected:
103  C_* buf_;
104  int w_;
105  int h_;
106  int offset_;
107 
112  ImageBuffer(int w, int h, int o) : buf_(nullptr), w_(w), h_(h), offset_(o) {}
113 
114 public:
116  virtual ~ImageBuffer() {}
117 
119  int width() const noexcept { return w_; }
121  int height() const noexcept { return h_; }
123  int offset() const noexcept { return offset_; }
124 
126  C_* buffer() noexcept { return buf_; }
128  const C_* buffer() const noexcept { return buf_; }
129 
131  C_& pixel(int x, int y) noexcept { return buf_[x + y * offset_]; }
133  const C_& pixel(int x, int y) const noexcept { return buf_[x + y * offset_]; }
134 
139  C_& at(int x, int y)
140  {
141  if (x < 0)
143  if (x >= w_)
145  if (y<0)
147  if (y >= h_)
149 
150  return buf_[x + y * offset_];
151  }
152 
157  const C_& at(int x, int y) const
158  {
159  if (x < 0)
161  if (x >= w_)
163  if (y < 0)
165  if (y >= h_)
167 
168  return buf_[x + y * offset_];
169  }
170 
171 
172  //======================================================================
173  // 圖形描写
174  //======================================================================
176  void line(int x1, int y1, int x2, int y2, const C_& col);
178  void box(int x1, int y1, int x2, int y2, const C_& col, bool fl=false);
180  void ellipse(int x, int y, int a, int b, const C_& col, bool fl=false);
181 
183  void circle(int x, int y, int r, const C_& col, bool fl=false)
184  {
185  ellipse(x, y, r, r, col, fl);
186  }
187 
189  void paintFill(int x, int y, const C_& col);
191  void clear(const C_& col);
192 
193 
194  //===================================================================
195  // 轉送
196  // tcol 附きのものは, tcol を透明色と看做して轉送
197  // mk 附きのものは, mk をマスクとして轉送
198  //===================================================================
207  void
208  blt(
209  int dx, int dy,
210  const polymnia::ImageBuffer<C_>* src, int sx, int sy, int w, int h);
211 
221  void blt(
222  int dx, int dy,
223  const polymnia::ImageBuffer<C_>* src, int sx, int sy, int w, int h,
224  const polymnia::Rect& mk);
225 
235  void blt(
236  int dx, int dy,
237  const polymnia::ImageBuffer<C_>* src, int sx, int sy, int w, int h,
238  const C_& tcol);
239 
250  void blt(
251  int dx, int dy,
252  const polymnia::ImageBuffer<C_>* src, int sx, int sy, int w, int h,
253  const C_& tcol, const polymnia::Rect& mk);
254 
266  template<class C2_>
267  void blt(
268  int dx, int dy, const polymnia::ImageBuffer<C2_>* src, int sx, int sy,
269  int w, int h);
270 
283  template<class C2_>
284  void blt(
285  int dx, int dy, const polymnia::ImageBuffer<C2_>* src,
286  int sx, int sy, int w, int h, const polymnia::Rect& mk);
287 
300  template<class C2_>
301  void blt(
302  int dx, int dy, const polymnia::ImageBuffer<C2_>* src, int sx, int sy,
303  int w, int h, const C2_& tcol);
304 
318  template<class C2_>
319  void blt(
320  int dx, int dy, const polymnia::ImageBuffer<C2_>* src,
321  int sx, int sy, int w, int h, const C2_& tcol, const polymnia::Rect& mk);
322 
323 
324  //===================================================
325  // エフェクトをかける
326  //===================================================
327  //void addEffect(const Effecter& efc);
328 };
329 
330 
331 #include "ibuf-imp_.h"
332 
333 
334 #endif // INC_POLYMNIA_IMAGEBUFFER_H___
Definition: dibio.h:20
int width() const noexcept
幅を取得
Definition: ibuf.h:119
int offset_
オフセット 水平方向の1ラインのバッファサイズ
Definition: ibuf.h:106
int y1
y座標1
Definition: ibuf.h:44
void blt(int dx, int dy, const polymnia::ImageBuffer< C_ > *src, int sx, int sy, int w, int h)
轉送
Definition: ibuf-imp_.h:55
void circle(int x, int y, int r, const C_ &col, bool fl=false)
圓を描畫
Definition: ibuf.h:183
void paintFill(int x, int y, const C_ &col)
塗り潰し
Definition: ibuf-imp_.h:632
int x2
x座標2
Definition: ibuf.h:45
int y
y座標
Definition: ibuf.h:31
constexpr Point(int xx, int yy)
Definition: ibuf.h:34
點を表す構造體
Definition: ibuf.h:28
Point()=default
C_ ColorType
Definition: ibuf.h:80
const C_ & at(int x, int y) const
ピクセル(x, y)を參照
Definition: ibuf.h:157
int height() const noexcept
高さを取得
Definition: ibuf.h:121
const C_ & pixel(int x, int y) const noexcept
ピクセル(x, y)を參照
Definition: ibuf.h:133
const char * what() const noexcept
Definition: ibuf.h:61
範圍逸脱例外
Definition: ibuf.h:58
Rect()=default
void line(int x1, int y1, int x2, int y2, const C_ &col)
直線を描畫
Definition: ibuf-imp_.h:222
int x1
x座標1
Definition: ibuf.h:43
virtual ~ImageBuffer()
解體子
Definition: ibuf.h:116
int x
x座標
Definition: ibuf.h:30
void ellipse(int x, int y, int a, int b, const C_ &col, bool fl=false)
楕圓を描畫
Definition: ibuf-imp_.h:455
長方形を表す構造體
Definition: ibuf.h:41
const C_ * buffer() const noexcept
バッファの先頭アドレスを取得
Definition: ibuf.h:128
ImageBuffer(int w, int h, int o)
構築子
Definition: ibuf.h:112
C_ & at(int x, int y)
ピクセル(x, y)を參照
Definition: ibuf.h:139
C_ * buffer() noexcept
バッファの先頭アドレスを取得
Definition: ibuf.h:126
C_ & pixel(int x, int y) noexcept
ピクセル(x, y)を參照
Definition: ibuf.h:131
void box(int x1, int y1, int x2, int y2, const C_ &col, bool fl=false)
長方形を描畫
Definition: ibuf-imp_.h:353
void clear(const C_ &col)
バッファ全體の塗り潰し
Definition: ibuf-imp_.h:187
int offset() const noexcept
オフセットを取得
Definition: ibuf.h:123
int h_
高さ
Definition: ibuf.h:105
C_ * buf_
畫像バッファ
Definition: ibuf.h:103
int y2
y座標2
Definition: ibuf.h:46
畫像バッファ基底クラステンプレート
Definition: ibuf.h:23
constexpr Rect(int x, int y, int xx, int yy)
Definition: ibuf.h:49
int w_
Definition: ibuf.h:104