• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_MaskPickInfo.cpp

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_MaskPickInfo.h"
00025 #include "MyGUI_ResourceManager.h"
00026 #include "MyGUI_RenderManager.h"
00027 
00028 namespace MyGUI
00029 {
00030 
00031     bool MaskPickInfo::load(const std::string& _file)
00032     {
00033         RenderManager& render = RenderManager::getInstance();
00034         ITexture* texture = render.createTexture(_file);
00035         texture->loadFromFile(_file);
00036 
00037         uint8 * buffer = (uint8*)texture->lock(TextureUsage::Read);
00038         if (buffer == 0)
00039         {
00040             render.destroyTexture(texture);
00041             return false;
00042         }
00043 
00044         size_t pixel_size = texture->getNumElemBytes();
00045 
00046         width = texture->getWidth();
00047         height = texture->getHeight();
00048         size_t size = width * height;
00049         data.resize(size);
00050 
00051         size_t pos = 0;
00052         for (size_t pos_pix=0; pos_pix<size; pos_pix++)
00053         {
00054             uint8 white = 0;
00055             for (size_t in_pix=0; in_pix<pixel_size; in_pix++)
00056             {
00057                 if (0xFF != buffer[pos])
00058                 {
00059                     white = 1;
00060                 }
00061                 pos++;
00062             }
00063 
00064             data[pos_pix] = white;
00065         }
00066 
00067         texture->unlock();
00068         render.destroyTexture(texture);
00069 
00070         return true;
00071     }
00072 
00073 } // namespace MyGUI

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1