Home > Archive > Tcl > July 2007 > Can't see image updates from Tcl
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can't see image updates from Tcl
|
|
|
| Hello,
I have a program that captures screenshots from an OpenGL window and
saves
them in JPEG format using Tk photo images. I'm using Tcl 8.4.7 and Img
1=2E3.
I've found a problem when I update the image from C++ and then try to
write it
to a file from Tcl. I have two versions of the code. One works, and
the other
doesn't, but I don't know why. Can anyone take a look and tell me what
I'm
missing? Thanks in advance!
This is the version that doesn't work.
=3D=3D=3D=3D=3D=3D=3D=3D Tcl code =3D=3D=3D=3D=3D=3D=3D=3D=3D
image create photo -format [list jpeg -quality 100]
# This returns image1
. . .
$myCPPcommandHandle grab-next-frame
# Now the image is updated from C++
image1 write $myOutputFileName
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D C++ code =3D=3D=3D=3D=3D=3D=3D=3D=3D
// First I get photo handler. (myImageName is "image1")
Tk_PhotoHandle tkphoto =3D Tk_FindPhoto(ptTclInterpreter, myImageName );
. . .
// Then I update the photo
Tk_PhotoSetSize( tkphoto, width, height );
for ( i =3D 0 ; i < height-1 ; i++ )
{
. . .
Tk_PhotoPutBlock( tkphoto, &lineblock, 0, height-i, width, 1,
TK_PHOTO_COMPOSITE_SET );
}
// Finally, and just in case, I notify the image change to Tcl. (Is
this correct?
// As no widgets are using the image, I think that it isn't needed.)
Tk_ImageType *typeptr;
ClientData imgdata =3D Tk_GetImageMasterData( ptTclInterpreter,
myImageName, &typeptr );
Tk_ImageMaster * masterptr =3D (Tk_ImageMaster*)imgdata;
Tk_ImageChanged( *masterptr, 0, 0, width, height, width, height );
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
When I run the program, I get the following error message:
couldn't write JPEG file "C:/Trabajo/.../capture.jpg": Empty JPEG
image (DNL not supported)
while executing
$Config(captureimage) write $myOutputFileName
. . .
In fact, if I call "puts [$Config(captureimage) configure]" after
updating the
image from C++ and before writing it, I get that the size is 0x0. I
cannot see
the image size change from Tcl.
And this is the version that works:
=3D=3D=3D=3D=3D=3D=3D=3D Tcl code =3D=3D=3D=3D=3D=3D=3D=3D=3D
image create photo -format [list jpeg -quality 100]
. . .
$myCPPcommandHandle grab-next-frame
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
=3D=3D=3D=3D=3D=3D=3D=3D C++ code =3D=3D=3D=3D=3D=3D=3D=3D=3D
// First I get photo handler
Tk_PhotoHandle tkphoto =3D Tk_FindPhoto(ptTclInterpreter, myImageName );
. . .
// Then I update the photo
Tk_PhotoSetSize( tkphoto, width, height );
for ( i =3D 0 ; i < height-1 ; i++ )
{
. . .
Tk_PhotoPutBlock( tkphoto, &lineblock, 0, height-i, width, 1,
TK_PHOTO_COMPOSITE_SET );
}
// And I write it to file using a Tcl_Eval.
char * tclcmd =3D "image1 write myOutputFileName";
Tcl_Eval( ptTclInterpreter, tclcmd );
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D
So when I call the image write command from C++ using a Tcl_Eval, the
image is
correctly saved. What is the difference between evaluating "image1
write" from
C++ or from Tcl? What should I do so that Tcl know that I've modified
the image?
Any suggestions are gratefully welcomed.
Regards,
Miguel Mu=F1oz
| |
| Gerald W. Lester 2007-07-20, 8:10 am |
| mgma wrote:
> Hello,
>
> I have a program that captures screenshots from an OpenGL window and
> saves
> them in JPEG format using Tk photo images. I'm using Tcl 8.4.7 and Img
> 1.3.
>
> I've found a problem when I update the image from C++ and then try to
> write it
> to a file from Tcl. I have two versions of the code. One works, and
> the other
> doesn't, but I don't know why. Can anyone take a look and tell me what
> I'm
> missing? Thanks in advance!
>
>
> This is the version that doesn't work.
>
> ======== Tcl code =========
> image create photo -format [list jpeg -quality 100]
> # This returns image1
>
> . . .
>
> $myCPPcommandHandle grab-next-frame
> # Now the image is updated from C++
> image1 write $myOutputFileName
My guess is that you may need an "update idletask" before the image write.
But this is just a wild guess.
> ===========================
>
>
> ======== C++ code =========
> // First I get photo handler. (myImageName is "image1")
> Tk_PhotoHandle tkphoto = Tk_FindPhoto(ptTclInterpreter, myImageName );
>
> . . .
>
> // Then I update the photo
> Tk_PhotoSetSize( tkphoto, width, height );
> for ( i = 0 ; i < height-1 ; i++ )
> {
> . . .
> Tk_PhotoPutBlock( tkphoto, &lineblock, 0, height-i, width, 1,
> TK_PHOTO_COMPOSITE_SET );
> }
>
> // Finally, and just in case, I notify the image change to Tcl. (Is
> this correct?
> // As no widgets are using the image, I think that it isn't needed.)
> Tk_ImageType *typeptr;
> ClientData imgdata = Tk_GetImageMasterData( ptTclInterpreter,
> myImageName, &typeptr );
> Tk_ImageMaster * masterptr = (Tk_ImageMaster*)imgdata;
> Tk_ImageChanged( *masterptr, 0, 0, width, height, width, height );
> ===========================
>
>
> When I run the program, I get the following error message:
>
> couldn't write JPEG file "C:/Trabajo/.../capture.jpg": Empty JPEG
> image (DNL not supported)
> while executing
> $Config(captureimage) write $myOutputFileName
> . . .
>
>
> In fact, if I call "puts [$Config(captureimage) configure]" after
> updating the
> image from C++ and before writing it, I get that the size is 0x0. I
> cannot see
> the image size change from Tcl.
>
>
> And this is the version that works:
>
> ======== Tcl code =========
> image create photo -format [list jpeg -quality 100]
>
> . . .
>
> $myCPPcommandHandle grab-next-frame
> ===========================
>
>
> ======== C++ code =========
> // First I get photo handler
> Tk_PhotoHandle tkphoto = Tk_FindPhoto(ptTclInterpreter, myImageName );
>
> . . .
>
> // Then I update the photo
> Tk_PhotoSetSize( tkphoto, width, height );
> for ( i = 0 ; i < height-1 ; i++ )
> {
> . . .
> Tk_PhotoPutBlock( tkphoto, &lineblock, 0, height-i, width, 1,
> TK_PHOTO_COMPOSITE_SET );
> }
>
> // And I write it to file using a Tcl_Eval.
> char * tclcmd = "image1 write myOutputFileName";
> Tcl_Eval( ptTclInterpreter, tclcmd );
> ===========================
>
> So when I call the image write command from C++ using a Tcl_Eval, the
> image is
> correctly saved. What is the difference between evaluating "image1
> write" from
> C++ or from Tcl? What should I do so that Tcl know that I've modified
> the image?
>
>
> Any suggestions are gratefully welcomed.
>
> Regards,
>
> Miguel Muņoz
>
--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
| |
|
| On 20 jul, 14:36, "Gerald W. Lester" <Gerald.Les...@cox.net> wrote:
>
> My guess is that you may need an "update idletask" before the image write.
> But this is just a wild guess.
>
I've tried that already with no avail. I guess that no events are
involved in the problem, so the update command has no effect.
Regards,
Miguel
|
|
|
|
|