Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- ### Image processing code from fyvushfinkle ###
- ### HOW TO USE: ###
- tArgs:
- [1] = name of input file
- [2] = name of output file
- [3] = width of image being converted
- [4] = height of image being converted
- Example program use:
- imgC shrek shrekC 64 64
- ]]
- local tArgs = {...}
- if tArgs[1] == nil then error("Missing input file name")
- elseif tArgs[2] == nil then error("Missing output file name")
- elseif tArgs[3] == nil then error("Missing image width")
- elseif tArgs[4] == nil then error("Missing image height")
- end
- local file, err = fs.open(tArgs[1], "r")
- assert(file, err)
- --local file = fs.open("texture", "r")
- local colorList = {
- size = { x = tArgs[3], y = tArgs[4] },
- }
- local W = tArgs[3] --16
- local H = tArgs[4] --16
- --pixelSize used for drawing to screen. Not needed for raw image processing
- local pixelSize = tArgs[5] or 5
- for y=1, H do
- for x=1, W do
- local r = file.readLine()
- local g = file.readLine()
- local b = file.readLine()
- local a = file.readLine()
- if a == nil then
- break
- end
- local rgb = 0
- if a ~= 0 then
- r = bit.blshift(r, 16)
- g = bit.blshift(g, 8)
- rgb = bit.bor(bit.bor(r, g), b)
- end
- colorList[y * W + x] = rgb
- end
- end
- file.close()
- local file, err = fs.open(tArgs[2], "w")
- assert(file, err)
- file.write(textutils.serialize(colorList))
- file.close()
- --[[
- for y = 1, H do
- for x = 1, W do
- local col = colorList[y * W + x]
- if col == nil then
- break
- end
- --print(string.format("%x", col))
- ar.fill(x * pixelSize, y * pixelSize, (x+1) * pixelSize, (y+1) * pixelSize, col)
- --os.sleep(0.1)
- end
- end
- ]]
Add Comment
Please, Sign In to add comment