14 December 2019, 10:47  #1 
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 190

Vertical scaling up  how to choose lines to stretch?
I've got a routine where I stretch an image vertically using BPLxMODs and it works great. But it looks obviously like a perspectivebased stretch from an origin because of how I am generating the data. That's actually the effect I initially wanted. But for another section of my intro I want something that looks more linear.
I'm just precalcing the lines to show normally or repeat by running a perspective function on 256 (screen height) points and a given Z distance (reusing normal vector code). Then I'm encoding those new points into 16 words. Then I repeat for however many zoom levels I want. You end up with a kind of "bitmap" (which I use as an actual bitmap elsewhere...). Then each frame I just pick a zoom level, read in a word at a time and shift bits into carry with each bit signalling if I should show a line normally (normal BPLMOD) or repeat it (ve BPLMOD) and write that into the copperlist. So the decoding part is plenty fast enough. All works fine, but it clearly looks like perspective stretch from an origin point. What is a good method to choose which lines to repeat for a more linear stretch? Googling leads me to lots of very modern graphics techniques that are a bit beyond me at the mo. Also tried to use the method here: http://www.stashofcode.fr/zoomhardw...on1suramiga/ which was for shrinking but I didn't think it looked quite right when plugging those numbers in for stretching. 
14 December 2019, 13:16  #2 
Lemon. / Core Design
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 587

It's essentially the same as a linear texture mapping...
you need to calculate dU dU = (U2U1) / (Y2Y1) where U1 & U2 are the source "lines" of your image (U1 will often be zero), and Y1 and Y2 are the start and end screen lines. Then in your loop (From Y1 to Y2 ) you just add dU to a value (usually initialised to U1) You will need to probably use fixed point for accuracy, so you can calculate dU like: dU = ( ( U2  U1 ) <<8 ) / ( Y2  Y1 ) 
14 December 2019, 14:23  #3 
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 190

Cheers, Dan. I think I get it.
E.g. Double size U1 = 0 U2 = 16 Y1 = 0 Y2 = 32 dU = (160) / (320) = 0.5 0 0.5 1 1.5 2 2.5 3 3.5 etc So that would give line 0,0,1,1,2,2,3,3. 
14 December 2019, 15:48  #4 
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 701

This could also be done with a version of Bresenham's linedrawing algorithm.
Imagine U1=0, U2=20, Y1=0, Y2=32, so a nonintegral ratio. Code:
dU=20, dY=32 V=0, c=0, where V is the output line for each iteration and c is a temporary counter repeat dY times { c+=dU while(c>=dY) { V+=1 c=dY } Store V } (If you only ever scale up, not down, then the inner "while" can be an "if".) For the second iteration c is 40, so V is increased to 1, and c is reduced by 32 leaving a remainder of 8. For the third iteration, c is 28, V remains at 1 For the fourth iteration, c is 48, V increases to 2, c reduces to 16. For the fifth iteration, c is 36, V increases to 3, c reduces to 4... 
14 December 2019, 16:04  #5  
Lemon. / Core Design
Join Date: Mar 2016
Location: Sunny Bournemouth, UK
Posts: 587

Quote:
True, but you have that extra compare in there to do the "stepping" which is not idea for something that is essentially a 1D operation (Bresenham's is "designed" for stepping in 2D) 

14 December 2019, 16:55  #6  
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 701

Quote:
True enough  but being able to derive the same result in multiple ways is good for understanding! (It may be designed for plotting lines on a 2D grid, but in that context one of the two coordinates increases monotonically, just as the line number does in the stretching application, so the two methods are analogous. At its heart, it's just a method of dealing with fractional ratios using integers.) 

14 December 2019, 17:39  #7 
OCS forever!
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 190

Thanks, all useful stuff. I need to write a CPU line draw soon and I've been watching videos on Bresenham. Oddly 99% of videos on youtube for Bresenham seem to be for Indian universities. This video was the one that made the penny drop for me
[ Show youtube player ] 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)  
Thread Tools  
Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Repeating vertical lines on screen on A2000 with ScanPlus ECS scandoubler  5kb  support.Hardware  3  03 January 2020 03:55 
PreScaling before Bilinear Scaling?  rsn8887  request.UAE Wishlist  6  05 September 2015 19:13 
Indivision AGA MkII vertical lines, banding and ghosting!  trixster  support.Hardware  25  02 August 2014 12:58 
Weird vertical lines (c64)  daznic  support.Hardware  12  16 December 2011 09:42 
How do I stretch the screen in WinUAE?  doomer  support.WinUAE  1  21 July 2003 21:27 

