libraryextensions/image/lib/Image.xtl
Image.xtl -- the facade of the image extension: PNG and JPEG files as Float arrays from 0 to 1, and back. Gray is h by w, color h by w by 3 (red, green, blue); alpha is dropped. Import: "im:" u_se< "Image" Files are named by paths under the working directory (or XETAL_IMAGE_ROOT), relative, with no .. Run with xetal-x (xetal-x --ext DIR puts this directory on XETAL_PATH). Each signature line is written out by the binding macro (lib/Ffi.xtlm).
ˡr̲ead : Char -> Float
im:r_ead "photo.png": the picture as it is (gray or color).
"r_ead : text -> floats" ᶠᶠⁱb̲ind< "image/read"
ᶠᶠⁱb̲ind< expands to
ˡr̲ead ← { a → pa ← a ⎕N̲PUT "ext:image/read?text" v ← n̲umbers ⎕N̲GET "ext:image/read" (f̲loor n̲umbers ⎕N̲GET "ext:image/read?shape") r̲eshape v }
ˡg̲ray : Char -> Float
im:g_ray "photo.jpg": the picture in gray (its luminance), h by w.
"g_ray : text -> floats" ᶠᶠⁱb̲ind< "image/gray"
ᶠᶠⁱb̲ind< expands to
ˡg̲ray ← { a → pa ← a ⎕N̲PUT "ext:image/gray?text" v ← n̲umbers ⎕N̲GET "ext:image/gray" (f̲loor n̲umbers ⎕N̲GET "ext:image/gray?shape") r̲eshape v }
ˡs̲ize : Char -> Int
im:s_ize "photo.jpg": height and width, without reading the pixels.
"s_ize : text -> ints" ᶠᶠⁱb̲ind< "image/size"
ˡw̲rite! : Num a => Char -> a -> Int
"out.png" im:w_rite! a: the array as a PNG (or a JPEG, by the name), values clamped to 0..1; how many pixels.
"w_rite! : text float -> int" ᶠᶠⁱb̲ind< "image/write"
ᶠᶠⁱb̲ind< expands to
ˡw̲rite! ← { a b → pa ← a ⎕N̲PUT "ext:image/write?text" pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:image/write?float=" c̲at f̲ormat s̲hape b f̲loor f̲irst n̲umbers ⎕N̲GET "ext:image/write" }
ˡr̲esize : (Num a, Num b) => a -> b -> Float
(h c_at w) im:r_esize a: resampled to h by w (Lanczos), gray or color.
"r_esize : float float -> floats" ᶠᶠⁱb̲ind< "image/resize"
ᶠᶠⁱb̲ind< expands to
ˡr̲esize ← { a b → pa ← (f̲ormat r̲avel f̲loat a) ⎕N̲PUT "ext:image/resize?float=" c̲at f̲ormat s̲hape a pb ← (f̲ormat r̲avel f̲loat b) ⎕N̲PUT "ext:image/resize?float=" c̲at f̲ormat s̲hape b v ← n̲umbers ⎕N̲GET "ext:image/resize" (f̲loor n̲umbers ⎕N̲GET "ext:image/resize?shape") r̲eshape v }