github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/pixel/cmc/image16.go (about)

     1  package main
     2  
     3  type Image16 struct {
     4  	Width  int
     5  	Height int
     6  	Pix    []uint16
     7  }
     8  
     9  func NewImage16() *Image16 {
    10  	return &Image16{}
    11  }
    12  
    13  func (m *Image16) SetSize(w, h int) bool {
    14  	if m.Width != w || m.Height != h {
    15  		m.Width = w
    16  		m.Height = h
    17  		m.Pix = make([]uint16, w*h)
    18  		return true
    19  	}
    20  	return false
    21  }
    22  
    23  func (m *Image16) Clear() {
    24  	for i := range m.Pix {
    25  		m.Pix[i] = 0
    26  	}
    27  }
    28  
    29  func (m *Image16) Put(v V) {
    30  	x, y := int(v.X), int(v.Y)
    31  	if x < 0 || m.Width <= x {
    32  		return
    33  	}
    34  	if y < 0 || m.Height <= y {
    35  		return
    36  	}
    37  
    38  	off := y*m.Width + x
    39  	if m.Pix[off] < 0xFFFF {
    40  		m.Pix[off]++
    41  	}
    42  }