Code: Select all
f = love.filesystem.newFile("data.bin");
f:open("r");
local data = f:read();
f:close();
Excerpt from hex data of the file:
Code: Select all
66 66 00 00 60 33 33 06
Code: Select all
f = love.filesystem.newFile("data.bin");
f:open("r");
local data = f:read();
f:close();
Code: Select all
66 66 00 00 60 33 33 06
Code: Select all
local n = string.byte(chunk, offset) -- n is between 0-255
local lo = n%16 -- low part, first hex
local hi = (n - lo)/16 -- high part, second hex
Code: Select all
local lo = 14 -- first hex, between 0-15
local hi = 3 -- second hex, between 0-15
local n = lo + hi*16
It's indexed color without a header or footer; it's 4-bit and 80x16, leading to 640 bytes. The palette and w/h is stored elsewhere. It's not practical, but I'm doing this whole thing as a sort of experiment.ivan wrote:What do you mean by "raw image data"? Even BMP files have headers and so on. If it's "indexed color" then the header may contain the palette too. A while ago I wrote a pure Lua BMP loader, but I'm not sure if this is really the route you want to be going in.
Code: Select all
local bit = require "bit"
local encoded = "your string or whatever data"
local decoded = {}
for i=1, #encoded do
local byte = string.char(encoded, i)
--Invert this line to match whatever endianness you need
table.insert(decoded, bit.rshift(byte, 4)) --Higher nibble
table.insert(decoded, bit.band(byte, 0x0F) --Lower nibble
end
You really don't want to be emulating this sort of thing in Lua for several reasons.RonanZero wrote:Wanted to see how close I could get to how the SNES does things. Also wanted to see how small I could get it.
Users browsing this forum: No registered users and 2 guests