Read and write 24bpp or 16bpp uncompressed windows bitmaps from pure Lua.
update at 2019/3/21:Suport 64K part load to save memory and direction(x,y) to udside down
This is SoraMame library for BMP.
SoraMame series are IoT gadgets of FlashAir.
Tested on FlashAir W-04 v4.00.03.
SlibBMP.lua -- Copy to somewhere in Lua's search path.
bgcolor : BBBBB_GGGGGG_RRRRR (64K(16bpp) background color)
bitmap = {}
bitmap.header -- copyed from BMP header
bitmap.width -- bitmap width
bitmap.height -- bitmap height
bitmap.bit -- bpp, 24 or 16(BBBBB_GGGGGG_RRRRR format)
bitmap.flat -- 1:Flat(Stuffing without leaving spaces for small image), 0:Stored in an array for each line.
bitmap.data -- bitmap data
command | description |
---|---|
bitmap,mes = BMP:loadFile(path, flat) | Read content from file and return as bitmap bitmap: bitmap table mes: error message, if bitmap is nil path: path+filename flat: 1:data flat mode, 0:data array mode |
res = BMP:saveFile(path, bitmap) | Dump bitmap to file res: "OK" or error message path: path+filename bitmap: bitmap table |
img,mes = BMP:conv64K(bitmap or path) | Convert 24bit bitmap to 16 bpp bitmap If given path, read content from file. img: 64K color bitmap table mes: error message, if bitmap is nil bitmap: bitmap table path: path+filename |
img,mes = BMP:conv64K(bitmap or path, x, y, width, height, bgcolor) |
Crop out the 24bpp bitmap and convert it to 16bpp bitmap And replace the area out of the original image with the background color. If given path, read content from file. img: 64K color bitmap table mes: error message, if bitmap is nil bitmap: bitmap table path: path+filename |