core/vil1/vil1_memory_image.cxx

Go to the documentation of this file.
00001 // This is core/vil1/vil1_memory_image.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 
00008 #include "vil1_memory_image.h"
00009 
00010 #include <vcl_cassert.h>
00011 #include <vcl_iostream.h>
00012 
00013 #include <vil1/vil1_image.h>
00014 #include <vil1/vil1_memory_image_impl.h>
00015 
00016 // macro to pull down data fields from the impl structure.
00017 #define cache_from_impl \
00018 { \
00019   if (ptr) { \
00020     vil1_memory_image_impl* mi = (vil1_memory_image_impl*)ptr; \
00021     this->width_  = mi->width_; \
00022     this->height_ = mi->height_; \
00023     this->rows0_  = mi->rows_ ? mi->rows_[0] : 0; \
00024   } \
00025   else { \
00026     this->width_  = 0; \
00027     this->height_ = 0; \
00028     this->rows0_  = 0; \
00029   } \
00030 }
00031 
00032 vil1_memory_image::vil1_memory_image()
00033 {
00034   cache_from_impl;
00035 }
00036 
00037 vil1_memory_image::vil1_memory_image(int planes, int w, int h,
00038                                      vil1_memory_image_format const& format)
00039   : vil1_image(new vil1_memory_image_impl(planes, w, h, format))
00040 {
00041   cache_from_impl;
00042 }
00043 
00044 vil1_memory_image::vil1_memory_image(int planes, int w, int h,
00045                                      int components, int bits_per_component,
00046                                      vil1_component_format component_format)
00047   : vil1_image(new vil1_memory_image_impl(planes, w, h, components, bits_per_component, component_format))
00048 {
00049   cache_from_impl;
00050 }
00051 
00052 vil1_memory_image::vil1_memory_image(int planes, int w, int h, vil1_pixel_format_t pixel_format)
00053   : vil1_image(new vil1_memory_image_impl(planes, w, h, pixel_format))
00054 {
00055   cache_from_impl;
00056 }
00057 
00058 vil1_memory_image::vil1_memory_image(int w, int h,
00059                                      int components, int bits_per_component,
00060                                      vil1_component_format component_format)
00061   : vil1_image(new vil1_memory_image_impl(1, w, h, components, bits_per_component, component_format))
00062 {
00063   cache_from_impl;
00064 }
00065 
00066 vil1_memory_image::vil1_memory_image(int w,int h, vil1_pixel_format_t pixel_format)
00067   : vil1_image(new vil1_memory_image_impl(1, w, h, pixel_format))
00068 {
00069   cache_from_impl;
00070 }
00071 
00072 // make a memory image if input is not already one.
00073 
00074 vil1_image make_memory_image(vil1_image const * thatp)
00075 {
00076   vil1_image const& that = *thatp;
00077   if (that.get_property("memory"))
00078     return that;
00079   assert(that.planes() > 0);
00080   assert(that.width() >= 0);
00081   assert(that.height() >= 0);
00082   assert(that.components() > 0);
00083   assert(that.bits_per_component() > 0);
00084 #ifdef DEBUG
00085   vcl_cout << "copying " << that.impl() << " to a "
00086            << that.planes() << 'x' << that.width() << 'x' <<that.height()
00087            << 'x' << that.components() << " memory image, "
00088            << that.bits_per_component() << " bpc, component format "
00089            << that.component_format() << '\n' << vcl_flush;
00090 #endif
00091   vil1_memory_image mem(that.planes(),
00092                         that.width(),
00093                         that.height(),
00094                         that.components(),
00095                         that.bits_per_component(),
00096                         that.component_format());
00097   that.get_section(mem.get_buffer(), 0, 0, that.width(), that.height());
00098   return mem;
00099 }
00100 
00101 //: If that is a memory image, just point to it, otherwise get_section
00102 vil1_memory_image::vil1_memory_image(vil1_image const & that)
00103   : vil1_image(make_memory_image(&that))
00104 {
00105   cache_from_impl;
00106 }
00107 
00108 vil1_memory_image::vil1_memory_image(vil1_memory_image const& that)
00109   : vil1_image(that)
00110 {
00111   cache_from_impl;
00112 }
00113 
00114 vil1_memory_image& vil1_memory_image::operator= (vil1_memory_image const& that)
00115 {
00116   vil1_image::operator= (that);
00117   cache_from_impl;
00118   return *this;
00119 }
00120 
00121 void vil1_memory_image::resize(int width, int height)
00122 {
00123   assert(ptr!=0);
00124   vil1_memory_image_impl* mi = (vil1_memory_image_impl*)ptr;
00125   mi->resize(1, width, height);
00126   cache_from_impl;
00127 }
00128 
00129 void vil1_memory_image::resize(int planes, int width, int height)
00130 {
00131   assert(ptr!=0);
00132   vil1_memory_image_impl* mi = (vil1_memory_image_impl*)ptr;
00133   mi->resize(planes, width, height);
00134   cache_from_impl;
00135 }
00136 
00137 void vil1_memory_image::assert_size(int width, int height) const
00138 {
00139   if ((width != width_) || (height != height_)) {
00140     vcl_cerr << __FILE__ ": In vil1_memory_image::assert_size():\n"
00141              << __FILE__ ": Image has size   " << width_ << 'x' << height_ << vcl_endl
00142              << __FILE__ ": but it should be " << width  << 'x' << height  << vcl_endl;
00143     assert(false);
00144   }
00145 }
00146 
00147 // Added by Brendan McCane for creating images with already allocated
00148 // memory. Useful for use with framegrabbers.
00149 vil1_memory_image::vil1_memory_image(void *buf, int planes, int w, int h,
00150                                      vil1_memory_image_format const& format)
00151   : vil1_image(new vil1_memory_image_impl(buf, planes, w, h, format))
00152 {
00153   cache_from_impl;
00154 }
00155 
00156 vil1_memory_image::vil1_memory_image(void *buf, int planes, int w, int h,
00157                                      int components, int bits_per_component,
00158                                      vil1_component_format component_format)
00159   : vil1_image(new vil1_memory_image_impl(buf, planes, w, h, components, bits_per_component, component_format))
00160 {
00161   cache_from_impl;
00162 }
00163 
00164 vil1_memory_image::vil1_memory_image(void *buf, int planes, int w, int h,
00165                                      vil1_pixel_format_t pixel_format)
00166   : vil1_image(new vil1_memory_image_impl(buf, planes, w, h, pixel_format))
00167 {
00168   cache_from_impl;
00169 }
00170 
00171 vil1_memory_image::vil1_memory_image(void *buf, int w, int h,
00172                                      int components, int bits_per_component,
00173                                      vil1_component_format component_format)
00174   : vil1_image(new vil1_memory_image_impl(buf, 1, w, h, components, bits_per_component, component_format))
00175 {
00176   cache_from_impl;
00177 }
00178 
00179 vil1_memory_image::vil1_memory_image(void *buf, int w, int h,
00180                                      vil1_pixel_format_t pixel_format)
00181   : vil1_image(new vil1_memory_image_impl(buf, 1, w, h, pixel_format))
00182 {
00183   cache_from_impl;
00184 }
00185 
00186 
00187 //: Reset this class's member variables from the image implementation
00188 // This is is useful if the impl object has been modified outside the control of this object.
00189 void vil1_memory_image::recache_from_impl()
00190 {
00191   cache_from_impl;
00192 }

Generated on Sat Nov 22 05:08:29 2008 for core/vil1 by  doxygen 1.5.1