source: project/wiki/eggref/4/stb-image-resize @ 35576

Last change on this file since 35576 was 35576, checked in by kristianlm, 22 months ago
File size: 2.1 KB
Line 
1== chicken-stb-image
2[[toc:]]
3This is a [[http://call-cc.org|CHICKEN]] egg that wraps [[https://github.com/nothings/stb|stb_image.h]] version 2.19 from
4Sean Barrett and friends. It works on [[http://call-cc.org|CHICKEN]] 4 and 5.
5
6
7== API
8[[toc:]]
9<procedure> (read-image #!key channels)</procedure>
10<procedure> (load-image u8vector #!key channels)</procedure>
11
12Decodes an image into raw pixel data. {{read-image}} reads the image
13from from {{(current-input-port)}} while {{load-image}} gets this from the
14provided u8vector. The image type is detected by content, and may be:
15JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM as explained in the
16heading comments of {{stb_image.h}}.
17
18Both procedures return 4 values:
19
20# raw pixel data (as u8vector)
21# width
22# height
23# number of channels
24
25You can force the number of channels with the {{channels}} keyword. If
26{{channels}} is {{#f}} or not given, the number of channels in the
27original image will be used.
28
29The size of the pixel data blob is always {{(* width height channels)}}
30bytes. The first pixel is the top-left-most in the image. Each pixel
31is {{channel}} number of bytes long. The number of channels define the
32pixel color, interleaved as follows:
33
34# grey
35# grey, alpha
36# red, green, blue
37# red, green, blue, alpha
38
39Note that [[https://github.com/nothings/stb|stb_image.h]]'s {{hdr}} and {{pnm}} support only works with
40{{load-image}}.
41
42<procedure> (read-image-info)</procedure>
43<procedure> (load-image-info blob)</procedure>
44
45Like {{read-image}} and {{load-image}}, but does not load pixel data and
46should be faster. Returns three values:
47
48# width
49# height
50# number of channels
51
52
53=== Examples
54For quick testing, you can read PNGs from ImageMagick's {{convert}}:
55
56    $ convert -size 4x4 xc:blue -draw 'line 0,0 4,4' png:- | csi -R stb-image -p '(read-image)'
57    #u8(0 0 0     0 0 234   0 0 255   0 0 255
58        0 0 234   0 0 0     0 0 234   0 0 255
59        0 0 255   0 0 234   0 0 0     0 0 234
60        0 0 255   0 0 255   0 0 234   0 0 0)
61    4
62    4
63    3
64
65Which reveal the black line along the diagonal and informs that the
66image is 4x4 with 3-channels.
67
Note: See TracBrowser for help on using the repository browser.