winop command¶
The ::rbc::winop command provides low-level Tk window operations and photo-image processing operations.
::rbc::winop query
::rbc::winop raise .top
::rbc::winop snap .g snapshot
Some operations manipulate native windows more directly than the normal Tk commands. They are primarily useful when ordinary Tk window-management operations are not sufficient.
winop also contains image-processing operations for Tk photo images:
image create photo source -file input.png
image create photo result
::rbc::winop convolve source result {1 1 1 1 1 1 1 1 1}
Command layout¶
The current interface contains both direct image operations and an image subgroup.
Operation |
Direct form |
|
|---|---|---|
convolve |
|
|
gradient |
— |
|
quantize |
|
— |
readjpeg |
|
|
resample |
|
|
rotate |
— |
|
snap |
|
|
subsample |
|
|
WINOPIMAGE is used below as a placeholder for:
::rbc::winop image
See WINOPIMAGE for the grouped image operations.
Window operations¶
winop can map, unmap, raise, lower, move, and capture Tk windows.
For example:
toplevel .top
::rbc::winop move .top 100 100
::rbc::winop raise .top
Tk path names are the portable form of window identifier and should normally be used.
Some low-level operations also accept integer native or X-style window identifiers. Such identifiers are platform dependent and should not be used by portable Tcl scripts.
Mapping and stacking¶
lower and raise alter the stacking order of one or more Tk windows:
::rbc::winop raise .top
::rbc::winop lower .other
Multiple windows may be supplied:
::rbc::winop raise .one .two .three
map and unmap directly map or unmap windows through the underlying window system:
::rbc::winop map .top
::rbc::winop unmap .top
These are low-level operations. Normal Tk applications should generally prefer Tk’s standard window and window manager commands when those provide the required behavior.
Pointer position¶
query returns the current pointer position in root-screen coordinates:
set position [::rbc::winop query]
# for example:
# @821,417
warpto can move the pointer either to an explicit root-screen coordinate:
::rbc::winop warpto @100,200
or to the center of a mapped Tk window:
::rbc::winop warpto .g
In all forms, warpto returns the resulting pointer position in the same @x,y form as query.
With no argument, warpto does not move the pointer and is equivalent to querying its current position:
set position [::rbc::winop warpto]
Pointer warping is generally most useful for testing or specialized interfaces where explicitly repositioning the pointer is required.
Window snapshots¶
snap captures a window into an existing Tk photo image.
image create photo snapshot
::rbc::winop snap .g snapshot
The destination photo must already exist.
A Tk widget pathname (including . or another toplevel) captures its client area, without the
window-manager title bar or outer frame. The default dimensions are winfo width and winfo height
for that widget. This also applies to the winop image snap compatibility form.
An optional output width and height may be supplied:
::rbc::winop snap .g snapshot 640 480
The dimensions are positive Tk screen distances. If a dimension is omitted, the corresponding source-window dimension is used.
The captured image is resampled when its requested size differs from the source window.
Capturing requires the underlying native window contents to be available. The operation may fail when the window cannot be grabbed, for example when the platform cannot provide the requested window pixels.
Photo-image operations¶
Image-processing operations operate on existing Tk photo images.
For example:
image create photo source -file input.png
image create photo destination
Unless stated otherwise, source and destination arguments must name Tk photo images rather than arbitrary Tk image types.
Convolution¶
convolve applies a two-dimensional convolution kernel.
The kernel is a Tcl list containing a square number of finite numeric values:
::rbc::winop convolve source destination {1 1 1 1 1 1 1 1 1}
The kernel above performs a simple averaging blur because the convolution result is normalized by the sum of the kernel values.
A kernel must contain n*n values for some positive integer n. An empty or non-square kernel is rejected.
Source-edge pixels are extended when the kernel reaches outside the image boundaries.
The source and destination may name the same photo image.
Color quantization¶
quantize reduces the number of colors in a photo image:
image create photo reduced
::rbc::winop quantize source reduced 16
nColors must be between 1 and 256. If omitted, it defaults to 1.
The destination photo is resized to match the source when necessary.
JPEG input¶
readjpeg reads a JPEG file into an existing Tk photo:
image create photo picture
::rbc::winop readjpeg image.jpg picture
JPEG support is optional at build time. If Rbc was built without JPEG support, the operation returns an error.
Tk’s normal image facilities or an image extension may be preferable when they already provide the required JPEG support.
Image resampling¶
resample copies or resizes one photo image into another.
To request a particular output size, first create or resize the destination photo to that size:
image create photo source -file input.png
image create photo small -width 320 -height 200
::rbc::winop resample source small lanczos3
If the destination has the same size as the source, the image is copied without resampling.
If either destination dimension is 1 or less, the destination is resized to the source dimensions and the
source is copied.
One horizontal and one vertical filter may be supplied:
::rbc::winop resample source destination lanczos3 gaussian
With only one filter, the same filter is used horizontally and vertically.
If no filter is specified, none is used.
The available filters are:
Filter |
Description |
|---|---|
|
Bell filter |
|
Bessel filter |
|
Box filter |
|
B-spline filter |
|
Catmull-Rom filter |
|
Rbc default resampling filter |
|
Dummy filter |
|
Wide Gaussian filter |
|
Gaussian filter |
|
Gaussian-integral approximation |
|
Lanczos-3 filter |
|
Mitchell filter |
|
Performs resizing without a resampling filter |
|
Sinc filter |
|
Triangle filter |
Subsampling¶
subsample extracts a rectangular region of a source photo and optionally resamples it into a destination
photo.
image create photo crop -width 200 -height 100
::rbc::winop subsample source crop 50 40 400 200 lanczos3
x and y specify the upper-left source position and must be non-negative. width and height specify a
positive source-region size.
The complete requested region must lie inside the source photo.
If either destination dimension is 1 or less, the destination is resized to the dimensions of the selected
source region.
As with resample, separate horizontal and vertical filters may be supplied. If only one is supplied it is
used in both directions.
The default filter for subsample is box.
Platform differences¶
Most winop operations are available on all supported platforms through Tk’s platform drawing interfaces.
colormap is available only on non-Windows builds. It is a legacy X11-oriented operation that examines the
colormap associated with a Tk window.
JPEG availability is also build dependent.
Copyright (c) George Yashin