Skip to content

Commit

Permalink
Merge pull request #50 from jangko/bump_version
Browse files Browse the repository at this point in the history
bump version to 0.3.1
  • Loading branch information
jangko authored Jun 20, 2020
2 parents 778fee7 + 2ad5894 commit 9de8e28
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ install:
- SET "NEED_REBUILD="

- 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 (
( cd Nim ) &
( git pull ) &
Expand Down
22 changes: 17 additions & 5 deletions apidoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ decodePNG24(input: string, settings = PNGDecoder(nil)): PNGResult


```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, colorType: PNGColorType, bitDepth, w, h: int, settings = PNGEncoder(nil)): PNG[T]
encodePNG32(input: T, w, h: int): PNG[T]
Expand Down Expand Up @@ -65,7 +66,7 @@ when not defined(js):
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, settings = PNGDecoder(nil)): PNG
decodePNG(T: type, s: Stream, settings = PNGDecoder(nil)): PNG[T]
type
PNGRes*[T] = Result[PNGResult[T], string]
Expand All @@ -82,7 +83,18 @@ decodePNG24(input: T, settings = PNGDecoder(nil)): PNGRes[T]
## How to use PNGRes?

```Nim
let res = loadPNG32(seq[uint8], fileName, settings)
if res.isOk: result = res.get() # get PNGResult[seq[uint8]]
else: debugEcho res.error() # get error string
type
PNGPix = seq[uint8]
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
```
2 changes: 1 addition & 1 deletion nimPNG.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import strutils
export typetraits, results

const
NIM_PNG_VERSION = "0.3.0"
NIM_PNG_VERSION = "0.3.1"

type
PNGChunkType = distinct int32
Expand Down
2 changes: 1 addition & 1 deletion nimPNG.nimble
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Package
version = "0.3.0"
version = "0.3.1"
author = "Andri Lim"
description = "PNG encoder and decoder"
license = "MIT"
Expand Down
24 changes: 12 additions & 12 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Notable releases:
- 0.2.0 support Animated PNG!
- 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.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](https://ci.appveyor.com/api/projects/status/7ap5r5a41t7ea04p?svg=true)](https://ci.appveyor.com/project/jangko/nimpng)
Expand Down Expand Up @@ -60,19 +61,19 @@ Supported color conversions:
import nimPNG
let png = loadPNG32("image.png")
#is equivalent to:
#let png = loadPNG("image.png", LCT_RGBA, 8)
#will produce rgba pixels:
#png.width -> width of the image
#png.height -> height of the image
#png.data -> pixels data in RGBA format
# is equivalent to:
# let png = loadPNG("image.png", LCT_RGBA, 8)
# will produce rgba pixels:
# png.width -> width of the image
# png.height -> height of the image
# png.data -> pixels data in RGBA format
```

if you already have the whole file in memory:

```Nim
let png = decodePNG32(raw_bytes)
#will do the same as above
# will do the same as above
```

other variants:
Expand All @@ -88,9 +89,9 @@ to create PNG:
special notes:

* 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 |
|:------------------------------:|:----------------:|
Expand All @@ -99,7 +100,6 @@ pixels are stored as raw bytes using Nim's string as container:
| grey1,grey2,grey3, ..., greyn | GREY 8 bit |
| grey1,a1,grey2,a2,...,greyn,an | GREY ALPHA 8 bit |


## Animated PNG (APNG)

Since version 0.2.0, nimPNG provides support for [Animated PNG](https://en.wikipedia.org/wiki/APNG).
Expand All @@ -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.
`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

Expand Down Expand Up @@ -155,7 +155,7 @@ the default image will be part of the animation. If `ctl` is nil, default image
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 also see an example in tester/test.nim -> generateAPNG
Expand Down

0 comments on commit 9de8e28

Please sign in to comment.