00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_IMAGEREADER_H
00024 #define LUX_IMAGEREADER_H
00025 #include "lux.h"
00026 #include "texturecolor.h"
00027 #include "mipmap.h"
00028 #include "error.h"
00029 using namespace std;
00030
00031 namespace lux
00032 {
00033
00034 class ImageData {
00035 public:
00036 enum PixelDataType {
00037 UNSIGNED_CHAR_TYPE,
00038 UNSIGNED_SHORT_TYPE,
00039 FLOAT_TYPE
00040 };
00041
00042 ImageData(int width, int height, PixelDataType type, int noChannels, TextureColorBase* data) {
00043 width_ = width;
00044 height_ = height;
00045 pixel_type_ = type;
00046 noChannels_ = noChannels;
00047
00048 data_ = data;
00049 isExrImage_ = false;
00050
00051 }
00052
00053 ~ImageData() {
00054 delete[] data_;
00055 }
00056
00057 int getWidth() {
00058 return width_;
00059 }
00060
00061 int getHeight() {
00062 return height_;
00063 }
00064
00065 int getChannels() {
00066 return noChannels_;
00067 }
00068
00069 PixelDataType getPixelDataType() {
00070 return pixel_type_;
00071 }
00072
00073 TextureColorBase * getData() {
00074 return data_;
00075 }
00076
00077 bool isExrImage() {
00078 return isExrImage_;
00079 }
00080
00081 void setIsExrImage(bool exrImage) {
00082 isExrImage_ = exrImage;
00083 }
00084
00085 template <class T> MIPMap<T> *createMIPMap(
00086 ImageTextureFilterType filterType = BILINEAR,
00087 float maxAniso = 8.f, ImageWrap wrapMode = TEXTURE_REPEAT,
00088 float gain = 1.0f, float gamma = 1.0f) {
00089 MIPMap<T> *mipmap = NULL;
00090
00091
00092 if (noChannels_ == 1) {
00093 if (pixel_type_ == UNSIGNED_CHAR_TYPE) {
00094 if ((gain == 1.0f) && (gamma == 1.0f))
00095 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned char, 1 > >(
00096 filterType, width_, height_,
00097 (TextureColor<unsigned char, 1 > *)data_,
00098 maxAniso, wrapMode);
00099 else
00100 mipmap = new MIPMapImpl<T, TextureColor<unsigned char, 1 > >(
00101 filterType, width_, height_,
00102 (TextureColor<unsigned char, 1 > *)data_,
00103 maxAniso, wrapMode, gain, gamma);
00104 } else if (pixel_type_ == FLOAT_TYPE) {
00105 if ((gain == 1.0f) && (gamma == 1.0f))
00106 mipmap = new MIPMapFastImpl<T, TextureColor<float, 1 > >(
00107 filterType, width_, height_,
00108 (TextureColor<float, 1 > *)data_,
00109 maxAniso, wrapMode);
00110 else
00111 mipmap = new MIPMapImpl<T, TextureColor<float, 1 > >(
00112 filterType, width_, height_,
00113 (TextureColor<float, 1 > *)data_,
00114 maxAniso, wrapMode, gain, gamma);
00115 } else if (pixel_type_ == UNSIGNED_SHORT_TYPE) {
00116 if ((gain == 1.0f) && (gamma == 1.0f))
00117 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned short, 1 > >(
00118 filterType, width_, height_,
00119 (TextureColor<unsigned short, 1 > *)data_,
00120 maxAniso, wrapMode);
00121 else
00122 mipmap = new MIPMapImpl<T, TextureColor<unsigned short, 1 > >(
00123 filterType, width_, height_,
00124 (TextureColor<unsigned short, 1 > *)data_,
00125 maxAniso, wrapMode, gain, gamma);
00126 }
00127 } else if (noChannels_ == 3) {
00128 if (pixel_type_ == UNSIGNED_CHAR_TYPE) {
00129 if ((gain == 1.0f) && (gamma == 1.0f)) {
00130 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned char, 3 > >(
00131 filterType, width_, height_,
00132 (TextureColor<unsigned char, 3 > *)data_,
00133 maxAniso, wrapMode);
00134 } else
00135 mipmap = new MIPMapImpl<T, TextureColor<unsigned char, 3 > >(
00136 filterType, width_, height_,
00137 (TextureColor<unsigned char, 3 > *)data_,
00138 maxAniso, wrapMode, gain, gamma);
00139 } else if (pixel_type_ == FLOAT_TYPE) {
00140 if ((gain == 1.0f) && (gamma == 1.0f))
00141 mipmap = new MIPMapFastImpl<T, TextureColor<float, 3 > >(
00142 filterType, width_, height_,
00143 (TextureColor<float, 3 > *)data_,
00144 maxAniso, wrapMode);
00145 else
00146 mipmap = new MIPMapImpl<T, TextureColor<float, 3 > >(
00147 filterType, width_, height_,
00148 (TextureColor<float, 3 > *)data_,
00149 maxAniso, wrapMode, gain, gamma);
00150 } else if (pixel_type_ == UNSIGNED_SHORT_TYPE) {
00151 if ((gain == 1.0f) && (gamma == 1.0f))
00152 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned short, 3 > >(
00153 filterType, width_, height_,
00154 (TextureColor<unsigned short, 3 > *)data_,
00155 maxAniso, wrapMode);
00156 else
00157 mipmap = new MIPMapImpl<T, TextureColor<unsigned short, 3 > >(
00158 filterType, width_, height_,
00159 (TextureColor<unsigned short, 3 > *)data_,
00160 maxAniso, wrapMode, gain, gamma);
00161 }
00162 } else if (noChannels_ == 4) {
00163 if (pixel_type_ == UNSIGNED_CHAR_TYPE) {
00164 if ((gain == 1.0f) && (gamma == 1.0f))
00165 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned char, 4 > >(
00166 filterType, width_, height_,
00167 (TextureColor<unsigned char, 4 > *)data_,
00168 maxAniso, wrapMode);
00169 else
00170 mipmap = new MIPMapImpl<T, TextureColor<unsigned char, 4 > >(
00171 filterType, width_, height_,
00172 (TextureColor<unsigned char, 4 > *)data_,
00173 maxAniso, wrapMode, gain, gamma);
00174 } else if (pixel_type_ == FLOAT_TYPE) {
00175 if ((gain == 1.0f) && (gamma == 1.0f))
00176 mipmap = new MIPMapFastImpl<T, TextureColor<float, 4 > >(
00177 filterType, width_, height_,
00178 (TextureColor<float, 4 > *)data_,
00179 maxAniso, wrapMode);
00180 else
00181 mipmap = new MIPMapImpl<T, TextureColor<float, 4 > >(
00182 filterType, width_, height_,
00183 (TextureColor<float, 4 > *)data_,
00184 maxAniso, wrapMode, gain, gamma);
00185 } else if (pixel_type_ == UNSIGNED_SHORT_TYPE) {
00186 if ((gain == 1.0f) && (gamma == 1.0f))
00187 mipmap = new MIPMapFastImpl<T, TextureColor<unsigned short, 4 > >(
00188 filterType, width_, height_,
00189 (TextureColor<unsigned short, 4 > *)data_,
00190 maxAniso, wrapMode);
00191 else
00192 mipmap = new MIPMapImpl<T, TextureColor<unsigned short, 4 > >(
00193 filterType, width_, height_,
00194 (TextureColor<unsigned short, 4 > *)data_,
00195 maxAniso, wrapMode, gain, gamma);
00196 }
00197 } else {
00198 luxError(LUX_SYSTEM, LUX_ERROR, "Unsupported channel count in ImageData::createMIPMap()");
00199
00200 return NULL;
00201 }
00202
00203 return mipmap;
00204 }
00205
00206 private:
00207 int width_;
00208 int height_;
00209 int noChannels_;
00210 TextureColorBase *data_;
00211 PixelDataType pixel_type_;
00212 bool isExrImage_;
00213 };
00214
00215 class ImageReader {
00216 public:
00217
00218 virtual ~ImageReader() {
00219 }
00220 virtual ImageData* read(const string &name) = 0;
00221 };
00222
00223 class ExrImageReader : public ImageReader {
00224 public:
00225
00226 virtual ~ExrImageReader() {
00227 }
00228
00229 ExrImageReader() {
00230 };
00231 virtual ImageData* read(const string &name);
00232 };
00233
00234 }
00235 #endif // LUX_IMAGEREADER_H