Skip to content

Commit

Permalink
Merge pull request #47 from jangko/apidoc
Browse files Browse the repository at this point in the history
update apidoc.md
  • Loading branch information
jangko authored Jun 5, 2020
2 parents ed12086 + 451907e commit a3d1040
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 33 deletions.
81 changes: 54 additions & 27 deletions apidoc.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,82 @@
## Legacy API

```Nim
proc encodePNG*(input: string, colorType: PNGColorType, bitDepth, w, h: int, settings = PNGEncoder(nil)): PNG
proc encodePNG32*(input: string, w, h: int): PNG
proc encodePNG24*(input: string, w, h: int): PNG
encodePNG(input: string, colorType: PNGColorType, bitDepth, w, h: int, settings = PNGEncoder(nil)): PNG
encodePNG32(input: string, w, h: int): PNG
encodePNG24(input: string, w, h: int): PNG
when not defined(js):
proc savePNG*(fileName, input: string, colorType: PNGColorType, bitDepth, w, h: int): bool
proc savePNG32*(fileName, input: string, w, h: int): bool
proc savePNG24*(fileName, input: string, w, h: int): bool
savePNG(fileName, input: string, colorType: PNGColorType, bitDepth, w, h: int): bool
savePNG32(fileName, input: string, w, h: int): bool
savePNG24(fileName, input: string, w, h: int): bool
proc prepareAPNG*(colorType: PNGColorType, bitDepth, numPlays: int, settings = PNGEncoder(nil)): PNG
proc prepareAPNG24*(numPlays = 0): PNG
proc prepareAPNG32*(numPlays = 0): PNG
proc addDefaultImage*(png: PNG, input: string, width, height: int, ctl = APNGFrameControl(nil)): bool
proc addFrame*(png: PNG, frame: string, ctl: APNGFrameControl): bool
proc encodeAPNG*(png: PNG): string
prepareAPNG(colorType: PNGColorType, bitDepth, numPlays: int, settings = PNGEncoder(nil)): PNG
prepareAPNG24(numPlays = 0): PNG
prepareAPNG32(numPlays = 0): PNG
addDefaultImage(png: PNG, input: string, width, height: int, ctl = APNGFrameControl(nil)): bool
addFrame(png: PNG, frame: string, ctl: APNGFrameControl): bool
encodeAPNG(png: PNG): string
when not defined(js):
proc saveAPNG*(png: PNG, fileName: string): bool
saveAPNG(png: PNG, fileName: string): bool
proc decodePNG*(s: Stream, colorType: PNGColorType, bitDepth: int, settings = PNGDecoder(nil)): PNGResult
proc decodePNG*(s: Stream, settings = PNGDecoder(nil)): PNG
decodePNG(s: Stream, colorType: PNGColorType, bitDepth: int, settings = PNGDecoder(nil)): PNGResult
decodePNG(s: Stream, settings = PNGDecoder(nil)): PNG
when not defined(js):
proc loadPNG*(fileName: string, colorType: PNGColorType, bitDepth: int, settings: PNGDecoder = nil): PNGResult
proc loadPNG32*(fileName: string, settings = PNGDecoder(nil)): PNGResult
proc loadPNG24*(fileName: string, settings = PNGDecoder(nil)): PNGResult
loadPNG(fileName: string, colorType: PNGColorType, bitDepth: int, settings: PNGDecoder = nil): PNGResult
loadPNG32(fileName: string, settings = PNGDecoder(nil)): PNGResult
loadPNG24(fileName: string, settings = PNGDecoder(nil)): PNGResult
proc decodePNG32*(input: string, settings = PNGDecoder(nil)): PNGResult
proc decodePNG24*(input: string, settings = PNGDecoder(nil)): PNGResult
decodePNG32(input: string, settings = PNGDecoder(nil)): PNGResult
decodePNG24(input: string, settings = PNGDecoder(nil)): PNGResult
```


## New API


```Nim
proc decodePNG*(T: type, s: Stream, colorType: PNGColorType, bitDepth: int, settings = PNGDecoder(nil)): PNGResult[T]
proc decodePNG*(T: type, s: Stream, settings = PNGDecoder(nil)): PNG
# generic version accept T = `string`, `seq[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]
encodePNG24(input: T, w, h: int): PNG[T]
writeChunks(png: PNG[T], s: Stream)
type
PNGStatus* = Result[void, string]
PNGBytes*[T] = Result[T, string]
prepareAPNG(T: type, colorType: PNGColorType, bitDepth, numPlays: int, settings = PNGEncoder(nil)): PNG[T]
prepareAPNG24(T: type, numPlays = 0): PNG[T]
prepareAPNG32(T: type, numPlays = 0): PNG[T]
addDefaultImage(png: PNG[T], input: T, width, height: int, ctl = APNGFrameControl(nil)): bool
addFrame(png: PNG[T], frame: T, ctl: APNGFrameControl): bool
when not defined(js):
savePNG(fileName: string, input: T, colorType: PNGColorType, bitDepth, w, h: int): PNGStatus
savePNG32(fileName: string, input: T, w, h: int): PNGStatus
savePNG24(fileName: string, input: T, w, h: int): PNGStatus
encodeAPNG(png: PNG[T]): PNGBytes[T]
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
type
PNGRes*[T] = Result[PNGResult[T], string]
when not defined(js):
proc loadPNG*(T: type, fileName: string, colorType: PNGColorType, bitDepth: int, settings: PNGDecoder = nil): PNGRes[T]
proc loadPNG32*(T: type, fileName: string, settings = PNGDecoder(nil)): PNGRes[T]
proc loadPNG24*(T: type, fileName: string, settings = PNGDecoder(nil)): PNGRes[T]
loadPNG(T: type, fileName: string, colorType: PNGColorType, bitDepth: int, settings: PNGDecoder = nil): PNGRes[T]
loadPNG32(T: type, fileName: string, settings = PNGDecoder(nil)): PNGRes[T]
loadPNG24(T: type, fileName: string, settings = PNGDecoder(nil)): PNGRes[T]
proc decodePNG32*(T: type, input: T, settings = PNGDecoder(nil)): PNGRes[T]
proc decodePNG24*(T: type, input: T, settings = PNGDecoder(nil)): PNGRes[T]
decodePNG32(input: T, settings = PNGDecoder(nil)): PNGRes[T]
decodePNG24(input: T, settings = PNGDecoder(nil)): PNGRes[T]
```

## How to use PNGRes?
Expand Down
24 changes: 18 additions & 6 deletions nimPNG.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@ when not defined(js):
proc loadPNG24*(T: type, fileName: string, settings = PNGDecoder(nil)): PNGRes[T] =
loadPNG(T, fileName, LCT_RGB, 8, settings)

proc decodePNG32*(T: type, input: T, settings = PNGDecoder(nil)): PNGRes[T] =
proc decodePNG32Impl*[T](input: T, settings = PNGDecoder(nil)): PNGRes[T] =
try:
when T is string:
var s = newStringStream(input)
Expand All @@ -1884,7 +1884,7 @@ proc decodePNG32*(T: type, input: T, settings = PNGDecoder(nil)): PNGRes[T] =
except PNGError, IOError, NZError:
result.err(getCurrentExceptionMsg())

proc decodePNG24*(T: type, input: T, settings = PNGDecoder(nil)): PNGRes[T] =
proc decodePNG24Impl*[T](input: T, settings = PNGDecoder(nil)): PNGRes[T] =
try:
when T is string:
var s = newStringStream(input)
Expand Down Expand Up @@ -1920,16 +1920,28 @@ when not defined(js):
if res.isOk: result = res.get()
else: debugEcho res.error()

proc decodePNG32*(input: string, settings = PNGDecoder(nil)): PNGResult[string] =
let res = decodePNG32(string, input, settings)
proc decodePNG32Legacy*(input: string, settings = PNGDecoder(nil)): PNGResult[string] =
let res = decodePNG32Impl(input, settings)
if res.isOk: result = res.get()
else: debugEcho res.error()

proc decodePNG24*(input: string, settings = PNGDecoder(nil)): PNGResult[string] =
let res = decodePNG24(string, input, settings)
proc decodePNG24Legacy*(input: string, settings = PNGDecoder(nil)): PNGResult[string] =
let res = decodePNG24Impl(input, settings)
if res.isOk: result = res.get()
else: debugEcho res.error()

template decodePNG32*[T](input: T, settings = PNGDecoder(nil)): untyped =
when T is string:
decodePNG32Legacy(input, settings)
else:
decodePNG32Impl(input, settings)

template decodePNG24*[T](input: T, settings = PNGDecoder(nil)): untyped =
when T is string:
decodePNG24Legacy(input, settings)
else:
decodePNG24Impl(input, settings)

#Encoder/Decoder demarcation line-----------------------------

type
Expand Down

0 comments on commit a3d1040

Please sign in to comment.