Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Troubles using img::raw

22 views
Skip to first unread message

Alex

unread,
Aug 27, 2010, 5:19:27 AM8/27/10
to
Hello,
I'm trying to use the img::raw library in my TCL/TK application.
What I want to do is display images that are stocked inside TCL
variables
containing binary data.
Here is a minimal exemple that should display a noisy image but that
instead only display a black one :

package require Img
package require img::raw

set f [open "a_big_file" r]
fconfigure $f -translation binary
set f_content [read $f]
close $f

set photo2 [image create photo -format "raw -useheader 0 -nomap 1
-verbose 1 -width 320 -height 240 -nchan 3 -pixeltype byte" -data
$f_content]
label .l2 -image $photo2
pack .l2

I don't understand what I am doing wrong, the image is fully black but
should be "noise"... do you have an exemple of how to use img::raw???

Best regards,
Alexandre.

Alexandre Ferrieux

unread,
Aug 27, 2010, 8:32:47 AM8/27/10
to

You're right, apparently there's a bug with the computation of the
default 'max' pixel value, and it stays zero, hence all pixels get
mapped to black.
I discovered this by looking at the output from the "-verbose 1":

Reading image: InlineData
Size in pixel : 320 x 240
No. of channels : 3
Pixel type : byte
Vertical encoding: TopDown
Gamma correction : 1.000000
Minimum map value: 0.000000

==> Maximum map value: 0.000000

Host byte order : Intel
File byte order : Intel

So you can work around this bug by adding the "-max 255" option.
But also be sure to create a bug report for the Img package...

-Alex (aussi)

Alex

unread,
Aug 27, 2010, 10:25:34 AM8/27/10
to
It seems to be even worst, if you apply twice the command
photo2 put $f_content -format "raw -verbose 1 - min 0 -max 255"

then the second time the image turn to black again. It seems that
parameters are not taken into account (although the verbose mode write
Maximum map value: 255.000000 on the console).

Ok, I will post a bug report ^_^


On 27 août, 14:32, Alexandre Ferrieux <alexandre.ferri...@gmail.com>
wrote:

Paul Obermeier

unread,
Aug 28, 2010, 9:52:39 AM8/28/10
to
The problem had to do with the auto-magic detection of uuencoded image
data supplied in a Tcl variable.
As your data has no header (with some magic key in it), the detection
failed.

I have added a new option (-uuencode bool) to the RAW format handler
(SVN Revision 300).
It is set to true by default, so the standard behaviour is not changed.

Note, that this only happens, if you supply the RAW image data without
header information via a Tcl variable.

If you don't want to update to the new Img version, you have the
following options:

# Method 1: Read directly from file with method "read".
set photo1 [image create photo]
$photo1 read $inFile \
-format "raw -nomap 1 -useheader 0 -verbose 1 -width $width
-height $height -nchan 3"

# Method 2: Read directly from file with option "-file".
set photo2 [image create photo -file $inFile \
-format "raw -nomap 1 -useheader 0 -verbose 1 -width $width
-height $height -nchan 3"]

If you update to the new Img version, you can do it this way:

# Method 3: Read from variable with method "put" and new option
"-uuencode".
# Only works with new version of Img.
set photo3 [image create photo]
$photo3 put $f_data \
-format "raw -nomap 1 -useheader 0 -verbose 1 -width $width
-height $height -nchan 3 -uuencode 0"

P.S.:
I have uploaded Img binaries of SVN revision 300 for Windows, Linux and
Mac to http://www.posoft.de/html/extTkImg.html

Paul

0 new messages