Updated 2018-10-16 20:35:49 by bll

How to post on this page edit

Please do not edit this part, it is meant as a guide!



This page runs the risk of being deleted and corrupted. Please be very careful when editing it. If you inadvertently delete it, immediately revert your edit using the History link on the left side of this page.

Do NOT attempt to restore it by copying and pasting the text from a previous revision, or all page formatting will be lost!

Please put new questions at the TOP of the page, below this section, so that as the page grows longer, new questions are seen first.

Also please put a section header on top of every question and put two stars in the beginning of the title and two stars in the end. This will make your question's section easily editable.

Once you have received a satisfactory answer, please cut your question and answer directly on an appropriate page of the wiki. If you cannot find an existing page, create a new one.

You might also simply want to put a hyperlink leading to a page of the wiki where your question is included. This will save you the trouble of cutting your question to an existing page afterwards.

Put your question below. Thanks!

Questions edit

Intercept/Observe command-line -geometry

Duoas 2018-10-16 Hey there. Is there any way to intercept/observe the processing of -geometry arguments at the command line when wish (tclkit) starts, not involving binary extensions or hacking the core?

I would like to permit multiple -geometry options to manage multiple windows (order/matching windows does not matter — they appear as clones). I can query the last supplied geometry with $::geometry, of course. I’ve tried both traces and pkgIndex.tcl trickery, but the Initialize() function in ~/generic/tkWindow.c appears to get called before any kind of user code gets a chance. Is this correct? Am I out of luck here?

If it makes any difference I am packaging in a starkit.

bll 2018-10-16 I think you will have to have the user put the -geometry arguments on the command line after a -- argument and process them yourself. There's no way to have wish do unusual things with its command line arguments.

<<Selection>> event for entry

Hi, has anyone written a script to add selection events like those for text widget to a one-line entry? (Or should I simply create a 1-line text instead?)

Hex String to Double

beware Hi all, I'm trying to decode some files. One of the values I need is stored as a double in hex. Example - "3fb999999999999a" -> "0.1". The double conversion here gets the correct result: https://gregstoll.dyndns.org/~gregstoll/floattohex/ currently my code just has the hex stored as a string (as in "set hexstr 3fb999999999999a"). How do I replicate the conversion done on that site?

Martyn Smith The TCL command is binary, you need to convert the hexadecimal string to a binary string with binary format then extract the big endian double from the binary string as follows
  binary scan [binary format H* $hexstr] Q floatValue

The Q is the format code for forced big endian double.

Google Photos

Has anyone written a tcl library that interfaces with [Google Photos] to allow one to download a "table of contents" of URLs to images and the albums to which they belong?

Image Scaling

MiR 2018-06-28:

On topic image scaling...

I was wondering, if Tk would in the future implement at least a robust image scaling alogrithm like in TkImageTools from (reference see Shrinking an image)? It's just to avoid having to deploy an externel dynamic library just to have an image resized...

AMG I did this just yesterday, but I'm probably not allowed to share the code though. I used libsamplerate [1] to do it. The interface works like this:

[imgscale sourcePhoto targetPhoto ?method?]

sourcePhoto and targetPhoto can be one-, three-, or five-element lists:
photoName
operate on full extents of photo
photoName width height
explicit width and height, top left defaults to (0,0)
photoName left top width height
explicit width, height, and top left coordinates

targetPhoto will be expanded (if possible) to accommodate the explicit width and height. Otherwise, the width and height are clipped to the photos' actual width and height. It is an error for left or top to be negative, or for width or height to be non-positive.

method can be sinc, linear, or point, corresponding to libsamplerate's SRC_SINC_FASTEST, SRC_LINEAR, and SRC_ZERO_ORDER_HOLD modes, respectively. (The other two SINC modes are significantly slower and actually look comparatively poor on images.) The default is linear.

Implementation guidelines:

  • Use the Simple API [2] which consists of only the src_simple() function. The more complicated APIs offer no benefit in this application because the image data is all available in advance.
  • Work on one channel (R, G, B, A) at a time. This requires less temporary space and offers better performance due to improved locality of reference and ability to use more optimized single-channel code within libsamplerate.
  • Step 1: Loop over each row of input R, G, B, or A bytes.
  • Step 1a: Convert the input row into a linear buffer of floats.
  • Step 1b: Rescale the width and store into an intermediate float buffer large enough to hold the whole channel.
  • Step 2: Transpose the intermediate buffer so that each column is contiguous in memory.
  • Step 3: Loop over each column of intermediate floats.
  • Step 3a: Rescale the height and store into a linear buffer of floats.
  • Step 3b: Convert the scaled column back into pixel bytes, storing into a pixel buffer large enough for the whole image.
  • Step 4: Use Tk_PhotoPutBlock() to write the pixel buffer to the target photo.

Regarding step 4: The pixel buffer will be divided into separate planes, each of which is transposed. This means the Tk_PhotoImageBlock will have to be arranged as follows:
pitch = 1
pixelSize = height
offset[n] = n * height * width

One other tip. I statically linked libsamplerate into my extension. Another possibility is to incorporate a subset of the source code, removing the unused SINC modes, to avoid their large coefficient tables. (BSD 2-clause license, by the way.)

Duoas 2018-10-19 Actually, was just working on a small binary extension to do the same thing, photo-resample.kit. Permits scaling using nearest neighbor, linear, cubic, box, and hqx algorithms, plus mirror and rotate, plus a few other resampling goodies like sharpen, gaussian blur, colorizing, desaturating, inverting an image, splitting and combining channels and alpha channel manipulations, and origin tracking, all with a very simple interface.