[opengtl-commits] [228] Introduce BufferImage that can holds any kind of GTLCore:: Buffer and update Image to inherits BufferImage using a GTLCore::Array

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


Revision: 228
Author:   cyrille
Date:     2008-06-24 21:36:28 +0200 (Tue, 24 Jun 2008)

Log Message:
-----------
Introduce BufferImage that can holds any kind of GTLCore::Buffer and update Image to inherits BufferImage using a GTLCore::Array

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

Added Paths:
-----------
    trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
    trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h


Modified: trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp	2008-06-24 19:35:21 UTC (rev 227)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.cpp	2008-06-24 19:36:28 UTC (rev 228)
@@ -19,5 +19,37 @@
 
 #include "AbstractImage.h"
 
+#include <GTLCore/PixelDescription.h>
+
+#include "Debug.h"
+
 using namespace OpenShiva;
 
+struct AbstractImage::Private {
+  Private( const GTLCore::PixelDescription& _pixelDescription) : pixelDescription(_pixelDescription)
+  {
+  }
+  GTLCore::PixelDescription pixelDescription;
+  int pixelSize;
+};
+
+AbstractImage::AbstractImage( const GTLCore::PixelDescription& _pixelDescription ) : d(new Private(_pixelDescription))
+{
+  SHIVA_ASSERT(d->pixelDescription.bitsSize() % 8 == 0);
+  d->pixelSize = d->pixelDescription.bitsSize() / 8;
+}
+
+AbstractImage::~AbstractImage()
+{
+  delete d;
+}
+
+const GTLCore::PixelDescription& AbstractImage::pixelDescription() const
+{
+  return d->pixelDescription;
+}
+
+int AbstractImage::pixelSize() const
+{
+  return d->pixelSize;
+}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-24 19:35:21 UTC (rev 227)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/AbstractImage.h	2008-06-24 19:36:28 UTC (rev 228)
@@ -20,6 +20,10 @@
 #ifndef _OPENSHIVA_ABSTRACT_IMAGE_H_
 #define _OPENSHIVA_ABSTRACT_IMAGE_H_
 
+namespace GTLCore {
+  class PixelDescription;
+}
+
 namespace OpenShiva {
   /**
    * Base class of Images. Reimplement the virtual functions to give access to
@@ -32,12 +36,21 @@
         Linear
       };
     public:
+      AbstractImage( const GTLCore::PixelDescription& _pixelDescription );
+      virtual ~AbstractImage();
+    public:
       /**
        * @param _x
        * @param _y
        * @return a pointer to the pixel at coordinates (_x,_y)
        */
       virtual char* data( int _x, int _y ) = 0;
+      const GTLCore::PixelDescription& pixelDescription() const;
+    protected:
+      int pixelSize() const;
+    private:
+      struct Private;
+      Private* const d;
   };
 };
 

Added: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp	2008-06-24 19:36:28 UTC (rev 228)
@@ -0,0 +1,69 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "BufferImage.h"
+
+#include <GTLCore/Buffer.h>
+
+#include "Debug.h"
+
+using namespace OpenShiva;
+
+struct BufferImage::Private
+{
+  GTLCore::Buffer* buffer;
+  int lineWidth;
+  int width;
+  int height;
+};
+
+BufferImage::BufferImage( int _width, int _height, GTLCore::Buffer* _buffer, const GTLCore::PixelDescription& _pixelDescription ) : AbstractImage(_pixelDescription), d(new Private)
+{
+  d->buffer = _buffer;
+  d->lineWidth = _width * pixelSize();
+  d->width = _width;
+  d->height = _height;
+  SHIVA_ASSERT( d->buffer->size() == d->lineWidth * _height );
+}
+
+BufferImage::~BufferImage()
+{
+  delete d->buffer;
+  delete d;
+}
+
+char* BufferImage::data( int _x, int _y )
+{
+  return d->buffer->rawData() + (_x * pixelSize() + _y * lineWidth());
+}
+
+int BufferImage::lineWidth() const
+{
+  return d->lineWidth;
+}
+
+int BufferImage::width() const
+{
+  return d->width;
+}
+
+int BufferImage::height() const
+{
+  return d->height;
+}


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h	                        (rev 0)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h	2008-06-24 19:36:28 UTC (rev 228)
@@ -0,0 +1,46 @@
+/*
+ *  Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPENSHIVA_BUFFER_IMAGE_H_
+#define _OPENSHIVA_BUFFER_IMAGE_H_
+
+#include <OpenShiva/AbstractImage.h>
+
+namespace GTLCore {
+  class Buffer;
+}
+
+namespace OpenShiva {
+  class BufferImage : public AbstractImage {
+    public:
+      BufferImage( int _width, int _height, GTLCore::Buffer* _buffer, const GTLCore::PixelDescription& _pixelDescription );
+      ~BufferImage();
+    public:
+      virtual char* data( int _x, int _y );
+      int width() const;
+      int height() const;
+    protected:
+      int lineWidth() const;
+    private:
+      struct Private;
+      Private* const d;
+  };
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenShiva/OpenShiva/BufferImage.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-24 19:35:21 UTC (rev 227)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/CMakeLists.txt	2008-06-24 19:36:28 UTC (rev 228)
@@ -4,6 +4,7 @@
 # List of files 
 set(OpenShiva_SRCS
   AbstractImage.cpp
+  BufferImage.cpp
   Image.cpp
   Kernel.cpp
 # Internal files
@@ -43,7 +44,7 @@
 
 # Install target
 install(TARGETS OpenShiva  DESTINATION ${LIB_INSTALL_DIR} )
-install( FILES AbstractImage.h Image.h Kernel.h Version.h DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
+install( FILES AbstractImage.h BufferImage.h Image.h Kernel.h Version.h DESTINATION ${INCLUDE_INSTALL_DIR}/OpenShiva )
 
 # Create and install pc file
 configure_file("OpenShiva.pc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/OpenShiva.pc" @ONLY)

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Image.cpp
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Image.cpp	2008-06-24 19:35:21 UTC (rev 227)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Image.cpp	2008-06-24 19:36:28 UTC (rev 228)
@@ -19,33 +19,19 @@
 
 #include "Image.h"
 
+#include "GTLCore/Array.h"
 #include "GTLCore/PixelDescription.h"
 
-#include "Debug.h"
-
 using namespace OpenShiva;
 
 struct Image::Private {
-  char* data;
-  int lineWidth;
-  int pixelSize;
 };
 
-Image::Image(int _width, int _height, const GTLCore::PixelDescription& _pixelDescription) : d(new Private)
+Image::Image(int _width, int _height, const GTLCore::PixelDescription& _pixelDescription) : BufferImage(_width, _height, new GTLCore::Array(_height * _width * _pixelDescription.bitsSize() / 8), _pixelDescription ), d(new Private)
 {
-  GTL_ASSERT(_pixelDescription.bitsSize() % 8 == 0);
-  d->pixelSize = _pixelDescription.bitsSize() / 8;
-  d->lineWidth = _width * d->pixelSize;
-  d->data = new char[ d->lineWidth * _height];
 }
 
 Image::~Image()
 {
-  delete[] d->data;
   delete d;
 }
-
-char* Image::data(int _x, int _y)
-{
-  return d->data + (_x * d->pixelSize + _y * d->lineWidth);
-}

Modified: trunk/OpenGTL/OpenShiva/OpenShiva/Image.h
===================================================================
--- trunk/OpenGTL/OpenShiva/OpenShiva/Image.h	2008-06-24 19:35:21 UTC (rev 227)
+++ trunk/OpenGTL/OpenShiva/OpenShiva/Image.h	2008-06-24 19:36:28 UTC (rev 228)
@@ -20,18 +20,17 @@
 #ifndef _OPENSHIVA_IMAGE_H_
 #define _OPENSHIVA_IMAGE_H_
 
-#include <OpenShiva/AbstractImage.h>
+#include <OpenShiva/BufferImage.h>
 
 namespace GTLCore {
   class PixelDescription;
 }
 
 namespace OpenShiva {
-  class Image : public AbstractImage {
+  class Image : public BufferImage {
     public:
       Image(int _width, int _height, const GTLCore::PixelDescription& _pixelDescription);
       ~Image();
-      char* data(int _x, int _y);
     private:
       struct Private;
       Private* const d;


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