MyGUI  3.0.1
MyGUI_MaskPickInfo.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
24 #include "MyGUI_MaskPickInfo.h"
25 #include "MyGUI_ResourceManager.h"
26 #include "MyGUI_RenderManager.h"
27 #include "MyGUI_DataManager.h"
28 
29 namespace MyGUI
30 {
31 
32  bool MaskPickInfo::load(const std::string& _file)
33  {
34  if (!DataManager::getInstance().isDataExist(_file))
35  return false;
36 
38  ITexture* texture = render.createTexture(_file);
39  texture->loadFromFile(_file);
40 
41  uint8 * buffer = (uint8*)texture->lock(TextureUsage::Read);
42  if (buffer == 0)
43  {
44  render.destroyTexture(texture);
45  return false;
46  }
47 
48  size_t pixel_size = texture->getNumElemBytes();
49 
50  width = texture->getWidth();
51  height = texture->getHeight();
52  size_t size = width * height;
53  data.resize(size);
54 
55  size_t pos = 0;
56  for (size_t pos_pix=0; pos_pix<size; pos_pix++)
57  {
58  uint8 white = 0;
59  for (size_t in_pix=0; in_pix<pixel_size; in_pix++)
60  {
61  if (0xFF != buffer[pos])
62  {
63  white = 1;
64  }
65  pos++;
66  }
67 
68  data[pos_pix] = white;
69  }
70 
71  texture->unlock();
72  render.destroyTexture(texture);
73 
74  return true;
75  }
76 
77 } // namespace MyGUI