zoomview.png

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.

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

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

«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 dimentions Px,Py and proportion.

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

«zoomview.ijs»=
  Ix=: <.0.5+ (Px-1) * (Zx-1) %~ i.Zx
  Iy=: <.0.5+ (Py-1) * (Zy-1) %~ i.Zy
  ''
)

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

«zoomview.ijs»=
zoomview_z_=: conew & 'pzoomview'

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

See Also


Contributed by OlegKobchenko


CategoryLiterate

Scripts/Zoom View (last edited 2009-09-08 04:11:21 by RicSherlock)