[opengtl-commits] [231] * ++dox

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


Revision: 231
Author:   cyrille
Date:     2008-06-25 21:43:30 +0200 (Wed, 25 Jun 2008)

Log Message:
-----------
* ++dox
* return a default pixel value in the BufferImage

Modified Paths:
--------------
    trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h
    trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
    trunk/OpenGTL/OpenShiva/OpenShiva/Image.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-24 19:37:40 UTC (rev 230)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-25 19:43:30 UTC (rev 231)
@@ -27,7 +27,12 @@
 namespace OpenShiva {
   /**
    * Base class of Images. Reimplement the virtual functions to give access to
-   * your internal image data.
+   * your own image data.
+   * 
+   * Alternatively you can use \ref BufferImage (with any \ref GTLCore::Buffer ) or
+   * \ref Image .
+   * 
+   * @ingroup OpenShiva
    */
   class AbstractImage {
     public:
@@ -43,6 +48,10 @@
        * @param _x
        * @param _y
        * @return a pointer to the pixel at coordinates (_x,_y)
+       * 
+       * If coordinates (_x,_y) are outside the image, it is still
+       * expected for the \ref AbstractImage to return a valid pointer
+       * to some default pixel value.
        */
       virtual char* data( int _x, int _y ) = 0;
       const GTLCore::PixelDescription& pixelDescription() const;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp	2008-06-24 19:37:40 UTC (rev 230)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp	2008-06-25 19:43:30 UTC (rev 231)
@@ -31,6 +31,7 @@
   int lineWidth;
   int width;
   int height;
+  char* defaultPixel;
 };
 
 BufferImage::BufferImage( int _width, int _height, GTLCore::Buffer* _buffer, const GTLCore::PixelDescription& _pixelDescription ) : AbstractImage(_pixelDescription), d(new Private)
@@ -39,18 +40,26 @@
   d->lineWidth = _width * pixelSize();
   d->width = _width;
   d->height = _height;
+  d->defaultPixel = new char[ pixelSize() ];
+  memset( d->defaultPixel, 0, pixelSize() );
   SHIVA_ASSERT( d->buffer->size() == d->lineWidth * _height );
 }
 
 BufferImage::~BufferImage()
 {
+  delete[] d->defaultPixel;
   delete d->buffer;
   delete d;
 }
 
 char* BufferImage::data( int _x, int _y )
 {
-  return d->buffer->rawData() + (_x * pixelSize() + _y * lineWidth());
+  if( _x >= 0 and _y >= 0 and _x < d->width and _y < d->height )
+  {
+    return d->buffer->rawData() + (_x * pixelSize() + _y * lineWidth());
+  } else {
+    return d->defaultPixel;
+  }
 }
 
 int BufferImage::lineWidth() const

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h	2008-06-24 19:37:40 UTC (rev 230)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h	2008-06-25 19:43:30 UTC (rev 231)
@@ -27,13 +27,33 @@
 }
 
 namespace OpenShiva {
+  /**
+   * This is an implementation of \ref AbstractImage which can be used with any \ref GTLCore::Buffer .
+   *
+   * @ingroup OpenShiva
+   */
   class BufferImage : public AbstractImage {
     public:
+      /**
+       * @param _width width of the image
+       * @param _height height of the image
+       * @param _buffer the buffer giving access to the image data (\ref BufferImage takes
+       *                ownership of the \ref GTLCore::Buffer )
+       * @param _pixelDescription the description of the pixel stored in the buffer
+       * 
+       * It is expected that (_width * _height * _pixelDescription.bitsSize() / 8) == _buffer->size()
+       */
       BufferImage( int _width, int _height, GTLCore::Buffer* _buffer, const GTLCore::PixelDescription& _pixelDescription );
       ~BufferImage();
     public:
       virtual char* data( int _x, int _y );
+      /**
+       * @return the width of the image
+       */
       int width() const;
+      /**
+       * @return the height of the image
+       */
       int height() const;
     protected:
       int lineWidth() const;

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Image.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Image.h	2008-06-24 19:37:40 UTC (rev 230)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Image.h	2008-06-25 19:43:30 UTC (rev 231)
@@ -27,6 +27,11 @@
 }
 
 namespace OpenShiva {
+  /**
+   * \ref Image is a convenient class inheriting \ref BufferImage and using a \ref GTLCore::Array
+   * for the image data.
+   * @ingroup OpenShiva
+   */
   class Image : public BufferImage {
     public:
       Image(int _width, int _height, const GTLCore::PixelDescription& _pixelDescription);


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