Use imageparam in CS2D
Opened this issue · 0 comments
MikuAuahDark commented
Yohane/Platform/YohaneCS2DPlatform.lua
Lines 79 to 148 in 2bfc225
local function GetImageWidthHeight(file) | |
local fileinfo = type(file) | |
local width, height | |
if fileinfo == "string" then | |
file = assert(io.open(file, "rb")) | |
else | |
fileinfo = file:seek("cur") | |
end | |
local function refresh() | |
if type(fileinfo) == "number" then | |
file:seek("set",fileinfo) | |
else | |
file:close() | |
end | |
end | |
file:seek("set", 0) | |
-- Detect if PNG | |
if file:read(8) == "\137PNG\r\n\26\n" then | |
--[[ | |
The strategy is | |
1. Seek to position 0x10 | |
2. Get value in big-endian order | |
]] | |
file:seek("set",16) | |
local widthstr, heightstr={file:read(4):byte(1, 4)}, {file:read(4):byte(1, 4)} | |
width = widthstr[1] * 16777216 + | |
widthstr[2] * 65536 + | |
widthstr[3] * 256 + | |
widthstr[4] | |
height = heightstr[1] * 16777216 + | |
heightstr[2] * 65536 + | |
heightstr[3] * 256 + | |
heightstr[4] | |
refresh() | |
return width, height | |
end | |
file:seek("set") | |
-- Detect if BMP | |
if file:read(2) == "BM" then | |
--[[ | |
The strategy is: | |
1. Seek to position 0x12 | |
2. Get value in little-endian order | |
]] | |
file:seek("set", 18) | |
local widthstr, heightstr={file:read(4):byte(1, 4)}, {file:read(4):byte(1, 4)} | |
width = widthstr[4] * 16777216 + | |
widthstr[3] * 65536 + | |
widthstr[2] * 256 + | |
widthstr[1] | |
height = heightstr[4] * 16777216 + | |
heightstr[3] * 65536 + | |
heightstr[2] * 256 + | |
heightstr[1] | |
refresh() | |
return width, height | |
end | |
return nil | |
end |