00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <algorithm>
00025 #include <fstream>
00026
00027 #include "lux.h"
00028 #include "error.h"
00029 #include "color.h"
00030 #include "spectrum.h"
00031
00032 #include "igiio.h"
00033
00034
00035 using namespace lux;
00036
00037
00038 namespace lux {
00039
00040 RGBColor *ReadIgiImage(const string &name, int *width, int *height) {
00041
00042 printf("IGI file format input not implemented yet");
00043 return NULL;
00044 }
00045
00046 void WriteIgiImage(const string &name, vector<RGBColor> &pixels,
00047 vector<float> &alpha, int xRes, int yRes,
00048 int totalXRes, int totalYRes,
00049 int xOffset, int yOffset) {
00050
00051 IndigoImageHeader header;
00052
00053
00054 u_int xyzSize = xRes * yRes;
00055 float *xyz = new float[3 * xyzSize];
00056 for (u_int i = 0; i < xyzSize; ++i) {
00057
00058 xyz[3 * i] = 0.436052025f * pixels[i].c[0] + 0.385081593f * pixels[i].c[1] + 0.143087414f * pixels[i].c[2];
00059 xyz[3 * i + 1] = 0.222491598f * pixels[i].c[0] + 0.71688606f * pixels[i].c[1] + 0.060621486f * pixels[i].c[2];
00060 xyz[3 * i + 2] = 0.013929122f * pixels[i].c[0] + 0.097097002f * pixels[i].c[1] + 0.71418547f * pixels[i].c[2];
00061 }
00062
00063 std::ofstream file(name.c_str(), std::ios::binary);
00064 if(!file) {
00065 std::stringstream ss;
00066 ss<< "Cannot open file '"<<name<<"' for output";
00067 luxError(LUX_SYSTEM, LUX_SEVERE, ss.str().c_str());
00068 return;
00069 }
00070
00071
00072 memset(&header, 0, sizeof(header));
00073 header.magic_number = INDIGO_IMAGE_MAGIC_NUMBER;
00074 header.format_version = 1;
00075
00076 header.num_samples = 1.;
00077 header.width = xRes;
00078 header.height = yRes;
00079 header.supersample_factor = 1;
00080 header.zipped = false;
00081 header.image_data_size = xyzSize * 12;
00082 header.colour_space = 0;
00083
00084
00085 file.write((const char*)&header, sizeof(header));
00086
00087 file.write((const char*)&xyz[0], header.image_data_size);
00088
00089 if(!file.good()) {
00090 std::stringstream ss;
00091 ss<< "Error writing IGI output file '"<<name<<"'";
00092 luxError(LUX_SYSTEM, LUX_SEVERE, ss.str().c_str());
00093 return;
00094 }
00095
00096 file.close();
00097 delete xyz;
00098 }
00099
00100 }