MyGUI
3.0.1
|
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 #include "MyGUI_DataManager.h" 00028 00029 namespace MyGUI 00030 { 00031 00032 bool MaskPickInfo::load(const std::string& _file) 00033 { 00034 if (!DataManager::getInstance().isDataExist(_file)) 00035 return false; 00036 00037 RenderManager& render = RenderManager::getInstance(); 00038 ITexture* texture = render.createTexture(_file); 00039 texture->loadFromFile(_file); 00040 00041 uint8 * buffer = (uint8*)texture->lock(TextureUsage::Read); 00042 if (buffer == 0) 00043 { 00044 render.destroyTexture(texture); 00045 return false; 00046 } 00047 00048 size_t pixel_size = texture->getNumElemBytes(); 00049 00050 width = texture->getWidth(); 00051 height = texture->getHeight(); 00052 size_t size = width * height; 00053 data.resize(size); 00054 00055 size_t pos = 0; 00056 for (size_t pos_pix=0; pos_pix<size; pos_pix++) 00057 { 00058 uint8 white = 0; 00059 for (size_t in_pix=0; in_pix<pixel_size; in_pix++) 00060 { 00061 if (0xFF != buffer[pos]) 00062 { 00063 white = 1; 00064 } 00065 pos++; 00066 } 00067 00068 data[pos_pix] = white; 00069 } 00070 00071 texture->unlock(); 00072 render.destroyTexture(texture); 00073 00074 return true; 00075 } 00076 00077 } // namespace MyGUI