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
2018-05-08 16:34
ChristopherJam

Registered: Aug 2004
Posts: 1409
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.
2018-05-08 16:43
ws

Registered: Apr 2012
Posts: 251
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: 251
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: 1409
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: 1409
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: 251
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: 5094
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: 11386
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: 480
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: 1409
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.
 
... 24 posts hidden. Click here to view all posts....
 
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
Flashback
DeeKay/Crest
swasti
Guests online: 122
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 Rainbow Connection  (9.5)
7 Dawnfall V1.1  (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 Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

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