1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-17 22:30:41 +00:00

Simplify interface to rgbPix match

This commit is contained in:
David Schmenk 2024-12-07 08:58:33 -08:00
parent 70fd56a93c
commit c3243f491e

View File

@ -56,8 +56,10 @@ def dist(x1, y1, z1, x2, y2, z2)#2
return xx:[0], xx:[1]
end
def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
var errptr
def rgbPix(rgbptr, errptr, cx)#1
var r0, g0, b0
var r1, g1, b1
var r2, g2, b2
var pr1, pg1, pb1
var pr2, pg2, pb2
var pr3, pg3, pb3
@ -65,30 +67,31 @@ def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
var lr1, lg1, lb1
var lr2, lg2, lb2
var er, eg, eb
var cr, cg, cb, cx
var cr, cg, cb
byte i
res[t_i32] pd, d0, d1, d2
// Error propogation
errptr = rgbErr + x * 3 * 2
// Previous 3/4 chroma cycle
i = ((x - 1) & 3) * 3
i = ((cx - 1) & 3) * 3
pr1 = ntscCycle[i+RED]
pg1 = ntscCycle[i+GRN]
pb1 = ntscCycle[i+BLU]
i = ((x - 2) & 3) * 3
i = ((cx - 2) & 3) * 3
pr2 = pr1 + ntscCycle[i+RED]
pg2 = pg1 + ntscCycle[i+GRN]
pb2 = pb1 + ntscCycle[i+BLU]
i = ((x - 3) & 3) * 3
i = ((cx - 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
i = cx * 3
cr = pr3 + ntscChroma[i+RED]
cg = pg3 + ntscChroma[i+GRN]
cb = pb3 + ntscChroma[i+BLU]
r0 = gamma[rgbptr->RED]]
g0 = gamma[rgbptr->GRN]]
b0 = gamma[rgbptr->BLU]]
if errDiv
r0 = r0 + errptr=>[RED] / errDiv
g0 = g0 + errptr=>[GRN] / errDiv
@ -98,10 +101,13 @@ def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
pd:[0], pd:[1] = dist(r0, g0, b0, pr3, pg3, pb3)
if lookahead > 0
// Look ahead in chroma cycle for possible better match for next RGB pixel
i = ((x + 1) & 3) * 3
i = ((cx + 1) & 3) * 3
lr1 = pr2 + ntscChroma[i+RED]
lg1 = pg2 + ntscChroma[i+GRN]
lb1 = pb2 + ntscChroma[i+BLU]
r1 = gamma[rgbptr->[3+RED]]]
g1 = gamma[rgbptr->[3+GRN]]]
b1 = gamma[rgbptr->[3+BLU]]]
if errDiv
r1 = r1 + (errptr=>[3+RED] + r0 - lr1) / errDiv
g1 = g1 + (errptr=>[3+GRN] + g0 - lg1) / errDiv
@ -111,14 +117,17 @@ def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
d1:[0], d1:[1] = dist(r1, g1, b1, lr1, lg1, lb1)
if lookahead > 1
// Look ahead in chroma cycle for possible better match for after next RGB pixel
i = ((x + 2) & 3) * 3
i = ((cx + 2) & 3) * 3
lr2 = pr1 + ntscChroma[i+RED]
lg2 = pg1 + ntscChroma[i+GRN]
lb2 = pb1 + ntscChroma[i+BLU]
r2 = gamma[rgbptr->[6+RED]]]
g2 = gamma[rgbptr->[6+GRN]]]
b2 = gamma[rgbptr->[6+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
r2 = r2 + (errptr=>[6+RED] + r1 - lr2) / errDiv
g2 = g2 + (errptr=>[6+GRN] + g1 - lg2) / errDiv
b2 = b2 + (errptr=>[6+BLU] + b1 - lb2) / errDiv
fin
// Calc match if next pixel is one
d2:[0], d2:[1] = dist(r2, g2, b2, lr2, lg2, lb2)
@ -131,7 +140,7 @@ def rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, x)#1
fin
// Calc match if current pixel is one
d0:[0], d0:[1] = dist(r0, g0, b0, cr, cg, cb)
i = (x & 3) * 3
i = cx * 3
load32(@d0)
if islt32(@pd) and islt32(@d1) and islt32(@d2)
// RGB better matched with current 1/4 chroma color
@ -194,9 +203,9 @@ def rgbExit#0
end
def rgbImportExport(rgbfile, dhgrfile)#0
byte refnum, r0, g0, b0, r1, g1, b1, r2, g2, b2
byte refnum
var i, j
var rgbScanline, rgbptr
var rgbScanline, rgbptr, errptr
refnum = fileio:open(rgbfile)
if refnum
@ -207,24 +216,14 @@ def rgbImportExport(rgbfile, dhgrfile)#0
for j = 0 to 191
fileio:read(refnum, rgbScanline, 560 * 3)
rgbptr = rgbScanline
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]
errptr = rgbErr
for i = 0 to 559
r0, g0, b0 = r1, g1, b1
r1, g1, b1 = r2, g2, b2
rgbptr = rgbptr + 3
r2 = gamma[rgbptr->RED]
g2 = gamma[rgbptr->GRN]
b2 = gamma[rgbptr->BLU]
if rgbPix(r0, g0, b0, r1, g1, b1, r2, g2, b2, i)
if rgbPix(rgbptr, errptr, i & 3)
dhgrSet(i, j)
fin
// Map dark grey to light grey
rgbptr = rgbptr + 3
errptr = errptr + 3 * 2
// Map dark grey to light grey
if (i & 3) == 3 and dcgrGetPixel(i >> 2, j) == 5
dhgrOp(OP_SRC)
dcgrColor(10)