Go to the documentation of this file.00001
00002 #include "vil_copy.h"
00003
00004
00005
00006
00007
00008 #include <vcl_algorithm.h>
00009 #include <vil/vil_property.h>
00010 #include <vil/vil_image_resource.h>
00011 #include <vil/vil_blocked_image_resource.h>
00012
00013
00014 static const unsigned long large_image_limit_ = 1024ul * 1024ul * 8ul;
00015
00016
00017
00018
00019 static bool copy_resource_by_blocks(const vil_image_resource_sptr& src,
00020 vil_image_resource_sptr& det)
00021 {
00022
00023 vil_blocked_image_resource_sptr bsrc = blocked_image_resource(src);
00024 vil_blocked_image_resource_sptr bdet = blocked_image_resource(det);
00025 for (unsigned bi = 0; bi<bsrc->n_block_i(); ++bi)
00026 for (unsigned bj = 0; bj<bsrc->n_block_j(); ++bj)
00027 {
00028 vil_image_view_base_sptr blk = bsrc->get_block(bi, bj);
00029 if (!blk) return false;
00030 if (!bdet->put_block(bi, bj, *blk)) return false;
00031 }
00032 return true;
00033 }
00034
00035
00036
00037
00038
00039
00040
00041 bool vil_copy_deep(const vil_image_resource_sptr &src, vil_image_resource_sptr &dest)
00042 {
00043 if (dest->ni() != src->ni() || dest->nj() != src->nj() ||
00044 dest->nplanes() != src->nplanes() || dest->pixel_format() != src->pixel_format() )
00045 return false;
00046
00047 if (src->ni() == 0 || src->nj() == 0 || src->nplanes() == 0) return true;
00048
00049
00050
00051 unsigned src_sbi=0, src_sbj=0, dest_sbi=0, dest_sbj=0;
00052
00053 src->get_property(vil_property_size_block_i, &src_sbi);
00054 src->get_property(vil_property_size_block_j, &src_sbj);
00055 dest->get_property(vil_property_size_block_i, &dest_sbi);
00056 dest->get_property(vil_property_size_block_j, &dest_sbj);
00057
00058
00059 if (src_sbi>0&&src_sbj>0&&src_sbi==dest_sbi&&src_sbj==dest_sbj)
00060 return copy_resource_by_blocks(src, dest);
00061
00062 if (src->ni() * src->nj() * src->nplanes() < large_image_limit_)
00063 {
00064 vil_image_view_base_sptr view_ref = src->get_view();
00065 if (!view_ref) return false;
00066 return dest->put_view(*view_ref);
00067 }
00068 else
00069 {
00070 unsigned got_to_line =0;
00071 unsigned block_size = vcl_max(static_cast<unsigned>(large_image_limit_ / src->ni()),1u);
00072
00073 while (got_to_line < src->nj())
00074 {
00075 vil_image_view_base_sptr view_ref = src->get_view(0, src->ni(), got_to_line,
00076 vcl_min(block_size, src->nj()-got_to_line));
00077 if (!view_ref) return false;
00078 if (!dest->put_view(*view_ref,0,got_to_line)) return false;
00079 got_to_line += block_size;
00080 }
00081 return true;
00082 }
00083 }
00084