Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Simple bilinear interpolation in assembler
2018-05-08 16:24
ws

Registered: Apr 2012
Posts: 251
Simple bilinear interpolation in assembler

Hello,

for some reason, with increasing age, i am no longer interested in spending much time on re-inventing the wheel.

Therefore, i'd like to ask if any of you wizards perhaps know of a close solution to this problem:

Lets say you have a "heatmap" in a matrix of 20x10 cells.

Does anyone perhaps already have a fast and simple routine for interpolating all the values within these cells, so that when you have some cells with very high values and some cells with very low values, that more or less smooth transitions (image blur) can be achieved in very few rasterlines?

Google just spat out hardcore math for me, which i feel unable to wrap my head around, when attempted to translate to a c64 assembler solution. (I code in assembly, directly, no c++ or the like, pretty please).

best regards
WS
 
... 24 posts hidden. Click here to view all posts....
 
2018-05-09 19:06
ws

Registered: Apr 2012
Posts: 251
i am currently like half out of the door for xyz but this came to mind, it is just code, not tested.



datafield byte $f,$8,$0,$0, $0,$0,$5,$0
byte $0,$f,$0,$0, $2,$0,$0,$0
byte $f,$0,$0,$0
byte $0,$0,$0 ;simple headroom

gamma byte $0,$0,$0,$1, $1,$1,$1,$1
byte $2,$2,$3,$4, $5,$6,$7,$8
byte $f,$f,$f,$f, $f,$f,$f,$f
byte $f,$f,$f,$f, $f,$f,$f,$f ; peak clipping for demonstration

stor byte $0

;================

blur ldx #$00

do_blur ldy datafield,x
lda gamma,y ;get target value for base cell
sta datafield,x

;----------------
tay ;remember last shade of blur
lda gamma,y ;and blur again

clc
adc datafield+1,x ;combine values
tay
lda gamma,y ;and blur the combined value

sta datafield+1,x ;store

;----------------

tay ;remember last shade of blur
lda gamma,y ;and blur again

clc
adc datafield+2,x ;combine values
tay
lda gamma,y ;and blur the combined value

sta datafield+2,x ;store

;----------------

tay ;remember last shade of blur
lda gamma,y ;and blur again

clc
adc datafield+3,x ;combine values
tay
lda gamma,y ;and blur the combined value

sta datafield+3,x ;store

;----------------

inx
cpx #$14
bne do_blur

rts

;================

please excuse the fucked-up formatting.
2018-05-09 19:23
lft

Registered: Jul 2007
Posts: 369
Quoting ChristopherJam
Quoting soci
It's ROR and not LSR, right? Otherwise the usable value range is half.


Argh! Yes, you're right of course. Same applies to my code in comment #6, I meant to use ROR there, too.

Thanks for catching that.


Although, if half the value range is acceptable, then one could use ASR #$fe to clear carry in preparation for the next computation.
2018-05-09 19:25
ws

Registered: Apr 2012
Posts: 251
i'd rather have some sort of gamma curve that i can adjust via table. but thanks for clearing up rol vs asl and lsr
2018-05-09 21:35
ChristopherJam

Registered: Aug 2004
Posts: 1409
Nice approach :)

Small optimisation suggestion, which would also give you a little more control:

I notice you have snippets like
    tay
    lda gamma,y       ; decay
    sta datafield+2,x ; store
    tay
    lda gamma,y       ; decay more

May I suggest instead:
    tay
    lda gamma,y       ; decay
    sta datafield+2,x ; store
    lda gamma2,y      ; decay more

where gamma2=gamma[gamma[i]], or some refinement thereof.

You can also drop all but the first CLC if your gamma/gamma2 values are all under 128.
2018-05-09 22:58
ws

Registered: Apr 2012
Posts: 251
that is actually a very nice hint, using stairs of tables.

but i just implemented my first attempt and obviously it just dampens all the values instead of mixing them, so as a conclusion:

after the first load of a cell, it cannot just be destructively set to a fixed translation value without being compared to its neighbours.
the reduction value must be related to the neighbouring cells.

example
f000 --> destructive --> 8421 - ok
f200 --> destructive --> 8531 - not ok, must be A531
(just arbitrary example values)

workin on that.


[update]
by the way, this totally out of the blue, super far fetched noise generator which i utilize for creating data to be blurred, works surprisingly well (IN VICE!):

drawdom ldx #$00
paintle
lda $dc01
eor $d800
sta $db00
eor $db00

eor $0400,x
adc $d800,x

sta $0400,x

inx
bne paintle

rts
2018-05-09 23:19
ws

Registered: Apr 2012
Posts: 251
[update 2 on noise generator: works surprisingly well on a real c64, too. actually best performance i had with bus noise to this day. duh. (it needs to run twice for good entropy.)
2018-05-11 00:05
chatGPZ

Registered: Dec 2001
Posts: 11386
i strongly advice against using open i/o space for "noise". it is _not_ noise in the first place (what you are reading is what was left on the bus by the previous vic fetch) and on some C64s you will see just zeros or $ff.
2018-05-11 11:15
ws

Registered: Apr 2012
Posts: 251
Youre probably right, i'd also confirm that a mechanism like this should not be used without prior testing on several "chipsets", i must admit that i am quite obsessed with that method, though :-) I only use it for testing purposes, because i am too lazy to setup the SID noise method (if i remember correctly that that was possible).
2018-05-18 23:19
ws

Registered: Apr 2012
Posts: 251
okay. this really seems to be the fastest way:
do_blur clc
lda datafield,x
adc datafield+1,x
ror
sta datafield,x

inx
cpx #$00
bne do_blur

demo: http://dl.dataelephant.net/blur.zip (press space to...)

this is a 2 iterations blur, only thing i am going to add is looking back n pixels plus avoiding backshift.

and yes, i must really learn to think less wishful. took me quite some time to grasp the simpleness of the problem. too many images in my head.

ps: if anyone hints me towards formatting source code nicely in this csdb thing, i will happily comply.
2018-05-18 23:51
ws

Registered: Apr 2012
Posts: 251
i am pretty satisfied already:

http://dl.dataelephant.net/blur_it4.zip

4 iterations simple 1 cell blur. i am impressed how easy this stuff is, compared to trying to imagine it.

(prg+src inside zip)
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Steffan/BOOM!
Doc Snyder/ONS
slimeysmine
Copyfault/Extend^tsn..
Walt/Bonzai
New Design/Excess
Magic/Nah-Kolor
ΛΛdZ
Gildan Jondal/Suicyc..
iAN CooG/HVSC
wil
Guests online: 156
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 No Listen  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.054 sec.