| 119 | } |
| 120 | |
| 121 | Vec2 NinePatchImageParser::parseVerticalMargin() const |
| 122 | { |
| 123 | unsigned char* data = _image->getData(); |
| 124 | int imageWidth = _image->getWidth(); |
| 125 | |
| 126 | int y1 = 0; |
| 127 | int y2 = 0; |
| 128 | |
| 129 | data = data + this->getPixelOriginOffset(Direction::VERTICAL); |
| 130 | unsigned char lastPixel = *(data + 3); |
| 131 | |
| 132 | int length = (int)(_imageFrame.origin.y + this->getFrameHeight()); |
| 133 | for (int i = _imageFrame.origin.y; i <= length; i++) |
| 134 | { |
| 135 | unsigned char pixel = *(data + (i - (int)_imageFrame.origin.y) * imageWidth * 4 + 3); |
| 136 | if (pixel != lastPixel) |
| 137 | { |
| 138 | if (pixel > 0) |
| 139 | { |
| 140 | y1 = (i - (int)_imageFrame.origin.y); |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | y2 = (i - (int)_imageFrame.origin.y); |
| 145 | break; |
| 146 | } |
| 147 | } |
| 148 | lastPixel = pixel; |
| 149 | } |
| 150 | return Vec2(y1, y2); |
| 151 | } |
| 152 | |
| 153 | Rect NinePatchImageParser::parseCapInset() const |
| 154 | { |
no test coverage detected