Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'This is a test to see if a fisheye image can be restored into a flattened panorama
- ' NOTE the resulting image is sadly reversed horizontaly fix this.
- SuperStrict
- Framework brl.blitz
- Import brl.standardio
- Import brl.pixmap
- Import brl.pngloader
- Import brl.glmax2d
- Graphics(800, 600, 0)
- Local source:TPixmap = LoadPixmap("fisheye.png")
- Local source_center:Float = source.width / 2.0
- Local source_radius:Float = source.width / 2.0
- Local panorama_width:Float = 800.0
- Local panorama_height:Float = 800.0 / 6.28 ' same as the width by default
- Local angle_step:Float = 360 / panorama_width ' size of the angle steps to slice up the image
- ' now set up two nexted for loops to grab pixels from the image and map them to the screen
- Local result_pixmap:TPixmap = TPixmap.Create(panorama_width, panorama_height, PF_RGBA8888)
- If result_pixmap
- Local sample_radius:Float, sample_angle:Float
- Local sample_x:Float, sample_y:Float
- For Local x:Int = 0 Until panorama_width
- For Local y:Int = 0 Until panorama_height
- ' Calculate the base radius
- sample_radius = y / (panorama_height - 1) * source_radius - 1
- sample_angle = x * angle_step
- sample_x = source_center + Cos(sample_angle) * sample_radius
- sample_y = source_center + Sin(sample_angle) * sample_radius
- result_pixmap.WritePixel(x, y, source.ReadPixel(sample_x, sample_y))
- Next
- Next
- SavePixmapPNG(result_pixmap, "result.png")
- Local image:TImage = LoadImage(result_pixmap)
- If image
- While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
- Cls()
- DrawImage(image, 0.0, 0.0)
- Flip()
- Delay(15)
- End While
- Else
- Print("Failed to load result pixmap as image")
- End If
- Else
- Print("Failed to create result pixmap")
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement