MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Image.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _MGImage_HH_
6 #define _MGImage_HH_
7 
8 #include "mg/MGCL.h"
9 #include "mgGL/Pixel.h"
10 #include <gdiplus.h>
11 #include <GdiPlusColorMatrix.h>
12 #include <gdipluseffects.h>
13 
14 //class MGOfstream;
15 //class MGIfstream;
16 
21 
26 class MG_DLL_DECLR MGImage{
27 
28 public:
29 
30 MGImage():m_width(0), m_height(0),m_image(0){;};
31 
33 MGImage(int wdth, int hght);
34 
36 MGImage(const MGImage& image2);
37 
39 MGImage(
40  const MGImage& image2,
41  int x,
42  int y,
43  int width,
44  int height
45 );
46 
48 MGImage(Gdiplus::Bitmap& bitmap);
49 
51 MGImage(
52  Gdiplus::Bitmap& bitmap,
53  int x,
54  int y,
55  int width,
56  int height
57 );
58 
60 MGImage(
61  Gdiplus::Bitmap& bitmap,
62  int x,
63  int y,
64  int width,
65  int height,
66  double alpha
67 );
68 
70 MGImage(
71  Gdiplus::Bitmap& bitmap,
72  const Gdiplus::BrightnessContrast& bc,
73  double alpha
74 );
75 
76 virtual ~MGImage();
77 
78 //Assignment.
80 MGImage& operator=(const MGImage& image2);
81 
85 MGImage* clone()const;
86 
87 int width()const{return m_width;};
88 int height()const{return m_height;};
89 MGPixel* image(){return m_image;};
90 const MGPixel* image()const{return m_image;};
91 MGPixel& operator()(int i, int j);
92 const MGPixel& operator()(int i, int j)const;
93 
96 bool is_zero_alpha(int i, int j)const;
97 
99 void fill_color(
100  const MGPixel& pdata
101 );
102 
104 //The color of Pixel(i,j) for i=i1,...i2 is set to pdata.
105 void fill_color(
106  const MGPixel& pdata,
107  int j,
108  int i1,
109  int i2
110 );
111 
113 //In ranges, range(j,i1,i2) are stored.
114 //Let m=ranges.size(), then m=3n(always a mutiple of 3) where n is the number of ranges.
115 //Let (j,i1,i2)=(ranges[3*k],ranges[3*k+1], ranges[3*k+2]) for k=0,...,n-1,
116 //then PixelData(i,j) for i=i1,...i2 is one range for the height j of this mesh.
117 void fill_color(
118  const MGPixel& pdata,
119  const std::vector<int>& ranges// Ranges(j,i1,i2) are input.
120 );
121 
122 //全てのpixelについて、alphaはそのままでinputされた色に変更する。
123 //inputされた色のalphaは無視される。
124 void fill_color_NoChangeAlpha(
125  const MGPixel& pdata
126 );
128 //alphaはそのままでinputされた色に変更する。
129 void fill_color_NoChangeAlpha(
130  const MGPixel& pdata,
131  int j,
132  int i1,
133  int i2
134 );
135 
136 //Copy all the pixels of image2 into this.
137 //This image's width and height are not changed. And part of this and image2
138 //are copied into this.
139 void copy_color(
140  const MGImage& image2//Source image data.
141 );
142 
143 //Test if any one of the four pixels of (i,j) to (i+1,j+1) is non zero or not.
144 //i must be < width()-1, and j must be < hieght()-1.
145 //If any one of them is nonzero, return true.
146 bool includeNonZeroAlpha(int i, int j)const;
147 
148 //Copy all the pixels of ranges in image2 into this.
149 //In ranges, range(j,i1,i2) are stored.
150 //Let m=ranges.size(), then m=3n(always a mutiple of 3) where n is the number of ranges.
151 //Let (j,i1,i2)=(ranges[3*k],ranges[3*k+1], ranges[3*k+2]) for k=0,...,n-1,
152 //then PixelData(i,j) for i=i1,...i2 is one range for the height j of this mesh.
153 void copy_color(
154  const MGImage& image2,
155  const std::vector<int>& ranges
156 );
158 
161 void resize(
162  int width,
163  int height
164 );
165 
171 void resize_with_fill_color(
172  int width,
173  int height,
174  const MGPixel& pdata
175 );
176 
178 void resize_and_add_zero_border(int nwidth2, int nheight2);
179 
180 private:
181  int m_width, m_height;
182  MGPixel* m_image;
183 
185 void extract(
186  Gdiplus::Bitmap& bitmap,
187  int x, int y,
188  int width, int height,
189  double alpha=-1.0
190 );
191 
192 };
193 
196  int width,
197  int height,
198  int& width2,
199  int& height2
200 );
201  // end of DisplayHandling group
203 #endif
MGPixel * image()
Definition: Image.h:89
void MGImageCompute_2spower(int width, int height, int &width2, int &height2)
Compute 2's power of width and height.
MGImage defines bit map image data.
Definition: Image.h:26
int height() const
Definition: Image.h:88
const MGPixel * image() const
Definition: Image.h:90
int width() const
Definition: Image.h:87
MGImage()
Definition: Image.h:30
Define MGPixel Class of (R,G,B,A) pixel data.
Definition: Pixel.h:18