00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include "Component/ModelManager.H"
00040 #include "Image/Image.H"
00041 #include "Psycho/PsychoDisplay.H"
00042 #include "GUI/GUIOpts.H"
00043 #include "Raster/Raster.H"
00044 #include "Util/Types.H"
00045 #include <cstdlib>
00046
00047
00048
00049 void updateLuminance(Image< PixRGB<byte> >& s2, int lumin, const float sat);
00050 extern "C" int main(const int argc, char** argv)
00051 {
00052 MYLOGVERB = LOG_INFO;
00053
00054
00055 ModelManager manager("Calibrate luminance");
00056
00057
00058 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager));
00059 manager.addSubComponent(d);
00060
00061
00062 manager.setOptionValString(&OPT_SDLdisplayDims, "1280x1024");
00063 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0));
00064 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255));
00065 d->setModelParamVal("PsychoDisplayBlack", PixRGB<byte>(255));
00066 d->setModelParamVal("PsychoDisplayWhite", PixRGB<byte>(128));
00067 d->setModelParamVal("PsychoDisplayFixSiz", 5);
00068 d->setModelParamVal("PsychoDisplayFixThick", 5);
00069
00070
00071 if (manager.parseCommandLine(argc, argv,
00072 "<img1.ppm> <img2.ppm>"
00073 " <luminance2> <saturation2> ", 1, -1)==false)
00074 return(1);
00075
00076
00077 manager.start();
00078
00079
00080 d->clearScreen();
00081 LINFO("Loading '%s'...", manager.getExtraArg(0).c_str());
00082 Image< PixRGB<byte> > s1 =
00083 Raster::ReadRGB(manager.getExtraArg(0));
00084 LINFO("Loading '%s'...", manager.getExtraArg(1).c_str());
00085 Image< PixRGB<byte> > s2 =
00086 Raster::ReadRGB(manager.getExtraArg(1));
00087
00088
00089 int lumin = manager.getExtraArgAs<int>(2);
00090 float sat = manager.getExtraArgAs<float>(3);
00091
00092 SDL_Surface *surf1 = d->makeBlittableSurface(s1, false);
00093 SDL_Surface *surf2 = d->makeBlittableSurface(s2, false);
00094
00095 LINFO("stimuli ready.");
00096
00097
00098 d->displayText("hit any key when ready");
00099 d->waitForKey();
00100 d->waitNextRequestedVsync(false, true);
00101 while (true) {
00102 d->clearScreen();
00103 d->displayFixation();
00104
00105 for (int j = 0; j < 9; j ++) {
00106 d->displaySurface(surf1, -2, true);
00107 d->waitFrames(3);
00108 d->displaySurface(surf2, -2, true);
00109 d->waitFrames(3);
00110 }
00111 d->displaySurface(surf1, -2, true);
00112
00113
00114 d->displayText("Press <+><NUM> to increase luminance,"
00115 " <-><NUM> to decrease luminance"
00116 " and <ENTER> to accept");
00117 int c1 = d->waitForKey();
00118 int c2 = d->waitForKey();
00119 if (c1 == 43){
00120
00121 SDL_FreeSurface(surf2);
00122 lumin += c2 - 48;
00123 updateLuminance(s2, lumin, sat);
00124 surf2 = d->makeBlittableSurface(s2, false);
00125 }
00126 else if (c1 == 45){
00127
00128 SDL_FreeSurface(surf2);
00129 lumin -= c2 - 48;
00130 updateLuminance(s2, lumin, sat);
00131 surf2 = d->makeBlittableSurface(s2, false);
00132 }
00133 else break;
00134 }
00135
00136 d->clearScreen();
00137
00138
00139 SDL_FreeSurface(surf1);
00140 SDL_FreeSurface(surf2);
00141
00142 d->clearScreen();
00143 d->displayText("Experiment complete. Thank you!");
00144 d->waitForKey();
00145
00146
00147 manager.stop();
00148
00149
00150 return 0;
00151 }
00152
00153 void updateLuminance(Image< PixRGB<byte> >& s2, int lumin, const float sat){
00154 LINFO ("test luminance = %d", lumin);
00155
00156 int red = (int)(lumin / (1.0f - 0.7875*sat));
00157 int green = (int) ((lumin - 0.2125*red)/0.7875);
00158 PixRGB<byte> zero(0, 0, 0);
00159
00160 LINFO ("r, g, b = %d, %d, %d", red, green, green);
00161 PixRGB<byte> rgb(red, green, green);
00162 int w = s2.getWidth(), h = s2.getHeight();
00163
00164 for (int x = 0; x < w; x++)
00165 for (int y = 0; y < h; y ++) {
00166 if (s2.getVal(x,y) == zero);
00167 else s2.setVal(x, y, rgb);
00168 }
00169 }
00170
00171
00172
00173
00174
00175
00176