File List
Not logged in

Files of check-in [775400ee76] in directory jni/tcl-stbimage   [history]


tcl-stbimage

stb is a single-file public domain (or MIT licensed) library for C/C++.

This is a Tcl extension for stb_image. The package is using the stb_image Easy-to-use API to load (e.g. jpg/png/tga/bmp), resize and write (e.g. jpg/png/tga/bmp) images.

Implemented commands

::stbimage::load filename
::stbimage::load filename photo
::stbimage::load_from_memory filedata
::stbimage::resize inputdata srcwidth srcheight dstwitdh dstheight channels
::stbimage::write format filename width height channels data
::stbimage::write format filename photo
::stbimage::rgb2rgba inputdata width height
::stbimage::bytes2photo inputdata photo width height channels
::stbimage::photo2bytes photo channels

::stbimage::rgb2rgba is a helper command to convert RGB image to RGBA.

format value should be - jpg, png, tga, bmp

When a function requires a photo the Tk package is automatically loaded.

UNIX BUILD

Building under most UNIX systems is easy, just run the configure script and then run make. For more information about the build process, see the tcl/unix/README file in the Tcl src dist. The following minimal example will install the extension in the /opt/tcl directory.

$ cd tcl-stbimage
$ ./configure --prefix=/opt/tcl
$ make
$ make install

If you need setup directory containing tcl configuration (tclConfig.sh), below is an example:

$ cd tcl-stbimage
$ ./configure --with-tcl=/opt/activetcl/lib
$ make
$ make install

Example

package require stbimage

set d [::stbimage::load test.jpg]
set width [dict get $d width]
set height [dict get $d height]
set channels [dict get $d channels]
set data [dict get $d data]
set neww [expr [dict get $d width] * 2]
set newh [expr [dict get $d height] * 2]
set d2 [::stbimage::resize $data $width $height $neww $newh $channels]
set newdata [dict get $d2 data]
::stbimage::write jpg test2.jpg $neww $newh $channels $newdata
::stbimage::write png test2.png $neww $newh $channels $newdata
::stbimage::write tga test2.tga $neww $newh $channels $newdata
::stbimage::write bmp test2.bmp $neww $newh $channels $newdata