# Scripts/Pan View

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).

${\displaystyle \\{\begin{array}{ll}O_{xy}=max\{0,{V_{wh}-P_{wh} \over 2}\},\\\\S_{xy}=max\{0,min\{S_{xy},P_{wh}-V_{wh}\}\}\end{array}}\\}$

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

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




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'