[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TVRD'ing under windows



Phil Aldis wrote:
> 
> I'm having trouble tvrd'ing under windows, when I'm running 16 bit
> mode, and using decomposed colour. If I display an image, and then
> tvrd it back in and the tv that image, I get a garbled mess. The only
> way I can get a representation of what is on the screen is to set it
> into 24 bit mode, image=tvrd (true=1) and then tv, image, true=1.
> 
> I'm not really sure what's going on. Is this anything to do with what
> David was saying a while bakc, that when you're using decomposed
> colous, it runs stuff through the table or something.
> 
> Cheers,
> Phil

Hi Phil -

I ran into this problem years ago under X-Windows (Sun OS and Solaris),
and at that time it was a bug, in that even with backing store
provided by IDL TVRD() could produce unexpected results if the window
was obscured or iconified, especially if the draw widget was 
scrollable.

I got around the problem by using DEVICE, COPY=[] to copy the window
contents to a pixmap, and then TVRD() from that pixmap. Works quite
well, at least under SunOS/Solaris.

I've attached my SAFE_TVRD.PRO and SAFE_TVRD.DOC files.

Dave
-- 

  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    David S. Foster         Univ. of California, San Diego
     Programmer/Analyst     Brain Image Analysis Laboratory
     foster@bial1.ucsd.edu  Department of Psychiatry
     (619) 622-5892         8950 Via La Jolla Drive, Suite 2240
                            La Jolla, CA  92037
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;   SAFE_TVRD.PRO   6-11-97   DSFoster
;
; This function is a safer version of IDL's TVRD() function. First,
; there was a bug related to the reading from a scrollable draw. Also,
; the TVRD() function uses an X routine that has problems if the
; window is obscured or iconified. This routine uses the DEVICE, COPY=
; command to first copy the window contents to a new window pixmap,
; and then reads from this pixmap into the array.
;
; Modifications
;
;  6-11-97 DSF Check validity of draw widget.

FUNCTION safe_tvrd, draw_widget, xsize, ysize

on_error, 2

if (widget_info(draw_widget, /valid_id) eq 0) then begin
	return, -1
endif else if (widget_info(draw_widget, /name) ne 'DRAW') then begin
	return, -1
endif else begin
	old_window = !d.window
	window, xsize=xsize, ysize=ysize, /free, /pixmap     ; Create new window

	widget_control, draw_widget, get_value=window
	device, copy=[0,0, xsize,ysize, 0,0, window]         ; Copy into new window

	image = tvrd()                                       ; Read into array
	wdelete, !d.window
	if (old_window ne -1) then wset, old_window
	return, image
endelse

END
SAFE_TVRD

This function replaces IDL's TVRD() function for reading the
contents of a window into an array. The TVRD() function returns
unexpected results if the window is scrollable or is obscured
onscreen. This function uses IDL's DEVICE, COPY=[] function
to more safely read the window contents.

Calling Sequence

  Array = SAFE_TVRD(Draw_widget, Xsize, Ysize)

Arguments

  Draw_widget

    The widget id of the draw widget which you will be
    reading into the array. Note that this is NOT the
    window id!

  Xsize, Ysize

    The dimensions of the window in the draw widget.

Outputs

  Array

    Returns the image read from the draw widget. Returns -1
    if the Draw_widget is not a valid draw widget ID.