Scripts/Pan View

From J Wiki
Jump to navigation Jump to search
Panview.png

Wm yes check.png

Pan View is a prototype of fast image panning using indexed subset of the original image in a view. The speed is such that the real-time mouse shift produces continuous seamless view update.

Given picture dimensions Pwh and view dimensions Vwh, the origin offset Oxy and origin shift Sxy are calculated as follows (all values represented as coordinate pairs).

The second step is to produce indices that correspond to the visible portion of the image.

  Ixy=: Sxy (+ i.)each Pwh <. Vwh
Panparams.png

With base mouse position Bxy and base shift Bs saved on mouse down, panning is performed on mouse move, by adjusting the origin shift Sxy using the base values and current mouse position xy, and updating the view.

  Sxy=: Bs + Bxy - xy

An additional performance boost comes from extended glpixelsx command, which accepts pointer to data values as opposed to actual values. Subset of indices along both axes can be taken with one { From.

  p=. (<|.Ixy) { PIC
  glpixelsx Oxy,(|.$p),symdat symget <'p'

The image is loaded from a file using Addons/media/platimg. A public verb in z locale is defined to open an arbitrary picture.

  panview jpath'~system/examples/data/jbw.bmp'
  panview wd 'mbopen'

See Also


Contributed by Oleg Kobchenko