summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/lpdf-img.lmt
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkxl/lpdf-img.lmt')
-rw-r--r--tex/context/base/mkxl/lpdf-img.lmt883
1 files changed, 442 insertions, 441 deletions
diff --git a/tex/context/base/mkxl/lpdf-img.lmt b/tex/context/base/mkxl/lpdf-img.lmt
index 50034c360..e1b822210 100644
--- a/tex/context/base/mkxl/lpdf-img.lmt
+++ b/tex/context/base/mkxl/lpdf-img.lmt
@@ -11,19 +11,20 @@ if not modules then modules = { } end modules ['lpdf-img'] = {
-- At some point we can also use it for fonts. For small images performance is ok
-- with pure lua but for bigger images we can use some helpers. Normally in a
-- typesetting workflow non-interlaced images are used. One should convert
--- interlaced images to more efficient non-interlaced ones (ok, we can cache
--- them if needed).
+-- interlaced images to more efficient non-interlaced ones (ok, we can cache them if
+-- needed).
--
--- The \LUA\ code is slightly optimized so we could have done with less lines if
--- we wanted but best gain a little. The idea is that we collect striped (in stages)
--- so that we can play with substitutions.
+-- The \LUA\ code is slightly optimized so we could have done with less lines if we
+-- wanted but best gain a little. The idea is that we collect striped (in stages) so
+-- that we can play with substitutions. We keep this variant commented but not
+-- embedding it saves some 14K bytecode in the format.
local type = type
local concat, move = table.concat, table.move
local ceil, min = math.ceil, math.min
local char, byte, find, gmatch = string.char, string.byte, string.find, string.gmatch
-local idiv = number.idiv
-local band, rshift = bit32.band, bit32.rshift
+----- idiv = number.idiv
+----- band, rshift = bit32.band, bit32.rshift
local loaddata = io.loaddata
local setmetatableindex = table.setmetatableindex
@@ -58,8 +59,8 @@ end)
local createimage = images.create
-local zlibcompress = (xzip or zlib).compress
-local zlibdecompress = (xzip or zlib).decompress
+local zlibcompress = xzip.compress
+local zlibdecompress = xzip.decompress
local trace = false
@@ -250,10 +251,10 @@ do
end
elseif filter == 3 then
for j=n+1,n+bpp do
- t[j] = (t[j] + idiv(t[j-len],2)) % 256
+ t[j] = (t[j] + (t[j-len] // 2)) % 256
end
for j=n+bpp+1,n+m do
- t[j] = (t[j] + idiv(t[j-bpp] + t[j-len],2)) % 256
+ t[j] = (t[j] + (t[j-bpp] + t[j-len]) // 2) % 256
end
elseif filter == 4 then
for j=n+1,n+bpp do
@@ -282,95 +283,95 @@ do
return t
end
- local filtermask_l = function (content,xsize,ysize,colordepth,colorspace,hasfilter)
- local mask = { }
- local bytes = colordepth == 16 and 2 or 1
- local bpp = colorspace == "DeviceRGB" and 3 or 1
- local length = #content
- local size = ysize * xsize * ((bpp+1)*bytes + (hasfilter and 1 or 0))
- local n = 1
- local l = 1
- if bytes == 2 then
- if bpp == 1 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- elseif bpp == 3 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- else
- return "", ""
- end
- else
- if bpp == 1 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- elseif bpp == 3 then
- for i=1,ysize do
- if hasfilter then
- content[n] = "" ; n = n + 1
- end
- for j=1,xsize do
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- content[n] = chars[content[n]] ; n = n + 1
- mask[l] = chars[content[n]] ; l = l + 1
- content[n] = "" ; n = n + 1
- end
- end
- else
- return "", ""
- end
- end
- return concat(content), concat(mask)
- end
-
- local decodemask_l = function(content,xsize,ysize,colordepth,colorspace)
- local bytes = colordepth == 16 and 2 or 1
- local bpp = colorspace == "DeviceRGB" and 3 or 1
- local slice = bytes*(bpp+1)
- local length = #content
- local size = ysize * xsize * ((bpp+1)*bytes + 1) -- assume filter
- content = openstring(content)
- content = readbytetable(content,length)
- setmetatableindex(content,zero)
- applyfilter(content,xsize,ysize,slice)
- content, mask = filtermask(content,xsize,ysize,colordepth,colorspace,true)
- return content, mask
- end
+ -- local filtermask_l = function (content,xsize,ysize,colordepth,colorspace,hasfilter)
+ -- local mask = { }
+ -- local bytes = colordepth == 16 and 2 or 1
+ -- local bpp = colorspace == "DeviceRGB" and 3 or 1
+ -- local length = #content
+ -- local size = ysize * xsize * ((bpp+1)*bytes + (hasfilter and 1 or 0))
+ -- local n = 1
+ -- local l = 1
+ -- if bytes == 2 then
+ -- if bpp == 1 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- elseif bpp == 3 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- else
+ -- return "", ""
+ -- end
+ -- else
+ -- if bpp == 1 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- elseif bpp == 3 then
+ -- for i=1,ysize do
+ -- if hasfilter then
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- for j=1,xsize do
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- content[n] = chars[content[n]] ; n = n + 1
+ -- mask[l] = chars[content[n]] ; l = l + 1
+ -- content[n] = "" ; n = n + 1
+ -- end
+ -- end
+ -- else
+ -- return "", ""
+ -- end
+ -- end
+ -- return concat(content), concat(mask)
+ -- end
+
+ -- local decodemask_l = function(content,xsize,ysize,colordepth,colorspace)
+ -- local bytes = colordepth == 16 and 2 or 1
+ -- local bpp = colorspace == "DeviceRGB" and 3 or 1
+ -- local slice = bytes*(bpp+1)
+ -- local length = #content
+ -- local size = ysize * xsize * ((bpp+1)*bytes + 1) -- assume filter
+ -- content = openstring(content)
+ -- content = readbytetable(content,length)
+ -- setmetatableindex(content,zero)
+ -- applyfilter(content,xsize,ysize,slice)
+ -- content, mask = filtermask(content,xsize,ysize,colordepth,colorspace,true)
+ -- return content, mask
+ -- end
local filtermask_c = function(content,xsize,ysize,colordepth,colorspace)
local bytes = colordepth == 16 and 2 or 1
@@ -388,12 +389,12 @@ do
return pngsplitmask(content,xsize,ysize,bpp,bytes,mask,filter)
end
- local function decodestrip_l(s,nx,ny,slice)
- local input = readbytetable(s,ny*(nx*slice+1))
- setmetatableindex(input,zero)
- applyfilter(input,nx,ny,slice)
- return input, true
- end
+ -- local function decodestrip_l(s,nx,ny,slice)
+ -- local input = readbytetable(s,ny*(nx*slice+1))
+ -- setmetatableindex(input,zero)
+ -- applyfilter(input,nx,ny,slice)
+ -- return input, true
+ -- end
local function decodestrip_c(s,nx,ny,slice)
local input = readstring(s,ny*(nx*slice+1))
@@ -409,204 +410,204 @@ do
local xblock = { 8, 4, 4, 2, 2, 1, 1 }
local yblock = { 8, 8, 4, 4, 2, 2, 1 }
- local function transpose_l(xsize,ysize,slice,pass,input,output,filter)
- local xstart = xstart[pass]
- local xstep = xstep[pass]
- local ystart = ystart[pass]
- local ystep = ystep[pass]
- local nx = idiv(xsize + xstep - xstart - 1,xstep)
- local ny = idiv(ysize + ystep - ystart - 1,ystep)
- local offset = filter and 1 or 0
- local xstep = xstep * slice
- local xstart = xstart * slice
- local xsize = xsize * slice
- local target = ystart * xsize + xstart + 1
- local ystep = ystep * xsize
- local start = 1
- local plus = nx * xstep
- local step = plus - xstep
- if not output then
- output = newoutput(xsize*(parts or slice)*ysize)
- end
- if slice == 1 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- start = start + slice
- end
- end
- elseif slice == 2 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- start = start + slice
- end
- end
- elseif slice == 3 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- output[target+2] = input[start+2]
- start = start + slice
- end
- end
- elseif slice == 4 then
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- output[target] = input[start]
- output[target+1] = input[start+1]
- output[target+2] = input[start+2]
- output[target+3] = input[start+3]
- start = start + slice
- end
- end
- else
- local delta = slice - 1
- for j=0,ny-1 do
- start = start + offset
- local target = target + j * ystep
- for target=target,target+step,xstep do
- move(input,start,start+delta,target,output)
- start = start + slice
- end
- end
- end
- return output;
- end
+ -- local function transpose_l(xsize,ysize,slice,pass,input,output,filter)
+ -- local xstart = xstart[pass]
+ -- local xstep = xstep[pass]
+ -- local ystart = ystart[pass]
+ -- local ystep = ystep[pass]
+ -- local nx = idiv(xsize + xstep - xstart - 1,xstep)
+ -- local ny = idiv(ysize + ystep - ystart - 1,ystep)
+ -- local offset = filter and 1 or 0
+ -- local xstep = xstep * slice
+ -- local xstart = xstart * slice
+ -- local xsize = xsize * slice
+ -- local target = ystart * xsize + xstart + 1
+ -- local ystep = ystep * xsize
+ -- local start = 1
+ -- local plus = nx * xstep
+ -- local step = plus - xstep
+ -- if not output then
+ -- output = newoutput(xsize*(parts or slice)*ysize)
+ -- end
+ -- if slice == 1 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 2 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 3 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- output[target+2] = input[start+2]
+ -- start = start + slice
+ -- end
+ -- end
+ -- elseif slice == 4 then
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- output[target] = input[start]
+ -- output[target+1] = input[start+1]
+ -- output[target+2] = input[start+2]
+ -- output[target+3] = input[start+3]
+ -- start = start + slice
+ -- end
+ -- end
+ -- else
+ -- local delta = slice - 1
+ -- for j=0,ny-1 do
+ -- start = start + offset
+ -- local target = target + j * ystep
+ -- for target=target,target+step,xstep do
+ -- move(input,start,start+delta,target,output)
+ -- start = start + slice
+ -- end
+ -- end
+ -- end
+ -- return output;
+ -- end
local transpose_c = pnginterlace
-- print(band(rshift(v,4),0x03),extract(v,4,2))
-- print(band(rshift(v,6),0x03),extract(v,6,2))
- local function expand_l(t,xsize,ysize,parts,run,factor,filter)
- local size = ysize * xsize + 1 -- a bit of overshoot, needs testing, probably a few bytes us ok
- local xline = filter and (run+1) or run
- local f = filter and 1 or 0
- local l = xline - 1
- local n = 1
- local o = newoutput(size)
- local k = 0
- if factor then
- if parts == 4 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 2
- else
- k = k + 1 ; o[k] = extract4(v,4) * 0x11
- k = k + 1 ; o[k] = extract4(v,0) * 0x11
- end
- end
- k = i * xsize
- n = n + xline
- end
- elseif parts == 2 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 4
- else
- k = k + 1 ; o[k] = extract2(v,6) * 0x55
- k = k + 1 ; o[k] = extract2(v,4) * 0x55
- k = k + 1 ; o[k] = extract2(v,2) * 0x55
- k = k + 1 ; o[k] = extract2(v,0) * 0x55
- end
- end
- k = i * xsize
- n = n + xline
- end
- else
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 8
- else
- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,7) * 0xFF
- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,6) * 0xFF
- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,5) * 0xFF
- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,4) * 0xFF
- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,3) * 0xFF
- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,2) * 0xFF
- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,1) * 0xFF
- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,0) * 0xFF
- end
- end
- k = i * xsize
- n = n + xline
- end
- end
- else
- if parts == 4 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 2
- else
- k = k + 1 ; o[k] = extract4(v,4)
- k = k + 1 ; o[k] = extract4(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- elseif parts == 2 then
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 4
- else
- k = k + 1 ; o[k] = extract2(v,6)
- k = k + 1 ; o[k] = extract2(v,4)
- k = k + 1 ; o[k] = extract2(v,2)
- k = k + 1 ; o[k] = extract2(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- else
- for i=1,ysize do
- for j=n+f,n+l do
- local v = t[j]
- if v == 0 then
- k = k + 8
- else
- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,7)
- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,6)
- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,5)
- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,4)
- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,3)
- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,2)
- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,1)
- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,0)
- end
- end
- k = i * xsize
- n = n + xline
- end
- end
- end
- for i=size,xsize * ysize +1,-1 do
- o[i] = nil
- end
- return o, false
- end
+ -- local function expand_l(t,xsize,ysize,parts,run,factor,filter)
+ -- local size = ysize * xsize + 1 -- a bit of overshoot, needs testing, probably a few bytes us ok
+ -- local xline = filter and (run+1) or run
+ -- local f = filter and 1 or 0
+ -- local l = xline - 1
+ -- local n = 1
+ -- local o = newoutput(size)
+ -- local k = 0
+ -- if factor then
+ -- if parts == 4 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 2
+ -- else
+ -- k = k + 1 ; o[k] = extract4(v,4) * 0x11
+ -- k = k + 1 ; o[k] = extract4(v,0) * 0x11
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- elseif parts == 2 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 4
+ -- else
+ -- k = k + 1 ; o[k] = extract2(v,6) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,4) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,2) * 0x55
+ -- k = k + 1 ; o[k] = extract2(v,0) * 0x55
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- else
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 8
+ -- else
+ -- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,7) * 0xFF
+ -- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,6) * 0xFF
+ -- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,5) * 0xFF
+ -- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,4) * 0xFF
+ -- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,3) * 0xFF
+ -- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,2) * 0xFF
+ -- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,1) * 0xFF
+ -- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 0xFF end -- o[k] = extract1(v,0) * 0xFF
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- end
+ -- else
+ -- if parts == 4 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 2
+ -- else
+ -- k = k + 1 ; o[k] = extract4(v,4)
+ -- k = k + 1 ; o[k] = extract4(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- elseif parts == 2 then
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 4
+ -- else
+ -- k = k + 1 ; o[k] = extract2(v,6)
+ -- k = k + 1 ; o[k] = extract2(v,4)
+ -- k = k + 1 ; o[k] = extract2(v,2)
+ -- k = k + 1 ; o[k] = extract2(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- else
+ -- for i=1,ysize do
+ -- for j=n+f,n+l do
+ -- local v = t[j]
+ -- if v == 0 then
+ -- k = k + 8
+ -- else
+ -- k = k + 1 ; if band(v,0x80) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,7)
+ -- k = k + 1 ; if band(v,0x40) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,6)
+ -- k = k + 1 ; if band(v,0x20) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,5)
+ -- k = k + 1 ; if band(v,0x10) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,4)
+ -- k = k + 1 ; if band(v,0x08) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,3)
+ -- k = k + 1 ; if band(v,0x04) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,2)
+ -- k = k + 1 ; if band(v,0x02) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,1)
+ -- k = k + 1 ; if band(v,0x01) ~= 0 then o[k] = 1 end -- o[k] = extract1(v,0)
+ -- end
+ -- end
+ -- k = i * xsize
+ -- n = n + xline
+ -- end
+ -- end
+ -- end
+ -- for i=size,xsize * ysize +1,-1 do
+ -- o[i] = nil
+ -- end
+ -- return o, false
+ -- end
local expand_c = pngexpand
@@ -672,8 +673,8 @@ do
local xstep = xstep[pass]
local ystart = ystart[pass]
local ystep = ystep[pass]
- local nx = idiv(xsize + xstep - xstart - 1,xstep)
- local ny = idiv(ysize + ystep - ystart - 1,ystep)
+ local nx = (xsize + xstep - xstart - 1) // xstep
+ local ny = (ysize + ystep - ystart - 1) // ystep
if nx > 0 and ny > 0 then
local input, filter
if parts then
@@ -715,95 +716,95 @@ do
return r
end
- local function createmask_l(content,palette,transparent,xsize,ysize,colordepth,colorspace)
- if palette then
- local r = expandvector(transparent)
- local size = xsize*ysize
- local len = ceil(xsize*colordepth/8) + 1
- local o = newoutput(xsize*ysize)
- local u = setmetatableindex(zero)
- content = zlibdecompress(content)
- content = openstring(content)
- for i=0,ysize-1 do
- local t = readbytetable(content,len)
- local k = i * xsize
- local filter = t[1]
- if filter == 0 then
- elseif filter == 1 then
- for j=3,len do
- t[j] = (t[j] + t[j-1]) % 256
- end
- elseif filter == 2 then
- for j=2,len do
- t[j] = (t[j] + u[j]) % 256
- end
- elseif filter == 3 then
- local j = 2
- t[j] = (t[j] + idiv(u[j],2)) % 256
- for j=3,len do
- t[j] = (t[j] + idiv(t[j-1] + u[j],2)) % 256
- end
- elseif filter == 4 then
- local j = 2
- local p = j - len
- local b = t[p]
- if b < 0 then
- b = - b
- end
- if b > 0 then
- t[j] = (t[j] + b) % 256
- end
- for j=3,len do
- local p = j - len
- local a = t[j-1]
- local b = t[p]
- local c = t[p-1]
- local pa = b - c
- local pb = a - c
- local pc = pa + pb
- if pa < 0 then pa = - pa end
- if pb < 0 then pb = - pb end
- if pc < 0 then pc = - pc end
- t[j] = (t[j] + ((pa <= pb and pa <= pc and a) or (pb <= pc and b) or c)) % 256
- end
- end
- if colordepth == 8 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[v]
- end
- elseif colordepth == 4 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract4(v,4)]
- k = k + 1 ; o[k] = r[extract4(v,0)]
- end
- elseif colordepth == 2 then
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract2(v,6)]
- k = k + 1 ; o[k] = r[extract2(v,4)]
- k = k + 1 ; o[k] = r[extract2(v,2)]
- k = k + 1 ; o[k] = r[extract2(v,0)]
- end
- else
- for j=2,len do
- local v = t[j]
- k = k + 1 ; o[k] = r[extract1(v,7)]
- k = k + 1 ; o[k] = r[extract1(v,6)]
- k = k + 1 ; o[k] = r[extract1(v,5)]
- k = k + 1 ; o[k] = r[extract1(v,4)]
- k = k + 1 ; o[k] = r[extract1(v,3)]
- k = k + 1 ; o[k] = r[extract1(v,2)]
- k = k + 1 ; o[k] = r[extract1(v,1)]
- k = k + 1 ; o[k] = r[extract1(v,0)]
- end
- end
- u = t
- end
- return concat(o,"",1,size)
- end
- end
+ -- local function createmask_l(content,palette,transparent,xsize,ysize,colordepth,colorspace)
+ -- if palette then
+ -- local r = expandvector(transparent)
+ -- local size = xsize*ysize
+ -- local len = ceil(xsize*colordepth/8) + 1
+ -- local o = newoutput(xsize*ysize)
+ -- local u = setmetatableindex(zero)
+ -- content = zlibdecompress(content)
+ -- content = openstring(content)
+ -- for i=0,ysize-1 do
+ -- local t = readbytetable(content,len)
+ -- local k = i * xsize
+ -- local filter = t[1]
+ -- if filter == 0 then
+ -- elseif filter == 1 then
+ -- for j=3,len do
+ -- t[j] = (t[j] + t[j-1]) % 256
+ -- end
+ -- elseif filter == 2 then
+ -- for j=2,len do
+ -- t[j] = (t[j] + u[j]) % 256
+ -- end
+ -- elseif filter == 3 then
+ -- local j = 2
+ -- t[j] = (t[j] + idiv(u[j],2)) % 256
+ -- for j=3,len do
+ -- t[j] = (t[j] + idiv(t[j-1] + u[j],2)) % 256
+ -- end
+ -- elseif filter == 4 then
+ -- local j = 2
+ -- local p = j - len
+ -- local b = t[p]
+ -- if b < 0 then
+ -- b = - b
+ -- end
+ -- if b > 0 then
+ -- t[j] = (t[j] + b) % 256
+ -- end
+ -- for j=3,len do
+ -- local p = j - len
+ -- local a = t[j-1]
+ -- local b = t[p]
+ -- local c = t[p-1]
+ -- local pa = b - c
+ -- local pb = a - c
+ -- local pc = pa + pb
+ -- if pa < 0 then pa = - pa end
+ -- if pb < 0 then pb = - pb end
+ -- if pc < 0 then pc = - pc end
+ -- t[j] = (t[j] + ((pa <= pb and pa <= pc and a) or (pb <= pc and b) or c)) % 256
+ -- end
+ -- end
+ -- if colordepth == 8 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[v]
+ -- end
+ -- elseif colordepth == 4 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract4(v,4)]
+ -- k = k + 1 ; o[k] = r[extract4(v,0)]
+ -- end
+ -- elseif colordepth == 2 then
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract2(v,6)]
+ -- k = k + 1 ; o[k] = r[extract2(v,4)]
+ -- k = k + 1 ; o[k] = r[extract2(v,2)]
+ -- k = k + 1 ; o[k] = r[extract2(v,0)]
+ -- end
+ -- else
+ -- for j=2,len do
+ -- local v = t[j]
+ -- k = k + 1 ; o[k] = r[extract1(v,7)]
+ -- k = k + 1 ; o[k] = r[extract1(v,6)]
+ -- k = k + 1 ; o[k] = r[extract1(v,5)]
+ -- k = k + 1 ; o[k] = r[extract1(v,4)]
+ -- k = k + 1 ; o[k] = r[extract1(v,3)]
+ -- k = k + 1 ; o[k] = r[extract1(v,2)]
+ -- k = k + 1 ; o[k] = r[extract1(v,1)]
+ -- k = k + 1 ; o[k] = r[extract1(v,0)]
+ -- end
+ -- end
+ -- u = t
+ -- end
+ -- return concat(o,"",1,size)
+ -- end
+ -- end
local function createmask_c(content,palette,transparent,xsize,ysize,colordepth,colorspace)
if palette then
@@ -825,28 +826,28 @@ do
elseif colordepth == 4 then
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract4(v,4)]
- k = k + 1 ; o[k] = r[extract4(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x0F] -- r[extract4(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x0F] -- r[extract4(v,0)]
end
elseif colordepth == 2 then
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract2(v,6)]
- k = k + 1 ; o[k] = r[extract2(v,4)]
- k = k + 1 ; o[k] = r[extract2(v,2)]
- k = k + 1 ; o[k] = r[extract2(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 6) & 0x03] -- r[extract2(v,6)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x03] -- r[extract2(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 2) & 0x03] -- r[extract2(v,2)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x03] -- r[extract2(v,0)]
end
else
for j=1,len do
local v = t[j]
- k = k + 1 ; o[k] = r[extract1(v,7)]
- k = k + 1 ; o[k] = r[extract1(v,6)]
- k = k + 1 ; o[k] = r[extract1(v,5)]
- k = k + 1 ; o[k] = r[extract1(v,4)]
- k = k + 1 ; o[k] = r[extract1(v,3)]
- k = k + 1 ; o[k] = r[extract1(v,2)]
- k = k + 1 ; o[k] = r[extract1(v,1)]
- k = k + 1 ; o[k] = r[extract1(v,0)]
+ k = k + 1 ; o[k] = r[(v >> 7) & 0x01] -- r[extract1(v,7)]
+ k = k + 1 ; o[k] = r[(v >> 6) & 0x01] -- r[extract1(v,6)]
+ k = k + 1 ; o[k] = r[(v >> 5) & 0x01] -- r[extract1(v,5)]
+ k = k + 1 ; o[k] = r[(v >> 4) & 0x01] -- r[extract1(v,4)]
+ k = k + 1 ; o[k] = r[(v >> 3) & 0x01] -- r[extract1(v,3)]
+ k = k + 1 ; o[k] = r[(v >> 2) & 0x01] -- r[extract1(v,2)]
+ k = k + 1 ; o[k] = r[(v >> 1) & 0x01] -- r[extract1(v,1)]
+ k = k + 1 ; o[k] = r[(v >> 0) & 0x01] -- r[extract1(v,0)]
end
end
end
@@ -854,25 +855,25 @@ do
end
end
- local function tocmyk_l(content,colordepth)
- local l = #content
- local t = { }
- local n = 0
- if colordepth == 8 then
- for i=1,l,3 do
- local r, g, b = byte(content,i,i+2)
- n = n + 1 ; t[n] = char(255-r,255-g,255-b,0) -- a tad faster than chars[...]
- end
- else
- for i=1,l,6 do
- local r1, r2, g1, g2, b1, b2 = byte(content,i,i+5)
- n = n + 1 ; t[n] = char(255-r1,255-r2,255-g1,255-g2,255-b1,255-b2,0,0)
- end
- end
- return concat(t)
- end
-
- local tocmyk_c = pngtocmyk or tocmyk_l
+ -- local function tocmyk_l(content,colordepth)
+ -- local l = #content
+ -- local t = { }
+ -- local n = 0
+ -- if colordepth == 8 then
+ -- for i=1,l,3 do
+ -- local r, g, b = byte(content,i,i+2)
+ -- n = n + 1 ; t[n] = char(255-r,255-g,255-b,0) -- a tad faster than chars[...]
+ -- end
+ -- else
+ -- for i=1,l,6 do
+ -- local r1, r2, g1, g2, b1, b2 = byte(content,i,i+5)
+ -- n = n + 1 ; t[n] = char(255-r1,255-r2,255-g1,255-g2,255-b1,255-b2,0,0)
+ -- end
+ -- end
+ -- return concat(t)
+ -- end
+
+ local tocmyk_c = pngtocmyk
local function converttocmyk(content,colorspace,colordepth)
if colorspace == "DeviceRGB" and colordepth == 8 or colordepth == 16 then
@@ -885,16 +886,16 @@ do
return content, colorspace
end
- local function switch(v)
- if v then
- filtermask = filtermask_l
- decodemask = decodemask_l
- decodestrip = decodestrip_l
- transpose = transpose_l
- expand = expand_l
- createmask = createmask_l
- tocmyk = tocmyk_l
- else
+ -- local function switch(v)
+ -- if v then
+ -- filtermask = filtermask_l
+ -- decodemask = decodemask_l
+ -- decodestrip = decodestrip_l
+ -- transpose = transpose_l
+ -- expand = expand_l
+ -- createmask = createmask_l
+ -- tocmyk = tocmyk_l
+ -- else
filtermask = filtermask_c
decodemask = decodemask_c
decodestrip = decodestrip_c
@@ -902,15 +903,15 @@ do
expand = expand_c
createmask = createmask_c
tocmyk = tocmyk_c
- end
- end
+ -- end
+ -- end
- if pngapplyfilter then
- switch(false)
- directives.register("graphics.png.purelua",switch)
- else
- switch(true)
- end
+ -- if pngapplyfilter then
+ -- switch(false)
+ -- directives.register("graphics.png.purelua",switch)
+ -- else
+ -- switch(true)
+ -- end
local alwaysdecode = false -- trucky with palettes
local compresslevel = 3
@@ -1125,7 +1126,7 @@ do
palette = pdfarray {
pdfconstant("Indexed"),
pdfconstant(colorspace),
- idiv(#palette,nofbytes),
+ #palette // nofbytes,
pdfreference(pdfflushstreamobject(palette)),
}
end