diff options
author | ubq323 <ubq323@ubq323.website> | 2022-08-04 22:28:06 +0100 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2022-08-04 22:28:06 +0100 |
commit | 4b37c7c8cacad50fa71bbdbc88789f235fa3d836 (patch) | |
tree | 50a463d15cb06bfc79d062acd272f18925817c2e | |
parent | 020c7bf0686a5f6235085ab7a2266d2d978fb41d (diff) |
img
-rw-r--r-- | img/load_pnm.lua | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/img/load_pnm.lua b/img/load_pnm.lua index ce1853a..0c89662 100644 --- a/img/load_pnm.lua +++ b/img/load_pnm.lua @@ -2,7 +2,7 @@ -- because the textual ones are annoying -- types: --- P1 ascii pbm +-- P1 ascii pbm -- P2 ascii pgm -- P3 ascii ppm -- P4 binary pbm @@ -17,7 +17,7 @@ local function np_p1(imgf,cur,depth) local val,ncur = imgf:match("[01]%s*()",cur) val = tonumber(val) assert(val,"bad image format at "..cur) - local p = (1-v) -- 1 is black (0), 0 is white (1) + local p = (1-val) -- 1 is black (0), 0 is white (1) local pixel = {p,p,p} return pixel,ncur end @@ -51,7 +51,7 @@ local function np_p5(imgf,cur,depth) return pixel,cur+1 end local function np_p6(imgf,cur,depth) - local vr,vg,vb = img:byte(cur,cur+3) + local vr,vg,vb = imgf:byte(cur,cur+3) for _,v in ipairs{vr,vg,vb} do assert(0<=v and v<=depth, "image value out of range at "..cur) end @@ -100,7 +100,7 @@ local function parse(imgf) local x,y=1,1 local nextpixel = nextpixel_fns[typech] - + while cur <= #imgf do local npixel,ncur = nextpixel(imgf,cur,depth) img[y][x] = npixel @@ -113,7 +113,7 @@ local function parse(imgf) break end end - + img.width = width img.height = height return img |