pixmix - a widget for displaying, zooming, rotating, blending overlapped images.
Just a screenshot of an included demo app
A new widget, not a Megawidget
pixmix 1.x
pixmix is entirely written in Tcl, but it is based on WinGdi, a custom library providing -at Tcl-level- support for a small part of the Windows Graphic Device Interface. Therefore it works only on Windows platforms.
pixmix 2.x
pixmix is entirely written in Tcl, but it is based on Blend2D, an high performance 2D vector graphics engine (included in the package), running on Windows-64bit, Linux-64bit. Support for MacOSX is in progress.
I like the idea of this package using WinGdi very much, but I cannot run the demos in ActiveTcl 8.5.14 or 8.6.0. When I try to run the demos there is an error loading Ffidl: couldn't load library "D:/Tcl8.6/lib/pixmix-1.0/lib/WinGdi-1.0/lib/ffidl-0.6.1.2/Ffidl06.dll": invalid argument Maybe the included Ffidl package has a problem?
APN Are you by chance on 64-bit Windows running a 64-bit version of Tcl? The above error often indicates an attempt to load 32-bit DLL on a 64-bit process (or vice versa). AFAIK there is no 64-bit version of ffidl.
ARR Yes, I use 64-bit ActiveTcl and exactly that is the problem. I will try 32-bit ActiveTcl. Thanks for the hint.
ARR One question: Can I use this package and WinGdi to run animated gif files with good performance? Thanks.
ABU It's not possible to load an animated-gif (i.e a set of images) in a layer. You should load each image on a different layer, then you should implement a logic for enabling one layer at time.
Reference manual - Pixmix 1.x
pixmix 1.0 Pictures Mixer
a widget for displaying,zooming,rotating,blending overlapped images.
pixmix is a widget for displaying,zooming,rotating,blending overlapped images. pixmix resembles the classic canvas widget but with some differences:
it has been designed for working with (large) images.
Images can be stacked in 'layers' and then zoomed, rotated and alpha-blended.
it's fast - and for Windows platform only !
pixmix is just a widget, not a full app, but you can browse some of the small included demos to discover how to build full apps.
LAYERS
pixmix can display any number of images organized in layers. Each layer can hold one image, and layers are ordered for purposes of display, with the first layer in the layer-list being displayed first, followed by the next layer in the list, and so on. Layers later in the layer-list obscure those that are earlier in the layer-list and are sometimes referred to as being “on top” of previous. When a new layer is created it is placed at the end of the layer-list, on top of everything else. Widget commands may be used to re-arrange the order of the layer-list.
COORDINATES and GEOMETRIC TRANSFORMATIONS
Each image loaded in a layer is placed at coord (0,0), with no scaling and no rotation. In order to move,scale,rotate the image, you must manipulate the layer's matrix parameter. Geometric (affine) transformations are performed with a 3x3 homogeneous matrix.
|m11 m12 0|
|m21 m22 0|
|dx dx 1|
Since the 3rd column MUST always be (0 0 1), you only need to specify the other six coefficients (m11 m12 m21 m22 dx dy). As alternative to direct matrix manipulation, some auxiliary methods like move, rotate and many others are provided. See also the section Working with Matrices
WIDGET COMMANDS
The pixmix command creates the pathName widget and returns a new Tcl command whose name is pathName.
pixmixpathName ?optionvalue...?
WIDGET OPTIONS
-backgroundcolor
Specifies the background color used for filling the widget area.
-cursorcursor
Specifies the mouse cursor to be used for the widget. The value may have any of the forms acceptable to Tk_GetCursor. In addition, if an empty string is specified, it indicates that the widget should defer to its parent for cursor specification.
WIDGET SUBCOMMANDS
The following subCommands are possible for pixmix widgets:
pathNamecgetoption
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the pixmix command.
pathNameconfigure ?option? ?valueoptionvalue ...?
Queries or modifies the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. Option may have any of the values accepted by the pixmix command.
pathNamecreatelayername ?optionvalue...?
Creates a new layer named name ( name must be unique ). New layer is placed on top of other layers. Each layer can be configured with the following options:
-alphanumber
Specifies the layer's alpha (opacity) coefficient; number may vary from 0.0 (transparentn) to 1.0 (opaque)
-visibleboolean
Specifies if layer should be visible or not.
-clipRegiorOrEmptyString
Region is a list of four integers {x1 y1 x2 y2} specifying a rectangular sub-region of the image to be dispayed. In order to reset the clip-region and then display the whole image, you should specify the empty string or {}. Note that the the origin of the clipped region is translated to (0,0). It's not an error if coordinates of the clip-region are larger than the image's real size.
-matrixmatrixOrEmptyString
matrix is a list of six numbers used for setting geometric transformations such as scale, rotation, translation. If matrix is the empty string or {}, then transformation is reset, i.e. the Identity-matrix is used. See the above section COORDINATES and GEOMETRIC TRANSFORMATIONS. Note that some auxiliary methods may alter the -matrix value, in a more comfortable way. NOTE: A new layer is invisible if no image is loaded (seed loadFile and loadPhoto)
# create a layer named abc
.c create layer abc
# create a layer with some options set ...
.c create layer layer#A -visible false
.c layerconfigure layer#A -alpha 0.8
pathNamelayercgetnameoption
Returns the current value of the configuration option option for the layer name. This command is similar to the cget widget command except that it applies to a particular layer rather than the widget as a whole. Option may have any of the values accepted by the create layer command.
This command is similar to the configure widget command except that it modifies layer-specific options instead of modifying options for the overall pixmix widget. If no option is specified, returns a list describing all of the available options and their actual values for the layer given by name. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given layer option(s); in this case the command returns an empty string. The options and values are the same as those permissible in the create layer. See the create layer command for details on the legal options and values.
pathNameloadFilenamefilename
Loads content of filename (Jpeg, png, ...) in layer name. Note that it's your responsability to load a package for supporting extra image formats. ( e.g. package Img )
pathNameloadPhotonamephoto
Loads content of photo in layer name
pathNameimagesizename
Returns a list of two integers: width and height (in pixels) of the image loaded in layer name. If no image has been loaded, return {0 0}
pathNamerenamenamenewName
Renames layer name to newName
pathNamedeletename
Deletes layer name
pathNamelayers
Lists all layers ; first layer is the bottom one, last layer is displayed on top.
pathNamelowername ?belowThis?
If belowThis is not specified, this command moves layer name at bottom, otherwise it moves layer name just below belowThis.
pathNameraisename ?aboveThis?
If aboveThis is not specified, this command moves layer name at top, otherwise it moves layer name just over aboveThis.
pathNamesavePhoto
Saves the overall resulting image in a new photo (see photo standard command). Returns the name of the photo
pathNamesaveFilefilename ?photoOptions...?
Saves the overall resulting image in filename. It is recommended to explicitely use all the photoOptions as described for the standard image write command.
.c saveFile c:/tmp/shot.jpg -format jpeg
Auxiliary subcommands
The following subcommand are programmer's helper . All these subcommands modify the layer's -matrix option.
pathNamemovenamedxdy
Applies a (dx,dy) translation to layer name.
pathNamemovetonamedxdy
Sets a (dx,dy) translation to layer name; scale and rotation don't change.
pathNamescalenamedf ?CxCy?
Applies a further df scale-factor to current transformation. Optional (Cx,Cy) is the zoom-center (default is (0,0).
pathNamescaletonamedf ?CxCy?
Sets the df scale-factor. Translation and rotation don't change. Optional (Cx,Cy) is the zoom-center (default is (0,0).
pathNamerotatenameangle ?CxCy?
Apply a rotation of angle radians to layer name. Optional (Cx,Cy) is the center of the rotation (default is (0,0). Note that the rotation 'seems' inverse just because the Y axis is inverted !
pathNamerotatetonameangle ?CxCy?
Sets a rotation of angle radians to layer name. Optional (Cx,Cy) is the center of the rotation (default is (0,0). Note that the rotation 'seems' inverse just because the Y axis is inverted !
pathNamefitname ?what?
Displays the image loaded in layer name at its 'best fit', i.e centered and fully visbile in the current window. Option what specifies which dimension should be used for computing the best-fit ; valid values are x (best-width), y (best-height)and xy(best-fit). Default is xy.
Working with Matrices
We recall that geometric transformations on layers should be made by setting the -matrix option. A matrix is a list of six numbers (m11 m12 m21 m22 dx dy). Working with these matrices can be simplified by using the pixmix::matrix command.
pixmix::matrix identity
Returns the identity matrix {1 0 0 1 0 0}
pixmix::matrix translatedxdy
Returns the matrix for (dx,dy) translation
pixmix::matrix rotatesx ?sy? ?CX CY?
- Returns the matrix for scaling by factor sx in x-dimension and sy in y-dimension. If sy is not specificied it is assumed to be equal to sx. CX,CY is the center of transformation
pixmix::matrix rotateangle ?CX CY?
Returns the matrix for an angle rotation (in radians). CX,CY is the center of transformation
pixmix::matrix skewxangle
Returns the matrix for a skew-distorsion on x-dimension. angle is expressed in radians.
pixmix::matrix skewyangle
Same as matrix skewx, just for the y-dimension
pixmix::matrix multiplymtx1mtx2
Returns a new matrix as the product (composition) of matrix mtx1 and mtx2.
BINDINGS
pixmix does not provide any default behavior. Bindings may be set to respond to some event (typically mouse-related events), like in the mini-apps included in the demos directory.
EVENTS
pixmix does not generate any virtual-event.
Examples
See the mini-apps within the demos directory.
BUGS, IDEAS, FEEDBACK
-
-
From an API point of view pixmix 2.x is identical to pixmix 1.x. The only difference is the addition of a new set of low-level commands for working with matrices that are going to supersede the pixmix::matrix commands.
Reference manual - Pixmix 2.x
pixmix 2.0 Pictures Mixer
a widget for displaying,zooming,rotating,blending overlapped images.
pixmix is a widget for displaying,zooming,rotating,blending overlapped images. pixmix resembles the classic canvas widget but with some differences:
it has been designed for working with (large) images.
Images can be stacked in 'layers' and then zoomed, rotated and alpha-blended.
it's fast - based on Blend2Dsupport, running on Windows/Linux/MacOSX)
pixmix is just a widget, not a full app, but you can browse some of the small included demos to discover how to build full apps.
LAYERS
pixmix can display any number of images organized in layers. Each layer can hold one image, and layers are ordered for purposes of display, with the first layer in the layer-list being displayed first, followed by the next layer in the list, and so on. Layers later in the layer-list obscure those that are earlier in the layer-list and are sometimes referred to as being “on top” of previous. When a new layer is created it is placed at the end of the layer-list, on top of everything else. Widget commands may be used to re-arrange the order of the layer-list.
COORDINATES and GEOMETRIC TRANSFORMATIONS
Each image loaded in a layer is placed at coord (0,0), with no scaling and no rotation. In order to move,scale,rotate the image, you must manipulate the layer's matrix parameter. Geometric (affine) transformations are performed with a 3x3 homogeneous matrix.
|m11 m12 0|
|m21 m22 0|
|dx dx 1|
Since the 3rd column MUST always be (0 0 1), you only need to specify the other six coefficients (m11 m12 m21 m22 dx dy). As alternative to direct matrix manipulation, some auxiliary methods like move, rotate and many others are provided. See also the section Working with Matrices
WIDGET COMMANDS
The pixmix command creates the pathName widget and returns a new Tcl command whose name is pathName.
pixmixpathName ?optionvalue...?
WIDGET OPTIONS
-backgroundcolor
Specifies the background color used for filling the widget area.
-cursorcursor
Specifies the mouse cursor to be used for the widget. The value may have any of the forms acceptable to Tk_GetCursor. In addition, if an empty string is specified, it indicates that the widget should defer to its parent for cursor specification.
WIDGET SUBCOMMANDS
The following subCommands are possible for pixmix widgets:
pathNamecgetoption
Returns the current value of the configuration option given by option. Option may have any of the values accepted by the pixmix command.
pathNameconfigure ?option? ?valueoptionvalue ...?
Queries or modifies the configuration options of the widget. If no option is specified, returns a list describing all of the available options for pathName (see Tk_ConfigureInfo for information on the format of this list). If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. Option may have any of the values accepted by the pixmix command.
pathNamecreatelayername ?optionvalue...?
Creates a new layer named name ( name must be unique ). New layer is placed on top of other layers. Each layer can be configured with the following options:
-alphanumber
Specifies the layer's alpha (opacity) coefficient; number may vary from 0.0 (transparent) to 1.0 (opaque)
-visibleboolean
Specifies if layer should be visible or not.
-clipRegiorOrEmptyString
Region is a list of four integers {x1 y1 x2 y2} specifying a rectangular sub-region of the image to be displayed. In order to reset the clip-region and then display the whole image, you should specify the empty string or {}. Note that the the origin of the clipped region is translated to (0,0). It's not an error if coordinates of the clip-region are larger than the image's real size.
-matrixmatrixOrEmptyString
matrix is a list of six numbers used for setting geometric transformations such as scale, rotation, translation. If matrix is the empty string or {}, then transformation is reset, i.e. the Identity-matrix is used. See the above section COORDINATES and GEOMETRIC TRANSFORMATIONS. Note that some auxiliary methods may alter the -matrix value, in a more comfortable way. NOTE: A new layer is invisible if no image is loaded (seed loadFile and loadPhoto)
# create a layer named abc
.c create layer abc
# create a layer with some options set ...
.c create layer layer#A -visible false
.c layerconfigure layer#A -alpha 0.8
pathNamelayercgetnameoption
Returns the current value of the configuration option option for the layer name. This command is similar to the cget widget command except that it applies to a particular layer rather than the widget as a whole. Option may have any of the values accepted by the create layer command.
This command is similar to the configure widget command except that it modifies layer-specific options instead of modifying options for the overall pixmix widget. If no option is specified, returns a list describing all of the available options and their actual values for the layer given by name. If option is specified with no value, then the command returns a list describing the one named option (this list will be identical to the corresponding sublist of the value returned if no option is specified). If one or more option-value pairs are specified, then the command modifies the given layer option(s); in this case the command returns an empty string. The options and values are the same as those permissible in the create layer. See the create layer command for details on the legal options and values.
pathNameloadFilenamefilename
Loads content of filename (Jpeg, png, ...) in layer name. Note that it's your responsibility to load a package for supporting extra image formats. ( e.g. package Img )
pathNameloadPhotonamephoto
Loads content of photo in layer name
pathNameimagesizename
Returns a list of two integers: width and height (in pixels) of the image loaded in layer name. If no image has been loaded, return {0 0}
pathNamerenamenamenewName
Renames layer name to newName
pathNamedeletename
Deletes layer name
pathNamelayers
Lists all layers ; first layer is the bottom one, last layer is displayed on top.
pathNamelowername ?belowThis?
If belowThis is not specified, this command moves layer name at bottom, otherwise it moves layer name just below belowThis.
pathNameraisename ?aboveThis?
If aboveThis is not specified, this command moves layer name at top, otherwise it moves layer name just over aboveThis.
pathNamesavePhoto
Saves the overall resulting image in a new photo (see photo standard command). Returns the name of the photo
pathNamesaveFilefilename ?photoOptions...?
Saves the overall resulting image in filename. It is recommended to explicitly use all the photoOptions as described for the standard image write command.
.c saveFile c:/tmp/shot.jpg -format jpeg
Auxiliary subcommands
The following subcommand are programmer's helper . All these subcommands modify the layer's -matrix option.
pathNamemovenamedxdy
Applies a (dx,dy) translation to layer name.
pathNamemovetonamedxdy
Sets a (dx,dy) translation to layer name; scale and rotation don't change.
pathNamescalenamedf ?CxCy?
Applies a further df scale-factor to current transformation. Optional (Cx,Cy) is the zoom-center (default is (0,0).
pathNamescaletonamedf ?CxCy?
Sets the df scale-factor. Translation and rotation don't change. Optional (Cx,Cy) is the zoom-center (default is (0,0).
pathNamerotatenameangle ?CxCy?
Apply a rotation of angle radians to layer name. Optional (Cx,Cy) is the center of the rotation (default is (0,0). Note that the rotation 'seems' inverse just because the Y axis is inverted !
pathNamerotatetonameangle ?CxCy?
Sets a rotation of angle radians to layer name. Optional (Cx,Cy) is the center of the rotation (default is (0,0). Note that the rotation 'seems' inverse just because the Y axis is inverted !
pathNamefitname ?what?
Displays the image loaded in layer name at its 'best fit', i.e centered and fully visbile in the current window. Option what specifies which dimension should be used for computing the best-fit ; valid values are x (best-width), y (best-height)and xy(best-fit). Default is xy.
Working with Matrices
We recall that geometric transformations on layers should be made by setting the -matrix option. A matrix is a list of six numbers (m11 m12 m21 m22 dx dy). Working with these matrices can be simplified by using the Mtx package from Blend2D. Note: the pixmix::matrix command used in Pixmix 1.x is still available, albeit deprecated.
Mtx::identity
Returns the identity matrix {1 0 0 1 0 0}
Mtx::translationdxdy
Returns the matrix for (dx,dy) translation
Mtx::scalesx ?sy? ?CX CY?
- Returns the matrix for scaling by factor sx in x-dimension and sy in y-dimension. If sy is not specified it is assumed to be equal to sx. CX,CY is the center of transformation
Mtx::rotationangle ?radian(s)|degree(s)? ?CX CY?
Returns the matrix for an angle rotation (in radians or degrees - default is degrees). CX,CY is the center of transformation
Mtx::skewsxsy
Returns the matrix for a skew-distortion.
Mtx::MxMmtx1mtx2
Returns a new matrix as the product (composition) of matrix mtx1 and mtx2.
BINDINGS
pixmix does not provide any default behavior. Bindings may be set to respond to some event (typically mouse-related events), like in the mini-apps included in the demos directory.