00001 #include "std/config.H"
00002 #include "texture.H"
00003
00004 static bool debug = Config::get_var_bool("DEBUG_TEXTURE",false);
00005
00006
00007
00008
00009
00010
00011
00012
00013 int
00014 TEXTURE::load_image()
00015 {
00016 if (_image_not_available)
00017 return 0;
00018
00019 _img.load_file(**_file);
00020 expand_image();
00021 if (_img.empty()) {
00022 _image_not_available = true;
00023 cerr << "TEXTURE::load_image - could not load " << _file << endl;
00024 }
00025 return !_img.empty();
00026 }
00027
00028
00029
00030
00031
00032
00033
00034
00035 int
00036 TEXTURE::set_image(unsigned char *data, int w, int h, uint bpp)
00037 {
00038 _img.set(w,h,bpp,data);
00039 expand_image();
00040 return !_img.empty();
00041 }
00042
00043 void
00044 TEXTURE::expand_image()
00045 {
00046
00047
00048
00049
00050 if (!_img.empty() && _expand_image) {
00051 int w = _img.width();
00052 int h = _img.height();
00053 if (!_img.expand_power2())
00054 return;
00055 err_adv(debug, "TEXTURE::expand_image: expanding from %dx%d to %dx%d",
00056 w, h, _img.width(), _img.height());
00057 _scale = mlib::Wtransf::scaling(
00058 mlib::Wvec((double)w/_img.width(), (double)h/_img.height(), 1)
00059 );
00060 }
00061 }
00062
00063 void
00064 TEXTURE::expand_power2(int width, int height)
00065 {
00066 _img.resize(width, height, _img.bpp());
00067 _img.expand_power2();
00068 }
00069
00070