-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayPpm.lua
More file actions
102 lines (81 loc) · 1.89 KB
/
Copy pathDisplayPpm.lua
File metadata and controls
102 lines (81 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
-- Development test/demo for ANSI terminal codes image encoder
--[[
Author: Martin Eden
Last mod.: 2025-04-06
]]
--[[ Dev
package.path = package.path .. ';' .. '../../?.lua'
require('workshop.base')
--]]
-- [[ Use
require('workshop')
--]]
local Config =
{
InputFileName = arg[1] or 'Plasm_1d.ppm',
}
-- Imports:
local AnsiTerm = request('!.frontend.AnsiTerm.Interface')
local GetCommand_SetRgbBackground =
function(RedByte, GreenByte, BlueByte)
return AnsiTerm.BackgroundSetColor(RedByte, GreenByte, BlueByte)
end
local GetCommand_Reset =
function()
return AnsiTerm.ResetAttributes
end
local PpmImageCodec = request('!.concepts.Netpbm.Interface')
local InputFile = request('!.concepts.StreamIo.Input.File')
local DenormalizeColor = request('!.concepts.Image.Color.Denormalize')
InputFile:Open(Config.InputFileName)
PpmImageCodec.Input = InputFile
local Image = PpmImageCodec:Load()
if not Image then
print('Failed to load image.')
return
end
print(Image.Width .. 'x' .. Image.Height)
-- '─│╭╮╰╯'
io.write(GetCommand_Reset())
io.write('╭')
for _ = 1, Image.Width + 2 do
io.write('─')
end
io.write('╮')
io.write('\n')
for Row = 1, Image.Height do
io.write(GetCommand_Reset())
io.write('│ ')
for Column = 1, Image.Width do
local Color = new(Image[Row][Column])
DenormalizeColor(Color)
local Red, Green, Blue
do
if (#Color == 1) then
Red = Color[1]
Green = Color[1]
Blue = 0-- Color[1]
elseif (#Color == 3) then
Red = Color[1]
Green = Color[2]
Blue = Color[3]
end
end
io.write(GetCommand_SetRgbBackground(Red, Green, Blue))
io.write(' ')
end
io.write(GetCommand_Reset())
io.write(' │')
io.write('\n')
end
io.write('╰')
for _ = 1, Image.Width + 2 do
io.write('─')
end
io.write('╯')
io.write('\n')
--[[
2024-12-12
2025-03-29
2025-03-31
]]