-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress_js.go
39 lines (33 loc) · 873 Bytes
/
compress_js.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// +build js
package psd
import (
"errors"
"io"
"github.com/gopherjs/gopherjs/js"
)
func decodePackBits(dest []byte, r io.Reader, width int, lines int, large bool) (read int, err error) {
intSize := get4or8(large) >> 1
b := make([]byte, lines*intSize)
var l int
if l, err = io.ReadFull(r, b); err != nil {
return
}
read += l
lens := js.Global.Get("$github.com/oov/psd$").Call("decodePackBitsLines", b, lines, large).Interface().([]uint)
if lens == nil {
return read, errors.New("psd: error occurred in decodePackBitsLines")
}
total := uint(0)
for _, ln := range lens {
total += ln
}
b = make([]byte, total)
if l, err = io.ReadFull(r, b); err != nil {
return
}
read += l
if !js.Global.Get("$github.com/oov/psd$").Call("decodePackBits", dest, b, lens).Bool() {
return read, errors.New("psd: error occurred in decodePackBits")
}
return
}