00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vil1_resample_image_impl.h"
00010 #include <vil1/vil1_resample_image.h>
00011 #include <vil1/vil1_rgb.h>
00012 #include <vil1/vil1_pixel.h>
00013 #include <vxl_config.h>
00014 #include <vcl_climits.h>
00015 #include <vcl_iostream.h>
00016 #include <vcl_cassert.h>
00017
00018 vil1_resample_image_impl::vil1_resample_image_impl(vil1_image const &underlying, unsigned nw, unsigned nh)
00019 : base(underlying)
00020 , new_width(nw)
00021 , new_height(nh)
00022 {
00023 assert(base);
00024 assert(new_width>0);
00025 assert(new_height>0);
00026 }
00027
00028
00029
00030 vil1_image vil1_resample_image_impl::get_plane(unsigned int p) const
00031 {
00032 vil1_image_impl *i = new vil1_resample_image_impl(base.get_plane(p), new_width, new_height);
00033 return vil1_image(i);
00034 }
00035
00036 bool vil1_resample_image_impl::put_section(void const * , int, int, int, int)
00037 {
00038 return false;
00039 }
00040
00041 bool vil1_resample_image_impl::get_property(char const *, void *) const
00042 {
00043 return false;
00044 }
00045
00046
00047
00048 bool vil1_resample_image_impl::get_section(void *buf, int x0, int y0, int w, int h) const
00049 {
00050 assert(buf!=0);
00051 #ifdef DEBUG
00052 vcl_cerr << "get_section() x0 y0 w h = " << x0 << ' ' << y0 << ' ' << w << ' ' << h << '\n';
00053 #endif
00054
00055 if (base.bits_per_component() % CHAR_BIT) {
00056 vcl_cerr << __FILE__ " : urgh!\n";
00057 return false;
00058 }
00059
00060
00061 if (x0 < 0 || y0 < 0 || x0+w > (int)new_width || y0+h > (int)new_height) {
00062 vcl_cerr << __FILE__ ": invalid section bounds\n";
00063 return false;
00064 }
00065
00066
00067 switch ( vil1_pixel_format(base) ) {
00068 case VIL1_BYTE:
00069 return vil1_resample_image(base, new_width, new_height,
00070 (vxl_byte*)buf, (unsigned*)0,
00071 x0, y0, w, h);
00072 case VIL1_RGB_BYTE:
00073 return vil1_resample_image(base, new_width, new_height,
00074 (vil1_rgb<vxl_byte>*)buf, (vil1_rgb<int>*)0,
00075 x0, y0, w, h);
00076
00077 default:
00078 vcl_cerr << __FILE__ ": not implemented for this pixel type\n";
00079 return false;
00080 }
00081 }