+ //If there are no stretch pixels then make the entire image stretchable
+ if( mStretchPixelsX.Size() == 0 )
+ {
+ mStretchPixelsX.PushBack( Uint16Pair( 0, width - 2 ) );
+ }
+ if( mStretchPixelsY.Size() == 0 )
+ {
+ mStretchPixelsY.PushBack( Uint16Pair( 0, height - 2 ) );
+ }
+
+ //Child Rectangle
+ //BOTTOM
+ const PixelBuffer* bottom = srcPixels + ( height - 1 ) * srcStride + pixelWidth;
+ index = 0;
+ Uint16Pair contentRangeX = ParseRange( index, width - 2, bottom, pixelWidth, testByte, testBits, testValue );
+ if( contentRangeX.GetX() == 0xFFFF )
+ {
+ contentRangeX = Uint16Pair();
+ }
+
+ //RIGHT
+ const PixelBuffer* right = srcPixels + srcStride + ( width - 1 ) * pixelWidth;
+ index = 0;
+ Uint16Pair contentRangeY = ParseRange( index, height - 2, right, srcStride, testByte, testBits, testValue );
+ if( contentRangeY.GetX() == 0xFFFF )
+ {
+ contentRangeY = Uint16Pair();
+ }
+
+ mChildRectangle.x = contentRangeX.GetX() + 1;
+ mChildRectangle.y = contentRangeY.GetX() + 1;
+ mChildRectangle.width = contentRangeX.GetY() - contentRangeX.GetX();
+ mChildRectangle.height = contentRangeY.GetY() - contentRangeY.GetX();
+
+ mParsedBorder = true;
+ }
+}
+
+Uint16Pair NinePatchImage::ParseRange( uint32_t& index, uint32_t width, const PixelBuffer* & pixel, uint32_t pixelStride, int testByte, int testBits, int testValue )
+{
+ uint32_t start = 0xFFFF;
+ for( ; index < width; ++index, pixel += pixelStride )
+ {
+ if( ( pixel[ testByte ] & testBits ) == testValue )
+ {
+ start = index;
+ ++index;
+ pixel += pixelStride;