Show
Ignore:
Timestamp:
01/24/12 15:34:02 (2 years ago)
Author:
robert
Message:

Added support for using GL_UNPACK_ROW_LENGTH in conjunction with texture's + osg::Image via new RowLength?
parameter in osg::Image. To support this Image::setData(..) now has a new optional rowLength parameter which
defaults to 0, which provides the original behaviour, Image::setRowLength(int) and int Image::getRowLength() are also provided.

With the introduction of RowLength? support in osg::Image it is now possible to create a sub image where
the t size of the image are smaller than the row length, useful for when you have a large image on the CPU
and which to use a small portion of it on the GPU. However, when these sub images are created the data
within the image is no longer contiguous so data access can no longer assume that all the data is in
one block. The new method Image::isDataContiguous() enables the user to check whether the data is contiguous,
and if not one can either access the data row by row using Image::data(column,row,image) accessor, or use the
new Image::DataIterator? for stepping through each block on memory assocatied with the image.

To support the possibility of non contiguous osg::Image usage of image objects has had to be updated to
check DataContiguous? and handle the case or use access via the DataIerator? or by row by row. To achieve
this a relatively large number of files has had to be modified, in particular the texture classes and
image plugins that doing writing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/nvtt/NVTTImageProcessor.cpp

    r12292 r12912  
    4747 
    4848    // 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 ); 
    5050 
    5151    // 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 ); 
    5353 
    5454}; 
     
    176176 
    177177// 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]; 
     178void 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        } 
    186192    } 
    187193} 
    188194 
    189195// 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; 
     196void 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        } 
    199210    } 
    200211} 
     
    228239    if (image.getPixelFormat() == GL_RGB) 
    229240    { 
    230         convertRGBToBGRA( imageData, image.data() ); 
     241        convertRGBToBGRA( imageData, image ); 
    231242    } 
    232243    else 
    233244    { 
    234         convertRGBAToBGRA( imageData, image.data() ); 
     245        convertRGBAToBGRA( imageData, image ); 
    235246    } 
    236247    inputOptions.setMipmapData(&imageData[0],image.s(),image.t());