comments: ops AudioOps / ImageOps Kernels
This commit is contained in:
1 parent
b8db3ed551
commit
5e6102d4b2
2 files changed
+7
-54
No files matched your search
@@ -1,12 +1,9 @@
|
||||
--!strict
|
||||
--!native
|
||||
--!optimize 2
|
||||
-- ops/ImageOps/Kernels: the hot loops behind ops/ImageOps (native; never throws). Every function trusts its caller
|
||||
-- (ops/ImageOps validates sizes, formats and buffer lengths first), so all buffer indexes are in range by
|
||||
-- construction. Samples are addressed by kind: 1 = u8, 2 = u16, 4 = f32 (little endian, as Types.Image buffers).
|
||||
-- The resampling follows Pillow's Resample.c (separable convolution, horizontal pass first, filter support scaled by
|
||||
-- the downscale ratio, 22-bit fixed-point coefficients for 8-bit samples) and Geometry.c (affine transforms through
|
||||
-- pixel centres, bilinear with clamped neighbours); the alpha compositing is Pillow's AlphaComposite.c.
|
||||
-- ops/ImageOps/Kernels: the hot loops behind ops/ImageOps; callers validate, so indexes are in range by construction.
|
||||
-- Sample kinds: 1 = u8, 2 = u16, 4 = f32 (little endian). Resampling follows Pillow's Resample.c (separable, 22-bit
|
||||
-- fixed point for 8-bit) and Geometry.c (affine through pixel centres); compositing is Pillow's AlphaComposite.c.
|
||||
local readu8, writeu8, readu16, writeu16, readf32, writef32 = buffer.readu8, buffer.writeu8, buffer.readu16, buffer.writeu16, buffer.readf32, buffer.writef32
|
||||
local floor, clamp = math.floor, math.clamp
|
||||
|
||||
@@ -36,7 +33,6 @@ local function wr(b: buffer, o: number, kind: number, v: number)
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ convert
|
||||
-- depth: 8 -> 0..255, 16 -> 0..65535, 0 -> float 0..1
|
||||
local DEPTH = { 8, 16, 0, 8, 8, 16, 8, 8 }
|
||||
|
||||
@@ -55,7 +51,6 @@ local function depthConv(v: number, from: number, to: number): number
|
||||
end
|
||||
return v / 65535
|
||||
end
|
||||
-- float
|
||||
if v ~= v then
|
||||
v = 0
|
||||
end
|
||||
@@ -201,8 +196,6 @@ function K.yuvToRgba(src: buffer, w: number, h: number, dst: buffer)
|
||||
local _ = ch
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ geometry
|
||||
-- flip(src, dst, w, h, bpp, horizontal)
|
||||
function K.flip(src: buffer, dst: buffer, w: number, h: number, bpp: number, horizontal: boolean)
|
||||
local stride = w * bpp
|
||||
if not horizontal then
|
||||
@@ -219,7 +212,7 @@ function K.flip(src: buffer, dst: buffer, w: number, h: number, bpp: number, hor
|
||||
end
|
||||
end
|
||||
|
||||
-- rotate90(src, dst, w, h, bpp, turns): counter-clockwise quarter turns 1..3
|
||||
-- counter-clockwise quarter turns 1..3
|
||||
function K.rotate90(src: buffer, dst: buffer, w: number, h: number, bpp: number, turns: number)
|
||||
for y = 0, h - 1 do
|
||||
for x = 0, w - 1 do
|
||||
@@ -241,7 +234,6 @@ function K.rotate90(src: buffer, dst: buffer, w: number, h: number, bpp: number,
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ resample
|
||||
local function bilinearF(x: number): number
|
||||
if x < 0 then
|
||||
x = -x
|
||||
@@ -303,7 +295,6 @@ function K.coeffs(inSize: number, outSize: number, filter: string): Coeffs
|
||||
return { start = start, count = count, weights = weights }
|
||||
end
|
||||
|
||||
-- one separable pass. horizontal: src w x h -> dst outN x h; vertical: src w x h -> dst w x outN. ch channels of kind.
|
||||
function K.resamplePass(src: buffer, w: number, h: number, ch: number, kind: number, dst: buffer, outN: number, c: Coeffs, horizontal: boolean)
|
||||
local start, count, weights = c.start, c.count, c.weights
|
||||
local size = kind
|
||||
@@ -421,8 +412,7 @@ function K.affine(src: buffer, w: number, h: number, ch: number, kind: number, d
|
||||
end
|
||||
end
|
||||
|
||||
-- ------------------------------------------------------------------------------------------------ compositing
|
||||
-- overRgba8(dst, dw, src, sw, sx, sy, dx, dy, w, h, opacity255): Pillow's alpha_composite of src onto dst, in place
|
||||
-- Pillow's alpha_composite of src onto dst, in place
|
||||
function K.overRgba8(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, opacity: number)
|
||||
for y = 0, h - 1 do
|
||||
for x = 0, w - 1 do
|
||||
@@ -475,14 +465,12 @@ function K.overFloat(dst: buffer, dw: number, src: buffer, sw: number, sx: numbe
|
||||
end
|
||||
end
|
||||
|
||||
-- copyRect: rows of a rectangle (bpp bytes per pixel)
|
||||
function K.copyRect(dst: buffer, dw: number, src: buffer, sw: number, sx: number, sy: number, dx: number, dy: number, w: number, h: number, bpp: number)
|
||||
for y = 0, h - 1 do
|
||||
buffer.copy(dst, ((dy + y) * dw + dx) * bpp, src, ((sy + y) * sw + sx) * bpp, w * bpp)
|
||||
end
|
||||
end
|
||||
|
||||
-- premultiply / unpremultiply in place: ch channels, alpha last, kind
|
||||
function K.premultiply(b: buffer, n: number, ch: number, kind: number, un: boolean)
|
||||
local max = if kind == 1 then 255 elseif kind == 2 then 65535 else 1
|
||||
local px = ch * kind
|
||||
|
||||
Reference in new issue
Block a user