X
18181 Rate this article:
5.0

TVRD can return corrupted image data because of X server backing store behavior on Mac, Linux and Solaris

Anonym

PROBLEM

When using TVRD may return corrupted image data retrieved from a draw window.

For example, running the following IDL code:

HELP, /PREFERENCES, NAMES='IDL_GR_X_RETAIN'
img = READ_IMAGE( FILE_WHICH('rose.jpg') )
WINDOW, 0, XSIZE=227, YSIZE=149, TITLE='ORIGINAL'
TV, img, /TRUE
imgout = TVRD(/TRUE)
WINDOW, 1, XSIZE=227, YSIZE=149, TITLE='TVRD'
TV, imgout, /TRUE

If there is a system backing store problem, the second of the two resulting displayed images may be corrupted or absent. For example:

Figure 1:  Original image

Figure 2: Example corrupted TVRD data

 

DISCUSSION

The problem described can sometimes occur on Mac, Linux or Solaris if the IDL session's backing-store graphics preference "IDL_GR_X_RETAIN" is set to "1".  The default setting for "IDL_GR_X_RETAIN" is "1" (or "system") which means that IDL makes requests to the operating system's X windowing system to manage and repair its graphics windows.  Note that such a request to the system to manage the backing store of the graphics windows is taken merely as a suggestion and rather than a requirement.  If the X server ignores the request, the result can be a corrupted image or garbage data in the graphical retain buffer, which can then result in bad data returned from TVRD.

(Note that if "IDL_GR_X_RETAIN" is set to "0" (or "none") the result from TVRD could also be bad data since backing store will never be maintained by either the system or by IDL.)

If you are encountering this problem, the solution is to have IDL manage its own backing store by setting the IDL_GR_X_RETAIN preference to "2".  You can do this by issuing the following command at your IDL> command prompt:

PREF_SET, 'IDL_GR_X_RETAIN', 2, /COMMIT

Or if you are using the IDL Workbench (not available on Solaris), you can set this preference via the IDL Preferences dialog (Window > Preferences on Linux, or IDL > Preferences on Mac), selecting IDL > Graphics on the left side pane, and then on the right selecting "IDL (2)" under the label "Backing store method for window contents". Click on Apply and then OK to save the change.

After changing this preference, be sure to exit out of your IDL session. Upon restarting IDL, try running the code above to confirm that the TVRD image data appears the same as the original image data.

Additional information about this topic can be found in the IDL Help system under the reference page for the TVRD function (see the sub-sections "Important Note about TVRD and Backing Store" and "Unexpected Results Using TVRD with X Windows"). This page can also be found on our Documentation Center area of our web site:

    http://www.harrisgeospatial.com/docs/TVRD.html.

 Additional information about the IDL_GR_X_RETAIN preference can be found in the IDL Online Help system, or on the Documentation Center at:

    http://www.harrisgeospatial.com/docs/prefs_gr_x.html

NOTE: A few IDL users have mistakenly attributed the problem described in this help article instead to the IDL "WRITE_BMP"routine. This is in the context of the following line of example code:

WRITE_BMP, filename, TVRD(/TRUE)

-- which is part of the first example included in the IDLHelp page for WRITE_BMP:

http://www.exelisvis.com/docs/WRITE_BMP.html

If the backing store problem described in the help article is the issue, then changing the IDL_GR_X_RETAIN setting as discussed shouldfix the problem.

 Reviewed for external JU 13-aug-2014, DS 14-aug-2014