00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009 #include "vil1_skip_image_impl.h"
00010
00011 #include <vcl_climits.h>
00012 #include <vcl_iostream.h>
00013 #include <vcl_cassert.h>
00014 #include <vcl_vector.h>
00015
00016 vil1_skip_image_impl::vil1_skip_image_impl(vil1_image const &underlying, unsigned sx, unsigned sy)
00017 : base(underlying)
00018 , skipx(sx)
00019 , skipy(sy)
00020 {
00021 assert(base);
00022 assert(skipx>0);
00023 assert(skipy>0);
00024 }
00025
00026
00027
00028 vil1_image vil1_skip_image_impl::get_plane(unsigned int p) const
00029 {
00030 vil1_image_impl *i = new vil1_skip_image_impl(base.get_plane(p), skipx, skipy);
00031 return i;
00032 }
00033
00034 bool vil1_skip_image_impl::put_section(void const * , int, int, int, int)
00035 {
00036 return false;
00037 }
00038
00039 bool vil1_skip_image_impl::get_property(char const *, void *) const
00040 {
00041 return false;
00042 }
00043
00044
00045
00046 bool vil1_skip_image_impl::get_section(void * buf, int x0, int y0, int w, int h) const
00047 {
00048 if (base.bits_per_component() % CHAR_BIT) {
00049 vcl_cerr << __FILE__ " : urgh!\n";
00050 return false;
00051 }
00052
00053
00054 unsigned cell_size = base.planes() * base.components() * base.bits_per_component();
00055 cell_size /= CHAR_BIT;
00056 unsigned buffer_size = (skipx*w * cell_size);
00057 vcl_vector<unsigned char> buffer(buffer_size);
00058
00059
00060 unsigned char *dst = static_cast<unsigned char*>(buf);
00061
00062
00063 for (int j=0; j<h; ++j) {
00064
00065 bool v = base.get_section(&buffer[0], skipx*x0, skipy*(y0+j), skipx*w, 1);
00066 if (!v)
00067 return false;
00068
00069
00070 for (int i=0; i<w; ++i)
00071
00072 for (unsigned k=0; k<cell_size; ++k)
00073 dst[cell_size*(j*w + i) + k] = buffer[cell_size*skipx*i + k];
00074 }
00075
00076 return true;
00077 }