| 62 | } |
| 63 | |
| 64 | bool Load(Image* image, Stream& stream, const ImageParams& parameters) |
| 65 | { |
| 66 | NazaraUnused(parameters); |
| 67 | |
| 68 | pcx_header header; |
| 69 | if (stream.Read(&header, sizeof(pcx_header)) != sizeof(pcx_header)) |
| 70 | { |
| 71 | NazaraError("Failed to read header"); |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | #ifdef NAZARA_BIG_ENDIAN |
| 76 | // Les fichiers PCX sont en little endian |
| 77 | SwapBytes(&header.xmin, sizeof(UInt16)); |
| 78 | SwapBytes(&header.ymin, sizeof(UInt16)); |
| 79 | SwapBytes(&header.xmax, sizeof(UInt16)); |
| 80 | SwapBytes(&header.ymax, sizeof(UInt16)); |
| 81 | SwapBytes(&header.horzRes, sizeof(UInt16)); |
| 82 | SwapBytes(&header.vertRes, sizeof(UInt16)); |
| 83 | |
| 84 | SwapBytes(&header.bytesPerScanLine, sizeof(UInt16)); |
| 85 | SwapBytes(&header.paletteType, sizeof(UInt16)); |
| 86 | SwapBytes(&header.horzSize, sizeof(UInt16)); |
| 87 | SwapBytes(&header.vertSize, sizeof(UInt16)); |
| 88 | #endif |
| 89 | |
| 90 | unsigned int bitCount = header.bitsPerPixel * header.numColorPlanes; |
| 91 | unsigned int width = header.xmax - header.xmin+1; |
| 92 | unsigned int height = header.ymax - header.ymin+1; |
| 93 | |
| 94 | if (!image->Create(ImageType_2D, PixelFormatType_RGB8, width, height, 1, (parameters.levelCount > 0) ? parameters.levelCount : 1)) |
| 95 | { |
| 96 | NazaraError("Failed to create image"); |
| 97 | return false; |
| 98 | } |
| 99 | |
| 100 | UInt8* pixels = image->GetPixels(); |
| 101 | |
| 102 | int rle_value = 0; |
| 103 | unsigned int rle_count = 0; |
| 104 | |
| 105 | switch (bitCount) |
| 106 | { |
| 107 | case 1: |
| 108 | { |
| 109 | for (unsigned int y = 0; y < height; ++y) |
| 110 | { |
| 111 | UInt8* ptr = &pixels[y * width * 3]; |
| 112 | int bytes = header.bytesPerScanLine; |
| 113 | |
| 114 | /* decode line number y */ |
| 115 | while (bytes--) |
| 116 | { |
| 117 | if (rle_count == 0) |
| 118 | { |
| 119 | if (!stream.Read(&rle_value, 1)) |
| 120 | { |
| 121 | NazaraError("Failed to read stream (byte " + String::Number(stream.GetCursorPos()) + ')'); |
nothing calls this directly
no test coverage detected