Funny behavior with GetImage

Hi,

We are running a task in which an observer is required to click on a
section of the Screen with a mouse. On the screen is a colour
wheel. The observer is to click on the portion of the colour wheel
which most closely matches a perceived colour presented elsewhere on
the screen.

The colour wheel is a tif image that is loaded and made into a
texture using:

[code]
wheel = imread(strcat(imDir,'wheel',num2str(wheelNum),'.tif'));
WheelTexture = Screen('MakeTexture',w,wheel);

Screen('DrawTexture',w,WheelTexture);
Screen('DrawText',w,stimLetter,[pixx/2-TextSize/2],[pixy/2-TextSize/
2],[0 0 0],[BackGround BackGround BackGround]);
Screen('Flip',w);

[/code]

Responses are taken using GetMouse:

[code]
% Put mouse in middle of screen
SetMouse(pixx/2,pixy/2,w);

% get a response
[x,y,buttons] = GetMouse;
while any(buttons) % if already down, wait for release
[x,y,buttons] = GetMouse;
end
while ~any(buttons) % wait for press
[x,y,buttons] = GetMouse;
end
while any(buttons) % wait for release
[x,y,buttons] = GetMouse;
end
xPos(t) = x;
yPos(t) = y;
posRect = [(xPos(t)) (yPos(t)) (xPos(t)+1) (yPos(t)+1)];
[\code]

The colour of the clicked on section of the wheel is extracted using
GetImage:

[code]

% Get an RGB value for that location on the screen
% imageArray=Screen('GetImage', windowPtr [,rect] [,bufferName])
rgb=Screen('GetImage',w,[posRect],'frontBuffer');

r = rgb(1,1,1);
g = rgb(1,1,2);
b = rgb(1,1,3);

[/code]

This works on an iBook G4 with an ATI radeon mobility 32 MB card, and
on an intel iMac with and ATI Radeon X1600 card. When this code is
run on an intel mac mini, the results of GetImage are always the set
colour level of the background window. It is as if it is not known
that the texture has been drawn to the screen, or it is being lost by
the framebuffer once the texture is 'flipped'.

I have pasted the results of 'ScreenTest.m' for the mini and the iMac
below. Is this a bug with the Intel video drivers? Any workaround
that can be thought of?

Cheers,

Kevin MacKenzie
Centre For Vision Research, York University


------------------------------------------------------------------------
------------------------------------------------------------------------
-----------------------
Screen test for iMac

***** ScreenTest: Testing Screen 0 *****


PTB-INFO: This is the OpenGL-Psychtoolbox version 3.0.8. Type
'PsychtoolboxVersion' for more detailed version information.
PTB-INFO: Psychtoolbox is licensed to you under terms of the GNU
General Public License (GPL). See file 'License.txt' in the
PTB-INFO: Psychtoolbox root folder for a copy of the GPL license.



OpenGL-Extensions are: GL_ARB_transpose_matrix GL_ARB_vertex_program
GL_ARB_vertex_blend GL_ARB_window_pos GL_ARB_shader_objects
GL_ARB_vertex_shader GL_EXT_multi_draw_arrays GL_EXT_clip_volume_hint
GL_EXT_rescale_normal GL_EXT_draw_range_elements GL_EXT_fog_coord
GL_APPLE_client_storage GL_APPLE_specular_vector
GL_APPLE_transform_hint GL_APPLE_packed_pixels GL_APPLE_fence
GL_APPLE_vertex_array_object GL_APPLE_vertex_program_evaluators
GL_APPLE_element_array GL_APPLE_flush_render GL_NV_texgen_reflection
GL_NV_light_max_exponent GL_IBM_rasterpos_clip
GL_SGIS_generate_mipmap GL_ARB_shading_language_100 GL_ARB_imaging
GL_ARB_point_parameters GL_ARB_texture_env_crossbar
GL_ARB_texture_border_clamp GL_ARB_multitexture
GL_ARB_texture_env_add GL_ARB_texture_cube_map
GL_ARB_texture_env_dot3 GL_ARB_multisample GL_ARB_texture_env_combine
GL_ARB_texture_compression GL_ARB_texture_mirrored_repeat
GL_ARB_shadow GL_ARB_depth_texture GL_ARB_shadow_ambient
GL_ARB_fragment_program GL_ARB_fragment_program_shadow
GL_ARB_fragment_shader GL_ARB_occlusion_query GL_ARB_point_sprite
GL_ARB_texture_non_power_of_two GL_ARB_vertex_buffer_object
GL_ARB_pixel_buffer_object GL_ARB_draw_buffers
GL_ARB_shader_texture_lod GL_EXT_compiled_vertex_array
GL_EXT_framebuffer_object GL_EXT_texture_rectangle
GL_ARB_texture_rectangle GL_EXT_texture_env_add GL_EXT_blend_color
GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_texture_lod_bias
GL_EXT_abgr GL_EXT_bgra GL_EXT_stencil_wrap
GL_EXT_texture_filter_anisotropic GL_EXT_separate_specular_color
GL_EXT_secondary_color GL_EXT_blend_func_separate GL_EXT_shadow_funcs
GL_EXT_stencil_two_side GL_EXT_texture_compression_s3tc
GL_EXT_texture_compression_dxt1 GL_EXT_blend_equation_separate
GL_EXT_texture_mirror_clamp GL_EXT_packed_depth_stencil
GL_EXT_gpu_program_parameters GL_APPLE_flush_buffer_range
GL_APPLE_ycbcr_422 GL_APPLE_vertex_array_range GL_APPLE_texture_range
GL_APPLE_float_pixels GL_ATI_texture_float GL_ARB_texture_float
GL_APPLE_pixel_buffer GL_NV_blend_square GL_NV_fog_distance
GL_ATI_texture_mirror_once GL_ATI_text_fragment_shader
GL_ATI_blend_equation_separate GL_ATI_blend_weighted_minmax
GL_ATI_texture_env_combine3 GL_ATI_separate_stencil
GL_ATI_texture_compression_3dc GL_SGIS_texture_edge_clamp
GL_SGIS_texture_lod GL_SGI_color_matrix



PTB-INFO: OpenGL-Renderer is ATI Technologies Inc. :: ATI Radeon
X1600 OpenGL Engine :: 2.0 ATI-1.4.40
PTB-INFO: Renderer has 128 MB of VRAM and a maximum 122 MB of texture
memory.
PTB-Info: VBL startline = 900 , VBL Endline = -1
PTB-Info: Beamposition queries unsupported on this system. Will try
to use kernel-level vbl interrupts as fallback.
PTB-Info: Measured monitor refresh interval from VBLsync = 16.420425
ms [60.899765 Hz]. (50 valid samples taken, stddev=0.074559 ms.)
PTB-Info: Small deviations between reported values are normal and no
reason to worry.
PTB-INFO: Using OpenGL GL_TEXTURE_RECTANGLE_EXT extension for
efficient high-performance texture mapping...

***** ScreenTest: Done With Screen 0 *****
>>

------------------------------------------------------------------------
------------------------------------------------------------------------
-----------------------
Screen test for mini

>> ScreenTest

***** ScreenTest: Testing Screen 0 *****


PTB-INFO: This is the OpenGL-Psychtoolbox version 3.0.8. Type
'PsychtoolboxVersion' for more detailed version information.
PTB-INFO: Psychtoolbox is licensed to you under terms of the GNU
General Public License (GPL). See file 'License.txt' in the
PTB-INFO: Psychtoolbox root folder for a copy of the GPL license.



OpenGL-Extensions are: GL_ARB_transpose_matrix GL_ARB_vertex_program
GL_ARB_vertex_blend GL_ARB_window_pos GL_ARB_shader_objects
GL_ARB_vertex_shader GL_EXT_multi_draw_arrays GL_EXT_clip_volume_hint
GL_EXT_rescale_normal GL_EXT_draw_range_elements GL_EXT_fog_coord
GL_APPLE_client_storage GL_APPLE_specular_vector
GL_APPLE_transform_hint GL_APPLE_packed_pixels GL_APPLE_fence
GL_APPLE_vertex_array_object GL_APPLE_vertex_program_evaluators
GL_APPLE_element_array GL_APPLE_flush_render GL_NV_texgen_reflection
GL_NV_light_max_exponent GL_IBM_rasterpos_clip
GL_SGIS_generate_mipmap GL_ARB_shading_language_100
GL_ARB_texture_border_clamp GL_ARB_multitexture
GL_ARB_texture_env_add GL_ARB_texture_cube_map
GL_ARB_texture_env_dot3 GL_ARB_texture_env_combine
GL_ARB_texture_compression GL_ARB_texture_mirrored_repeat
GL_ARB_shadow GL_ARB_depth_texture GL_ARB_fragment_program
GL_ARB_fragment_shader GL_ARB_point_sprite
GL_ARB_texture_non_power_of_two GL_ARB_vertex_buffer_object
GL_ARB_pixel_buffer_object GL_EXT_framebuffer_object
GL_EXT_texture_rectangle GL_ARB_texture_rectangle
GL_EXT_texture_env_add GL_EXT_blend_color GL_EXT_blend_minmax
GL_EXT_blend_subtract GL_EXT_texture_lod_bias GL_EXT_abgr GL_EXT_bgra
GL_EXT_stencil_wrap GL_EXT_texture_filter_anisotropic
GL_EXT_separate_specular_color GL_EXT_secondary_color
GL_EXT_blend_func_separate GL_EXT_shadow_funcs
GL_EXT_stencil_two_side GL_EXT_texture_compression_s3tc
GL_EXT_texture_compression_dxt1 GL_EXT_blend_equation_separate
GL_EXT_gpu_program_parameters GL_APPLE_flush_buffer_range
GL_APPLE_ycbcr_422 GL_APPLE_texture_range GL_APPLE_pixel_buffer
GL_NV_blend_square GL_ATI_texture_env_combine3
GL_SGIS_texture_edge_clamp GL_SGIS_texture_lod



PTB-INFO: OpenGL-Renderer is Intel Inc. :: Intel GMA 950 OpenGL
Engine :: 1.2 APPLE-1.4.40
PTB-INFO: Renderer has 64 MB of VRAM and a maximum 64 MB of texture
memory.
PTB-Info: VBL startline = 1024 , VBL Endline = -1
PTB-Info: Beamposition queries unsupported on this system. Will try
to use kernel-level vbl interrupts as fallback.
PTB-Info: Measured monitor refresh interval from VBLsync = 13.387519
ms [74.696437 Hz]. (50 valid samples taken, stddev=0.054764 ms.)
PTB-Info: Reported monitor refresh interval from operating system =
13.333333 ms [75.000000 Hz].
PTB-Info: Small deviations between reported values are normal and no
reason to worry.
PTB-INFO: Using OpenGL GL_TEXTURE_RECTANGLE_EXT extension for
efficient high-performance texture mapping...

***** ScreenTest: Done With Screen 0 *****
Hi Mario,

Thanks for the advice here.

..
Screen('Flip',w);
Screen('FillRect'
, w, [someweirdcolorvalue]);
rgb = Screen('GetImage'
, ....);
...


This code leads to the rgb value to be equal to <someweirdcolorvalue>.

...
Screen('DrawingFinished', w);
rgb=Screen('
GetImage', ...., 'backBuffer');
Screen('Flip'
, w);
...

This works. We now are extracting a full screen rect image and storing it in a temp variable. This we reference to extract a colour value from the pixel location on screen. As always, thanks for the tips.

Kevin
Centre for Vision Research



On 12-Mar-07, at 8:15 PM, Mario Kleiner wrote:

This is certainly an Intel driver bug. Could you try what happens if you do this:

...
Screen('Flip',w);
Screen('FillRect', w, [someweirdcolorvalue]);
rgb = Screen('GetImage', ....);
...

Do you get the background clear color or do you get the 'someweirdcolorvalue'?
What could happen is that the driver ignores the request to read from the front buffer and
instead reads from the backbuffer. In that case it would read the background clear color
immediately after a Flip, or in our case the someweirdcolorvalue...

As a workaround, try reading the backbuffer *before* Flip -- should be the same as the
frontbuffer after a flip:
...
Screen('DrawingFinished', w);
rgb=Screen('GetImage', ...., 'backBuffer');
Screen('Flip', w);
...

Generally i have the feeling that reading from the frontbuffer seems to be more buggy on
a couple of systems and that reading the backbuffer is safer.

best,
-mario

--- In psychtoolbox@yahoogroups.com, "Kevin J. MacKenzie" <kjmacken@...> wrote:
>
> Hi,
>
> We are running a task in which an observer is required to click on a
> section of the Screen with a mouse. On the screen is a colour
> wheel. The observer is to click on the portion of the colour wheel
> which most closely matches a perceived colour presented elsewhere on
> the screen.
>
> The colour wheel is a tif image that is loaded and made into a
> texture using:
>
> [code]
> wheel = imread(strcat(imDir,'wheel',num2str(wheelNum),'.tif'));
> WheelTexture = Screen('MakeTexture',w,wheel);
>
> Screen('DrawTexture',w,WheelTexture);
> Screen('DrawText',w,stimLetter,[pixx/2-TextSize/2],[pixy/2-TextSize/
> 2],[0 0 0],[BackGround BackGround BackGround]);
> Screen('Flip',w);
>
> [/code]
>
> Responses are taken using GetMouse:
>
> [code]
> % Put mouse in middle of screen
> SetMouse(pixx/2,pixy/2,w);
>
> % get a response
> [x,y,buttons] = GetMouse;
> while any(buttons) % if already down, wait for release
> [x,y,buttons] = GetMouse;
> end
> while ~any(buttons) % wait for press
> [x,y,buttons] = GetMouse;
> end
> while any(buttons) % wait for release
> [x,y,buttons] = GetMouse;
> end
> xPos(t) = x;
> yPos(t) = y;
> posRect = [(xPos(t)) (yPos(t)) (xPos(t)+1) (yPos(t)+1)];
> [\code]
>
> The colour of the clicked on section of the wheel is extracted using
> GetImage:
>
> [code]
>
> % Get an RGB value for that location on the screen
> % imageArray=Screen('GetImage', windowPtr [,rect] [,bufferName])
> rgb=Screen('GetImage',w,[posRect],'frontBuffer');
>
> r = rgb(1,1,1);
> g = rgb(1,1,2);
> b = rgb(1,1,3);
>
> [/code]
>
> This works on an iBook G4 with an ATI radeon mobility 32 MB card, and
> on an intel iMac with and ATI Radeon X1600 card. When this code is
> run on an intel mac mini, the results of GetImage are always the set
> colour level of the background window. It is as if it is not known
> that the texture has been drawn to the screen, or it is being lost by
> the framebuffer once the texture is 'flipped'.
>
> I have pasted the results of 'ScreenTest.m' for the mini and the iMac
> below. Is this a bug with the Intel video drivers? Any workaround
> that can be thought of?
>
> Cheers,
>
> Kevin MacKenzie
> Centre For Vision Research, York University
>
>
> ----------------------------------------------------------
> ----------------------------------------------------------
> -----------------------
> Screen test for iMac
>
> ***** ScreenTest: Testing Screen 0 *****
>
>
> PTB-INFO: This is the OpenGL-Psychtoolbox version 3.0.8. Type
> 'PsychtoolboxVersion' for more detailed version information.
> PTB-INFO: Psychtoolbox is licensed to you under terms of the GNU
> General Public License (GPL). See file 'License.txt' in the
> PTB-INFO: Psychtoolbox root folder for a copy of the GPL license.
>
>
>
> OpenGL-Extensions are: GL_ARB_transpose_matrix GL_ARB_vertex_program
> GL_ARB_vertex_blend GL_ARB_window_pos GL_ARB_shader_objects
> GL_ARB_vertex_shader GL_EXT_multi_draw_arrays GL_EXT_clip_volume_hint
> GL_EXT_rescale_normal GL_EXT_draw_range_elements GL_EXT_fog_coord
> GL_APPLE_client_storage GL_APPLE_specular_vector
> GL_APPLE_transform_hint GL_APPLE_packed_pixels GL_APPLE_fence
> GL_APPLE_vertex_array_object GL_APPLE_vertex_program_evaluators
> GL_APPLE_element_array GL_APPLE_flush_render GL_NV_texgen_reflection
> GL_NV_light_max_exponent GL_IBM_rasterpos_clip
> GL_SGIS_generate_mipmap GL_ARB_shading_language_100 GL_ARB_imaging
> GL_ARB_point_parameters GL_ARB_texture_env_crossbar
> GL_ARB_texture_border_clamp GL_ARB_multitexture
> GL_ARB_texture_env_add GL_ARB_texture_cube_map
> GL_ARB_texture_env_dot3 GL_ARB_multisample GL_ARB_texture_env_combine
> GL_ARB_texture_compression GL_ARB_texture_mirrored_repeat
> GL_ARB_shadow GL_ARB_depth_texture GL_ARB_shadow_ambient
> GL_ARB_fragment_program GL_ARB_fragment_program_shadow
> GL_ARB_fragment_shader GL_ARB_occlusion_query GL_ARB_point_sprite
> GL_ARB_texture_non_power_of_two GL_ARB_vertex_buffer_object
> GL_ARB_pixel_buffer_object GL_ARB_draw_buffers
> GL_ARB_shader_texture_lod GL_EXT_compiled_vertex_array
> GL_EXT_framebuffer_object GL_EXT_texture_rectangle
> GL_ARB_texture_rectangle GL_EXT_texture_env_add GL_EXT_blend_color
> GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_texture_lod_bias
> GL_EXT_abgr GL_EXT_bgra GL_EXT_stencil_wrap
> GL_EXT_texture_filter_anisotropic GL_EXT_separate_specular_color
> GL_EXT_secondary_color GL_EXT_blend_func_separate GL_EXT_shadow_funcs
> GL_EXT_stencil_two_side GL_EXT_texture_compression_s3tc
> GL_EXT_texture_compression_dxt1 GL_EXT_blend_equation_separate
> GL_EXT_texture_mirror_clamp GL_EXT_packed_depth_stencil
> GL_EXT_gpu_program_parameters GL_APPLE_flush_buffer_range
> GL_APPLE_ycbcr_422 GL_APPLE_vertex_array_range GL_APPLE_texture_range
> GL_APPLE_float_pixels GL_ATI_texture_float GL_ARB_texture_float
> GL_APPLE_pixel_buffer GL_NV_blend_square GL_NV_fog_distance
> GL_ATI_texture_mirror_once GL_ATI_text_fragment_shader
> GL_ATI_blend_equation_separate GL_ATI_blend_