diff --git a/src/osgUtil/Optimizer.cpp b/src/osgUtil/Optimizer.cpp index f762c0ff5..fc75d9a20 100644 --- a/src/osgUtil/Optimizer.cpp +++ b/src/osgUtil/Optimizer.cpp @@ -3191,6 +3191,12 @@ bool Optimizer::TextureAtlasBuilder::Source::suitableForAtlas(unsigned int maxim break; } + if ((_image->getPixelSizeInBits() % 8) != 0) + { + // pixel size not byte aligned so report as not suitable to prevent other atlas code from having problems with byte boundaries. + return false; + } + if (_texture.valid()) { @@ -3517,20 +3523,137 @@ void Optimizer::TextureAtlasBuilder::Atlas::copySources() const osg::Image* sourceImage = source->_image.get(); osg::Image* atlasImage = atlas->_image.get(); + unsigned int rowSize = sourceImage->getRowSizeInBytes(); + unsigned int pixelSizeInBits = sourceImage->getPixelSizeInBits(); + unsigned int pixelSizeInBytes = pixelSizeInBits/8; + unsigned int marginSizeInBytes = pixelSizeInBytes*_margin; + unsigned int x = source->_x; unsigned int y = source->_y; - unsigned int rowWidth = sourceImage->getRowSizeInBytes(); - for(int t=0; tt(); ++t, ++y) + + int t; + for(t=0; tt(); ++t, ++y) { unsigned char* destPtr = atlasImage->data(x, y); const unsigned char* sourcePtr = sourceImage->data(0, t); - for(unsigned int i=0; i_y + sourceImage->t(); + unsigned int m; + for(m=0; m<_margin; ++m, ++y) + { + unsigned char* destPtr = atlasImage->data(x, y); + const unsigned char* sourcePtr = sourceImage->data(0, sourceImage->t()-1); + for(unsigned int i=0; i_y-1; + for(m=0; m<_margin; ++m, --y) + { + unsigned char* destPtr = atlasImage->data(x, y); + const unsigned char* sourcePtr = sourceImage->data(0, 0); + for(unsigned int i=0; i_y; + for(t=0; tt(); ++t, ++y) + { + x = source->_x-1; + for(m=0; m<_margin; ++m, --x) + { + unsigned char* destPtr = atlasImage->data(x, y); + const unsigned char* sourcePtr = sourceImage->data(0, t); + for(unsigned int i=0; i_y; + for(t=0; tt(); ++t, ++y) + { + x = source->_x + sourceImage->s(); + for(m=0; m<_margin; ++m, ++x) + { + unsigned char* destPtr = atlasImage->data(x, y); + const unsigned char* sourcePtr = sourceImage->data(sourceImage->s()-1, t); + for(unsigned int i=0; i_y + sourceImage->t(); + for(m=0; m<_margin; ++m, ++y) + { + unsigned char* destPtr = atlasImage->data(source->_x - _margin, y); + unsigned char* sourcePtr = atlasImage->data(source->_x - _margin, y-1); // copy from row below + for(unsigned int i=0; i_y + sourceImage->t(); + for(m=0; m<_margin; ++m, ++y) + { + unsigned char* destPtr = atlasImage->data(source->_x + sourceImage->s(), y); + unsigned char* sourcePtr = atlasImage->data(source->_x + sourceImage->s(), y-1); // copy from row below + for(unsigned int i=0; i_y - 1; + for(m=0; m<_margin; ++m, --y) + { + unsigned char* destPtr = atlasImage->data(source->_x - _margin, y); + unsigned char* sourcePtr = atlasImage->data(source->_x - _margin, y+1); // copy from row below + for(unsigned int i=0; i_y - 1; + for(m=0; m<_margin; ++m, --y) + { + unsigned char* destPtr = atlasImage->data(source->_x + sourceImage->s(), y); + unsigned char* sourcePtr = atlasImage->data(source->_x + sourceImage->s(), y+1); // copy from row below + for(unsigned int i=0; igetFileName()<getFileName());