libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd/cvd image.h vector_image_ref.h


From: Damian Eads
Subject: [libcvd-members] libcvd/cvd image.h vector_image_ref.h
Date: Wed, 17 Nov 2010 02:35:24 +0000

CVSROOT:        /sources/libcvd
Module name:    libcvd
Changes by:     Damian Eads <eads>      10/11/17 02:35:24

Modified files:
        cvd            : image.h vector_image_ref.h 

Log message:
        Adapted Image constructors, Image::dup_from, and 
Image::resize(ImageRef) so that images can be initialised or resized with a 
size of a zero pixel image, e.g. size=(0,0), size=(0,k), or size=(k,0) where k 
is non-zero. Previously, (1) CVD::resize(ImageRef(0,0)) caused a segfault, and 
(2) sizes with one zero dimension and the other non-zero was impossible. This 
has been fixed.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/image.h?cvsroot=libcvd&r1=1.50&r2=1.51
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/vector_image_ref.h?cvsroot=libcvd&r1=1.9&r2=1.10

Patches:
Index: image.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/image.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -b -r1.50 -r1.51
--- image.h     12 Nov 2010 14:07:31 -0000      1.50
+++ image.h     17 Nov 2010 02:35:24 -0000      1.51
@@ -732,12 +732,24 @@
                ///@param size The size of image to create
                Image(const ImageRef& size)
                {
+          //If the size of the image is zero pixels along any dimension,
+          //still keep any of the non-zero dimensions in the size. The
+          //caller should expect the size passed to the constructor
+          //to be the same as the value returned by .size()
+          if (size.x == 0 || size.y == 0) {
+            dup_from(NULL);
+            this->my_size = size;
+            this->my_stride = size.x;
+          }
+          else
+          {
                        num_copies = new int;
                        *num_copies = 1;
                        this->my_size = size;
                        this->my_stride = size.x;
             this->my_data = Internal::aligned_alloc<T>(this->totalsize(), 16);
                }
+               }
 
                ///Create a filled image of a given size
                ///@param size The size of image to create
@@ -811,19 +823,27 @@
 
                inline void dup_from(const Image* copyof)  //Duplicate from 
another image
                {
-                       if(copyof != NULL && copyof->my_data != NULL)
+                       if(copyof != NULL)
                        {
+              //For images with zero pixels (e.g. 0 by 100 image),
+              //we still want to preserve non-zero dimensions in the size.
                                this->my_size = copyof->my_size;
                                this->my_stride = copyof->my_stride;
+                if (copyof->my_data != NULL) {
                                this->my_data = copyof->my_data;
                                num_copies = copyof->num_copies;
                                (*num_copies)++;
                        }
+                else {
+                  this->my_data = 0;
+                  num_copies = 0;
+                }
+                       }
                        else
                        {
                                this->my_size.home();
-                               this->my_stride=0;
                                this->my_data = 0;
+                this->my_stride = 0;
                                num_copies = 0;
                        }
                }

Index: vector_image_ref.h
===================================================================
RCS file: /sources/libcvd/libcvd/cvd/vector_image_ref.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- vector_image_ref.h  20 Apr 2006 10:29:24 -0000      1.9
+++ vector_image_ref.h  17 Nov 2010 02:35:24 -0000      1.10
@@ -45,6 +45,14 @@
                return ImageRef((int)v[0], (int)v[1]);
        }
        
+       /// Rescale an ImageRef by a scaling factor
+       /// @param v The Vector to convert
+       /// @ingroup gImage
+       inline ImageRef ir_rescale_rounded(const ImageRef &v, double 
rescaling_factor)
+       {
+         return ir_rounded(vec(v) * rescaling_factor);
+       }
+
        /// Convert a Vector into an image co-ordinate. Numbers are rounded
        /// @param v The Vector to convert
        /// @ingroup gImage



reply via email to

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