13 Impl(std::string fileName,
bool wrapAroundEOF) {
16 _wrapAroundEOF = wrapAroundEOF;
31 _fileSignature = 293390619;
42 if (_framePoisson!=NULL)
59 assert(maxPoisson>minPoisson);
65 _framePoisson =
new PoissonRate(_width*_height*_channels);
66 for (
int i=0; i<_width*_height*_channels; i++) {
67 _framePoisson->
setRate(i, _frame[i]*(maxPoisson-minPoisson)/255.0f + minPoisson);
75 fseek(_fileId, _fileHeaderSizeBytes, SEEK_SET);
79 fprintf(stdout,
"VisualStimulus loaded (\"%s\", Type %d, Size %dx%dx%dx%d).\n", _fileName.c_str(), _type,
80 _width, _height, _channels, _length);
98 void readFramePrivate() {
105 if (_framePoisson!=NULL)
106 delete _framePoisson;
107 _frame = NULL; _framePoisson = NULL;
110 if (feof(_fileId) || (_frameNum==_length-1)) {
114 if (!_wrapAroundEOF) {
116 fprintf(stderr,
"WARNING: End of file reached, starting from the top\n");
124 _frame =
new unsigned char[_width*_height*_channels];
125 size_t result = fread(_frame,
sizeof(
unsigned char), _width*_height*_channels, _fileId);
126 if (result!=(
size_t) (_width*_height*_channels)) {
127 fprintf(stderr,
"VisualStimulus Error: Error while reading stimulus frame (expected %d elements, found %d\n",
128 _width*_height*_channels, (
int)result);
138 _fileId = fopen(_fileName.c_str(),
"rb");
140 fprintf(stderr,
"VisualStimulus Error: Could not open stimulus file %s\n",_fileName.c_str());
144 bool readErr =
false;
151 result = fread(&tmpInt,
sizeof(
int), 1, _fileId);
152 readErr |= (result!=1);
153 if (tmpInt != _fileSignature) {
154 fprintf(stderr,
"VisualStimulus Error: Unknown file signature\n");
159 result = fread(&tmpFloat,
sizeof(
float), 1, _fileId);
160 readErr |= (result!=1);
161 if (tmpFloat != _version) {
162 fprintf(stderr,
"VisualStimulus Error: Unknown file version (%1.1f), must have 1.0\n",tmpFloat);
167 result = fread(&tmpInt,
sizeof(
int), 1, _fileId);
168 readErr |= (result!=1);
170 fprintf(stderr,
"VisualStimulus Error: Unknown stimulus type found (%d)\n",tmpInt);
176 result = fread(&tmpChar,
sizeof(
char), 1, _fileId);
177 readErr |= (result!=1);
178 _channels = (int)tmpChar;
181 result = fread(&tmpInt,
sizeof(
int), 1, _fileId); readErr |= (result!=1);
183 result = fread(&tmpInt,
sizeof(
int), 1, _fileId); readErr |= (result!=1);
185 result = fread(&tmpInt,
sizeof(
int), 1, _fileId); readErr |= (result!=1);
190 fprintf(stderr,
"VisualStimulus Error: Error while reading file %s\n",_fileName.c_str());
195 _fileHeaderSizeBytes = ftell(_fileId);
202 std::string _fileName;
207 long _fileHeaderSizeBytes;
210 unsigned char* _frame;