Scripts/Zoom View

From J Wiki
Jump to: navigation, search
Zoomview.png

Template:Tick

Zoom View is a prototype of fast image zooming using indexed nearest neighbor interpolation. The speed is such that real-time mouse resize of the window produces continuous seamless view update. Download script: zoomview.ijs

NB. zoomview - very fast proportional image zoom
NB. 05/30/07 Oleg Kobchenko - initial version
NB. 05/31/07 Oleg Kobchenko - glpixelsx pass by pointer
NB. 06/07/07 Oleg Kobchenko - single dual-index From
NB. 02/06/08 Oleg Kobchenko - literate

The image is loaded from a file using Addons/media/platimg. Download script: zoomview.ijs

require 'gl2 media/platimg'

coclass 'pzoomview'
coinsert 'jgl2'

F=: 0 : 0
pc f; pn "Zoom View";
xywh 0 0 300 200;cc g isigraph rightmove bottommove;
pas 0 0;pcenter;
rem form end;
)

create=: 3 : 0
  wd F
  read y
  wd 'pshow;'
)

destroy=: 3 : 0
  wd'pclose'
  codestroy''
)

f_close=: destroy

f_g_paint=: 3 : 0
  glclear''
  (|.$PIC) calcZoom glqwh''

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. Download script: zoomview.ijs

  p=. (<Iy;Ix) { PIC
  glpixelsx Ox,Oy,Zx,Zy,symdat symget <'p'
  glpaint''
)

calcZoom=: 4 : 0
  'Px Py'=: x
  'Vx Vy'=: y

Zoomed picture dimensions Zx,Zy and origin offset Ox,Oy are calculated based on view dimensions Vx,Vy and original picture dimensions Px,Py and proportion.

 $$\left\{ \begin{array}{ll} Z_y=V_y, \quad Z_x=V_y{P_x\over P_y}, \quad O_x={V_x-Z_x\over 2}, \quad O_y=0 & \quad \textrm{if} \quad {V_x\over V_y}>{P_x\over P_y} \\ Z_x=V_x, \quad Z_y=V_x{P_y\over P_x}, \quad O_y={V_y-Z_y\over 2}, \quad O_x=0 & \quad \textrm{otherwise} \end{array} \right. $$ Download script: zoomview.ijs

  if. (Vx%Vy)>(Px%Py) do.
    Zx=: <.0.5+Vy*Px%Py
    Zy=: Vy
    Ox=: <.0.5+0.5*Vx-Zx
    Oy=: 0
  else.
    Zx=: Vx
    Zy=: <.0.5+Vx*Py%Px
    Ox=: 0
    Oy=: <.0.5+0.5*Vy-Zy
  end.

The second step is to produce nearest neighbor interpolation using scaled indices. Download script: zoomview.ijs

  Ix=: <.0.5+ (Px-1) * (Zx-1) %~ i.Zx
  Iy=: <.0.5+ (Py-1) * (Zy-1) %~ i.Zy
  ''
)
Zoomparams.png

Download script: zoomview.ijs

read=: 3 : 0
  PIC=: readimg y
)

require 'dll'
symdat_z_=: 3 : 0   NB. symdat symget <'name'
  had=. {.memr y,(IF64{4 8),1,JPTR
  had+{.memr had,0,1,JPTR
)

A public verb in z locale is defined to open an arbitrary picture. Download script: zoomview.ijs

zoomview_z_=: conew & 'pzoomview'

Note 'Test'
  zoomview jpath'~system/examples/data/toucan.bmp'
  zoomview wd 'mbopen'
)

See Also


Contributed by Oleg Kobchenko