internal/atlas: bug fix: wrong logic to create a new mask with edges

* Fixed wrong operator orders
 * Cleared an allocated region explicitlly

Closes #2089
This commit is contained in:
Hajime Hoshi 2022-05-08 23:05:05 +09:00
parent 9cfa84ddaa
commit faf1e7350d

View File

@ -570,21 +570,25 @@ func (i *Image) replacePixels(pix []byte, mask []byte) {
if mask != nil { if mask != nil {
origMask := mask origMask := mask
mask = theTemporaryBytes.alloc((pw*ph-1)/8 + 1) mask = theTemporaryBytes.alloc((pw*ph-1)/8 + 1)
// Clear the allocated region explicitly (#2089).
for i := range mask {
mask[i] = 0
}
for i := 0; i < pw; i++ { for i := 0; i < pw; i++ {
// Top edge // Top edge
idx := i idx := i
mask[idx/8] |= 1 << idx % 8 mask[idx/8] |= 1 << (idx % 8)
// Bottom edge // Bottom edge
idx = (ph-1)*pw + i idx = (ph-1)*pw + i
mask[idx/8] |= 1 << idx % 8 mask[idx/8] |= 1 << (idx % 8)
} }
for j := 1; j < ph-1; j++ { for j := 1; j < ph-1; j++ {
// Left edge // Left edge
idx := j * pw idx := j * pw
mask[idx/8] |= 1 << idx % 8 mask[idx/8] |= 1 << (idx % 8)
// Right edge // Right edge
idx = j*pw + pw - 1 idx = j*pw + pw - 1
mask[idx/8] |= 1 << idx % 8 mask[idx/8] |= 1 << (idx % 8)
// Content // Content
for i := 1; i < pw-1; i++ { for i := 1; i < pw-1; i++ {