[opengtl-commits] [545] allow to set a special order on channels

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 545
Author:   cyrille
Date:     2008-12-18 22:37:17 +0100 (Thu, 18 Dec 2008)

Log Message:
-----------
allow to set a special order on channels

Modified Paths:
--------------
    trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.h


Modified: trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-12-18 21:36:31 UTC (rev 544)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Debug.cpp	2008-12-18 21:37:17 UTC (rev 545)
@@ -237,7 +237,7 @@
     {
       _ostr << _pixelDescription.channels() << " x " << *_pixelDescription.channelTypes()[0];
     } else {
-      for( int i = 0; i < _pixelDescription.channels(); ++i)
+      for( std::size_t i = 0; i < _pixelDescription.channels(); ++i)
       {
         _ostr << *_pixelDescription.channelTypes()[i];
         if( i != _pixelDescription.channels() - 1 )

Modified: trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.cpp	2008-12-18 21:36:31 UTC (rev 544)
+++ trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.cpp	2008-12-18 21:37:17 UTC (rev 545)
@@ -27,9 +27,20 @@
 
 struct PixelDescription::Private {
   std::vector<const Type*> channelsType;
+  std::vector< std::size_t > channelPositions;
   int bitsSize;
+  void initChannelPositions();
 };
 
+void PixelDescription::Private::initChannelPositions()
+{
+  for( std::size_t i = 0; i < channelsType.size(); ++i )
+  {
+    channelPositions.push_back( i );
+  }
+  GTL_ASSERT( channelPositions.size() == channelsType.size() );
+}
+
 PixelDescription::PixelDescription( const Type* channelType_, int channels_) : d(new Private)
 {
   GTL_ASSERT( channelType_->bitsSize() > 0 );
@@ -39,6 +50,7 @@
   {
     d->channelsType.push_back( channelType_ );
   }
+  d->initChannelPositions();
 }
 
 PixelDescription::PixelDescription( const std::vector<const Type* >& channelsType_) : d(new Private)
@@ -51,6 +63,7 @@
     GTL_ASSERT( (*it)->bitsSize() > 0 );
     d->bitsSize += (*it)->bitsSize();
   }
+  d->initChannelPositions();
 }
 
 PixelDescription::PixelDescription( const PixelDescription& rhs) : d(new Private(*rhs.d))
@@ -73,7 +86,7 @@
   return d->channelsType;
 }
 
-int PixelDescription::channels() const
+std::size_t PixelDescription::channels() const
 {
   return d->channelsType.size();
 }
@@ -128,7 +141,8 @@
   } else {
     for(unsigned int i = 0; i < d->channelsType.size(); ++i)
     {
-      if( d->channelsType[i] != _rhs.d->channelsType[i] )
+      if( d->channelsType[i] != _rhs.d->channelsType[i]
+          or d->channelPositions[i] != _rhs.d->channelPositions[i] )
       {
         return false;
       }
@@ -141,3 +155,14 @@
 {
   return not ( *this == _rhs );
 }
+
+const std::vector< std::size_t >& PixelDescription::channelPositions() const
+{
+  return d->channelPositions;
+}
+
+void PixelDescription::setChannelPositions( const std::vector< std::size_t >& _positions )
+{
+  GTL_ASSERT( _positions.size() == channels() );
+  d->channelPositions = _positions;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.h	2008-12-18 21:36:31 UTC (rev 544)
+++ trunk/OpenGTL/OpenGTL/GTLCore/PixelDescription.h	2008-12-18 21:37:17 UTC (rev 545)
@@ -52,12 +52,21 @@
       /**
        * @return the number of channels
        */
-      int channels() const;
+      std::size_t channels() const;
       /**
        * @return true if all channels have the same type
        */
       bool sameTypeChannels() const;
       /**
+       * @return the list of channel positions
+       */
+      const std::vector< std::size_t >& channelPositions() const;
+      /**
+       * This allow to reshuffle the channels position before using with an algorithms.
+       * This is usefull if the data buffer is using BGRA and the algorithm assume RGBA.
+       */
+      void setChannelPositions( const std::vector< std::size_t >& _positions );
+      /**
        * @return the size of a pixel in bits
        */
       int bitsSize() const;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/