face-engine icon indicating copy to clipboard operation
face-engine copied to clipboard

小建议

Open neil-mao opened this issue 1 year ago • 1 comments

拜读了你的代码,非常不错的工作,看到你的Util,有几个小建议

  1. 没有必要进行resize,因为虹软的要求是 4 的倍数的宽度,读取 rgba 数组的时候,可以直接取整

for starty := 0; starty < height; starty++ { for startx := 0; startx < newWidth; startx++ { <---- 这里直接读到4 的倍数即可 R := imgMatrix[starty][startx][0] G := imgMatrix[starty][startx][1] B := imgMatrix[starty][startx][2] bgrData = append(bgrData, B, G, R) } }

  1. util 的接口都是 文件 filename ,可以改一下,有时候是从网络上读取的字节流

  2. image 转换 nrgba 可以直接 用 "golang.org/x/image/draw"

b := src.Bounds() m := image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy())) draw.Draw(m, m.Bounds(), src, b.Min, draw.Src)

neil-mao avatar Dec 16 '23 13:12 neil-mao

https://gist.github.com/neil-mao/b4d14ce901cd50a355e638dfb7bb3cad 我重新包装了一下,感谢你的工作

neil-mao avatar Dec 16 '23 13:12 neil-mao