Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change the Bitmap -data parameter. 1

Status
Not open for further replies.

joe90

Technical User
Dec 18, 2000
10
US
Actually, I know how to change the parameter:
picc configure -data {
#define picc_width 2
#define picc_height 2
static char picc_bits[] = { 0xff 0xff }:
}
will do the job. However, I want to display a video sequence in TCL and the best way I can thingk of doing it is by writing each frame as a bitmap on a canvas. The source of the video information isn't important (let's assume it's a file) and the format is the same as a b&w (well grayscale) bitmap image.
A bitmap image (vid_frm) would be displayed on the canvas and then each new frame of data would be read into a variable 'next_frame' and then used to update the data for vid_frm:
vid_frm configure -data {
#define vid_frm_width 128
#define vid_frm 256
static char picc_bits[] = $nextframe
}

Unfortunately, this does not treat $nextframe as a variable and instead tries to set the bitmap data to the string "$nextframe".

So, how do I persuade TCL to treat $nextframe as a variable?

TIA

Joe
 
The problem in this case is that the {} quoting characters surrounding your -data parameter prevent the Tcl interpreter from performing any substitutions -- including variable substitutions -- anywhere within the quoted argument.

One option for solving your problem is to use Tcl's other set of quoting characters. The "" quoting characters allow the Tcl interpreter to perform substitutions anywhere within the argument.

The problem with this approach in your example, though, is that your argument contains other characters beyond the "$nextframe" part that have significance during substitution: specifically, the [ignore][][/ignore] characters, which signal command substitution. If you use "" to quote the argument, you'll then also need to "protect" these characters from substitution by escaping them with "\" characters. For example:

Code:
vid_frm configure -data "
  #define vid_frm_width 128
  #define vid_frm_height 256
  static char vid_frm_bits\[\] = { $nextframe};
"

Admittedly, this is a bit ugly. Which is why in a long string like this where I want to perform selective substitution, I typically use the format command. The format command generates a "formatted" string given one or more values to format. (It works almost exactly like the C-language sprintf() function, if you're familiar with that.) Read the format reference page ( for more information on how to use it, but in your situation, you could do something like this:

Code:
set frameTemplate {
  #define vid_frm_width 128
  #define vid_frm_height 256
  static char vid_frm_bits[] = { %s };
}

set data [format $frameTemplate $nextframe]

vid_frm configure -data $data
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top