mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-04-05 03:37:43 +00:00
Ad an extra pixel of lookup to reduce streaking
This commit is contained in:
parent
6ae6a343b2
commit
8ded05fcfb
Binary file not shown.
@ -55,82 +55,102 @@ def dist(x1, y1, z1, x2, y2, z2)#2
|
||||
return xx:[0], xx:[1]
|
||||
end
|
||||
|
||||
def rgbPix(r, g, b, nr, ng, nb, x, y)#0
|
||||
def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
|
||||
var errptr
|
||||
var pr, pg, pb
|
||||
var lr, lg, lb
|
||||
var pr1, pg1, pb1
|
||||
var pr2, pg2, pb2
|
||||
var pr3, pg3, pb3
|
||||
var lr0, lg0, lb0
|
||||
var lr1, lg1, lb1
|
||||
var lr2, lg2, lb2
|
||||
var er, eg, eb
|
||||
var cr, cg, cb, cx
|
||||
byte i
|
||||
res[t_i32] pd, cd, nd
|
||||
res[t_i32] pd, d0, d1, d2
|
||||
|
||||
// Error propogation
|
||||
errptr = rgbErr + x * 3 * 2
|
||||
if errDiv
|
||||
r = r + errptr=>[RED] / errDiv
|
||||
g = g + errptr=>[GRN] / errDiv
|
||||
b = b + errptr=>[BLU] / errDiv
|
||||
fin
|
||||
pr = 0
|
||||
pg = 0
|
||||
pb = 0
|
||||
// Previous 3/4 chroma cycle
|
||||
for cx = x - 1 downto x - 3
|
||||
i = (cx & 3) * 3
|
||||
pr = pr + ntscCycle[i+RED]
|
||||
pg = pg + ntscCycle[i+GRN]
|
||||
pb = pb + ntscCycle[i+BLU]
|
||||
next
|
||||
pd:[0], pd:[1] = dist(r, g, b, pr, pg, pb)
|
||||
i = ((x - 1) & 3) * 3
|
||||
pr1 = ntscCycle[i+RED]
|
||||
pg1 = ntscCycle[i+GRN]
|
||||
pb1 = ntscCycle[i+BLU]
|
||||
i = ((x - 2) & 3) * 3
|
||||
pr2 = pr1 + ntscCycle[i+RED]
|
||||
pg2 = pg1 + ntscCycle[i+GRN]
|
||||
pb2 = pb1 + ntscCycle[i+BLU]
|
||||
i = ((x - 3) & 3) * 3
|
||||
pr3 = pr2 + ntscCycle[i+RED]
|
||||
pg3 = pg2 + ntscCycle[i+GRN]
|
||||
pb3 = pb2 + ntscCycle[i+BLU]
|
||||
// Current chroma cycle
|
||||
i = (x & 3) * 3
|
||||
cr = pr3 + ntscChroma[i+RED]
|
||||
cg = pg3 + ntscChroma[i+GRN]
|
||||
cb = pb3 + ntscChroma[i+BLU]
|
||||
if errDiv
|
||||
r0 = r0 + errptr=>[RED] / errDiv
|
||||
g0 = g0 + errptr=>[GRN] / errDiv
|
||||
b0 = b0 + errptr=>[BLU] / errDiv
|
||||
fin
|
||||
// Look ahead in chroma cycle for possible better match for next RGB pixel
|
||||
i = ((x + 1) & 3) * 3
|
||||
lr = pr - ntscCycle[i+RED] + ntscChroma[i+RED]
|
||||
lg = pg - ntscCycle[i+GRN] + ntscChroma[i+GRN]
|
||||
lb = pb - ntscCycle[i+BLU] + ntscChroma[i+BLU]
|
||||
lr1 = pr2 + ntscChroma[i+RED]
|
||||
lg1 = pg2 + ntscChroma[i+GRN]
|
||||
lb1 = pb2 + ntscChroma[i+BLU]
|
||||
if errDiv
|
||||
nr = nr + (errptr=>[3+RED] + r - lr) / errDiv
|
||||
ng = ng + (errptr=>[3+GRN] + g - lg) / errDiv
|
||||
nb = nb + (errptr=>[3+BLU] + b - lb) / errDiv
|
||||
r1 = r1 + (errptr=>[3+RED] + r0 - lr1) / errDiv
|
||||
g1 = g1 + (errptr=>[3+GRN] + g0 - lg1) / errDiv
|
||||
b1 = b1 + (errptr=>[3+BLU] + b0 - lb1) / errDiv
|
||||
fin
|
||||
nd:[0], nd:[1] = dist(nr, ng, nb, lr, lg, lb)
|
||||
// Current 1/4 chroma color
|
||||
i = (x & 3) * 3
|
||||
cr = pr + ntscChroma[i+RED]
|
||||
cg = pg + ntscChroma[i+GRN]
|
||||
cb = pb + ntscChroma[i+BLU]
|
||||
cd:[0], cd:[1] = dist(r, g, b, cr, cg, cb)
|
||||
load32(@cd)
|
||||
if islt32(@pd) and islt32(@nd)
|
||||
// Look ahead in chroma cycle for possible better match for after next RGB pixel
|
||||
i = ((x + 2) & 3) * 3
|
||||
lr2 = pr1 + ntscChroma[i+RED]
|
||||
lg2 = pg1 + ntscChroma[i+GRN]
|
||||
lb2 = pb1 + ntscChroma[i+BLU]
|
||||
if errDiv
|
||||
r2 = r2 + (errptr=>[3+RED] + r1 - lr2) / errDiv
|
||||
g2 = g2 + (errptr=>[3+GRN] + g1 - lg2) / errDiv
|
||||
b2 = b2 + (errptr=>[3+BLU] + b1 - lb2) / errDiv
|
||||
fin
|
||||
// Calc match if current pixel is zero
|
||||
pd:[0], pd:[1] = dist(r0, g0, b0, pr3, pg3, pb3)
|
||||
// Calc match if next pixel is one
|
||||
d2:[0], d2:[1] = dist(r2, g2, b2, lr2, lg2, lb2)
|
||||
// Calc match if after next pixel is one
|
||||
d1:[0], d1:[1] = dist(r1, g1, b1, lr1, lg1, lb1)
|
||||
// Calc match if current pixel is one
|
||||
d0:[0], d0:[1] = dist(r0, g0, b0, cr, cg, cb)
|
||||
i = (x & 3) * 3
|
||||
load32(@d0)
|
||||
if islt32(@pd) and islt32(@d1) and islt32(@d2)
|
||||
// RGB better matched with current 1/4 chroma color
|
||||
nr = r - cr
|
||||
ng = g - cg
|
||||
nb = b - cb
|
||||
er = r0 - cr
|
||||
eg = g0 - cg
|
||||
eb = b0 - cb
|
||||
ntscCycle[i+RED] = ntscChroma[i+RED]
|
||||
ntscCycle[i+GRN] = ntscChroma[i+GRN]
|
||||
ntscCycle[i+BLU] = ntscChroma[i+BLU]
|
||||
dhgrSet(x, y)
|
||||
i = 1
|
||||
else
|
||||
// RGB closer to black
|
||||
nr = r - pr
|
||||
ng = g - pg
|
||||
nb = b - pb
|
||||
er = r0 - pr3
|
||||
eg = g0 - pg3
|
||||
eb = b0 - pb3
|
||||
ntscCycle[i+RED] = 0
|
||||
ntscCycle[i+GRN] = 0
|
||||
ntscCycle[i+BLU] = 0
|
||||
i = 0
|
||||
fin
|
||||
// Propogate error down and forward
|
||||
errptr=>[RED] = nr
|
||||
errptr=>[GRN] = ng
|
||||
errptr=>[BLU] = nb
|
||||
errptr=>[RED] = er
|
||||
errptr=>[GRN] = eg
|
||||
errptr=>[BLU] = eb
|
||||
errptr = errptr + 6
|
||||
errptr=>[RED] = nr + errptr=>[RED]
|
||||
errptr=>[GRN] = ng + errptr=>[GRN]
|
||||
errptr=>[BLU] = nb + errptr=>[BLU]
|
||||
// Map dark grey to light grey
|
||||
if (x & 3) == 3 and dcgrGetPixel(x >> 2, y) == 5
|
||||
dhgrOp(OP_SRC)
|
||||
dcgrColor(10)
|
||||
dcgrPixel(x >> 2, y)
|
||||
fin
|
||||
errptr=>[RED] = er + errptr=>[RED]
|
||||
errptr=>[GRN] = eg + errptr=>[GRN]
|
||||
errptr=>[BLU] = eb + errptr=>[BLU]
|
||||
return i
|
||||
end
|
||||
|
||||
def rgbInit#0
|
||||
@ -151,8 +171,8 @@ def rgbInit#0
|
||||
fin
|
||||
dhgrMode(DHGR_COLOR_MODE)
|
||||
// Init error propogation array
|
||||
rgbErr = heapalloc(561 * 3 * 2)
|
||||
memset(rgberr, 0, 561 * 3 * 2)
|
||||
rgbErr = heapalloc(563 * 3 * 2)
|
||||
memset(rgberr, 0, 563 * 3 * 2)
|
||||
rgberr=>[RED] = -1
|
||||
rgberr=>[GRN] = -1
|
||||
rgberr=>[BLU] = -1
|
||||
@ -164,30 +184,42 @@ def rgbExit#0
|
||||
end
|
||||
|
||||
def rgbImportExport(rgbfile, dhgrfile)#0
|
||||
byte refnum, r, g, b, nxtr, nxtg, nxtb
|
||||
byte refnum, r0, g0, b0, r1, g1, b1, r2, g2, b2
|
||||
var i, j
|
||||
var rgbScanline, rgbptr
|
||||
|
||||
refnum = fileio:open(rgbfile)
|
||||
if refnum
|
||||
rgbScanline = heapalloc(560 * 3)
|
||||
rgbScanline = heapalloc(563 * 3)
|
||||
memset(rgbScanline, 0, 563 * 3)
|
||||
if rgbScanline
|
||||
rgbInit
|
||||
for j = 0 to 191
|
||||
fileio:read(refnum, rgbScanline, 560 * 3)
|
||||
rgbptr = rgbScanline
|
||||
nxtr = gamma[rgbptr->RED]
|
||||
nxtg = gamma[rgbptr->GRN]
|
||||
nxtb = gamma[rgbptr->BLU]
|
||||
r1 = gamma[rgbptr->RED]
|
||||
g1 = gamma[rgbptr->GRN]
|
||||
b1 = gamma[rgbptr->BLU]
|
||||
rgbptr = rgbptr + 3
|
||||
r2 = gamma[rgbptr->RED]
|
||||
g2 = gamma[rgbptr->GRN]
|
||||
b2 = gamma[rgbptr->BLU]
|
||||
for i = 0 to 559
|
||||
r = nxtr
|
||||
g = nxtg
|
||||
b = nxtb
|
||||
r0, g0, b0 = r1, g1, b1
|
||||
r1, g1, b1 = r2, g2, b2
|
||||
rgbptr = rgbptr + 3
|
||||
nxtr = gamma[rgbptr->RED]
|
||||
nxtg = gamma[rgbptr->GRN]
|
||||
nxtb = gamma[rgbptr->BLU]
|
||||
rgbPix(r, g, b, nxtr, nxtg, nxtb, i, j)
|
||||
r2 = gamma[rgbptr->RED]
|
||||
g2 = gamma[rgbptr->GRN]
|
||||
b2 = gamma[rgbptr->BLU]
|
||||
if rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, i)
|
||||
dhgrSet(i, j)
|
||||
fin
|
||||
// Map dark grey to light grey
|
||||
if (i & 3) == 3 and dcgrGetPixel(i >> 2, j) == 5
|
||||
dhgrOp(OP_SRC)
|
||||
dcgrColor(10)
|
||||
dcgrPixel(i >> 2, j)
|
||||
fin
|
||||
next
|
||||
if ^$C000 == $83
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user