Advertisement
dalvorsn

Untitled

May 14th, 2012
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | None | 0 0
  1. -- saveBMP(2,2,{255,0,0,0,255,0,0,0,255,255,255,255})
  2. function saveBMP(filename, width, height, pixels)
  3.     size_1, size_2, size_3, size_4 = convert(height*width*3, 4)
  4.     width_1, width_2, width_3, width_4 = convert(width, 4)
  5.     height_1, height_2, height_3, height_4 = convert(height, 4)
  6.     sizeArrayColors = 4 * width * height
  7.     size_array_1, size_array_2, size_array_3, size_array_4 = convert(sizeArrayColors, 4)
  8.     local byteArray =
  9.     {
  10.     --bmp header
  11.     0x42, 0x4D, -- magic numbers
  12.     size_1, size_2, size_3, size_4, --0x00, 0x12, 0x00, 0x00, -- tamanho em bytes da imagem (3072)
  13.     0x00, 0x00, 0x00, 0x00, -- sem uso
  14.     0x36, 0x00, 0x00, 0x00, -- endereço de onde começam as cores
  15.     --dib header
  16.     0x28, 0x00, 0x00, 0x00, -- tamanho do dib header em bytes - 40
  17.     width_1, width_2, width_3, width_4, -- largura
  18.     height_1, height_2, height_3, height_4, -- altura
  19.     0x01, 0x00,
  20.     0x18, 0x00,    -- numero de bits por pixel (24bits/pixel)
  21.     0x00, 0x00, 0x00, 0x00,
  22.     size_array_1, size_array_2, size_array_3, size_array_4, -- numeros de bytes no array de cores
  23.     0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
  24.     0x13, 0x0B, 0x00, 0x00, -- resolução horizontal bit/meter
  25.     0x00, 0x00, 0x00, 0x00,
  26.     0x00, 0x00, 0x00, 0x00
  27.     }
  28.    
  29.     file = io.open(filename..".bmp", "w+b")
  30.     for _, byte in pairs(byteArray) do
  31.         file:write(type(byte) == "number" and string.char(byte) or byte)
  32.     end
  33.     for index, byte in pairs(pixels) do
  34.         file:write(type(byte) == "number" and string.char(byte) or byte)
  35.         if((index/(width*3)) % 1 == 0)then
  36.             for i=1, width do
  37.                 file:write(0x00)
  38.             end
  39.         end
  40.     end
  41.     file:close()
  42. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement