Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'This is a test to see if a fisheye image can be restored into a flattened panorama
  2. ' NOTE the resulting image is sadly reversed horizontaly fix this.
  3. SuperStrict
  4.  
  5. Framework brl.blitz
  6. Import brl.standardio
  7. Import brl.pixmap
  8. Import brl.pngloader
  9. Import brl.glmax2d
  10.  
  11. Graphics(800, 600, 0)
  12.  
  13. Local source:TPixmap = LoadPixmap("fisheye.png")
  14. Local source_center:Float = source.width / 2.0
  15. Local source_radius:Float = source.width / 2.0
  16.  
  17. Local panorama_width:Float = 800.0
  18. Local panorama_height:Float = 800.0 / 6.28 ' same as the width by default
  19.  
  20. Local angle_step:Float = 360 / panorama_width ' size of the angle steps to slice up the image
  21.  
  22. ' now set up two nexted for loops to grab pixels from the image and map them to the screen
  23. Local result_pixmap:TPixmap = TPixmap.Create(panorama_width, panorama_height, PF_RGBA8888)
  24. If result_pixmap
  25.     Local sample_radius:Float, sample_angle:Float
  26.     Local sample_x:Float, sample_y:Float
  27.     For Local x:Int = 0 Until panorama_width
  28.         For Local y:Int = 0 Until panorama_height
  29.             ' Calculate the base radius
  30.             sample_radius = y / (panorama_height - 1) * source_radius - 1
  31.             sample_angle = x * angle_step
  32.             sample_x = source_center + Cos(sample_angle) * sample_radius
  33.             sample_y = source_center + Sin(sample_angle) * sample_radius
  34.             result_pixmap.WritePixel(x, y, source.ReadPixel(sample_x, sample_y))
  35.         Next
  36.     Next
  37.     SavePixmapPNG(result_pixmap, "result.png")
  38.     Local image:TImage = LoadImage(result_pixmap)
  39.     If image
  40.         While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
  41.             Cls()
  42.             DrawImage(image, 0.0, 0.0)
  43.             Flip()
  44.             Delay(15)
  45.         End While
  46.     Else
  47.         Print("Failed to load result pixmap as image")
  48.     End If
  49. Else
  50.     Print("Failed to create result pixmap")
  51. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement