Go to the documentation of this file.00001 #include "vil_j2k_pyramid_image_resource.h"
00002
00003
00004
00005
00006
00007
00008 #include <vcl_cmath.h>
00009
00010
00011 static float scale_at_level(unsigned level)
00012 {
00013 if (level == 0)
00014 return 1.0f;
00015 float s = vcl_pow(2.0f, -static_cast<float>(level));
00016 return s;
00017 }
00018
00019 vil_j2k_pyramid_image_resource::
00020 vil_j2k_pyramid_image_resource(vil_image_resource_sptr const& j2k): j2k_sptr_(j2k)
00021 {
00022 ptr_ = 0;
00023 if (!j2k_sptr_)
00024 return;
00025 vcl_string fmt = j2k_sptr_->file_format();
00026 if (fmt=="j2k")
00027 ptr_=static_cast<vil_j2k_image*>(j2k_sptr_.ptr());
00028 }
00029
00030 unsigned vil_j2k_pyramid_image_resource::nplanes()const
00031 {
00032 unsigned ret = 0;
00033 if (ptr_)
00034 ret = ptr_->nplanes();
00035 return ret;
00036 }
00037
00038
00039
00040
00041 unsigned vil_j2k_pyramid_image_resource::ni() const
00042 {
00043 unsigned ret = 0;
00044 if (ptr_)
00045 ret = ptr_->ni();
00046 return ret;
00047 }
00048
00049
00050
00051
00052 unsigned vil_j2k_pyramid_image_resource::nj() const
00053 {
00054 unsigned ret = 0;
00055 if (ptr_)
00056 ret = ptr_->nj();
00057 return ret;
00058 }
00059
00060
00061 vil_pixel_format vil_j2k_pyramid_image_resource::pixel_format() const
00062 {
00063 if (ptr_)
00064 return ptr_->pixel_format();
00065 return VIL_PIXEL_FORMAT_UNKNOWN;
00066 }
00067
00068
00069
00070 char const* vil_j2k_pyramid_image_resource::file_format() const
00071 {
00072 return "j2k_pyramid";
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 unsigned vil_j2k_pyramid_image_resource::nlevels() const
00082 {
00083 if (!ptr_)
00084 return 0;
00085 unsigned max_dim = this->ni(), nj = this->nj();
00086 if (nj>max_dim)
00087 max_dim = nj;
00088 if (max_dim<1000)
00089 return 1;
00090
00091 double scale = max_dim/1000.0;
00092 if (scale<=1.0)
00093 return 1;
00094 double lscale = vcl_log(scale);
00095 unsigned nlev = static_cast<unsigned>(lscale/vcl_log(2.0));
00096 return nlev;
00097 }
00098
00099
00100 vil_image_view_base_sptr
00101 vil_j2k_pyramid_image_resource::get_copy_view(unsigned i0, unsigned n_i,
00102 unsigned j0, unsigned n_j,
00103 unsigned level) const
00104 {
00105 if (!ptr_||!(ptr_->is_valid()))
00106 return 0;
00107 if (level>this->nlevels())
00108 level = this->nlevels()-1;
00109 double s = scale_at_level(level);
00110 double factor = static_cast<unsigned>(1/s);
00111 return ptr_->get_copy_view_decimated(i0, n_i, j0, n_j, factor, factor);
00112 }
00113
00114
00115
00116
00117 vil_image_view_base_sptr
00118 vil_j2k_pyramid_image_resource::get_copy_view(unsigned i0, unsigned n_i,
00119 unsigned j0, unsigned n_j,
00120 const float scale,
00121 float& actual_scale) const
00122 {
00123 if (scale>=1.0f)
00124 {
00125 actual_scale = 1.0f;
00126 return this->get_copy_view(i0, n_i, j0, n_j, 0);
00127 }
00128 float f_lev = -vcl_log(scale)/vcl_log(2.0f);
00129 unsigned level = static_cast<unsigned>(f_lev);
00130 if (level>this->nlevels())
00131 level = this->nlevels()-1;
00132 actual_scale = scale_at_level(level);
00133 return this->get_copy_view(i0, n_i, j0, n_j, level);
00134 }
00135
00136
00137 vil_image_resource_sptr
00138 vil_j2k_pyramid_image_resource::get_resource(const unsigned level) const
00139 {
00140 if (level==0)
00141 return j2k_sptr_;
00142 return 0;
00143 }
00144
00145
00146 void vil_j2k_pyramid_image_resource::print(const unsigned level)
00147 {
00148 }
00149