Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_IMAGE_IO_IMAGE_READ_H
00002 #define OPENTISSUE_GPU_IMAGE_IO_IMAGE_READ_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/gpu/image/image.h>
00013 #include <OpenTissue/gpu/image/io/image_il_wrap.h>
00014
00015 #include <iostream>
00016 #include <string>
00017
00018 namespace OpenTissue
00019 {
00020 namespace image
00021 {
00030 bool read(
00031 std::string const & filename
00032 , OpenTissue::image::Image<unsigned char> & image
00033 , bool show_statistics = true
00034 )
00035 {
00036
00037
00038
00039 glBindTexture( GL_TEXTURE_2D, 0 );
00040
00041 ilInit();
00042 iluInit();
00043 ilutInit();
00044
00045
00046
00047
00048 OpenTissue::image::detail::ilImage devil;
00049
00050 ILboolean result = devil.Load(const_cast< char * >(filename.c_str()));
00051 if (!result)
00052 {
00053 return false;
00054 }
00055
00056 if (show_statistics)
00057 {
00058 std::cout << "--- file : " << filename << "---------------------------" << std::endl;
00059 std::cout << "\twidth = " << (int)devil.Width() << std::endl;
00060 std::cout << "\theight = " << (int)devil.Height() << std::endl;
00061 std::cout << "\tdepth = " << (int)devil.Depth() << std::endl;
00062 std::cout << "\tBpp = " << (int)devil.Bpp() << std::endl;
00063 std::cout << "\tBitpp = " << (int)devil.Bitpp() << std::endl;
00064 std::cout << "\tPallette Type = " << OpenTissue::image::detail::get_IL_string(devil.PaletteType()) << std::endl;
00065 std::cout << "\tFormat = " << OpenTissue::image::detail::get_IL_string(devil.Format()) << std::endl;
00066 std::cout << "\tType = " << OpenTissue::image::detail::get_IL_string(devil.Type()) << std::endl;
00067 std::cout << "\tNumImages = " << (int)devil.NumImages() << std::endl;
00068 std::cout << "\tNumMipmaps = " << (int)devil.NumMipmaps() << std::endl;
00069 std::cout << "\tOrigin = " << OpenTissue::image::detail::get_IL_string(devil.GetOrigin()) << std::endl;
00070 }
00071
00072 if (devil.GetOrigin() != IL_ORIGIN_LOWER_LEFT)
00073 devil.Flip();
00074
00075 size_t width = devil.Width();
00076 size_t height = devil.Height();
00077 image.create(width, height, 4);
00078
00079 devil.Bind();
00080 ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA, IL_UNSIGNED_BYTE, image.get_data() );
00081
00082 ilShutDown();
00083
00084 return true;
00085 }
00086
00087 }
00088 }
00089
00090
00091 #endif