/*************************************************************************/ /* bit_mask.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* http://www.godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "bit_mask.h" #include "io/image_loader.h" void BitMap::create(const Size2& p_size) { ERR_FAIL_COND(p_size.width<1); ERR_FAIL_COND(p_size.height<1); width=p_size.width; height=p_size.height; bitmask.resize(((width*height)/8)+1); zeromem(bitmask.ptr(),bitmask.size()); } void BitMap::create_from_image_alpha(const Image& p_image){ ERR_FAIL_COND(p_image.empty()); Image img=p_image; img.convert(Image::FORMAT_LA8); ERR_FAIL_COND(img.get_format()!=Image::FORMAT_LA8); create(Size2(img.get_width(),img.get_height())); DVector::Read r = img.get_data().read(); uint8_t *w = bitmask.ptr(); for(int i=0;i>7; c+=(d[i]&(1<<6))>>6; c+=(d[i]&(1<<5))>>5; c+=(d[i]&(1<<4))>>4; c+=(d[i]&(1<<3))>>3; c+=(d[i]&(1<<2))>>2; c+=d[i]&1; } return c; } void BitMap::set_bit(const Point2& p_pos,bool p_value){ int x=Math::fast_ftoi(p_pos.x); int y=Math::fast_ftoi(p_pos.y); ERR_FAIL_INDEX(x,width); ERR_FAIL_INDEX(y,height); int ofs = width * y + x; int bbyte = ofs/8; int bbit = ofs % 8; uint8_t b = bitmask[bbyte]; if (p_value) b|=(1<