Changeset 12912
- Timestamp:
- 01/24/12 15:34:02 (16 months ago)
- Location:
- OpenSceneGraph/trunk
- Files:
-
- 34 modified
-
examples/osgphotoalbum/PhotoArchive.cpp (modified) (2 diffs)
-
examples/osgscreencapture/osgscreencapture.cpp (modified) (1 diff)
-
examples/osgtexture2D/osgtexture2D.cpp (modified) (2 diffs)
-
include/osg/Array (modified) (1 diff)
-
include/osg/BufferObject (modified) (1 diff)
-
include/osg/Image (modified) (9 diffs)
-
include/osg/PrimitiveSet (modified) (1 diff)
-
src/osg/BufferObject.cpp (modified) (1 diff)
-
src/osg/DrawPixels.cpp (modified) (2 diffs)
-
src/osg/Image.cpp (modified) (29 diffs)
-
src/osg/Texture.cpp (modified) (9 diffs)
-
src/osg/Texture1D.cpp (modified) (1 diff)
-
src/osg/Texture2DArray.cpp (modified) (1 diff)
-
src/osg/Texture3D.cpp (modified) (1 diff)
-
src/osg/TextureRectangle.cpp (modified) (3 diffs)
-
src/osgDB/OutputStream.cpp (modified) (1 diff)
-
src/osgPlugins/Inventor/ConvertFromInventor.cpp (modified) (1 diff)
-
src/osgPlugins/Inventor/ReaderWriterIV.cpp (modified) (2 diffs)
-
src/osgPlugins/bmp/ReaderWriterBMP.cpp (modified) (1 diff)
-
src/osgPlugins/dds/ReaderWriterDDS.cpp (modified) (3 diffs)
-
src/osgPlugins/exr/ReaderWriterEXR.cpp (modified) (1 diff)
-
src/osgPlugins/hdr/hdrwriter.cpp (modified) (5 diffs)
-
src/osgPlugins/hdr/hdrwriter.h (modified) (2 diffs)
-
src/osgPlugins/imageio/ReaderWriterImageIO.cpp (modified) (3 diffs)
-
src/osgPlugins/ive/Image.cpp (modified) (1 diff)
-
src/osgPlugins/jp2/ReaderWriterJP2.cpp (modified) (2 diffs)
-
src/osgPlugins/jpeg/ReaderWriterJPEG.cpp (modified) (1 diff)
-
src/osgPlugins/logo/ReaderWriterLOGO.cpp (modified) (1 diff)
-
src/osgPlugins/nvtt/NVTTImageProcessor.cpp (modified) (3 diffs)
-
src/osgPlugins/pov/ReaderWriterPOV.cpp (modified) (1 diff)
-
src/osgPlugins/rgb/ReaderWriterRGB.cpp (modified) (2 diffs)
-
src/osgPlugins/tga/ReaderWriterTGA.cpp (modified) (3 diffs)
-
src/osgPlugins/xine/ReaderWriterXine.cpp (modified) (2 diffs)
-
src/osgText/Glyph.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgphotoalbum/PhotoArchive.cpp
r12577 r12912 223 223 osg::PixelStorageModes psm; 224 224 psm.pack_alignment = image->getPacking(); 225 psm.pack_row_length = image->getRowLength(); 225 226 psm.unpack_alignment = image->getPacking(); 226 227 … … 290 291 osg::PixelStorageModes psm; 291 292 psm.pack_alignment = image->getPacking(); 293 psm.pack_row_length = image->getRowLength(); 292 294 psm.unpack_alignment = image->getPacking(); 293 295 -
OpenSceneGraph/trunk/examples/osgscreencapture/osgscreencapture.cpp
r12292 r12912 385 385 { 386 386 memcpy(image->data(), src, image->getTotalSizeInBytes()); 387 387 388 ext->glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); 388 389 } -
OpenSceneGraph/trunk/examples/osgtexture2D/osgtexture2D.cpp
r9636 r12912 537 537 { 538 538 539 539 #if 1 540 osg::ref_ptr<osg::Image> originalImage = osgDB::readImageFile("Images/dog_left_eye.jpg"); 541 542 osg::ref_ptr<osg::Image> subImage = new osg::Image; 543 subImage->setUserData(originalImage.get()); // attach the originalImage as user data to prevent it being deleted. 544 545 // now assign the appropriate portion data from the originalImage 546 subImage->setImage(originalImage->s()/2, originalImage->t()/2, originalImage->r(), // half the width and height 547 originalImage->getInternalTextureFormat(), // same internal texture format 548 originalImage->getPixelFormat(),originalImage->getDataType(), // same pixel foramt and data type 549 originalImage->data(originalImage->s()/4,originalImage->t()/4), // offset teh start point to 1/4 into the image 550 osg::Image::NO_DELETE, // don't attempt to delete the image data, leave this to the originalImage 551 originalImage->getPacking(), // use the the same packing 552 originalImage->s()); // use the width of the original image as the row width 553 554 555 subImage->setPixelBufferObject(new osg::PixelBufferObject(subImage.get())); 556 557 #if 0 558 OSG_NOTICE<<"orignalImage iterator"<<std::endl; 559 for(osg::Image::DataIterator itr(originalImage.get()); itr.valid(); ++itr) 560 { 561 OSG_NOTICE<<" "<<(void*)itr.data()<<", "<<itr.size()<<std::endl; 562 } 563 564 OSG_NOTICE<<"subImage iterator, size "<<subImage->s()<<", "<<subImage->t()<<std::endl; 565 unsigned int i=0; 566 for(osg::Image::DataIterator itr(subImage.get()); itr.valid(); ++itr, ++i) 567 { 568 OSG_NOTICE<<" "<<i<<", "<<(void*)itr.data()<<", "<<itr.size()<<std::endl; 569 570 for(unsigned char* d=const_cast<unsigned char*>(itr.data()); d<(itr.data()+itr.size()); ++d) 571 { 572 *d = 255-*d; 573 } 574 } 575 #endif 576 577 578 _imageList.push_back(subImage.get()); 579 580 #else 540 581 _imageList.push_back(osgDB::readImageFile("Images/dog_left_eye.jpg")); 582 #endif 541 583 _textList.push_back("Subloaded Image 1 - dog_left_eye.jpg"); 542 584 … … 585 627 protected: 586 628 629 587 630 typedef std::vector< osg::ref_ptr<osg::Image> > ImageList; 588 631 typedef std::vector<std::string> TextList; -
OpenSceneGraph/trunk/include/osg/Array
r12608 r12912 105 105 GLint getDataSize() const { return _dataSize; } 106 106 GLenum getDataType() const { return _dataType; } 107 108 virtual osg::Array* asArray() { return this; } 109 virtual const osg::Array* asArray() const { return this; } 110 107 111 virtual const GLvoid* getDataPointer() const = 0; 108 112 virtual unsigned int getTotalDataSize() const = 0; -
OpenSceneGraph/trunk/include/osg/BufferObject
r12797 r12912 621 621 virtual unsigned int getTotalDataSize() const = 0; 622 622 623 virtual osg::Array* asArray() { return 0; } 624 virtual const osg::Array* asArray() const { return 0; } 625 626 virtual osg::PrimitiveSet* asPrimitiveSet() { return 0; } 627 virtual const osg::PrimitiveSet* asPrimitiveSet() const { return 0; } 628 629 virtual osg::Image* asImage() { return 0; } 630 virtual const osg::Image* asImage() const { return 0; } 631 623 632 void setBufferObject(BufferObject* bufferObject); 624 633 BufferObject* getBufferObject() { return _bufferObject.get(); } -
OpenSceneGraph/trunk/include/osg/Image
r12842 r12912 115 115 virtual const char* className() const { return "Image"; } 116 116 117 virtual osg::Image* asImage() { return this; } 118 virtual const osg::Image* asImage() const { return this; } 119 117 120 virtual const GLvoid* getDataPointer() const { return data(); } 118 121 virtual unsigned int getTotalDataSize() const { return getTotalSizeInBytesIncludingMipmaps(); } … … 158 161 unsigned char* data, 159 162 AllocationMode mode, 160 int packing=1 );163 int packing=1, int rowLength=0); 161 164 162 165 /** Read pixels from current frame buffer at specified position and size, using glReadPixels. … … 214 217 /** Depth of image. */ 215 218 inline int r() const { return _r; } 219 220 void setRowLength(int length) { _rowLength = length; } 221 inline int getRowLength() const { return _rowLength; } 216 222 217 223 void setInternalTextureFormat(GLint internalFormat); … … 242 248 inline unsigned int getRowSizeInBytes() const { return computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing); } 243 249 250 /** Return the number of bytes between each successive row. 251 * Note, getRowSizeInBytes() will only equal getRowStepInBytes() when isDataContiguous() return true. */ 252 inline unsigned int getRowStepInBytes() const { return computeRowWidthInBytes(_rowLength==0?_s:_rowLength,_pixelFormat,_dataType,_packing); } 253 244 254 /** Return the number of bytes each image (_s*_t) of pixels occupies. */ 245 255 inline unsigned int getImageSizeInBytes() const { return getRowSizeInBytes()*_t; } 246 256 257 /** Return the number of bytes between each successive image. 258 * Note, getImageSizeInBytes() will only equal getImageStepInBytes() when isDataContiguous() return true. */ 259 inline unsigned int getImageStepInBytes() const { return getRowStepInBytes()*_t; } 260 247 261 /** Return the number of bytes the whole row/image/volume of pixels occupies. */ 248 262 inline unsigned int getTotalSizeInBytes() const { return getImageSizeInBytes()*_r; } … … 254 268 bool valid() const { return _s!=0 && _t!=0 && _r!=0 && _data!=0 && _dataType!=0; } 255 269 256 /** Raw image data. */ 270 /** Raw image data. 271 * Note, data in successive rows may not be contiguous, isDataContiguous() return false then you should 272 * take care to access the data per row rather than treating the whole data as a single block. */ 257 273 inline unsigned char* data() { return _data; } 258 274 259 /** Raw const image data. */ 275 /** Raw const image data. 276 * Note, data in successive rows may not be contiguous, isDataContiguous() return false then you should 277 * take care to access the data per row rather than treating the whole data as a single block. */ 260 278 inline const unsigned char* data() const { return _data; } 261 279 262 263 280 inline unsigned char* data(int column, int row=0,int image=0) 264 281 { 265 282 if (!_data) return NULL; 266 return _data+(column*getPixelSizeInBits())/8+row*getRowS izeInBytes()+image*getImageSizeInBytes();283 return _data+(column*getPixelSizeInBits())/8+row*getRowStepInBytes()+image*getImageSizeInBytes(); 267 284 } 268 285 … … 270 287 { 271 288 if (!_data) return NULL; 272 return _data+(column*getPixelSizeInBits())/8+row*getRowS izeInBytes()+image*getImageSizeInBytes();289 return _data+(column*getPixelSizeInBits())/8+row*getRowStepInBytes()+image*getImageSizeInBytes(); 273 290 } 291 292 /** return true if the data stored in the image is a contiguous block of data.*/ 293 bool isDataContiguous() const { return _rowLength==0 || _rowLength==_s; } 294 295 /** Convenience class for assisting the copying of image data when the image data isn't contiguous.*/ 296 class OSG_EXPORT DataIterator 297 { 298 public: 299 DataIterator(const Image* image); 300 DataIterator(const DataIterator& ri); 301 ~DataIterator() {} 302 303 /** advance iterator to next block of data.*/ 304 void operator ++ (); 305 306 /** is iterator valid.*/ 307 bool valid() const { return _currentPtr!=0; } 308 309 /** data pointer of current block to copy.*/ 310 const unsigned char* data() const { return _currentPtr; } 311 312 /** Size of current block to copy.*/ 313 unsigned int size() const { return _currentSize; } 314 315 protected: 316 317 318 void assign(); 319 320 const osg::Image* _image; 321 int _rowNum; 322 int _imageNum; 323 unsigned int _mipmapNum; 324 const unsigned char* _currentPtr; 325 unsigned int _currentSize; 326 }; 274 327 275 328 /** Get the color value for specified texcoord.*/ … … 302 355 static GLenum computePixelFormat(GLenum pixelFormat); 303 356 static GLenum computeFormatDataType(GLenum pixelFormat); 357 static unsigned int computeBlockSize(GLenum pixelFormat, GLenum packing); 304 358 static unsigned int computeNumComponents(GLenum pixelFormat); 305 359 static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum type); 306 360 static unsigned int computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing); 361 static unsigned int computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat,GLenum type,int packing); 307 362 static int computeNearestPowerOfTwo(int s,float bias=0.5f); 308 363 static int computeNumberOfMipmapLevels(int s,int t = 1, int r = 1); … … 342 397 } 343 398 344 /*inline const unsigned char* getMipmapData(unsigned int row, unsigned int column, unsigned int mipmapLevel) const345 {346 if (!_data) return NULL;347 return getMipmapData(mipmapLevel) + (column*getPixelSizeInBits())/8+row*getRowSizeInBytes();348 }*/349 350 399 /** Return true if this image is translucent - i.e. it has alpha values that are less 1.0 (when normalized). */ 351 400 virtual bool isImageTranslucent() const; … … 400 449 401 450 int _s, _t, _r; 451 int _rowLength; 402 452 GLint _internalTextureFormat; 403 453 GLenum _pixelFormat; -
OpenSceneGraph/trunk/include/osg/PrimitiveSet
r12360 r12912 198 198 199 199 Type getType() const { return _primitiveType; } 200 201 virtual osg::PrimitiveSet* asPrimitiveSet() { return this; } 202 virtual const osg::PrimitiveSet* asPrimitiveSet() const { return this; } 203 200 204 virtual const GLvoid* getDataPointer() const { return 0; } 201 205 virtual unsigned int getTotalDataSize() const { return 0; } -
OpenSceneGraph/trunk/src/osg/BufferObject.cpp
r12522 r12912 205 205 entry.modifiedCount = entry.dataSource->getModifiedCount(); 206 206 207 _extensions->glBufferSubData(_profile._target, (GLintptrARB)entry.offset, (GLsizeiptrARB)entry.dataSize, entry.dataSource->getDataPointer()); 207 const osg::Image* image = entry.dataSource->asImage(); 208 if (image && !(image->isDataContiguous())) 209 { 210 unsigned int offset = entry.offset; 211 for(osg::Image::DataIterator img_itr(image); img_itr.valid(); ++img_itr) 212 { 213 //OSG_NOTICE<<"Copying to buffer object using DataIterator, offset="<<offset<<", size="<<img_itr.size()<<", data="<<(void*)img_itr.data()<<std::endl; 214 _extensions->glBufferSubData(_profile._target, (GLintptrARB)offset, (GLsizeiptrARB)img_itr.size(), img_itr.data()); 215 offset += img_itr.size(); 216 } 217 } 218 else 219 { 220 _extensions->glBufferSubData(_profile._target, (GLintptrARB)entry.offset, (GLsizeiptrARB)entry.dataSize, entry.dataSource->getDataPointer()); 221 } 208 222 209 223 } -
OpenSceneGraph/trunk/src/osg/DrawPixels.cpp
r11472 r12912 97 97 { 98 98 const GLvoid* pixels = _image->data(_offsetX,_offsetY); 99 glPixelStorei(GL_UNPACK_ALIGNMENT,_image->getPacking()); 99 100 glPixelStorei(GL_UNPACK_ROW_LENGTH,_image->s()); 100 101 glDrawPixels(_width,_height, … … 106 107 else 107 108 { 109 glPixelStorei(GL_UNPACK_ALIGNMENT,_image->getPacking()); 110 glPixelStorei(GL_UNPACK_ROW_LENGTH,0); 108 111 glDrawPixels(_image->s(), _image->t(), 109 112 (GLenum)_image->getPixelFormat(), -
OpenSceneGraph/trunk/src/osg/Image.cpp
r12842 r12912 49 49 } 50 50 51 Image::DataIterator::DataIterator(const Image* image): 52 _image(image), 53 _rowNum(0), 54 _imageNum(0), 55 _mipmapNum(0), 56 _currentPtr(0), 57 _currentSize(0) 58 { 59 assign(); 60 } 61 62 Image::DataIterator::DataIterator(const DataIterator& ri): 63 _image(ri._image), 64 _rowNum(ri._rowNum), 65 _imageNum(ri._imageNum), 66 _mipmapNum(ri._mipmapNum), 67 _currentPtr(0), 68 _currentSize(0) 69 { 70 assign(); 71 } 72 73 void Image::DataIterator::operator ++ () 74 { 75 if (!_image || _image->isDataContiguous()) 76 { 77 // for contiguous image data we never need more than one block of data 78 _currentPtr = 0; 79 _currentSize = 0; 80 return; 81 } 82 83 if (_image->isMipmap()) 84 { 85 // advance to next row 86 ++_rowNum; 87 88 if (_rowNum>=_image->t()) 89 { 90 // moved over end of current image so move to next 91 _rowNum = 0; 92 ++_imageNum; 93 94 if (_imageNum>=_image->r()) 95 { 96 // move to next mipmap 97 _imageNum = 0; 98 ++_mipmapNum; 99 100 if (_mipmapNum>=_image->getNumMipmapLevels()) 101 { 102 _currentPtr = 0; 103 _currentSize = 0; 104 return; 105 } 106 } 107 } 108 } 109 else 110 { 111 // advance to next row 112 ++_rowNum; 113 114 if (_rowNum>=_image->t()) 115 { 116 // moved over end of current image so move to next 117 _rowNum = 0; 118 ++_imageNum; 119 120 if (_imageNum>=_image->r()) 121 { 122 // we've moved off the end of the osg::Image so reset to null 123 _currentPtr = 0; 124 _currentSize = 0; 125 return; 126 } 127 } 128 } 129 130 assign(); 131 } 132 133 void Image::DataIterator::assign() 134 { 135 //OSG_NOTICE<<"DataIterator::assign A"<<std::endl; 136 if (!_image) 137 { 138 _currentPtr = 0; 139 _currentSize = 0; 140 return; 141 } 142 143 //OSG_NOTICE<<"DataIterator::assign B"<<std::endl; 144 145 if (_image->isDataContiguous()) 146 { 147 _currentPtr = _image->data(); 148 _currentSize = _image->getTotalSizeInBytesIncludingMipmaps(); 149 150 //OSG_NOTICE<<" _currentPtr="<<(void*)_currentPtr<<std::endl; 151 //OSG_NOTICE<<" _currentSize="<<_currentSize<<std::endl; 152 153 return; 154 } 155 156 //OSG_NOTICE<<"DataIterator::assign C"<<std::endl; 157 158 if (_image->isMipmap()) 159 { 160 //OSG_NOTICE<<"DataIterator::assign D"<<std::endl; 161 162 if (_mipmapNum>=_image->getNumMipmapLevels()) 163 { 164 _currentPtr = 0; 165 _currentSize = 0; 166 return; 167 } 168 const unsigned char* ptr = _image->getMipmapData(_mipmapNum); 169 170 int rowLength = _image->getRowLength()>>_mipmapNum; 171 if (rowLength==0) rowLength = 1; 172 173 int imageHeight = _image->t()>>_mipmapNum; 174 if (imageHeight==0) imageHeight = 1; 175 176 unsigned int rowWidthInBytes = Image::computeRowWidthInBytes(rowLength,_image->getPixelFormat(),_image->getDataType(),_image->getPacking()); 177 unsigned int imageSizeInBytes = rowWidthInBytes*imageHeight; 178 179 _currentPtr = ptr + rowWidthInBytes*_rowNum + imageSizeInBytes*_imageNum; 180 _currentSize = rowWidthInBytes; 181 } 182 else 183 { 184 //OSG_NOTICE<<"DataIterator::assign E"<<std::endl; 185 186 if (_imageNum>=_image->r() || _rowNum>=_image->t()) 187 { 188 _currentPtr = 0; 189 _currentSize = 0; 190 return; 191 } 192 193 //OSG_NOTICE<<"DataIterator::assign F"<<std::endl; 194 195 _currentPtr = _image->data(0, _rowNum, _imageNum); 196 _currentSize = _image->getRowSizeInBytes(); 197 return; 198 } 199 } 200 201 51 202 Image::Image() 52 203 :BufferData(), … … 55 206 _origin(BOTTOM_LEFT), 56 207 _s(0), _t(0), _r(0), 208 _rowLength(0), 57 209 _internalTextureFormat(0), 58 210 _pixelFormat(0), … … 72 224 _origin(image._origin), 73 225 _s(image._s), _t(image._t), _r(image._r), 226 _rowLength(0), 74 227 _internalTextureFormat(image._internalTextureFormat), 75 228 _pixelFormat(image._pixelFormat), … … 85 238 int size = image.getTotalSizeInBytesIncludingMipmaps(); 86 239 setData(new unsigned char [size],USE_NEW_DELETE); 87 memcpy(_data,image._data,size); 240 unsigned char* dest_ptr = _data; 241 for(DataIterator itr(&image); itr.valid(); ++itr) 242 { 243 memcpy(dest_ptr, itr.data(), itr.size()); 244 dest_ptr += itr.size(); 245 } 88 246 } 89 247 } … … 511 669 } 512 670 671 unsigned int Image::computeBlockSize(GLenum pixelFormat, GLenum packing) 672 { 673 switch(pixelFormat) 674 { 675 case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): 676 case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): 677 return osg::maximum(8u,packing); // block size of 8 678 case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): 679 case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): 680 case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG): 681 case(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG): 682 case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG): 683 case(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG): 684 case(GL_ETC1_RGB8_OES): 685 return osg::maximum(16u,packing); // block size of 16 686 case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT): 687 case(GL_COMPRESSED_RED_RGTC1_EXT): 688 return osg::maximum(8u,packing); // block size of 8 689 break; 690 case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): 691 case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT): 692 return osg::maximum(16u,packing); // block size of 16 693 default: 694 break; 695 } 696 return packing; 697 } 698 513 699 unsigned int Image::computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing) 514 700 { … … 518 704 //OSG_INFO << "width="<<width<<" pixelSize="<<pixelSize<<" width in bit="<<widthInBits<<" packingInBits="<<packingInBits<<" widthInBits%packingInBits="<<widthInBits%packingInBits<<std::endl; 519 705 return (widthInBits/packingInBits + ((widthInBits%packingInBits)?1:0))*packing; 706 } 707 708 unsigned int Image::computeImageSizeInBytes(int width,int height, int depth, GLenum pixelFormat,GLenum type,int packing) 709 { 710 if (width==0 || height==0 || depth==0) return 0; 711 712 return osg::maximum( 713 Image::computeRowWidthInBytes(width,pixelFormat,type,packing)*height*depth, 714 computeBlockSize(pixelFormat, packing) 715 ); 520 716 } 521 717 … … 582 778 int t = _t; 583 779 int r = _r; 584 585 unsigned int maxValue = 0; 586 for(unsigned int i=0;i<_mipmapData.size() && _mipmapData[i];++i) 587 { 780 unsigned int totalSize = 0; 781 for(unsigned int i=0;i<_mipmapData.size()+1;++i) 782 { 783 totalSize += computeImageSizeInBytes(s, t, r, _pixelFormat, _dataType, _packing); 784 588 785 s >>= 1; 589 786 t >>= 1; 590 787 r >>= 1; 591 maxValue = maximum(maxValue,_mipmapData[i]); 788 789 if (s<1) s=1; 790 if (t<1) t=1; 791 if (r<1) r=1; 592 792 } 593 594 if (s==0) s=1; 595 if (t==0) t=1; 596 if (r==0) r=1; 597 598 unsigned int sizeOfLastMipMap = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing)* r*t; 599 switch(_pixelFormat) 600 { 601 case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): 602 case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): 603 sizeOfLastMipMap = maximum(sizeOfLastMipMap, 8u); // block size of 8 604 break; 605 case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): 606 case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): 607 case(GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG): 608 case(GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG): 609 case(GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG): 610 case(GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG): 611 case(GL_ETC1_RGB8_OES): 612 sizeOfLastMipMap = maximum(sizeOfLastMipMap, 16u); // block size of 16 613 break; 614 case(GL_COMPRESSED_SIGNED_RED_RGTC1_EXT): 615 case(GL_COMPRESSED_RED_RGTC1_EXT): 616 sizeOfLastMipMap = maximum(sizeOfLastMipMap, 8u); // block size of 8 617 break; 618 case(GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT): 619 case(GL_COMPRESSED_RED_GREEN_RGTC2_EXT): 620 sizeOfLastMipMap = maximum(sizeOfLastMipMap, 16u); // block size of 8 621 break; 622 default: break; 623 } 624 625 // OSG_INFO<<"sizeOfLastMipMap="<<sizeOfLastMipMap<<"\ts="<<s<<"\tt="<<t<<"\tr"<<r<<std::endl; 626 627 return maxValue+sizeOfLastMipMap; 628 793 794 return totalSize; 629 795 } 630 796 … … 686 852 _dataType = type; 687 853 _packing = packing; 854 _rowLength = 0; 688 855 689 856 // preserve internalTextureFormat if already set, otherwise … … 701 868 _dataType = 0; 702 869 _packing = 0; 870 _rowLength = 0; 703 871 704 872 // commenting out reset of _internalTextureFormat as we are changing … … 715 883 unsigned char *data, 716 884 AllocationMode mode, 717 int packing) 885 int packing, 886 int rowLength) 718 887 { 719 888 _mipmapData.clear(); … … 730 899 731 900 _packing = packing; 901 _rowLength = rowLength; 732 902 733 903 dirty(); … … 741 911 742 912 glPixelStorei(GL_PACK_ALIGNMENT,_packing); 913 glPixelStorei(GL_PACK_ROW_LENGTH,_rowLength); 743 914 744 915 glReadPixels(x,y,width,height,format,type,_data); … … 776 947 GLint depth; 777 948 GLint packing; 949 GLint rowLength; 778 950 779 951 GLint numMipMaps = 0; … … 857 1029 glGetIntegerv(GL_UNPACK_ALIGNMENT, &packing); 858 1030 glPixelStorei(GL_PACK_ALIGNMENT, packing); 1031 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowLength); 1032 glPixelStorei(GL_PACK_ROW_LENGTH, rowLength); 859 1033 860 1034 _data = data; … … 869 1043 _allocationMode=USE_NEW_DELETE; 870 1044 _packing = packing; 871 1045 _rowLength = rowLength; 1046 872 1047 for(i=0;i<numMipMaps;++i) 873 1048 { … … 887 1062 glGetIntegerv(GL_UNPACK_ALIGNMENT, &packing); 888 1063 glPixelStorei(GL_PACK_ALIGNMENT, packing); 1064 glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowLength); 1065 glPixelStorei(GL_PACK_ROW_LENGTH, rowLength); 889 1066 890 1067 unsigned int total_size = 0; … … 928 1105 _allocationMode=USE_NEW_DELETE; 929 1106 _packing = packing; 1107 _rowLength = rowLength; 930 1108 931 1109 for(i=0;i<numMipMaps;++i) … … 970 1148 PixelStorageModes psm; 971 1149 psm.pack_alignment = _packing; 1150 psm.pack_row_length = _rowLength; 972 1151 psm.unpack_alignment = _packing; 973 1152 … … 988 1167 _s = s; 989 1168 _t = t; 1169 _rowLength = 0; 990 1170 _dataType = newDataType; 991 1171 setData(newData,USE_NEW_DELETE); … … 1035 1215 PixelStorageModes psm; 1036 1216 psm.pack_alignment = _packing; 1037 psm.pack_row_length = _s; 1038 psm.unpack_alignment = _packing; 1217 psm.pack_row_length = _rowLength!=0 ? _rowLength : _s; 1218 psm.unpack_alignment = source->getPacking(); 1219 psm.unpack_row_length = source->getRowLength(); 1039 1220 1040 1221 GLint status = gluScaleImage(&psm, _pixelFormat, … … 1048 1229 data_destination); 1049 1230 1050 glPixelStorei(GL_PACK_ROW_LENGTH,0);1051 1052 1231 if (status!=0) 1053 1232 { … … 1068 1247 if (_mipmapData.empty()) 1069 1248 { 1070 1249 unsigned int rowStepInBytes = getRowStepInBytes(); 1250 unsigned int imageStepInBytes = getImageStepInBytes(); 1251 1071 1252 for(int r=0;r<_r;++r) 1072 1253 { 1073 1254 for (int t=0; t<_t; ++t) 1074 1255 { 1075 unsigned char* rowData = _data +t*getRowSizeInBytes()+r*getImageSizeInBytes();1256 unsigned char* rowData = _data + t*rowStepInBytes + r*imageStepInBytes; 1076 1257 unsigned char* left = rowData ; 1077 1258 unsigned char* right = rowData + ((_s-1)*getPixelSizeInBits())/8; … … 1098 1279 } 1099 1280 1100 void flipImageVertical(unsigned char* top, unsigned char* bottom, unsigned int rowSize )1281 void flipImageVertical(unsigned char* top, unsigned char* bottom, unsigned int rowSize, unsigned int rowStep) 1101 1282 { 1102 1283 while(top<bottom) 1103 1284 { 1104 for(unsigned int i=0;i<rowSize;++i, ++top,++bottom) 1105 { 1106 unsigned char temp=*top; 1107 *top = *bottom; 1108 *bottom = temp; 1109 } 1110 bottom -= 2*rowSize; 1285 unsigned char* t = top; 1286 unsigned char* b = bottom; 1287 for(unsigned int i=0;i<rowSize;++i, ++t,++b) 1288 { 1289 unsigned char temp=*t; 1290 *t = *b; 1291 *b = temp; 1292 } 1293 top += rowStep; 1294 bottom -= rowStep; 1111 1295 } 1112 1296 } … … 1126 1310 return; 1127 1311 } 1312 1313 unsigned int rowSize = getRowSizeInBytes(); 1314 unsigned int rowStep = getRowStepInBytes(); 1128 1315 1129 1316 if (_mipmapData.empty()) … … 1136 1323 { 1137 1324 // its not a compressed image, so implement flip oursleves. 1138 1139 unsigned int rowSize = computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing);1140 1325 unsigned char* top = data(0,0,r); 1141 unsigned char* bottom = top + (_t-1)*rowS ize;1326 unsigned char* bottom = top + (_t-1)*rowStep; 1142 1327 1143 flipImageVertical(top, bottom, rowSize );1328 flipImageVertical(top, bottom, rowSize, rowStep); 1144 1329 } 1145 1330 } … … 1150 1335 { 1151 1336 // its not a compressed image, so implement flip oursleves. 1152 unsigned int rowSize = computeRowWidthInBytes(_s,_pixelFormat,_dataType,_packing);1153 1337 unsigned char* top = data(0,0,0); 1154 unsigned char* bottom = top + (_t-1)*rowS ize;1155 1156 flipImageVertical(top, bottom, rowSize );1338 unsigned char* bottom = top + (_t-1)*rowStep; 1339 1340 flipImageVertical(top, bottom, rowSize, rowStep); 1157 1341 } 1158 1342 … … 1170 1354 { 1171 1355 // its not a compressed image, so implement flip oursleves. 1172 unsigned int rowSize = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing);1173 1356 unsigned char* top = _data+_mipmapData[i]; 1174 unsigned char* bottom = top + (t-1)*rowS ize;1175 1176 flipImageVertical(top, bottom, rowSize );1357 unsigned char* bottom = top + (t-1)*rowStep; 1358 1359 flipImageVertical(top, bottom, rowSize, rowStep); 1177 1360 } 1178 1361 } … … 1201 1384 } 1202 1385 1203 unsigned int sizeOfSlice = getImageSizeInBytes(); 1204 1205 int r_top = 0; 1206 int r_bottom = _r-1; 1207 for(; r_top<r_bottom; ++r_top,--r_bottom) 1208 { 1209 unsigned char* top_slice = data(0,0,r_top); 1210 unsigned char* bottom_slice = data(0,0,r_bottom); 1211 for(unsigned int i=0; i<sizeOfSlice; ++i, ++top_slice, ++bottom_slice) 1212 { 1213 std::swap(*top_slice, *bottom_slice); 1386 unsigned int sizeOfRow = getRowSizeInBytes(); 1387 1388 int r_front = 0; 1389 int r_back = _r-1; 1390 for(; r_front<r_back; ++r_front,--r_back) 1391 { 1392 for(int row=0; row<_t; ++row) 1393 { 1394 unsigned char* front = data(0, row, r_front); 1395 unsigned char* back = data(0, row, r_back); 1396 for(unsigned int i=0; i<sizeOfRow; ++i, ++front, ++back) 1397 { 1398 std::swap(*front, *back); 1399 } 1214 1400 } 1215 1401 } … … 1426 1612 dstate->setTextureAttributeAndModes(0, texture,osg::StateAttribute::ON); 1427 1613 1428 // set up the geoset. 1614 // set up the geoset. unsigned int rowSize = computeRowWidthInBytes(s,_pixelFormat,_dataType,_packing); 1615 1429 1616 Geometry* geom = new Geometry; 1430 1617 geom->setStateSet(dstate); -
OpenSceneGraph/trunk/src/osg/Texture.cpp
r12727 r12912 1843 1843 1844 1844 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 1845 unsigned int rowLength = image->getRowLength(); 1845 1846 1846 1847 bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); … … 1892 1893 PixelStorageModes psm; 1893 1894 psm.pack_alignment = image->getPacking(); 1895 psm.pack_row_length = image->getRowLength(); 1894 1896 psm.unpack_alignment = image->getPacking(); 1895 1897 … … 1900 1902 dataPtr); 1901 1903 1904 rowLength = 0; 1902 1905 } 1903 1906 … … 1911 1914 state.bindPixelBufferObject(pbo); 1912 1915 dataPtr = reinterpret_cast<unsigned char*>(pbo->getOffset(image->getBufferIndex())); 1916 rowLength = 0; 1913 1917 #ifdef DO_TIMING 1914 1918 OSG_NOTICE<<"after PBO "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; … … 1919 1923 pbo = 0; 1920 1924 } 1925 1926 glPixelStorei(GL_UNPACK_ROW_LENGTH,rowLength); 1921 1927 1922 1928 if( !mipmappingRequired || useHardwareMipMapGeneration) … … 2109 2115 2110 2116 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 2117 unsigned int rowLength = image->getRowLength(); 2111 2118 2112 2119 unsigned char* dataPtr = (unsigned char*)image->data(); … … 2148 2155 inwidth,inheight,image->getDataType(), 2149 2156 dataPtr); 2157 2158 rowLength = 0; 2150 2159 } 2151 2160 … … 2160 2169 state.bindPixelBufferObject(pbo); 2161 2170 dataPtr = reinterpret_cast<unsigned char*>(pbo->getOffset(image->getBufferIndex())); 2171 rowLength = 0; 2162 2172 #ifdef DO_TIMING 2163 2173 OSG_NOTICE<<"after PBO "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; … … 2168 2178 pbo = 0; 2169 2179 } 2180 2181 glPixelStorei(GL_UNPACK_ROW_LENGTH,rowLength); 2170 2182 2171 2183 if( !mipmappingRequired || useHardwareMipMapGeneration) -
OpenSceneGraph/trunk/src/osg/Texture1D.cpp
r11817 r12912 287 287 288 288 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 289 glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); 289 290 290 291 static MyCompressedTexImage1DArbProc glCompressedTexImage1D_ptr = -
OpenSceneGraph/trunk/src/osg/Texture2DArray.cpp
r12292 r12912 456 456 457 457 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 458 glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); 458 459 459 460 bool useHardwareMipmapGeneration = -
OpenSceneGraph/trunk/src/osg/Texture3D.cpp
r11881 r12912 381 381 382 382 glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); 383 glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); 383 384 384 385 bool useHardwareMipMapGeneration = !image->isMipmap() && _useHardwareMipMapGeneration && texExtensions->isGenerateMipMapSupported(); -
OpenSceneGraph/trunk/src/osg/TextureRectangle.cpp
r11808 r12912 313 313 314 314 glPixelStorei(GL_UNPACK_ALIGNMENT, image->getPacking()); 315 glPixelStorei(GL_UNPACK_ROW_LENGTH,image->getRowLength()); 315 316 316 317 bool useClientStorage = extensions->isClientStorageSupported() && getClientStorageHint(); … … 393 394 394 395 glPixelStorei(GL_UNPACK_ALIGNMENT, image->getPacking()); 396 unsigned int rowLength = image->getRowLength(); 397 395 398 396 399 #ifdef DO_TIMING … … 404 407 state.bindPixelBufferObject(pbo); 405 408 dataPtr = reinterpret_cast<unsigned char*>(pbo->getOffset(image->getBufferIndex())); 409 rowLength = 0; 406 410 #ifdef DO_TIMING 407 411 OSG_NOTICE<<"after PBO "<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 408 412 #endif 409 413 } 410 414 415 glPixelStorei(GL_UNPACK_ROW_LENGTH,rowLength); 411 416 412 417 if(isCompressedInternalFormat(_internalFormat) && extensions->isCompressedTexSubImage2DSupported()) -
OpenSceneGraph/trunk/src/osgDB/OutputStream.cpp
r12896 r12912 370 370 // _data 371 371 unsigned int size = img->getTotalSizeInBytesIncludingMipmaps(); 372 writeSize(size); writeCharArray( (char*)img->data(), size ); 372 writeSize(size); 373 374 for(osg::Image::DataIterator img_itr(img); img_itr.valid(); ++img_itr) 375 { 376 writeCharArray( (char*)img_itr.data(), img_itr.size() ); 377 } 373 378 374 379 // _mipmapData 375 const osg::Image::MipmapDataType& levels = img->getMipmapLevels(); 376 writeSize(levels.size()); 377 for ( osg::Image::MipmapDataType::const_iterator itr=levels.begin(); 378 itr!=levels.end(); ++itr ) 380 unsigned int numMipmaps = img->getNumMipmapLevels()-1; 381 writeSize(numMipmaps); 382 int s = img->s(); 383 int t = img->t(); 384 int r = img->r(); 385 unsigned int offset = 0; 386 for (unsigned int i=0; i<numMipmaps; ++i) 379 387 { 380 *this << *itr; 388 unsigned int size = osg::Image::computeImageSizeInBytes(s,t,r,img->getPixelFormat(),img->getDataType(),img->getPacking()); 389 offset += size; 390 391 *this << offset; 392 393 s >>= 1; 394 t >>= 1; 395 r >>= 1; 396 if (s<1) s=1; 397 if (t<1) t=1; 398 if (r<1) r=1; 381 399 } 382 400 } -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/ConvertFromInventor.cpp
r12625 r12912 1094 1094 static osg::Image* loadImage(const char *fileName, osgDB::ReaderWriter::Options *options) 1095 1095 { 1096 osg:: Image *osgImage = osgDB::readImageFile(fileName, options);1096 osg::ref_ptr<osg::Image> osgImage = osgDB::readImageFile(fileName, options); 1097 1097 1098 1098 if (!osgImage) 1099 { 1099 1100 OSG_WARN << NOTIFY_HEADER << "Could not read texture file '" << fileName << "'."; 1100 1101 return osgImage; 1101 return 0; 1102 } 1103 1104 if (!osgImage->isDataContiguous()) 1105 { 1106 OSG_WARN << NOTIFY_HEADER << "Inventor cannot handle non contiguous image data found in texture file '" << fileName << "'."; 1107 return 0; 1108 } 1109 1110 return osgImage.release(); 1102 1111 } 1103 1112 -
OpenSceneGraph/trunk/src/osgPlugins/Inventor/ReaderWriterIV.cpp
r12577 r12912 143 143 { 144 144 OSG_NOTICE << "osgDB::ReaderWriterIV::readNode() " 145 << "File " << fileName .data()145 << "File " << fileName 146 146 << " loaded successfully." << std::endl; 147 147 } … … 155 155 { 156 156 OSG_WARN << "osgDB::ReaderWriterIV::readNode() " 157 << "Failed to load file " << fileName .data()157 << "Failed to load file " << fileName 158 158 << "." << std::endl; 159 159 } -
OpenSceneGraph/trunk/src/osgPlugins/bmp/ReaderWriterBMP.cpp
r12574 r12912 528 528 for (int y = 0; y < img.t(); ++y) 529 529 { 530 const unsigned char* imgp = img.data( ) + img.s() * y * channelsPerPixel;530 const unsigned char* imgp = img.data(0, y); 531 531 for (int x = 0; x < img.s(); ++x) 532 532 { -
OpenSceneGraph/trunk/src/osgPlugins/dds/ReaderWriterDDS.cpp
r12597 r12912 879 879 } 880 880 881 int size = img->getTotalSizeInBytes();882 883 881 // set even more flags 884 882 if( !img->isMipmap() ) { … … 896 894 897 895 ddsd.dwMipMapCount = img->getNumMipmapLevels(); 898 899 size = img->getTotalSizeInBytesIncludingMipmaps();900 896 901 897 OSG_INFO<<"writing out with mipmaps ddsd.dwMipMapCount"<<ddsd.dwMipMapCount<<std::endl; … … 914 910 fout.write("DDS ", 4); /* write FOURCC */ 915 911 fout.write(reinterpret_cast<char*>(&ddsd), sizeof(ddsd)); /* write file header */ 916 fout.write(reinterpret_cast<const char*>(img->data()), size ); 912 913 for(osg::Image::DataIterator itr(img); itr.valid(); ++itr) 914 { 915 fout.write(reinterpret_cast<const char*>(itr.data()), itr.size() ); 916 } 917 917 918 918 // Check for correct saving -
OpenSceneGraph/trunk/src/osgPlugins/exr/ReaderWriterEXR.cpp
r12292 r12912 277 277 if (dataType == GL_HALF_FLOAT_ARB) 278 278 { 279 half* pOut = (half*) img.data();280 279 for (long i = height-1; i >= 0; i--) 281 280 { 281 half* pOut = (half*) img.data(0,i); 282 282 for (long j = 0 ; j < width; j++) 283 283 { -
OpenSceneGraph/trunk/src/osgPlugins/hdr/hdrwriter.cpp
r12292 r12912 37 37 38 38 39 bool HDRWriter::writeRLE(const osg::Image *img, std::ostream& fout)40 {41 return writePixelsRLE(fout,(float*) img->data(), img->s(), img->t());42 }43 44 39 bool HDRWriter::writeRAW(const osg::Image *img, std::ostream& fout) 45 40 { 46 return writePixelsRAW(fout,(unsigned char*) img->data(), img->s() * img->t()); 47 } 48 49 50 51 41 bool result = true; 42 for(int row=0; result && row<img->t(); ++row) 43 { 44 result = writePixelsRAW(fout,(unsigned char*) img->data(0, row), img->s()); 45 } 46 return result; 47 } 52 48 53 49 /* number of floats per pixel */ … … 87 83 /* These routines can be made faster by allocating a larger buffer and 88 84 fread-ing and fwrite-ing the data in larger chunks */ 89 bool HDRWriter::write PixelsNoRLE( std::ostream& fout, float* data, int numpixels)85 bool HDRWriter::writeNoRLE( std::ostream& fout, const osg::Image* img) 90 86 { 91 87 unsigned char rgbe[4]; 92 88 93 while (numpixels-- > 0)89 for(int row=0; row<img->t(); ++row) 94 90 { 95 float2rgbe( 91 float* data = (float*)img->data(0,row); 92 for(int column=0; column<img->s(); ++column) 93 { 94 float2rgbe( 96 95 rgbe, 97 96 data[R], … … 99 98 data[B] 100 99 ); 101 data += RGBE_DATA_SIZE; 102 fout.write(reinterpret_cast<const char*>(rgbe), sizeof(rgbe)); //img->getTotalSizeInBytesIncludingMipmaps() 100 data += RGBE_DATA_SIZE; 101 fout.write(reinterpret_cast<const char*>(rgbe), sizeof(rgbe)); 102 } 103 103 } 104 104 105 return true; 105 106 } … … 184 185 } 185 186 186 bool HDRWriter::writePixelsRLE( std::ostream& fout, float* data, int scanline_width, int num_scanlines ) 187 188 { 187 bool HDRWriter::writeRLE( const osg::Image* img, std::ostream& fout) 188 { 189 int scanline_width = img->s(); 190 int num_scanlines = img->t(); 191 189 192 unsigned char rgbe[4]; 190 193 unsigned char *buffer; … … 192 195 if ((scanline_width < MINELEN)||(scanline_width > MAXELEN)) 193 196 // run length encoding is not allowed so write flat 194 return write PixelsNoRLE(fout,data,scanline_width*num_scanlines);197 return writeNoRLE(fout,img); 195 198 196 199 buffer = (unsigned char *)malloc(sizeof(unsigned char)*4*scanline_width); 197 200 if (buffer == NULL) 198 201 // no buffer space so write flat 199 return writePixelsNoRLE(fout,data,scanline_width*num_scanlines); 200 201 while(num_scanlines-- > 0) 202 { 202 return writeNoRLE(fout,img); 203 204 for(int row = 0; row<num_scanlines; ++row) 205 { 206 float* data = (float*) img->data(0, row); 207 203 208 rgbe[0] = 2; 204 209 rgbe[1] = 2; -
OpenSceneGraph/trunk/src/osgPlugins/hdr/hdrwriter.h
r12292 r12912 40 40 41 41 // can read or write pixels in chunks of any size including single pixels 42 static bool write PixelsNoRLE( std::ostream& fout, float* data, int numpixels);42 static bool writeNoRLE( std::ostream& fout, const osg::Image* image); 43 43 static bool writePixelsRAW( std::ostream& fout, unsigned char* data, int numpixels); 44 44 … … 46 46 // must be called to read or write whole scanlines 47 47 static bool writeBytesRLE(std::ostream& fout, unsigned char *data, int numbytes); 48 static bool writePixelsRLE( std::ostream& fout, float* data, int scanline_width, int num_scanlines );49 48 50 49 // inline conversions -
OpenSceneGraph/trunk/src/osgPlugins/imageio/ReaderWriterImageIO.cpp
r12789 r12912 1200 1200 WriteResult writeImageStream(const osg::Image& osg_image, std::ostream& fout, const osgDB::ReaderWriter::Options* the_options) const 1201 1201 { 1202 if (!osg_image.isDataContiguous()) 1203 { 1204 return WriteResult::FILE_NOT_HANDLED; 1205 } 1206 1202 1207 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 1203 1208 … … 1236 1241 WriteResult writeImageFile(const osg::Image& osg_image, const std::string& full_file_name, const osgDB::ReaderWriter::Options* the_options) const 1237 1242 { 1243 if (!osg_image.isDataContiguous()) 1244 { 1245 return WriteResult::FILE_NOT_HANDLED; 1246 } 1247 1248 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 1238 1249 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 1239 1250 // Call ImageIO to load the image. … … 1269 1280 if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; 1270 1281 1282 if (!osg_image.isDataContiguous()) 1283 { 1284 return WriteResult::FILE_NOT_HANDLED; 1285 } 1286 1287 WriteResult ret_val = WriteResult::ERROR_IN_WRITING_FILE; 1271 1288 #if 1 1272 1289 // FIXME: Something may need to provide a proper writable location for the files. -
OpenSceneGraph/trunk/src/osgPlugins/ive/Image.cpp
r11807 r12912 73 73 out->writeInt(size); 74 74 // Write the data 75 out->writeCharArray((char*)data(), size); 75 for(osg::Image::DataIterator itr(this); itr.valid(); ++itr) 76 { 77 out->writeCharArray((char*)itr.data(), itr.size()); 78 } 76 79 } 77 80 -
OpenSceneGraph/trunk/src/osgPlugins/jp2/ReaderWriterJP2.cpp
r12597 r12912 354 354 if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; 355 355 356 if (!img.isDataContiguous()) 357 { 358 OSG_WARN<<"Warning: Writing of image data, that is non contiguous, is not supported by JPEG2000 plugin."<<std::endl; 359 return WriteResult::ERROR_IN_WRITING_FILE; 360 } 361 356 362 jas_image_cmptparm_t cmptparms[4]; 357 363 jas_image_cmptparm_t *cmptparm; … … 430 436 WriteResult writeImage(const osg::Image& img, std::ostream& fout, const Options* options) const 431 437 { 438 if (!img.isDataContiguous()) 439 { 440 OSG_WARN<<"Warning: Writing of image data, that is non contiguous, is not supported by JPEG2000 plugin."<<std::endl; 441 return WriteResult::ERROR_IN_WRITING_FILE; 442 } 443 432 444 jas_image_cmptparm_t cmptparms[4]; 433 445 jas_image_cmptparm_t *cmptparm; -
OpenSceneGraph/trunk/src/osgPlugins/jpeg/ReaderWriterJPEG.cpp
r12545 r12912 648 648 WriteResult::WriteStatus write_JPEG_file (std::ostream &fout, const osg::Image &img, int quality = 100) const 649 649 { 650 if (!img.isDataContiguous()) 651 { 652 OSG_WARN<<"Warning: Writing of image data, that is non contiguous, is not supported by JPEG plugin."<<std::endl; 653 return WriteResult::ERROR_IN_WRITING_FILE; 654 } 655 650 656 int image_width = img.s(); 651 657 int image_height = img.t(); -
OpenSceneGraph/trunk/src/osgPlugins/logo/ReaderWriterLOGO.cpp
r11516 r12912 153 153 { 154 154 osg::Image *img = (*p).get(); 155 glPixelStorei(GL_UNPACK_ALIGNMENT, img->getPacking()); 156 glPixelStorei(GL_UNPACK_ROW_LENGTH, img->getRowLength()); 155 157 x = place[i][0] + xi * img->s(); 156 158 if( i == Center || i == UpperLeft || i == UpperRight || i == UpperCenter) -
OpenSceneGraph/trunk/src/osgPlugins/nvtt/NVTTImageProcessor.cpp
r12292 r12912 47 47 48 48 // Convert RGBA to BGRA : nvtt only accepts BGRA pixel format 49 void convertRGBAToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData);49 void convertRGBAToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ); 50 50 51 51 // Convert RGB to BGRA : nvtt only accepts BGRA pixel format 52 void convertRGBToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData);52 void convertRGBToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ); 53 53 54 54 }; … … 176 176 177 177 // Convert RGBA to BGRA : nvtt only accepts BGRA pixel format 178 void NVTTProcessor::convertRGBAToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData ) 179 { 180 for (unsigned n=0; n<outputData.size(); n += 4) 181 { 182 outputData[n] = inputData[n+2]; 183 outputData[n+1] = inputData[n+1]; 184 outputData[n+2] = inputData[n]; 185 outputData[n+3] = inputData[n+3]; 178 void NVTTProcessor::convertRGBAToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ) 179 { 180 unsigned int n=0; 181 for(int row=0; row<image.t(); ++row) 182 { 183 const unsigned char* data = image.data(0,row); 184 for(int column=0; column<image.s(); ++column) 185 { 186 outputData[n] = data[column*4+2]; 187 outputData[n+1] = data[column*4+1]; 188 outputData[n+2] = data[column*4+n]; 189 outputData[n+3] = data[column*4+3]; 190 n+=4; 191 } 186 192 } 187 193 } 188 194 189 195 // Convert RGB to BGRA : nvtt only accepts BGRA pixel format 190 void NVTTProcessor::convertRGBToBGRA( std::vector<unsigned char>& outputData, const unsigned char* inputData ) 191 { 192 unsigned int numberOfPixels = outputData.size()/4; 193 for (unsigned n=0; n<numberOfPixels; n++) 194 { 195 outputData[4*n] = inputData[3*n+2]; 196 outputData[4*n+1] = inputData[3*n+1]; 197 outputData[4*n+2] = inputData[3*n]; 198 outputData[4*n+3] = 255; 196 void NVTTProcessor::convertRGBToBGRA( std::vector<unsigned char>& outputData, const osg::Image& image ) 197 { 198 unsigned int n=0; 199 for(int row=0; row<image.t(); ++row) 200 { 201 const unsigned char* data = image.data(0,row); 202 for(int column=0; column<image.s(); ++column) 203 { 204 outputData[n] = data[column*3+2]; 205 outputData[n+1] = data[column*3+1]; 206 outputData[n+2] = data[column*3+n]; 207 outputData[n+3] = 255; 208 n+=4; 209 } 199 210 } 200 211 } … … 228 239 if (image.getPixelFormat() == GL_RGB) 229 240 { 230 convertRGBToBGRA( imageData, image .data());241 convertRGBToBGRA( imageData, image ); 231 242 } 232 243 else 233 244 { 234 convertRGBAToBGRA( imageData, image .data());245 convertRGBAToBGRA( imageData, image ); 235 246 } 236 247 inputOptions.setMipmapData(&imageData[0],image.s(),image.t()); -
OpenSceneGraph/trunk/src/osgPlugins/pov/ReaderWriterPOV.cpp
r12292 r12912 102 102 if( !acceptsExtension( ext ) ) return WriteResult::FILE_NOT_HANDLED; 103 103 104 notify( NOTICE ) << "ReaderWriterPOV::writeNode() Writing file " 105 << fileName.data() << endl; 104 notify( NOTICE ) << "ReaderWriterPOV::writeNode() Writing file " << fileName << endl; 106 105 107 106 osgDB::ofstream fout( fileName.c_str(), ios::out | ios::trunc ); -
OpenSceneGraph/trunk/src/osgPlugins/rgb/ReaderWriterRGB.cpp
r11563 r12912 661 661 virtual WriteResult writeImage(const osg::Image& img,std::ostream& fout,const osgDB::ReaderWriter::Options*) const 662 662 { 663 if (img.isCompressed()) 664 { 665 OSG_NOTICE<<"Warning: RGB plugin does not supporting writing compressed imagery."<<std::endl; 666 return WriteResult::ERROR_IN_WRITING_FILE; 667 } 668 if (!img.isDataContiguous()) 669 { 670 OSG_NOTICE<<"Warning: RGB plugin does not supporting writing non contiguous imagery."<<std::endl; 671 return WriteResult::ERROR_IN_WRITING_FILE; 672 } 673 663 674 return writeRGBStream(img,fout,""); 664 675 } … … 666 677 virtual WriteResult writeImage(const osg::Image &img,const std::string& fileName, const osgDB::ReaderWriter::Options*) const 667 678 { 679 if (img.isCompressed()) 680 { 681 OSG_NOTICE<<"Warning: RGB plugin does not supporting writing compressed imagery."<<std::endl; 682 return WriteResult::ERROR_IN_WRITING_FILE; 683 } 684 if (!img.isDataContiguous()) 685 { 686 OSG_NOTICE<<"Warning: RGB plugin does not supporting writing non contiguous imagery."<<std::endl; 687 return WriteResult::ERROR_IN_WRITING_FILE; 688 } 689 668 690 std::string ext = osgDB::getFileExtension(fileName); 669 691 if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; -
OpenSceneGraph/trunk/src/osgPlugins/tga/ReaderWriterTGA.cpp
r12574 r12912 546 546 bool saveTGAStream(const osg::Image& image, std::ostream& fout) const 547 547 { 548 if (!image.data()) return false; 549 548 550 // At present, I will only save the image to unmapped RGB format 549 551 // Other data types can be added soon with different options … … 554 556 int numPerPixel = image.computeNumComponents(pixelFormat); 555 557 int pixelMultiplier = (image.getDataType()==GL_FLOAT ? 255 : 1); 556 const unsigned char* data = image.data();557 if ( !data ) return false;558 558 559 559 // Headers … … 582 582 for (int y=0; y<height; ++y) 583 583 { 584 const unsigned char* ptr = data + y * width * numPerPixel;584 const unsigned char* ptr = image.data(0,y); 585 585 for (int x=0; x<width; ++x) 586 586 { -
OpenSceneGraph/trunk/src/osgPlugins/xine/ReaderWriterXine.cpp
r12262 r12912 193 193 GLenum pixelFormat = GL_BGRA; 194 194 195 #if 0 196 if (!imageStream->_ready) 197 { 198 imageStream->allocateImage(width,height,1,pixelFormat,GL_UNSIGNED_BYTE,1); 199 imageStream->setInternalTextureFormat(GL_RGBA); 200 } 201 202 osg::Timer_t start_tick = osg::Timer::instance()->tick(); 203 204 memcpy(imageStream->data(),data,imageStream->getTotalSizeInBytes()); 205 206 OSG_INFO<<"image memcpy size="<<imageStream->getTotalSizeInBytes()<<" time="<<osg::Timer::instance()->delta_m(start_tick,osg::Timer::instance()->tick())<<"ms"<<std::endl; 207 208 209 imageStream->dirty(); 210 #else 211 imageStream->setImage(width,height,1, 195 imageStream->setImage(width,height,1, 212 196 GL_RGB, 213 197 pixelFormat,GL_UNSIGNED_BYTE, … … 215 199 osg::Image::NO_DELETE, 216 200 1); 217 #endif 201 218 202 imageStream->_ready = true; 219 203 } -
OpenSceneGraph/trunk/src/osgText/Glyph.cpp
r12407 r12912 475 475 476 476 glPixelStorei(GL_UNPACK_ALIGNMENT,getPacking()); 477 glPixelStorei(GL_UNPACK_ROW_LENGTH,getRowLength()); 477 478 478 479 glTexSubImage2D(GL_TEXTURE_2D,0,
