|
1 | | -import pixie/fileformats/tiff |
| 1 | +import pixie/common, pixie/fileformats/tiff |
2 | 2 |
|
3 | 3 | let |
4 | 4 | data = readFile("tests/fileformats/tiff/pc260001.tif") |
@@ -50,3 +50,52 @@ doAssert grayInt16Image.data[2].r == 255 |
50 | 50 | doAssert floatImage.width == 1 |
51 | 51 | doAssert floatImage.height == 1 |
52 | 52 | doAssert floatImage.data[0].r == 128 |
| 53 | + |
| 54 | +block: |
| 55 | + proc addLe16(data: var string, value: int) = |
| 56 | + data.add(char(value and 0xff)) |
| 57 | + data.add(char((value shr 8) and 0xff)) |
| 58 | + |
| 59 | + proc addLe32(data: var string, value: int) = |
| 60 | + data.add(char(value and 0xff)) |
| 61 | + data.add(char((value shr 8) and 0xff)) |
| 62 | + data.add(char((value shr 16) and 0xff)) |
| 63 | + data.add(char((value shr 24) and 0xff)) |
| 64 | + |
| 65 | + proc addIfdEntry( |
| 66 | + data: var string, |
| 67 | + tag, fieldType, numValues, valueOrOffset: int |
| 68 | + ) = |
| 69 | + data.addLe16(tag) |
| 70 | + data.addLe16(fieldType) |
| 71 | + data.addLe32(numValues) |
| 72 | + data.addLe32(valueOrOffset) |
| 73 | + |
| 74 | + const |
| 75 | + ifdOffset = 8 |
| 76 | + entryCount = 9 |
| 77 | + colorMapOffset = ifdOffset + 2 + entryCount * 12 + 4 |
| 78 | + pixelDataOffset = colorMapOffset + 6 |
| 79 | + |
| 80 | + var payload = "" |
| 81 | + payload.add("II") |
| 82 | + payload.addLe16(42) |
| 83 | + payload.addLe32(ifdOffset) |
| 84 | + payload.addLe16(entryCount) |
| 85 | + payload.addIfdEntry(0x0100, 4, 1, 1) # ImageWidth |
| 86 | + payload.addIfdEntry(0x0101, 4, 1, 1) # ImageLength |
| 87 | + payload.addIfdEntry(0x0102, 3, 1, 8) # BitsPerSample |
| 88 | + payload.addIfdEntry(0x0103, 3, 1, 1) # Compression = none |
| 89 | + payload.addIfdEntry(0x0106, 3, 1, 3) # PhotometricInterpretation = palette |
| 90 | + payload.addIfdEntry(0x0111, 4, 1, pixelDataOffset) |
| 91 | + payload.addIfdEntry(0x0116, 4, 1, 1) # RowsPerStrip |
| 92 | + payload.addIfdEntry(0x0117, 4, 1, 1) # StripByteCounts |
| 93 | + payload.addIfdEntry(0x0140, 3, 3, colorMapOffset) |
| 94 | + payload.addLe32(0) |
| 95 | + payload.addLe16(0) |
| 96 | + payload.addLe16(0) |
| 97 | + payload.addLe16(0) |
| 98 | + payload.add(char(0x01)) |
| 99 | + |
| 100 | + doAssertRaises PixieError: |
| 101 | + discard decodeTiff(payload) |
0 commit comments