libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd cvd/image.h cvd/image_io.h cvd_src/image...


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd/image.h cvd/image_io.h cvd_src/image...
Date: Thu, 28 Sep 2006 00:28:33 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        06/09/28 00:28:33

Modified files:
        cvd            : image.h image_io.h 
        cvd_src        : image_io.cc 

Log message:
        Image loading convinience functions.
        Now you can do:
        
        Image<byte> im = img_load("file.ppm");
        
        The type deduction is performed using lazy evaluation.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image.h?cvsroot=libcvd&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image_io.h?cvsroot=libcvd&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/image_io.cc?cvsroot=libcvd&r1=1.21&r2=1.22

Patches:
Index: cvd/image.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/image.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- cvd/image.h 27 Sep 2006 15:26:59 -0000      1.24
+++ cvd/image.h 28 Sep 2006 00:28:32 -0000      1.25
@@ -71,6 +71,13 @@
     }
 }
 
+#ifndef DOXYGEN_IGNORE_INTERNAL
+namespace Internal
+{
+       template<class C> class ImagePromise
+       {};
+};
+#endif
 
 #ifdef CVD_IMAGE_DEBUG
        #define CVD_IMAGE_ASSERT(X,Y)  if(!(X)) throw Y()
@@ -695,6 +702,20 @@
                        return *this;
                }
                
+               #ifndef DOXYGEN_IGNORE_INTERNAL
+               template<class C> const Image& 
operator=(Internal::ImagePromise<C> p)
+               {
+                       p.execute(*this);
+                       return *this;
+               }
+
+               template<class C> Image(Internal::ImagePromise<C> p)
+               {
+                       dup_from(NULL);
+                       p.execute(*this);
+               }
+               #endif
+               
                ///Default constructor
                Image()
                {

Index: cvd/image_io.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/image_io.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- cvd/image_io.h      9 Jun 2006 16:12:49 -0000       1.29
+++ cvd/image_io.h      28 Sep 2006 00:28:32 -0000      1.30
@@ -70,6 +70,35 @@
                        CVD_IMAGE_HAVE_JPEG  //This is a macro, ending in ,
                };
        }
+
+       namespace Internal
+       {
+               class ImageLoaderIstream{};
+               template<> struct ImagePromise<ImageLoaderIstream>
+               {
+                       ImagePromise(std::istream& is)
+                       :i(is){}
+
+                       std::istream& i;
+                       template<class C> void execute(Image<C>& im)
+                       {
+                               img_load(im, i);
+                       }
+               };
+
+               class ImageLoaderString{};
+               template<> struct ImagePromise<ImageLoaderString>
+               {
+                       ImagePromise(const std::string& ss)
+                       :s(ss){}
+
+                       const std::string& s;
+                       template<class C> void execute(Image<C>& im)
+                       {
+                               img_load(im, s);
+                       }
+               };
+       };
        #endif
 
        #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
@@ -103,6 +132,39 @@
        }
        #endif
        
+       #ifndef DOXYGEN_IGNORE_INTERNAL
+
+       Internal::ImagePromise<Internal::ImageLoaderIstream> 
img_load(std::istream& i);
+       Internal::ImagePromise<Internal::ImageLoaderString> img_load(const 
std::string &s);
+       #endif
+
+       #if DOXYGEN_INCLUDE_ONLY_FOR_DOCS
+       
+       /// Load an image from an istream, and return the image.
+       /// The template type is deduced automatically, and must not be 
specified.
+       ///
+       /// The type deduction is performed using lazy evaluation, so the load 
operation 
+       /// is only performed if an image is assigned from this.
+       ///
+       /// @param i The istream to load from
+       /// @ingroup gImageIO
+       template<class C> Image<C> img_load(std::istream& i);
+       
+       /// Load an image from a file, and return the image.
+       /// The template type is deduced automatically, and must not be 
specified.
+       ///
+       /// The type deduction is performed using lazy evaluation, so the load 
operation 
+       /// is only performed if an image is assigned from this.
+       ///
+       /// @param i The istream to load from
+       /// @ingroup gImageIO
+       template<class C> Image<C> img_load(std::string& i);
+
+
+
+       #endif  
+
+
        /// Load an image from a stream. This function resizes the Image as 
necessary.
        /// It will also perform image type conversion (e.g. colour to 
greyscale)
        /// according the Pixel:::CIE conversion.

Index: cvd_src/image_io.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/image_io.cc,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- cvd_src/image_io.cc 6 Jun 2006 12:32:31 -0000       1.21
+++ cvd_src/image_io.cc 28 Sep 2006 00:28:32 -0000      1.22
@@ -117,4 +117,18 @@
                return ImageType::Unknown;
 }
 
+
+Internal::ImagePromise<Internal::ImageLoaderIstream> img_load(std::istream& i)
+{
+       return Internal::ImagePromise<Internal::ImageLoaderIstream>(i);
+}
+
+Internal::ImagePromise<Internal::ImageLoaderString> img_load(const std::string 
&s)
+{
+       return Internal::ImagePromise<Internal::ImageLoaderString>(s);
+}
+
+
+
+
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]