* Loads the contents of an X-Com DAT image file into the * surface. Unlike the PCK, a DAT file is an uncompressed * image with no offsets so these have to be figured out * manually, usually by splitting the image into equal portions. * @param filename Filename of the DAT image. * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SCR_.26_DAT */
| 156 | * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#SCR_.26_DAT |
| 157 | */ |
| 158 | void SurfaceSet::loadDat(const std::string &filename) |
| 159 | { |
| 160 | int nframes = 0; |
| 161 | |
| 162 | // Load file and put pixels in surface |
| 163 | std::ifstream imgFile (filename.c_str(), std::ios::in | std::ios::binary); |
| 164 | if (!imgFile) |
| 165 | { |
| 166 | throw Exception(filename + " not found"); |
| 167 | } |
| 168 | |
| 169 | imgFile.seekg(0, std::ios::end); |
| 170 | std::streamoff size = imgFile.tellg(); |
| 171 | imgFile.seekg(0, std::ios::beg); |
| 172 | |
| 173 | nframes = (int)size / (_width * _height); |
| 174 | |
| 175 | for (int i = 0; i < nframes; ++i) |
| 176 | { |
| 177 | Surface *surface = new Surface(_width, _height); |
| 178 | _frames[i] = surface; |
| 179 | } |
| 180 | |
| 181 | Uint8 value; |
| 182 | int x = 0, y = 0, frame = 0; |
| 183 | |
| 184 | // Lock the surface |
| 185 | _frames[frame]->lock(); |
| 186 | |
| 187 | while (imgFile.read((char*)&value, 1)) |
| 188 | { |
| 189 | _frames[frame]->setPixelIterative(&x, &y, value); |
| 190 | |
| 191 | if (y >= _height) |
| 192 | { |
| 193 | // Unlock the surface |
| 194 | _frames[frame]->unlock(); |
| 195 | |
| 196 | frame++; |
| 197 | x = 0; |
| 198 | y = 0; |
| 199 | |
| 200 | if (frame >= nframes) |
| 201 | break; |
| 202 | else |
| 203 | _frames[frame]->lock(); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | imgFile.close(); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Returns a particular frame from the surface set. |
nothing calls this directly
no test coverage detected