1 Star 0 Fork 0

橙子/psd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
compress_wasm_js.go 1.39 KB
一键复制 编辑 原始数据 按行查看 历史
oov 提交于 2022-01-22 02:26 . go fmt
//go:build wasm && js
// +build wasm,js
package psd
import (
"io"
)
func decodePackBits(dest []byte, r io.Reader, width int, lines int, large bool) (read int, err error) {
buf := make([]byte, lines*(get4or8(large)>>1))
var l int
if l, err = io.ReadFull(r, buf); err != nil {
return
}
read += l
total := 0
lens := make([]int, lines)
offsets := make([]int, lines)
ofs := 0
if large {
for i := range lens {
l = int(readUint32(buf, ofs))
lens[i] = l
offsets[i] = total
total += l
ofs += 4
}
} else {
for i := range lens {
l = int(readUint16(buf, ofs))
lens[i] = l
offsets[i] = total
total += l
ofs += 2
}
}
buf = make([]byte, total)
if l, err = io.ReadFull(r, buf); err != nil {
return
}
read += l
err = decodePackBitsPerLine(dest, buf, lens)
return
}
func decodePackBitsPerLine(dest []byte, buf []byte, lens []int) error {
var l int
for _, ln := range lens {
for i := 0; i < ln; {
if buf[i] <= 0x7f {
l = int(buf[i]) + 1
if len(dest) < l || ln-i-1 < l {
return errBrokenPackBits
}
copy(dest[:l], buf[i+1:])
dest = dest[l:]
i += l + 1
continue
}
if buf[i] == 0x80 {
i++
continue
}
l = int(-buf[i]) + 1
if len(dest) < l || i+1 >= ln {
return errBrokenPackBits
}
for j, c := 0, buf[i+1]; j < l; j++ {
dest[j] = c
}
dest = dest[l:]
i += 2
}
buf = buf[ln:]
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xuchengzhi/psd.git
[email protected]:xuchengzhi/psd.git
xuchengzhi
psd
psd
master

搜索帮助