00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vil1_image_as.h"
00010
00011 #include <vcl_cassert.h>
00012 #include <vcl_iostream.h>
00013 #include <vcl_vector.h>
00014 #include <vcl_string.h>
00015
00016 #include <vil1/vil1_pixel.h>
00017 #include <vil1/vil1_memory_image_of_format.txx>
00018
00019 #include <vxl_config.h>
00020
00021
00022 template <class T>
00023 struct vil1_image_as_impl : public vil1_image_impl, public vil1_memory_image_of_format<T>
00024 {
00025 typedef vil1_memory_image_of_format<T> format;
00026 vil1_image image;
00027 vil1_image_as_impl(vil1_image const &underlying) : image(underlying) { }
00028 int planes() const { return 1; }
00029 int width() const { return image.width(); }
00030 int height() const { return image.height(); }
00031 int components() const { return format::components; }
00032 int bits_per_component() const { return format::bits_per_component; }
00033 vil1_component_format component_format() const { return format::component_format; }
00034 vil1_image get_plane(unsigned int p) const { assert(p==0); return const_cast<vil1_image_as_impl*>(this); }
00035
00036 #if 0
00037 char const* file_format() const { return 0; }
00038 bool get_property(char const* tag, void* property_value_out = 0) const { return false; }
00039 #endif
00040
00041
00042
00043 bool get_section(void *buf, int x0, int y0, int width, int height) const;
00044
00045
00046 bool put_section(void const *, int, int, int, int) { return false; }
00047
00048
00049 virtual vcl_string is_a() const;
00050
00051
00052 virtual bool is_class(vcl_string const&) const;
00053 };
00054
00055
00056
00057 template<class Inp, class Out>
00058 bool convert_grey_to_grey( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00059 {
00060 vcl_vector<Inp> scan(width);
00061 for (int j=0; j<height; ++j) {
00062 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00063 return false;
00064 for (int i=0; i<width; ++i)
00065 static_cast<Out*>(buf)[i + width*j] = Out(scan[i]);
00066 }
00067 return true;
00068 }
00069
00070
00071 template<class Inp, class Out>
00072 bool convert_rgb_to_grey( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00073 {
00074 vcl_vector<Inp> scan(3*width);
00075 for (int j=0; j<height; ++j) {
00076 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00077 return false;
00078 for (int i=0; i<width; ++i) {
00079 Inp r(scan[3*i+0]);
00080 Inp g(scan[3*i+1]);
00081 Inp b(scan[3*i+2]);
00082
00083
00084
00085 static_cast<Out*>(buf)[i + width*j] = Out(0.2125*r+0.7154*g+0.072*b);
00086
00087
00088 }
00089 }
00090 return true;
00091 }
00092
00093
00094 template<class Inp, class Out>
00095 bool convert_grey_to_rgb( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00096 {
00097 vcl_vector<Inp> scan(width);
00098 for (int j=0; j<height; ++j) {
00099 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00100 return false;
00101 for (int i=0; i<width; ++i) {
00102 static_cast<Out*>(buf)[3*(i + width*j)+0] = Out(scan[i]);
00103 static_cast<Out*>(buf)[3*(i + width*j)+1] = Out(scan[i]);
00104 static_cast<Out*>(buf)[3*(i + width*j)+2] = Out(scan[i]);
00105 }
00106 }
00107 return true;
00108 }
00109
00110
00111 template<class Inp, class Out>
00112 bool convert_rgb_to_rgb( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00113 {
00114 vcl_vector<Inp> scan(3*width);
00115 for (int j=0; j<height; ++j) {
00116 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00117 return false;
00118 for (int i=0; i<width; ++i) {
00119 static_cast<Out*>(buf)[3*(i + width*j)+0] = Out(scan[3*i + 0]);
00120 static_cast<Out*>(buf)[3*(i + width*j)+1] = Out(scan[3*i + 1]);
00121 static_cast<Out*>(buf)[3*(i + width*j)+2] = Out(scan[3*i + 2]);
00122 }
00123 }
00124 return true;
00125 }
00126
00127 template<class Inp, class Out>
00128 bool convert_rgba_to_rgb( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00129 {
00130 vcl_vector<Inp> scan(4*width);
00131 for (int j=0; j<height; ++j) {
00132 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00133 return false;
00134 for (int i=0; i<width; ++i) {
00135 static_cast<Out*>(buf)[3*(i + width*j)+0] = Out(scan[4*i + 0]);
00136 static_cast<Out*>(buf)[3*(i + width*j)+1] = Out(scan[4*i + 1]);
00137 static_cast<Out*>(buf)[3*(i + width*j)+2] = Out(scan[4*i + 2]);
00138 }
00139 }
00140 return true;
00141 }
00142
00143
00144 template<class Inp, class Out>
00145 bool convert_rgba_to_grey( const vil1_image& image, void* buf, int x0, int y0, int width, int height, Inp* , Out* )
00146 {
00147 vcl_vector<Inp> scan(4*width);
00148 for (int j=0; j<height; ++j) {
00149 if (!image.get_section(&scan[0], x0, y0+j, width, 1))
00150 return false;
00151 for (int i=0; i<width; ++i) {
00152 Inp r(scan[4*i+0]);
00153 Inp g(scan[4*i+1]);
00154 Inp b(scan[4*i+2]);
00155
00156
00157
00158 static_cast<Out*>(buf)[i + width*j] = Out(0.2125*r+0.7154*g+0.072*b);
00159
00160
00161 }
00162 }
00163 return true;
00164 }
00165
00166
00167
00168
00169
00170 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,vxl_byte*);
00171 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,vxl_byte*);
00172 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, float*,vxl_byte*);
00173 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, double*,vxl_byte*);
00174 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_byte*);
00175 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,vxl_byte*);
00176 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, float*,vxl_byte*);
00177 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, double*,vxl_byte*);
00178 template bool convert_rgba_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_byte*);
00179
00180 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_uint_16*);
00181
00182 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,vxl_uint_16*);
00183 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, float*,vxl_uint_16*);
00184 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, double*,vxl_uint_16*);
00185 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_uint_16*);
00186 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,vxl_uint_16*);
00187 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, float*,vxl_uint_16*);
00188 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, double*,vxl_uint_16*);
00189
00190 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,int*);
00191 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,int*);
00192
00193 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, float*,int*);
00194 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, double*,int*);
00195 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,int*);
00196 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,int*);
00197 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, float*,int*);
00198 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, double*,int*);
00199
00200 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,float*);
00201 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,float*);
00202 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,float*);
00203
00204 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, double*,float*);
00205 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,float*);
00206 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,float*);
00207 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, float*,float*);
00208 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, double*,float*);
00209
00210 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,double*);
00211 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,double*);
00212 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,double*);
00213 template bool convert_grey_to_grey( const vil1_image&, void*, int, int, int, int, float*,double*);
00214
00215 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_byte*,double*);
00216 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,double*);
00217 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, float*,double*);
00218 template bool convert_rgb_to_grey( const vil1_image&, void*, int, int, int, int, double*,double*);
00219
00220 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,unsigned char* );
00221 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,unsigned char* );
00222 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,unsigned char* );
00223 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, float*,unsigned char* );
00224 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, double*,unsigned char* );
00225
00226 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,unsigned char* );
00227 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, float*,unsigned char* );
00228 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, double*,unsigned char* );
00229 template bool convert_rgba_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,unsigned char* );
00230
00231 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_uint_16*);
00232 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,vxl_uint_16*);
00233 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,vxl_uint_16*);
00234 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, float*,vxl_uint_16*);
00235 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, double*,vxl_uint_16*);
00236 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_uint_16*);
00237
00238 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, float*,vxl_uint_16*);
00239 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, double*,vxl_uint_16*);
00240 template bool convert_rgba_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,vxl_uint_16*);
00241
00242 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,float*);
00243 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,float*);
00244 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_32*,float*);
00245 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, float*,float*);
00246 template bool convert_grey_to_rgb( const vil1_image&, void*, int, int, int, int, double*,float*);
00247 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,float*);
00248 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_uint_16*,float*);
00249
00250 template bool convert_rgb_to_rgb( const vil1_image&, void*, int, int, int, int, double*,float*);
00251 template bool convert_rgba_to_rgb( const vil1_image&, void*, int, int, int, int, vxl_byte*,float*);
00252
00253
00254
00255
00256 VCL_DEFINE_SPECIALIZATION
00257 bool vil1_image_as_impl<vxl_byte>::get_section(void *buf, int x0, int y0, int width, int height) const
00258 {
00259 typedef vxl_byte Outtype;
00260
00261 switch ( vil1_pixel_format(image) )
00262 {
00263 case VIL1_BYTE:
00264 return image.get_section( buf, x0, y0, width, height );
00265 case VIL1_UINT16:
00266 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00267 case VIL1_UINT32:
00268 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0);
00269 case VIL1_FLOAT:
00270 return convert_grey_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00271 case VIL1_DOUBLE:
00272 return convert_grey_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00273 case VIL1_RGB_BYTE:
00274 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00275 case VIL1_RGB_UINT16:
00276 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00277 case VIL1_RGB_FLOAT:
00278 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00279 case VIL1_RGB_DOUBLE:
00280 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00281 case VIL1_RGBA_BYTE:
00282 return convert_rgba_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00283 default:
00284 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00285 assert(false);
00286 return false;
00287 }
00288 }
00289
00290 VCL_DEFINE_SPECIALIZATION
00291 vcl_string vil1_image_as_impl<vxl_byte>::is_a() const
00292 {
00293 static const vcl_string class_name_="vil1_image_as_impl<vxl_byte>";
00294 return class_name_;
00295 }
00296
00297 VCL_DEFINE_SPECIALIZATION
00298 bool vil1_image_as_impl<vxl_byte>::is_class(vcl_string const& s) const
00299 {
00300 return s==vil1_image_as_impl<vxl_byte>::is_a() || vil1_image_impl::is_class(s);
00301 }
00302
00303
00304 template struct vil1_image_as_impl<vxl_byte>;
00305
00306 vil1_image vil1_image_as_byte(vil1_image const &image)
00307 {
00308 return vil1_image(new vil1_image_as_impl<vxl_byte>(image));
00309 }
00310
00311 VCL_DEFINE_SPECIALIZATION
00312 vil1_image vil1_image_as(vil1_image const &image, vxl_byte*)
00313 {
00314 return vil1_image(new vil1_image_as_impl<vxl_byte>(image));
00315 }
00316
00317
00318
00319 VCL_DEFINE_SPECIALIZATION
00320 bool vil1_image_as_impl<vxl_uint_16>::get_section(void *buf, int x0, int y0, int width, int height) const
00321 {
00322 typedef vxl_uint_16 Outtype;
00323
00324 switch ( vil1_pixel_format(image) )
00325 {
00326 case VIL1_BYTE:
00327 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00328 case VIL1_UINT16:
00329 return image.get_section( buf, x0, y0, width, height );
00330 case VIL1_UINT32:
00331 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0);
00332 case VIL1_FLOAT:
00333 return convert_grey_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00334 case VIL1_DOUBLE:
00335 return convert_grey_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00336 case VIL1_RGB_BYTE:
00337 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00338 case VIL1_RGB_UINT16:
00339 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00340 case VIL1_RGB_FLOAT:
00341 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00342 case VIL1_RGB_DOUBLE:
00343 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00344 default:
00345 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00346 assert(false);
00347 return false;
00348 }
00349 }
00350
00351 VCL_DEFINE_SPECIALIZATION
00352 vcl_string vil1_image_as_impl<vxl_uint_16>::is_a() const
00353 {
00354 static const vcl_string class_name_="vil1_image_as_impl<vxl_uint_16>";
00355 return class_name_;
00356 }
00357
00358 VCL_DEFINE_SPECIALIZATION
00359 bool vil1_image_as_impl<vxl_uint_16>::is_class(vcl_string const& s) const
00360 {
00361 return s==vil1_image_as_impl<vxl_uint_16>::is_a() || vil1_image_impl::is_class(s);
00362 }
00363
00364
00365 template struct vil1_image_as_impl<vxl_uint_16>;
00366
00367 vil1_image vil1_image_as_uint16(vil1_image const &image)
00368 {
00369 return vil1_image(new vil1_image_as_impl<vxl_uint_16>(image));
00370 }
00371
00372 VCL_DEFINE_SPECIALIZATION
00373 vil1_image vil1_image_as(vil1_image const &image, vxl_uint_16*)
00374 {
00375 return vil1_image(new vil1_image_as_impl<vxl_uint_16>(image));
00376 }
00377
00378
00379
00380
00381 VCL_DEFINE_SPECIALIZATION
00382 bool vil1_image_as_impl<int>::get_section(void *buf, int x0, int y0, int width, int height) const
00383 {
00384 typedef int Outtype;
00385
00386 switch ( vil1_pixel_format(image) )
00387 {
00388 case VIL1_BYTE:
00389 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00390 case VIL1_UINT16:
00391 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00392 case VIL1_UINT32:
00393 return image.get_section( buf, x0, y0, width, height );
00394 case VIL1_FLOAT:
00395 return convert_grey_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00396 case VIL1_DOUBLE:
00397 return convert_grey_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00398 case VIL1_RGB_BYTE:
00399 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00400 case VIL1_RGB_UINT16:
00401 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00402 case VIL1_RGB_FLOAT:
00403 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00404 case VIL1_RGB_DOUBLE:
00405 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00406 default:
00407 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00408 assert(false);
00409 return false;
00410 }
00411 }
00412
00413 VCL_DEFINE_SPECIALIZATION
00414 vcl_string vil1_image_as_impl<int>::is_a() const
00415 {
00416 static const vcl_string class_name_="vil1_image_as_impl<int>";
00417 return class_name_;
00418 }
00419
00420 VCL_DEFINE_SPECIALIZATION
00421 bool vil1_image_as_impl<int>::is_class(vcl_string const& s) const
00422 {
00423 return s==vil1_image_as_impl<int>::is_a() || vil1_image_impl::is_class(s);
00424 }
00425
00426
00427 template struct vil1_image_as_impl<int>;
00428
00429 vil1_image vil1_image_as_int(vil1_image const &image)
00430 {
00431 return vil1_image(new vil1_image_as_impl<int>(image));
00432 }
00433
00434 VCL_DEFINE_SPECIALIZATION
00435 vil1_image vil1_image_as(vil1_image const &image, int*)
00436 {
00437 return vil1_image(new vil1_image_as_impl<int>(image));
00438 }
00439
00440
00441
00442 VCL_DEFINE_SPECIALIZATION
00443 bool vil1_image_as_impl<float>::get_section(void *buf, int x0, int y0, int width, int height) const
00444 {
00445 typedef float Outtype;
00446
00447 switch ( vil1_pixel_format(image) )
00448 {
00449 case VIL1_BYTE:
00450 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00451 case VIL1_UINT16:
00452 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00453 case VIL1_UINT32:
00454 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0);
00455 case VIL1_FLOAT:
00456 return image.get_section( buf, x0, y0, width, height );
00457 case VIL1_DOUBLE:
00458 return convert_grey_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00459 case VIL1_RGB_BYTE:
00460 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00461 case VIL1_RGB_UINT16:
00462 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00463 case VIL1_RGB_FLOAT:
00464 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00465 case VIL1_RGB_DOUBLE:
00466 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00467 default:
00468 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00469 assert(false);
00470 return false;
00471 }
00472 }
00473
00474 VCL_DEFINE_SPECIALIZATION
00475 vcl_string vil1_image_as_impl<float>::is_a() const
00476 {
00477 static const vcl_string class_name_="vil1_image_as_impl<float>";
00478 return class_name_;
00479 }
00480
00481 VCL_DEFINE_SPECIALIZATION
00482 bool vil1_image_as_impl<float>::is_class(vcl_string const& s) const
00483 {
00484 return s==vil1_image_as_impl<float>::is_a() || vil1_image_impl::is_class(s);
00485 }
00486
00487
00488 template struct vil1_image_as_impl<float>;
00489
00490 vil1_image vil1_image_as_float(vil1_image const &image)
00491 {
00492 return vil1_image(new vil1_image_as_impl<float>(image));
00493 }
00494
00495 VCL_DEFINE_SPECIALIZATION
00496 vil1_image vil1_image_as(vil1_image const &image, float*)
00497 {
00498 return vil1_image(new vil1_image_as_impl<float>(image));
00499 }
00500
00501
00502
00503 VCL_DEFINE_SPECIALIZATION
00504 bool vil1_image_as_impl<double>::get_section(void *buf, int x0, int y0, int width, int height) const
00505 {
00506 typedef double Outtype;
00507
00508 switch ( vil1_pixel_format(image) )
00509 {
00510 case VIL1_BYTE:
00511 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00512 case VIL1_UINT16:
00513 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00514 case VIL1_UINT32:
00515 return convert_grey_to_grey( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0);
00516 case VIL1_FLOAT:
00517 return convert_grey_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00518 case VIL1_DOUBLE:
00519 return image.get_section( buf, x0, y0, width, height );
00520 case VIL1_RGB_BYTE:
00521 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00522 case VIL1_RGB_UINT16:
00523 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00524 case VIL1_RGB_FLOAT:
00525 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00526 case VIL1_RGB_DOUBLE:
00527 return convert_rgb_to_grey( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00528 default:
00529 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00530 assert(false);
00531 return false;
00532 }
00533 }
00534
00535 VCL_DEFINE_SPECIALIZATION
00536 vcl_string vil1_image_as_impl<double>::is_a() const
00537 {
00538 static const vcl_string class_name_="vil1_image_as_impl<double>";
00539 return class_name_;
00540 }
00541
00542 VCL_DEFINE_SPECIALIZATION
00543 bool vil1_image_as_impl<double>::is_class(vcl_string const& s) const
00544 {
00545 return s==vil1_image_as_impl<double>::is_a() || vil1_image_impl::is_class(s);
00546 }
00547
00548
00549 template struct vil1_image_as_impl<double>;
00550
00551 vil1_image vil1_image_as_double(vil1_image const &image)
00552 {
00553 return vil1_image(new vil1_image_as_impl<double>(image));
00554 }
00555
00556 VCL_DEFINE_SPECIALIZATION
00557 vil1_image vil1_image_as(vil1_image const &image, double*)
00558 {
00559 return vil1_image(new vil1_image_as_impl<double>(image));
00560 }
00561
00562
00563
00564 VCL_DEFINE_SPECIALIZATION
00565 bool vil1_image_as_impl<vil1_rgb<unsigned char> >::get_section(void *buf,
00566 int x0, int y0,
00567 int width, int height) const
00568 {
00569 typedef unsigned char Outtype;
00570
00571 switch ( vil1_pixel_format(image) )
00572 {
00573 case VIL1_BYTE:
00574 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0 );
00575 case VIL1_UINT16:
00576 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0 );
00577 case VIL1_UINT32:
00578 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0 );
00579 case VIL1_FLOAT:
00580 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0 );
00581 case VIL1_DOUBLE:
00582 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0 );
00583 case VIL1_RGB_BYTE:
00584 return image.get_section( buf, x0, y0, width, height );
00585 case VIL1_RGB_UINT16:
00586 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0 );
00587 case VIL1_RGB_FLOAT:
00588 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0 );
00589 case VIL1_RGB_DOUBLE:
00590 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0 );
00591 case VIL1_RGBA_BYTE:
00592 return convert_rgba_to_rgb( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0 );
00593 default:
00594 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00595 assert(false);
00596 return false;
00597 }
00598 }
00599
00600 VCL_DEFINE_SPECIALIZATION
00601 vcl_string vil1_image_as_impl<vil1_rgb<unsigned char> >::is_a() const
00602 {
00603 static const vcl_string class_name_="vil1_image_as_impl<vil1_rgb<unsigned char> >";
00604 return class_name_;
00605 }
00606
00607 VCL_DEFINE_SPECIALIZATION
00608 bool vil1_image_as_impl<vil1_rgb<unsigned char> >::is_class(vcl_string const& s) const
00609 {
00610 return s==vil1_image_as_impl<vil1_rgb<unsigned char> >::is_a() || vil1_image_impl::is_class(s);
00611 }
00612
00613
00614 template struct vil1_image_as_impl<vil1_rgb<unsigned char> >;
00615
00616 vil1_image vil1_image_as_rgb_byte(vil1_image const &image)
00617 {
00618 return vil1_image(new vil1_image_as_impl<vil1_rgb<unsigned char> >(image));
00619 }
00620
00621 VCL_DEFINE_SPECIALIZATION
00622 vil1_image vil1_image_as(vil1_image const &image, vil1_rgb<vxl_byte>*)
00623 {
00624 return vil1_image(new vil1_image_as_impl<vil1_rgb<vxl_byte> >(image));
00625 }
00626
00627
00628
00629 VCL_DEFINE_SPECIALIZATION
00630 bool vil1_image_as_impl<vil1_rgb<float> >::get_section(void *buf,
00631 int x0, int y0,
00632 int width, int height) const
00633 {
00634 typedef float Outtype;
00635
00636 switch ( vil1_pixel_format(image) )
00637 {
00638 case VIL1_BYTE:
00639 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00640 case VIL1_UINT16:
00641 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00642 case VIL1_UINT32:
00643 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_32*)0,(Outtype*)0);
00644 case VIL1_FLOAT:
00645 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (float*)0,(Outtype*)0);
00646 case VIL1_DOUBLE:
00647 return convert_grey_to_rgb( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00648 case VIL1_RGB_BYTE:
00649 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00650 case VIL1_RGB_UINT16:
00651 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (vxl_uint_16*)0,(Outtype*)0);
00652 case VIL1_RGB_FLOAT:
00653 return image.get_section( buf, x0, y0, width, height );
00654 case VIL1_RGB_DOUBLE:
00655 return convert_rgb_to_rgb( image, buf, x0, y0, width, height, (double*)0,(Outtype*)0);
00656 case VIL1_RGBA_BYTE:
00657 return convert_rgba_to_rgb( image, buf, x0, y0, width, height, (vxl_byte*)0,(Outtype*)0);
00658 default:
00659 vcl_cerr << __FILE__ ": get_section() not implemented for " << image << vcl_endl;
00660 assert(false);
00661 return false;
00662 }
00663 }
00664
00665 VCL_DEFINE_SPECIALIZATION
00666 vcl_string vil1_image_as_impl<vil1_rgb<float> >::is_a() const
00667 {
00668 static const vcl_string class_name_="vil1_image_as_impl<vil1_rgb<float> >";
00669 return class_name_;
00670 }
00671
00672 VCL_DEFINE_SPECIALIZATION
00673 bool vil1_image_as_impl<vil1_rgb<float> >::is_class(vcl_string const& s) const
00674 {
00675 return s==vil1_image_as_impl<vil1_rgb<float> >::is_a() || vil1_image_impl::is_class(s);
00676 }
00677
00678
00679 template struct vil1_image_as_impl<vil1_rgb<float> >;
00680
00681 vil1_image vil1_image_as_rgb_float(vil1_image const &image)
00682 {
00683 return vil1_image(new vil1_image_as_impl<vil1_rgb<float> >(image));
00684 }
00685
00686 VCL_DEFINE_SPECIALIZATION
00687 vil1_image vil1_image_as(vil1_image const &image, vil1_rgb<float>*)
00688 {
00689 return vil1_image(new vil1_image_as_impl<vil1_rgb<float> >(image));
00690 }
00691
00692
00693
00694
00695 VCL_DEFINE_SPECIALIZATION
00696 bool vil1_image_as_impl<vil1_rgb<vxl_uint_16> >::get_section(void *buf,
00697 int