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: 228
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 21:35
ChristopherJam

Registered: Aug 2004
Posts: 1378
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: 228
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: 228
[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: 11114
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: 228
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: 228
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: 228
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)
2018-05-19 08:03
ChristopherJam

Registered: Aug 2004
Posts: 1378
Quoting wertstahl
ps: if anyone hints me towards formatting source code nicely in this csdb thing, i will happily comply.

Just follow the Read more link on the comment entry form.

But in short, wrap your code segments in [ code]/[ /code] (only without the spaces after the "["s)
2018-06-09 00:39
ws

Registered: Apr 2012
Posts: 228

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

linenums    = #$05
linecount   byte $05 ;(+1)

blur        lda  linenums  ;---
            sta  linecount ;---

            ldx #$00

do_blurX    ldy #$26

x_blurX     lda $0400+1,x
            lsr
            lsr
            lsr
            sta pot

            lda $0400-1,x
            lsr
            lsr
            lsr
            clc
            adc pot
            sta pot

            lda $0400,x
            lsr
            clc
            adc pot
            bcc noclip
            lda #$ff
noclip      sta $0400,x

            inx

            dey
            bne x_blurX

            inx ;---
            inx ;--- these and this mechanism is 
                ;--- just there to provide a visual gap
                ;--- ofcourse the scanning could be seamless 

            dec linecount ;---
            bne do_blurX  ;---

            rts

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

pot         byte $0



needs deeper thought, but it works, horizontally, though.
2018-06-09 11:04
Digger

Registered: Mar 2005
Posts: 421
.prg would be good :)
Previous - 1 | 2 | 3 | 4 | 5 - 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
Menace/Spaceballs
chesser/Nigaz
Fred/Channel 4
Airwolf/F4CG
Firelord/EX/TRX
Guests online: 152
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Fullscreen Graphicians
1 Carrion  (9.8)
2 Joe  (9.8)
3 Duce  (9.8)
4 Mirage  (9.7)
5 Facet  (9.7)

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