* Loads the contents of an X-Com set of PCK/TAB image files * into the surface. The PCK file contains an RLE compressed * image, while the TAB file contains the offsets to each * frame in the image. * @param pck Filename of the PCK image. * @param tab Filename of the TAB offsets. * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#PCK */
| 71 | * @sa http://www.ufopaedia.org/index.php?title=Image_Formats#PCK |
| 72 | */ |
| 73 | void SurfaceSet::loadPck(const std::string &pck, const std::string &tab) |
| 74 | { |
| 75 | int nframes = 0; |
| 76 | |
| 77 | // Load TAB and get image offsets |
| 78 | if (!tab.empty()) |
| 79 | { |
| 80 | std::ifstream offsetFile(tab.c_str(), std::ios::in | std::ios::binary); |
| 81 | if (!offsetFile) |
| 82 | { |
| 83 | throw Exception(tab + " not found"); |
| 84 | } |
| 85 | Uint16 off; |
| 86 | while (offsetFile.read((char*) &off, sizeof(off))) |
| 87 | { |
| 88 | off = SDL_SwapLE16(off); |
| 89 | Surface *surface = new Surface(_width, _height); |
| 90 | _frames[nframes] = surface; |
| 91 | nframes++; |
| 92 | } |
| 93 | offsetFile.close(); |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | nframes = 1; |
| 98 | Surface *surface = new Surface(_width, _height); |
| 99 | _frames[0] = surface; |
| 100 | } |
| 101 | |
| 102 | // Load PCX and put pixels in surfaces |
| 103 | std::ifstream imgFile (pck.c_str(), std::ios::in | std::ios::binary); |
| 104 | if (!imgFile) |
| 105 | { |
| 106 | throw Exception(pck + " not found"); |
| 107 | } |
| 108 | |
| 109 | Uint8 value; |
| 110 | |
| 111 | for (int frame = 0; frame < nframes; frame++) |
| 112 | { |
| 113 | int x = 0, y = 0; |
| 114 | |
| 115 | // Lock the surface |
| 116 | _frames[frame]->lock(); |
| 117 | |
| 118 | imgFile.read((char*)&value, 1); |
| 119 | for (int i = 0; i < value; ++i) |
| 120 | { |
| 121 | for (int j = 0; j < _width; ++j) |
| 122 | { |
| 123 | _frames[frame]->setPixelIterative(&x, &y, 0); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | while (imgFile.read((char*)&value, 1) && value != 255) |
| 128 | { |
| 129 | if (value == 254) |
| 130 | { |