diff options
author | Hans Hagen <pragma@wxs.nl> | 2023-01-15 14:50:04 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2023-01-15 14:50:04 +0100 |
commit | 0caec226a633182402b349c3ac5b3bf9e0bc76c2 (patch) | |
tree | 30524574e0b41eb771f5f9af8cadc60354652aa3 /tex/context/base/mkxl/lpdf-grp.lmt | |
parent | 659b8f28e591006b6d0669c05d809d6ccf60cec0 (diff) | |
download | context-0caec226a633182402b349c3ac5b3bf9e0bc76c2.tar.gz |
2023-01-15 13:55:00
Diffstat (limited to 'tex/context/base/mkxl/lpdf-grp.lmt')
-rw-r--r-- | tex/context/base/mkxl/lpdf-grp.lmt | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/tex/context/base/mkxl/lpdf-grp.lmt b/tex/context/base/mkxl/lpdf-grp.lmt index 48853ab83..585d11459 100644 --- a/tex/context/base/mkxl/lpdf-grp.lmt +++ b/tex/context/base/mkxl/lpdf-grp.lmt @@ -177,10 +177,12 @@ do return wrapimage(image) end - local zlibcompress = xzip.compress - local lpegmatch = lpeg.match - local compresslevel = 3 - local pattern = lpeg.Cs((lpeg.patterns.space/"" + lpeg.patterns.hextobyte)^0) + -- local lpegmatch = lpeg.match + -- local pattern = lpeg.Cs((lpeg.patterns.space/"" + lpeg.patterns.hextobyte)^0) + + local zlibcompress = xzip.compress + local hextocharacters = string.hextocharacters + local compresslevel = 3 methods.png = function(t) -- encoding is ascii hex, no checking here @@ -190,20 +192,36 @@ do if xresolution == 0 or yresolution == 0 or data == "" then return -- fatal error end + data = hextocharacters(data) + if not data then + return + end local colorspace = t.colorspace local colordepth = 8 local colors = 1 +-- if colorspace ~= "rgb" and colorspace ~= "gray" then +-- -- not that efficient but ok +-- local d = gsub(t.data,"[^0-9a-f]","") +-- local b = round(#d / (xresolution * yresolution)) +-- if b == 2 then +-- colorspace = "gray" +-- colors = 1 +-- elseif b == 6 then +-- colorspace = "rgb" +-- colors = 3 +-- elseif b == 8 then +-- return -- for now, todo: convert +-- end +-- end if colorspace ~= "rgb" and colorspace ~= "gray" then - -- not that efficient but ok - local d = gsub(t.data,"[^0-9a-f]","") - local b = round(#d / (xresolution * yresolution)) - if b == 2 then + local b = round(#data / (xresolution * yresolution)) + if b == 1 then colorspace = "gray" colors = 1 - elseif b == 6 then + elseif b == 3 then colorspace = "rgb" colors = 3 - elseif b == 8 then + elseif b == 4 then return -- for now, todo: convert end end @@ -221,7 +239,8 @@ do elseif height == 0 then height = width * yresolution / xresolution end - data = zlibcompress(lpegmatch(pattern,data),compresslevel) + -- data = zlibcompress(lpegmatch(pattern,data),compresslevel) + data = zlibcompress(data,compresslevel) local xobject = pdfdictionary { Type = pdfconstant("XObject"), Subtype = pdfconstant("Image"), |