Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user maak ! (Registered 2024-04-18) 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-08 16:43
ws

Registered: Apr 2012
Posts: 228
I want to smooth the values - without changing the number of cells-, preferably using a lookup table (thats what is always the simplest solution i have in my head) but it must be 2-dimensional - and that is actually what gives me some sort of headache..

do i first process all lines horizontally and then vertically? is that the way to go?

because from what i saw it looks like "they" (the math people) are using a 4 point sampling grid (or something like that).

EDIT: and i dont only want to have a result like this:

0000F00000F = 00028200028
but
01248421248

(for example)
2018-05-08 17:14
ws

Registered: Apr 2012
Posts: 228
i made a graphical example of what i want to achieve.

http://www.wertstahl.de/example.jpg

maybe this clears up things alot, please excuse that i find no other way to express what i am trying to do.
2018-05-08 17:18
ChristopherJam

Registered: Aug 2004
Posts: 1370
Quoting wertstahl
do i first process all lines horizontally and then vertically? is that the way to go?

Yes.
2018-05-08 18:21
ChristopherJam

Registered: Aug 2004
Posts: 1370
If you want nice long tails without summing multiple elements per output value, you might need to use an infinite impulse response filter, and probably run it left to right then right to left to make it symmetric.

Maybe something like this? (untested)
.for i in 0,39
  adc screen+i
  lsr
  tax
  lda times_3_over_2,x
  sta screen+i
  lda times_1_over_2,x
.endfor


(basically moves a quarter of the contents of each cell into the next one along, so any peaks get smeared over the next several cells, getting weaker as it goes along)
2018-05-08 19:11
ws

Registered: Apr 2012
Posts: 228
Thank you so much for the immediate responses!

I have been discussing and chewing on it a little bit and in addition with your thoughts (which all in all is interpolation of thoughts, right?) i'll be playing around with some code soon and i'll post my results here.
2018-05-09 07:59
Oswald

Registered: Apr 2002
Posts: 5017
Quote: i made a graphical example of what i want to achieve.

http://www.wertstahl.de/example.jpg

maybe this clears up things alot, please excuse that i find no other way to express what i am trying to do.


by the looks of this you need rather blur routine. Simply average 4 neighbour cells for each cell, or fire effect in other words.

The question is what you have in mind, how does that differ from blur ?

there have been "plasmas" out there wich work by averaging (interpolating if you like) out between a few hotspots, but they do look ugly.
2018-05-09 15:50
chatGPZ

Registered: Dec 2001
Posts: 11100
depending on what you are doing, you can also try randomly tweaking your own filters, perhaps throw some dithering into the mix, vary the number of taps you are using. (eg using 3 values only, with different factors). you can perhaps also speed it up a lot by limiting the range of the source values (again depends on what you are doing) so you can use table lookups for everything.
2018-05-09 15:53
soci

Registered: Sep 2003
Posts: 473
Quote: Are you looking to interpolate between the values, to get higher resolution?

Or are you wanting to smooth the data without changing the number of cells?

Either way, a useful building block is to calculate a mean with
  clc
  lda value1
  adc value2   ; computes a 9 bit sum in [carry, acc7..acc0]
  lsr          ; divides result by two, leaving 8 bit value in A
  sta result

Unroll.


It's ROR and not LSR, right? Otherwise the usable value range is half.
2018-05-09 19:02
ChristopherJam

Registered: Aug 2004
Posts: 1370
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.
2018-05-09 19:06
ws

Registered: Apr 2012
Posts: 228
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.
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
Fred/Channel 4
HOL2001/Quantum
hedning/G★P
cba
Steffan/BOOM!
Acidchild/Padua
Guests online: 84
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 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (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 Graphicians
1 Sulevi  (10)
2 Mirage  (9.8)
3 Lobo  (9.7)
4 Mikael  (9.7)
5 Archmage  (9.7)

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