-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusage.lua
More file actions
38 lines (30 loc) · 1.12 KB
/
Copy pathusage.lua
File metadata and controls
38 lines (30 loc) · 1.12 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
local stb = require("lua_stb")
local image = stb.image
local writer = stb.image_write
local resizer = stb.image_resize
local data, w, h, n = image:load("input.pgm")
print("loaded:", w, h, n, #data)
local info_w, info_h, info_n = image:info("input.pgm")
print("info:", info_w, info_h, info_n)
for x = 1, w do
local i = (x - 1) * n + 1
if i <= #data then
data[i] = 255
end
end
local resized = resizer:resize(data, w * 2, h * 2, n)
writer:write_png("output.png", resized.w, resized.h, resized.n, resized, resized.w * resized.n)
local file = assert(io.open("output_callback.png", "wb"))
writer:write_png_to_func(resized.w, resized.h, resized.n, resized, resized.w * resized.n, function(chunk)
file:write(chunk)
end)
file:close()
local png_blob = writer:write_png_to_string(resized.w, resized.h, resized.n, resized, resized.w * resized.n)
print("png blob bytes:", #png_blob)
local f = assert(io.open("input.pgm", "rb"))
local memory = f:read("*a")
f:close()
local data2, w2, h2, n2 = image:load_from_memory(memory)
print("memory:", w2, h2, n2, #data2)
local mw, mh, mn = image:info_from_memory(memory)
print("memory info:", mw, mh, mn)