GE Lua Documentation

Press F to search!

testGBitmap

Definition


-- @/lua/ge/ge_utils.lua:215

function testGBitmap()
  --print("testGBitmap...")

  local bitmap = GBitmap()

  -- GBitmap:init( uint width, uint heigt )
    -- create a RGBA image of widthXheight dimension
  bitmap:init(16, 16)
  -- test size
  -- uint GBitmap::getWidth - return the width of the image
  assert( bitmap:getWidth() == 16 )
  -- uint GBitmap::getHeight - return the height of the image
  assert( bitmap:getHeight() == 16 )

  local colorWhite = ColorI(255,255,255,255)
  local colorBlack = ColorI(0, 0, 0, 255)
  assert( colorBlack == colorBlack )
  assert( colorWhite == colorWhite )
  assert( colorBlack ~= colorWhite )

  -- GBitmap:fillColor( ColotI color )
  --    set color for all pixels in the image
  bitmap:fillColor( colorWhite )

  local col = colorBlack

  -- bool GBitmap::setColor( uint pixelAtWidth, uint pixelAtHeight, ColorI color )
  --    set color at requested pixel position.
  --    Return: Bool - false on failed
  bitmap:setColor(8,8, col)

  -- bool GBitmap::getColor( uint pixelAtWidth, uint pixelAtHeight, OUT ColorI color )
  --    set color at requested pixel position.
  --    Return: Bool - false on failed
  --    OUT color - the requested color
  assert( bitmap:getColor( 8, 8, col ) )
  assert( col == colorBlack )
  assert( bitmap:getColor( 0, 0, col ) )
  assert( col == colorWhite )

  --print("testGBitmap... loading/saving")
  local filePath = "test/GBitmap.png"

  -- bool GBitmap::saveFile( string filePath )
  bitmap:saveFile( filePath )
  bitmap:fillColor( ColorI(0, 0, 0, 0) )

  -- bool GBitmap::loadFile( string filePath )
  bitmap:loadFile( filePath )

  assert( bitmap:getColor( 8, 8, col ) )
  assert( col == colorBlack )
  assert( bitmap:getColor( 0, 0, col ) )
  assert( col == colorWhite )
end

Callers