Fix gif test.
This commit is contained in:
parent
5e7096dfd7
commit
c7ff50660e
2 changed files with 25 additions and 33 deletions
|
@ -1,9 +1,32 @@
|
|||
import chroma, flatty/binny, pixie/common, pixie/images, math, bitty
|
||||
import chroma, flatty/binny, pixie/common, pixie/images, math
|
||||
|
||||
const gifSignatures* = @["GIF87a", "GIF89a"]
|
||||
|
||||
# See: https://en.wikipedia.org/wiki/GIF
|
||||
|
||||
type
|
||||
BitStream* = ref object
|
||||
data: seq[uint8] # data
|
||||
pos: int # position in bits
|
||||
len: int # len in bits
|
||||
|
||||
proc newBitStream*(data: string): BitStream =
|
||||
result = BitStream()
|
||||
result.data = cast[seq[uint8]](data)
|
||||
result.len = result.data.len * 8
|
||||
|
||||
proc readBit(bs: BitStream, pos: int): int =
|
||||
let byteIndex = pos div 8
|
||||
let bitIndex = pos mod 8
|
||||
result = bs.data[byteIndex].int shr (bitIndex) and 1
|
||||
|
||||
proc read*(bs: BitStream, bits: int): int =
|
||||
## Reads number of bits
|
||||
for i in 0 ..< bits:
|
||||
result = result shl 1
|
||||
result += bs.readBit(bs.pos + bits - i - 1)
|
||||
bs.pos += bits
|
||||
|
||||
proc decodeGIF*(data: string): Image =
|
||||
## Decodes GIF data into an Image.
|
||||
|
||||
|
|
|
@ -1,35 +1,4 @@
|
|||
import pixie/fileformats/gif, pixie/fileformats/png, print, parseutils, flatty/hexprint, flatty/binlisting
|
||||
|
||||
# let binary = decodeBinListing """
|
||||
# 0: 47 49 46 38 39 61
|
||||
# 6: 03 00
|
||||
# 8: 05 00
|
||||
# A: F7
|
||||
# B: 00
|
||||
# C: 00
|
||||
# D: 00 00 00
|
||||
# 10: 80 00 00
|
||||
# 85: 00 00 00
|
||||
# 30A: FF FF FF
|
||||
# 30D: 21 F9
|
||||
# 30F: 04
|
||||
# 310: 01
|
||||
# 311: 00 00
|
||||
# 313: 10 16
|
||||
# 314: 00
|
||||
# 315: 2C
|
||||
# 316: 00 00 00 00
|
||||
# 31A: 03 00 05 00
|
||||
# 31E: 00
|
||||
# 31F: 08
|
||||
# 320: 0B
|
||||
# 321: 00 51 FC 1B 28 70 A0 C1 83 01 01
|
||||
# 32C: 00
|
||||
# 32D: 3B
|
||||
# """
|
||||
|
||||
# echo hexPrint(binary)
|
||||
# writeFile("tests/images/gif/3x5.gif", binary)
|
||||
import pixie/fileformats/gif, pixie/fileformats/png
|
||||
|
||||
var img = decodeGIF(readFile("tests/images/gif/3x5.gif"))
|
||||
writeFile("tests/images/gif/3x5.png", img.encodePng())
|
||||
|
|
Loading…
Reference in a new issue