mirror of
https://github.com/status-im/nimPNG.git
synced 2025-01-28 21:34:47 +00:00
commit
9de8e28dd7
@ -42,7 +42,7 @@ install:
|
|||||||
- SET "NEED_REBUILD="
|
- SET "NEED_REBUILD="
|
||||||
|
|
||||||
- IF NOT EXIST "Nim\\.git\\" (
|
- IF NOT EXIST "Nim\\.git\\" (
|
||||||
git clone https://github.com/nim-lang/Nim.git
|
git clone --depth 1 https://github.com/nim-lang/Nim.git
|
||||||
) ELSE (
|
) ELSE (
|
||||||
( cd Nim ) &
|
( cd Nim ) &
|
||||||
( git pull ) &
|
( git pull ) &
|
||||||
|
22
apidoc.md
22
apidoc.md
@ -37,7 +37,8 @@ decodePNG24(input: string, settings = PNGDecoder(nil)): PNGResult
|
|||||||
|
|
||||||
|
|
||||||
```Nim
|
```Nim
|
||||||
# generic version accept T = `string`, `seq[uint8]`
|
# generic version accept T = `string`, `seq[TT]`, or openArray[TT]
|
||||||
|
# TT can be `byte`, `char`, or `uint8`
|
||||||
encodePNG(input: T, w, h: int, settings = PNGEncoder(nil)): PNG[T]
|
encodePNG(input: T, w, h: int, settings = PNGEncoder(nil)): PNG[T]
|
||||||
encodePNG(input: T, colorType: PNGColorType, bitDepth, w, h: int, settings = PNGEncoder(nil)): PNG[T]
|
encodePNG(input: T, colorType: PNGColorType, bitDepth, w, h: int, settings = PNGEncoder(nil)): PNG[T]
|
||||||
encodePNG32(input: T, w, h: int): PNG[T]
|
encodePNG32(input: T, w, h: int): PNG[T]
|
||||||
@ -65,7 +66,7 @@ when not defined(js):
|
|||||||
saveAPNG(png: PNG[T], fileName: string): PNGStatus
|
saveAPNG(png: PNG[T], fileName: string): PNGStatus
|
||||||
|
|
||||||
decodePNG(T: type, s: Stream, colorType: PNGColorType, bitDepth: int, settings = PNGDecoder(nil)): PNGResult[T]
|
decodePNG(T: type, s: Stream, colorType: PNGColorType, bitDepth: int, settings = PNGDecoder(nil)): PNGResult[T]
|
||||||
decodePNG(T: type, s: Stream, settings = PNGDecoder(nil)): PNG
|
decodePNG(T: type, s: Stream, settings = PNGDecoder(nil)): PNG[T]
|
||||||
|
|
||||||
type
|
type
|
||||||
PNGRes*[T] = Result[PNGResult[T], string]
|
PNGRes*[T] = Result[PNGResult[T], string]
|
||||||
@ -82,7 +83,18 @@ decodePNG24(input: T, settings = PNGDecoder(nil)): PNGRes[T]
|
|||||||
## How to use PNGRes?
|
## How to use PNGRes?
|
||||||
|
|
||||||
```Nim
|
```Nim
|
||||||
let res = loadPNG32(seq[uint8], fileName, settings)
|
type
|
||||||
if res.isOk: result = res.get() # get PNGResult[seq[uint8]]
|
PNGPix = seq[uint8]
|
||||||
else: debugEcho res.error() # get error string
|
|
||||||
|
var pix: PNGResult[PNGPix]
|
||||||
|
let res = loadPNG32(PNGPix, fileName)
|
||||||
|
if res.isOk: pix = res.get() # get PNGResult[PNGPix]
|
||||||
|
else: debugEcho res.error() # get error string
|
||||||
|
|
||||||
|
# now you can access PNGResult as usual:
|
||||||
|
debugEcho "width: ", pix.width
|
||||||
|
debugEcho "height: ", pix.height
|
||||||
|
|
||||||
|
# draw(pix.data)
|
||||||
|
# or drawFrames(pix.frames) if it is a APNG
|
||||||
```
|
```
|
||||||
|
@ -33,7 +33,7 @@ import strutils
|
|||||||
export typetraits, results
|
export typetraits, results
|
||||||
|
|
||||||
const
|
const
|
||||||
NIM_PNG_VERSION = "0.3.0"
|
NIM_PNG_VERSION = "0.3.1"
|
||||||
|
|
||||||
type
|
type
|
||||||
PNGChunkType = distinct int32
|
PNGChunkType = distinct int32
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Package
|
# Package
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
author = "Andri Lim"
|
author = "Andri Lim"
|
||||||
description = "PNG encoder and decoder"
|
description = "PNG encoder and decoder"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
24
readme.md
24
readme.md
@ -5,6 +5,7 @@ Notable releases:
|
|||||||
- 0.2.0 support Animated PNG!
|
- 0.2.0 support Animated PNG!
|
||||||
- 0.2.6 compile with --gc:arc.
|
- 0.2.6 compile with --gc:arc.
|
||||||
- 0.3.0 [new set of API](apidoc.md) using seq[uint8] and new method to handle error.
|
- 0.3.0 [new set of API](apidoc.md) using seq[uint8] and new method to handle error.
|
||||||
|
- 0.3.1 fix new API bug and add openArray API
|
||||||
|
|
||||||
[![Build Status (Travis)](https://img.shields.io/travis/jangko/nimPNG/master.svg?label=Linux%20/%20macOS "Linux/macOS build status (Travis)")](https://travis-ci.org/jangko/nimPNG)
|
[![Build Status (Travis)](https://img.shields.io/travis/jangko/nimPNG/master.svg?label=Linux%20/%20macOS "Linux/macOS build status (Travis)")](https://travis-ci.org/jangko/nimPNG)
|
||||||
[![Build status](https://ci.appveyor.com/api/projects/status/7ap5r5a41t7ea04p?svg=true)](https://ci.appveyor.com/project/jangko/nimpng)
|
[![Build status](https://ci.appveyor.com/api/projects/status/7ap5r5a41t7ea04p?svg=true)](https://ci.appveyor.com/project/jangko/nimpng)
|
||||||
@ -60,19 +61,19 @@ Supported color conversions:
|
|||||||
import nimPNG
|
import nimPNG
|
||||||
|
|
||||||
let png = loadPNG32("image.png")
|
let png = loadPNG32("image.png")
|
||||||
#is equivalent to:
|
# is equivalent to:
|
||||||
#let png = loadPNG("image.png", LCT_RGBA, 8)
|
# let png = loadPNG("image.png", LCT_RGBA, 8)
|
||||||
#will produce rgba pixels:
|
# will produce rgba pixels:
|
||||||
#png.width -> width of the image
|
# png.width -> width of the image
|
||||||
#png.height -> height of the image
|
# png.height -> height of the image
|
||||||
#png.data -> pixels data in RGBA format
|
# png.data -> pixels data in RGBA format
|
||||||
```
|
```
|
||||||
|
|
||||||
if you already have the whole file in memory:
|
if you already have the whole file in memory:
|
||||||
|
|
||||||
```Nim
|
```Nim
|
||||||
let png = decodePNG32(raw_bytes)
|
let png = decodePNG32(raw_bytes)
|
||||||
#will do the same as above
|
# will do the same as above
|
||||||
```
|
```
|
||||||
|
|
||||||
other variants:
|
other variants:
|
||||||
@ -88,9 +89,9 @@ to create PNG:
|
|||||||
special notes:
|
special notes:
|
||||||
|
|
||||||
* Use **loadPNG** or **savePNG** if you need specific input/output format by supplying supported **colorType** and **bitDepth** information.
|
* Use **loadPNG** or **savePNG** if you need specific input/output format by supplying supported **colorType** and **bitDepth** information.
|
||||||
* Use **encodePNG** or **decodePNG** to do *in-memory* encoding/decoding by supplying desired **colorType** and **bitDepth** information
|
* Use **encodePNG** or **decodePNG** to do *in-memory* encoding/decoding by supplying desired **colorType** and **bitDepth** information.
|
||||||
|
|
||||||
pixels are stored as raw bytes using Nim's string as container:
|
pixels are stored as raw bytes using Nim's `string`/`seq[T]` as container:
|
||||||
|
|
||||||
| Byte Order | Format |
|
| Byte Order | Format |
|
||||||
|:------------------------------:|:----------------:|
|
|:------------------------------:|:----------------:|
|
||||||
@ -99,7 +100,6 @@ pixels are stored as raw bytes using Nim's string as container:
|
|||||||
| grey1,grey2,grey3, ..., greyn | GREY 8 bit |
|
| grey1,grey2,grey3, ..., greyn | GREY 8 bit |
|
||||||
| grey1,a1,grey2,a2,...,greyn,an | GREY ALPHA 8 bit |
|
| grey1,a1,grey2,a2,...,greyn,an | GREY ALPHA 8 bit |
|
||||||
|
|
||||||
|
|
||||||
## Animated PNG (APNG)
|
## Animated PNG (APNG)
|
||||||
|
|
||||||
Since version 0.2.0, nimPNG provides support for [Animated PNG](https://en.wikipedia.org/wiki/APNG).
|
Since version 0.2.0, nimPNG provides support for [Animated PNG](https://en.wikipedia.org/wiki/APNG).
|
||||||
@ -125,7 +125,7 @@ Right now nimPNG is just a PNG encoder/decoder.
|
|||||||
|
|
||||||
The usual loadPNG and decodePNG can decode both unanimated and animated PNG.
|
The usual loadPNG and decodePNG can decode both unanimated and animated PNG.
|
||||||
`png.width`, `png.height`, `png.data` works as usual. If the decoded PNG is an APNG, `png.data` will contains default frame.
|
`png.width`, `png.height`, `png.data` works as usual. If the decoded PNG is an APNG, `png.data` will contains default frame.
|
||||||
Animation frames can be accessible via `png.frames`. If it is not an APNG, `png.frames` will be nil.
|
Animation frames can be accessible via `png.frames`. If it is not an APNG, `png.frames` will be have zero length.
|
||||||
|
|
||||||
### Encoding
|
### Encoding
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ the default image will be part of the animation. If `ctl` is nil, default image
|
|||||||
var str = png.encodeAPNG()
|
var str = png.encodeAPNG()
|
||||||
```
|
```
|
||||||
|
|
||||||
* Final step is to call `saveAPNG` if you want save it to file or call `encodeAPNG` if you want to get the result in a string container
|
* Final step is to call `saveAPNG` if you want save it to a file or call `encodeAPNG` if you want to get the result in memory.
|
||||||
|
|
||||||
You can read the details of frame control from [spec](https://wiki.mozilla.org/APNG_Specification).
|
You can read the details of frame control from [spec](https://wiki.mozilla.org/APNG_Specification).
|
||||||
You can also see an example in tester/test.nim -> generateAPNG
|
You can also see an example in tester/test.nim -> generateAPNG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user