github.com/Kintar/etxt@v0.0.0-20221224033739-2fc69f000137/ecache/ebiten_yes.go (about)

     1  //go:build !gtxt
     2  
     3  package ecache
     4  
     5  import "github.com/hajimehoshi/ebiten/v2"
     6  
     7  // Same as etxt.GlyphMask.
     8  type GlyphMask = *ebiten.Image
     9  
    10  const constMaskSizeFactor = 192
    11  
    12  // Returns an approximation of the GlyphMask's size in bytes.
    13  //
    14  // With Ebitengine, the exact amount of mipmaps and helper fields is
    15  // not known, so the values may not be very representative of actual
    16  // memory usage. With gtxt, the returned values are precise.
    17  func GlyphMaskByteSize(mask GlyphMask) uint32 {
    18  	if mask == nil {
    19  		return constMaskSizeFactor
    20  	}
    21  	w, h := mask.Size()
    22  	return maskDimsByteSize(w, h)
    23  }
    24  
    25  func maskDimsByteSize(width, height int) uint32 {
    26  	return uint32(width*height)*4 + constMaskSizeFactor
    27  }