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/hdr/hdrwriter.cpp

    r12292 r12912  
    3737 
    3838 
    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  
    4439bool HDRWriter::writeRAW(const osg::Image *img, std::ostream& fout) 
    4540{ 
    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} 
    5248 
    5349/* number of floats per pixel */ 
     
    8783/* These routines can be made faster by allocating a larger buffer and 
    8884   fread-ing and fwrite-ing the data in larger chunks */ 
    89 bool HDRWriter::writePixelsNoRLE( std::ostream& fout, float* data, int numpixels) 
     85bool HDRWriter::writeNoRLE( std::ostream& fout, const osg::Image* img) 
    9086{ 
    9187  unsigned char rgbe[4]; 
    9288 
    93   while (numpixels-- > 0) 
     89  for(int row=0; row<img->t(); ++row) 
    9490  { 
    95     float2rgbe( 
     91    float* data = (float*)img->data(0,row); 
     92    for(int column=0; column<img->s(); ++column) 
     93    { 
     94      float2rgbe( 
    9695        rgbe, 
    9796        data[R], 
     
    9998        data[B] 
    10099        ); 
    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    } 
    103103  } 
     104 
    104105  return true; 
    105106} 
     
    184185} 
    185186 
    186 bool HDRWriter::writePixelsRLE( std::ostream& fout, float* data, int scanline_width, int num_scanlines ) 
    187  
    188 { 
     187bool HDRWriter::writeRLE( const osg::Image* img, std::ostream& fout) 
     188{ 
     189    int scanline_width = img->s(); 
     190    int num_scanlines = img->t(); 
     191 
    189192    unsigned char rgbe[4]; 
    190193    unsigned char *buffer; 
     
    192195    if ((scanline_width < MINELEN)||(scanline_width > MAXELEN)) 
    193196        // run length encoding is not allowed so write flat 
    194         return writePixelsNoRLE(fout,data,scanline_width*num_scanlines); 
     197        return writeNoRLE(fout,img); 
    195198 
    196199    buffer = (unsigned char *)malloc(sizeof(unsigned char)*4*scanline_width); 
    197200    if (buffer == NULL)  
    198201        // 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         
    203208        rgbe[0] = 2; 
    204209        rgbe[1] = 2;