summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-fil.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-03-02 23:00:09 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-03-02 23:00:09 +0100
commit8f5c555274eb48fcaaa3d7f340ee77710846fb7e (patch)
tree7e1802669127ba84d78ba62534f34e556b5c6e59 /tex/context/base/mkiv/util-fil.lua
parent6c9a5085dc2cee2c277d69d2dfcb397dab7aeb19 (diff)
downloadcontext-8f5c555274eb48fcaaa3d7f340ee77710846fb7e.tar.gz
2017-03-02 22:28:00
Diffstat (limited to 'tex/context/base/mkiv/util-fil.lua')
-rw-r--r--tex/context/base/mkiv/util-fil.lua24
1 files changed, 15 insertions, 9 deletions
diff --git a/tex/context/base/mkiv/util-fil.lua b/tex/context/base/mkiv/util-fil.lua
index 4e66ba461..d0ffe07c6 100644
--- a/tex/context/base/mkiv/util-fil.lua
+++ b/tex/context/base/mkiv/util-fil.lua
@@ -218,6 +218,15 @@ function files.readinteger4le(f)
end
end
+function files.readfixed2(f)
+ local a, b = byte(f:read(2),1,2)
+ if a >= 0x80 then
+ return (0x100 * a + b - 0x10000)/256.0
+ else
+ return (0x100 * a + b)/256.0
+ end
+end
+
function files.readfixed4(f)
local a, b, c, d = byte(f:read(4),1,4)
if a >= 0x80 then
@@ -230,17 +239,13 @@ end
if extract then
+ local extract = bit32.extract
+ local band = bit32.band
+
function files.read2dot14(f)
local a, b = byte(f:read(2),1,2)
local n = 0x100 * a + b
- local m = extract(n,0,30)
- if n > 0x7FFF then
- n = extract(n,30,2)
- return m/0x4000 - 4
- else
- n = extract(n,30,2)
- return n + m/0x4000
- end
+ return extract(n,14,2) + (band(n,0x3FFF) / 16384.0)
end
end
@@ -291,12 +296,13 @@ if fio and fio.readcardinal1 then
files.readinteger2 = fio.readinteger2
files.readinteger3 = fio.readinteger3
files.readinteger4 = fio.readinteger4
+ files.readfixed2 = fio.readfixed2
files.readfixed4 = fio.readfixed4
files.read2dot14 = fio.read2dot14
files.setposition = fio.setposition
files.getposition = fio.getposition
- files.readbyte = files.readcardinel1
+ files.readbyte = files.readcardinal1
files.readsignedbyte = files.readinteger1
files.readcardinal = files.readcardinal1
files.readinteger = files.readinteger1