Add GIF file format.
This commit is contained in:
parent
d248457b0b
commit
c8269d5db9
3 changed files with 11 additions and 3 deletions
|
@ -28,6 +28,7 @@ Format | Read | Write |
|
|||
PNG | ✅ | ✅ |
|
||||
JPEG | ✅ | |
|
||||
BMP | ✅ | ✅ |
|
||||
GIF | ✅ | |
|
||||
SVG | ✅ | |
|
||||
|
||||
### Joins and caps
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import bumpy, chroma, flatty/binny, os, pixie/blends, pixie/common,
|
||||
pixie/fileformats/bmp, pixie/fileformats/jpg, pixie/fileformats/png,
|
||||
pixie/fileformats/bmp, pixie/fileformats/gif, pixie/fileformats/jpg, pixie/fileformats/png,
|
||||
pixie/fileformats/svg, pixie/images, pixie/masks, pixie/paints, pixie/paths, vmath
|
||||
|
||||
export blends, bumpy, chroma, common, images, masks, paints, paths, vmath
|
||||
|
||||
type
|
||||
FileFormat* = enum
|
||||
ffPng, ffBmp, ffJpg
|
||||
ffPng, ffBmp, ffJpg, ffGif
|
||||
|
||||
proc decodeImage*(data: string | seq[uint8]): Image =
|
||||
## Loads an image from a memory.
|
||||
|
@ -19,6 +19,8 @@ proc decodeImage*(data: string | seq[uint8]): Image =
|
|||
elif data.len > 5 and
|
||||
(data.readStr(0, 5) == xmlSignature or data.readStr(0, 4) == svgSignature):
|
||||
decodeSvg(data)
|
||||
elif data.len > 6 and data.readStr(0, 6) in gifSignatures:
|
||||
decodeGif(data)
|
||||
else:
|
||||
raise newException(PixieError, "Unsupported image file format")
|
||||
|
||||
|
@ -35,6 +37,8 @@ proc encodeImage*(image: Image, fileFormat: FileFormat): string =
|
|||
image.encodeJpg()
|
||||
of ffBmp:
|
||||
image.encodeBmp()
|
||||
of ffGif:
|
||||
raise newException(PixieError, "Unsupported image format")
|
||||
|
||||
proc writeFile*(image: Image, filePath: string, fileFormat: FileFormat) =
|
||||
## Writes an image to a file.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import pixie/fileformats/gif, pixie/fileformats/png
|
||||
import pixie/fileformats/gif, pixie/fileformats/png, pixie
|
||||
|
||||
var img = decodeGIF(readFile("tests/images/gif/3x5.gif"))
|
||||
writeFile("tests/images/gif/3x5.png", img.encodePng())
|
||||
|
@ -8,3 +8,6 @@ writeFile("tests/images/gif/audrey.png", img2.encodePng())
|
|||
|
||||
var img3 = decodeGIF(readFile("tests/images/gif/sunflower.gif"))
|
||||
writeFile("tests/images/gif/sunflower.png", img3.encodePng())
|
||||
|
||||
var img4 = readImage("tests/images/gif/sunflower.gif")
|
||||
doAssert img3.data == img4.data
|
||||
|
|
Loading…
Reference in a new issue