From c4e7a07367cb6c8db400f3ed424a1846d0984def Mon Sep 17 00:00:00 2001 From: Laurens Voerman Date: Fri, 1 Nov 2019 16:42:50 +0100 Subject: [PATCH] fix copySubImage crash on compressed files --- src/osg/Image.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index d27e5e4b8..24895386f 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -1696,11 +1696,11 @@ void Image::copySubImage(int s_offset, int t_offset, int r_offset, const osg::Im } unsigned int rowWidthInBlocks = (_s + footprint.x() - 1) / footprint.x(); unsigned int blockSize = computeBlockSize(_pixelFormat, 0); - data_destination = _data + blockSize * (rowWidthInBlocks * t_offset + (s_offset / footprint.x())); + data_destination = _data + blockSize * (rowWidthInBlocks * (t_offset / footprint.y()) + (s_offset / footprint.x())); unsigned int copy_width = (osg::minimum(source->s(), _s - s_offset) + footprint.x() - 1) / footprint.x(); unsigned int copy_height = (osg::minimum(source->t(), _t - t_offset) + footprint.y() - 1) / footprint.y(); unsigned int dstRowStep = blockSize * rowWidthInBlocks; - unsigned int srcRowStep = blockSize * (source->_s + footprint.x() - 1) / footprint.x(); + unsigned int srcRowStep = blockSize * ((source->_s + footprint.x() - 1) / footprint.x()); const unsigned char* data_source = source->data(0, 0, 0); for (unsigned int row = 0; row < copy_height; row += 1) { //copy blocks in a row, footprint.y() rows at a time memcpy(data_destination, data_source, copy_width * blockSize);