Changeset 35578 in project


Ignore:
Timestamp:
06/11/18 20:37:54 (5 months ago)
Author:
kristianlm
Message:

obs: stb-image-resize using markdown-svnwiki

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/stb-image-resize

    r35576 r35578  
    1 == chicken-stb-image
     1== stb-image-resize
    22[[toc:]]
    3 This is a [[http://call-cc.org|CHICKEN]] egg that wraps [[https://github.com/nothings/stb|stb_image.h]] version 2.19 from
    4 Sean Barrett and friends. It works on [[http://call-cc.org|CHICKEN]] 4 and 5.
     3This is a [[http://call-cc.org|CHICKEN]] egg that wraps [[https://github.com/nothings/stb|stb''image''resize.h]] version 0.95
     4from Jorge L Rodriguez and friends. It works on [[http://call-cc.org|CHICKEN]] 4 and 5.
    55
    66
    77== API
    88[[toc:]]
    9 <procedure> (read-image #!key channels)</procedure>
    10 <procedure> (load-image u8vector #!key channels)</procedure>
     9<procedure> (image-resize pixels width height channels target-width target-height #!key filter region alpha-channel)</procedure>
    1110
    12 Decodes an image into raw pixel data. {{read-image}} reads the image
    13 from from {{(current-input-port)}} while {{load-image}} gets this from the
    14 provided u8vector. The image type is detected by content, and may be:
    15 JPEG, PNG, TGA, BMP, PSD, GIF, HDR, PIC, PNM as explained in the
    16 heading comments of {{stb_image.h}}.
     11Takes in raw {{pixels}} (a srfi-4 u8/u16/u32/f32vector) of size
     12{{width}}''{{height}}''{{channels}} and returns raw pixels after resizing. The
     13returned type is the same as {{pixels}}' of size
     14{{target-width}}''{{target-height}}''{{channels}}.
    1715
    18 Both procedures return 4 values:
     16{{channels}} must be an integer between 0 and 64 and keys are processed
     17as follows.
    1918
    20 # raw pixel data (as u8vector)
    21 # width
    22 # height
    23 # number of channels
    24 
    25 You can force the number of channels with the {{channels}} keyword. If
    26 {{channels}} is {{#f}} or not given, the number of channels in the
    27 original image will be used.
    28 
    29 The size of the pixel data blob is always {{(* width height channels)}}
    30 bytes. The first pixel is the top-left-most in the image. Each pixel
    31 is {{channel}} number of bytes long. The number of channels define the
    32 pixel color, interleaved as follows:
    33 
    34 # grey
    35 # grey, alpha
    36 # red, green, blue
    37 # red, green, blue, alpha
    38 
    39 Note 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 
    45 Like {{read-image}} and {{load-image}}, but does not load pixel data and
    46 should be faster. Returns three values:
    47 
    48 # width
    49 # height
    50 # number of channels
     19* {{filter:}} one of {{box}}, {{triangle}}, {{cubicbspline}}, {{catmullrom}} or
     20  {{mitchell}}. The default uses {{catmullrom}} for up-sampling and
     21  {{mitchell}} for down-sampling.
     22* {{region:}} a vector of 4 elements {{s0 t0 s1 t1}}, representing the
     23  UV-coordinates to use as source image. This can be used to crop the
     24  image. These values must be in the range of {{[0, 1]}} and represent
     25  the fraction of the input image. {{#(0 0 0.5 1)}}, for example, cuts
     26  off the right half of the image.
     27* {{alpha-channel:}} index of channel which is the alpha channel in the
     28  image. supply {{#f}} (default) for no alpha channel.
    5129
    5230
    53 === Examples
    54 For quick testing, you can read PNGs from ImageMagick's {{convert}}:
     31== Examples
     32[[toc:]]
     33You can try {{example-thumbnail.scm}} like this:
    5534
    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
     35[[image:example.png?raw=true|screenshot of running example-thumbnail.scm]]
    6436
    65 Which reveal the black line along the diagonal and informs that the
    66 image is 4x4 with 3-channels.
     37Or turn a 4x1 greyscale image into a single pixel like this:
    6738
     39{{
     40$ csi -R srfi-4 -R stb-image-resize -p '(image-resize (f32vector 0 4 8) 3 1 1   1 1)'
     41#f32(4.0)
     42}}
     43
Note: See TracChangeset for help on using the changeset viewer.