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