Files in directory jni/tcl-stbimage from the latest check-in
- generic
- tclconfig
- aclocal.m4
- Android.mk
- ChangeLog
- configure
- configure.ac
- LICENSE
- Makefile.in
- README.md
- tcl-stbimage.spec
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 data
::stbimage::load_from_memory data photo
::stbimage::load_from_chan chan
::stbimage::load_from_chan chan photo
::stbimage::resize inputdata srcwidth srcheight dstwitdh dstheight channels
::stbimage::write format filename width height channels data
::stbimage::write format filename photo
::stbimage::write_to_chan format chan width height channels data
::stbimage::write to_chan format chan photo
::stbimage::rgb2rgba inputdata width height
::stbimage::bytes2photo inputdata photo width height channels
::stbimage::photo2bytes photo channels
::stbimage::ascii_art inputdata srcwidth srcheight dstwitdh dstheight channels ?indentstring?
::stbimage::crop inputdata srcwidth srcheight startcolumn startrow dstwitdh dstheight 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.
Load functions which don't load into a photo return a dictionary with
the items width
, height
, channels
, and data
, where the latter
is a bytearray with pixel data.
The number of channels determines the layout of the pixel data, 1 for greyscale, 2 for greyscale with alpha channel, 3 for RGB, and 4 for RGB with alpha channel.
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 Tcl's source code archive. 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