Addons/media/platimg

From J Wiki
Jump to: navigation, search
User Guide | Installation | Development | Categories | Git | Build Log


media/platimg - platform neutral image I/O utilities

Supports BMP, GIF, JPEG, PNG, TIFF, Exif, ICO, WMF, and EMF formats where available. Returns pixel matrix in ARGB (Alpha most significant) integer format. Expects ARGB, or triples of RGB in any axis of rank 3 array. Good for glpixels.
Implementations for Windows, Linux and Mac OS X. Uses GDI+, Core Graphics (Quartz), The gdk-pixbuf Library from GTK+.
See also: examples test.ijs in SVN; change history.

Installation

Use JAL/Package Manager or download the media_platimg archive from JAL:j601/addons and extract it into the ~addons/media/platimg folder.

Bubbles.png

Usage

Load platimg addon with the following line

   load 'media/platimg'

Features

  • Supports BMP, GIF, JPEG, PNG, TIFF, Exif, ICO, WMF, and EMF formats, where available.
  • Has very simple api similar to bmp. Returns pixel matrix in ARGB (Alpha most significant) integer format.
  • Good for glpixels.
  • Windows code uses GDI+.
  • Mac code uses Core Graphics (Quartz).
  • Linux code uses The gdk-pixbuf Library from GTK+.

Images in GUI

Winimg.png Macimg.png Linimg.png

The above examples were obtained on the respective platforms with the following same code.

require 'gl2 media/platimg'
coinsert 'jgl2'

F=: 0 : 0
pc f;pn "Image Formats";
xywh 20 22 8 8;cc g1 isigraph;
xywh 5 48 36 10;cc s1 static ss_center;cn "jicon.gif";
xywh 52 20 16 16;cc g2 isigraph;
xywh 43 49 33 10;cc s2 static ss_center;cn "jr.ico";
xywh 9 80 64 64;cc g3 isigraph;
xywh 17 151 50 10;cc s3 static ss_center;cn "j.bmp";
xywh 86 27 100 100;cc g4 isigraph;
xywh 113 131 50 10;cc s4 static ss_center;cn "box.jpg";
pas 6 6;pcenter;
rem form end;
)

f_run=: 3 : 0
  wd F
  smoutput 'g1' glimg '~profile/jicon.gif'
  smoutput 'g2' glimg^:(UNAME-:'Win'"_) '~profile/jr.ico'
  smoutput 'g3' glimg '~system/examples/data/j.bmp'
  smoutput 'g4' glimg '~system/extras/help/box.jpg'
  wd 'pshow;'
)

f_close=: wd bind 'pclose'

f_run''

Capture Graphics

The following can be used to save contents of isigraph control as a screenshot to file.

   load 'viewmat media/platimg'
   coinsert 'jgl2'
   glqall=: (|. $ [:glqpixels 0 0&,)@glqwh

   viewmat i.3 4
   'test.png' writeimg~ glqall''
   viewrgb readimg 'test.png'

To resize window precisely use

   glwh=: 3 : 'wd''pmovex '',(+0 0,y-glqwh_jgl2_@$@#)&.".wd''qformx'''
   glwh 4 3*30

Reference

platimg.ijs  - platimg - image file I/O for specific platform

readimg v returns RGB matrix from file
getimg v converts format buffer to RGB matrix
writeimg v writes RGB matrix to file
putimg v converts RGB matrix to format buffer
glimg v places image from file on gl2 at 0,0
glgetimg v places image from format buffer on gl2 at 0,0
glimgrgb v places image from RGB matrix on gl2 at 0,0
QUALITY n image quality 0..100

readimg

readimg (v) returns RGB matrix from file

  rgbMatrix=. readimg filename

getimg

getimg (v) converts format buffer to RGB matrix

  rgbMatrix =: getimg formatData   png,jpg,...

writeimg

writeimg (v) writes RGB matrix to file

  bytesWritten=: rgbMatrix writeimg filename

putimg

putimg (v) converts RGB matrix to format buffer

  formatData=: rgbMatrix putimg format   'png','jpg',...

glimg

glimg (v) places image from file on gl2 at 0,0

  [controlId] glimg filename

glgetimg

glgetimg (v) places image from format buffer on gl2 at 0,0

  [controlId] glgetimg formatData

glimgrgb

glimgrgb (v) places image from RGB matrix on gl2 at 0,0

  [controlId] glimgrgb rgbMatrix

QUALITY

QUALITY (n) image quality 0..100

  QUALITY=. 85    NB. ''=default

See Also

Authors