From cf99c3c9bdb5610e272914885ac37f2411c493fa Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 16 Aug 2004 20:57:24 +0000 Subject: [PATCH] Added support in Image::flipVertical for flipping mipmapped imagery and for flipping compressed imagery. --- include/osg/Image | 7 +-- src/osg/Image.cpp | 122 +++++++++++++++++++++++++++++++++------------- 2 files changed, 89 insertions(+), 40 deletions(-) diff --git a/include/osg/Image b/include/osg/Image index f1e14bd7e..1127cdcf4 100644 --- a/include/osg/Image +++ b/include/osg/Image @@ -181,10 +181,10 @@ class SG_EXPORT Image : public Object } /** Flip the image horizontally.*/ - void flipHorizontal(int image=0); + void flipHorizontal(); /** Flip the image vertically.*/ - void flipVertical(int image=0); + void flipVertical(); /** Ensure image dimensions are a power of two. @@ -236,9 +236,6 @@ class SG_EXPORT Image : public Object }; - /** converts a single image into mip mapped version image.*/ - void computeMipMaps(); - /** return true of this image is translucent - i.e. it has alpha values that are less 1.0 (when normalized).*/ bool isImageTranslucent() const; diff --git a/src/osg/Image.cpp b/src/osg/Image.cpp index 33b7e9d79..b1a0f443f 100644 --- a/src/osg/Image.cpp +++ b/src/osg/Image.cpp @@ -21,6 +21,7 @@ #include #include +#include "dxtctool.h" using namespace osg; using namespace std; @@ -657,7 +658,7 @@ void Image::copySubImage(int s_offset,int t_offset,int r_offset,osg::Image* sour } -void Image::flipHorizontal(int image) +void Image::flipHorizontal() { if (_data==NULL) { @@ -667,28 +668,45 @@ void Image::flipHorizontal(int image) unsigned int elemSize = getPixelSizeInBits()/8; - for (int t=0; t<_t; ++t) + for(int r=0;r<_r;++r) { - unsigned char* rowData = _data+t*getRowSizeInBytes()+image*getImageSizeInBytes(); - unsigned char* left = rowData ; - unsigned char* right = rowData + ((_s-1)*getPixelSizeInBits())/8; - - while (left < right) + for (int t=0; t<_t; ++t) { - char tmp[32]; // max elem size is four floats - memcpy(tmp, left, elemSize); - memcpy(left, right, elemSize); - memcpy(right, tmp, elemSize); - left += elemSize; - right -= elemSize; + unsigned char* rowData = _data+t*getRowSizeInBytes()+r*getImageSizeInBytes(); + unsigned char* left = rowData ; + unsigned char* right = rowData + ((_s-1)*getPixelSizeInBits())/8; + + while (left < right) + { + char tmp[32]; // max elem size is four floats + memcpy(tmp, left, elemSize); + memcpy(left, right, elemSize); + memcpy(right, tmp, elemSize); + left += elemSize; + right -= elemSize; + } } } - + ++_modifiedTag; } +void flipImageVertical(unsigned char* top, unsigned char* bottom, unsigned int rowSize) +{ + while(top1) { - unsigned char* srcRowData = imageData+t*rowSizeInBytes; - unsigned char* dstRowData = tmpData+(_t-1-t)*rowSizeInBytes; - memcpy(dstRowData, srcRowData, rowSizeInBytes); + notify(WARN) << "Error Image::flipVertical() do not succeed : flipping of mipmap 3d textures not yet supported."<>= 1; + t >>= 1; + if (s==0) s=1; + if (t==0) t=1; + if (!dxtc_tool::VerticalFlip(s,t,_pixelFormat,_data+_mipmapData[i])) + { + // its not a compressed image, so implement flip oursleves. + unsigned int rowSize = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing); + unsigned char* top = _data+_mipmapData[i]; + unsigned char* bottom = top + (t-1)*rowSize; + + flipImageVertical(top, bottom, rowSize); + } + } + } - delete [] tmpData; - ++_modifiedTag; } @@ -737,11 +794,6 @@ void Image::ensureValidSizeForTexturing(GLint maxTextureSize) } } -void Image::computeMipMaps() -{ -} - - bool Image::isImageTranslucent() const {