| |
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 |
|
| |
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. |
| |
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) |
| |
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. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Quoting wertstahldo i first process all lines horizontally and then vertically? is that the way to go?
Yes. |
| |
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) |
| |
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. |
| |
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. |
| |
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. |
| |
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. |
| |
ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Quoting sociIt'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 |