summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lpdf-img.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/lpdf-img.lua')
-rw-r--r--tex/context/base/mkiv/lpdf-img.lua93
1 files changed, 67 insertions, 26 deletions
diff --git a/tex/context/base/mkiv/lpdf-img.lua b/tex/context/base/mkiv/lpdf-img.lua
index a299a023d..64ed642fa 100644
--- a/tex/context/base/mkiv/lpdf-img.lua
+++ b/tex/context/base/mkiv/lpdf-img.lua
@@ -26,6 +26,7 @@ local band, rshift = bit32.band, bit32.rshift
local loaddata = io.loaddata
local setmetatableindex = table.setmetatableindex
+local formatters = string.formatters
local streams = utilities.streams
local openstring = streams.openstring
@@ -41,6 +42,7 @@ local pdfconstant = lpdf.constant
local pdfstring = lpdf.string
local pdfflushstreamobject = lpdf.flushstreamobject
local pdfreference = lpdf.reference
+local pdfverbose = lpdf.verbose
local pdfmajorversion = lpdf.majorversion
local pdfminorversion = lpdf.minorversion
@@ -1117,37 +1119,66 @@ do
if what == "mask" then
d = specification.mask
s = 1
+ elseif what == "indexed" then
+ s = 1
+ elseif what == "index" then
+ d = specification.index
+ s = - s
end
- if s == 1 then
- for i=1,y do
- local r = d[i]
- for j=1,x do
- n = n + 1 ; t[n] = chars[r[j]]
+ if s > 0 then
+ if s == 1 then
+ for i=1,y do
+ local r = d[i]
+ for j=1,x do
+ n = n + 1 ; t[n] = chars[r[j]]
+ end
end
- end
- elseif s == 2 then
- for i=1,y do
- local r = d[i]
- for j=1,x do
- local c = r[j]
- n = n + 1 ; t[n] = chars[c[1]]
- n = n + 1 ; t[n] = chars[c[2]]
- n = n + 1 ; t[n] = chars[c[3]]
+ elseif s == 2 then
+ for i=1,y do
+ local r = d[i]
+ for j=1,x do
+ local c = r[j]
+ n = n + 1 ; t[n] = chars[c[1]]
+ n = n + 1 ; t[n] = chars[c[2]]
+ n = n + 1 ; t[n] = chars[c[3]]
+ end
+ end
+ elseif s == 3 then
+ for i=1,y do
+ local r = d[i]
+ for j=1,x do
+ local c = r[j]
+ n = n + 1 ; t[n] = chars[c[1]]
+ n = n + 1 ; t[n] = chars[c[2]]
+ n = n + 1 ; t[n] = chars[c[3]]
+ n = n + 1 ; t[n] = chars[c[4]]
+ end
end
end
- elseif s == 3 then
- for i=1,y do
- local r = d[i]
- for j=1,x do
- local c = r[j]
- n = n + 1 ; t[n] = chars[c[1]]
- n = n + 1 ; t[n] = chars[c[2]]
- n = n + 1 ; t[n] = chars[c[3]]
- n = n + 1 ; t[n] = chars[c[4]]
+ return concat(t)
+ else
+ local z = d[0] and 0 or 1
+ if s == -1 then
+ local f = formatters["%02X"]
+ for i=z,#d do
+ n = n + 1 ; t[n] = f(d[i])
+ end
+ elseif s == -2 then
+ local f = formatters["%02X%02X%02X"]
+ for i=z,#d do
+ local c = d[i]
+ n = n + 1 ; t[n] = f(c[1],c[2],c[3])
+ end
+ elseif s == -3 then
+ local f = formatters["%02X%02X%02X%02X"]
+ for i=z,#d do
+ local c = d[i]
+ n = n + 1 ; t[n] = f(c[1],c[2],c[3],c[4])
end
end
+ return "<" .. concat(t," ") .. ">"
end
- return concat(t)
+ return ""
end
function injectors.bitmap(specification)
@@ -1169,8 +1200,18 @@ do
colorspace = "DeviceCMYK"
end
local colordepth = (specification.colordepth or 2) == 16 or 8
- local content = pack(specification,"data")
+ local index = specification.index
+ local content = pack(specification,index and "indexed" or "data")
local mask = specification.mask
+ local colorspace = pdfconstant(colorspace)
+if index then
+ colorspace = pdfarray {
+ pdfconstant("Indexed"),
+ colorspace,
+ #index + (index[0] and 0 or -1), -- upper index
+ pdfverbose(pack(specification,"index"))
+ }
+end
local xobject = pdfdictionary {
Type = pdfconstant("XObject"),
Subtype = pdfconstant("Image"),
@@ -1178,7 +1219,7 @@ do
Width = xsize,
Height = ysize,
BitsPerComponent = colordepth,
- ColorSpace = pdfconstant(colorspace),
+ ColorSpace = colorspace,
Length = #content, -- specification.length
}
if mask then