DESCRIPTION

%f3glReadPixelsfP returns pixel data from the frame buffer,
starting with the pixel whose lower left corner
is at location (f2xfP, f2yfP),
into client memory starting at location f2pixelsfP.
Several parameters control the processing of the pixel data before
it is placed into client memory.
These parameters are set with three commands:
%f3glPixelStorefP,
%f3glPixelTransferfP, and
%f3glPixelMapfP.
This reference page describes the effects on %f3glReadPixelsfP of most,
but not all of the parameters specified by these three commands.
When the %f3GL_ARB_imagingfP extension is supported, the pixel data may
be processed by additional operations including color table lookup,
color matrix tranformations, convolutions, histograms and minimum and
maximun pixel value computations.
%f3glReadPixelsfP returns values from each pixel with lower left corner at
(f2xfP + $i$, f2yfP + $j$) for 0 (<= $i$ < f2widthfP and
0 (<= $j$ < f2heightfP.
This pixel is said to be the $i$th pixel in the $j$th row.
Pixels are returned in row order from the lowest to the highest row,
left to right in each row.
f2formatfP specifies the for the returned pixel values;
accepted values are:

%f3GL_COLOR_INDEXfP

Color indices are read from the color buffer
selected by %f3glReadBufferfP.
Each index is converted to fixed point,
shifted left or right depending on the value and sign of %f3GL_INDEX_SHIFTfP,
and added to %f3GL_INDEX_OFFSETfP.
If %f3GL_MAP_COLORfP is %f3GL_TRUEfP,
indices are replaced by their mappings in the table %f3GL_PIXEL_MAP_I_TO_IfP.

%f3GL_STENCIL_INDEXfP

Stencil values are read from the stencil buffer.
Each index is converted to fixed point,
shifted left or right depending on the value and sign of %f3GL_INDEX_SHIFTfP,
and added to %f3GL_INDEX_OFFSETfP.
If %f3GL_MAP_STENCILfP is %f3GL_TRUEfP,
indices are replaced by their mappings in the table %f3GL_PIXEL_MAP_S_TO_SfP.

%f3GL_DEPTH_COMPONENTfP

Depth values are read from the depth buffer.
Each component is converted to floating point such that the minimum depth
value maps to 0 and the maximum value maps to 1.
Each component is then multiplied by %f3GL_DEPTH_SCALEfP,
added to %f3GL_DEPTH_BIASfP,
and finally clamped to the range [0,1].

%f3GL_REDfP

%f3GL_GREENfP

%f3GL_BLUEfP

%f3GL_ALPHAfP

%f3GL_RGBfP

%f3GL_BGRfP

%f3GL_RGBAfP

%f3GL_BGRAfP

%f3GL_LUMINANCEfP

%f3GL_LUMINANCE_ALPHAfP

Processing differs depending on whether color buffers store color indices
or RGBA color components.
If color indices are stored,
they are read from the color buffer selected by %f3glReadBufferfP.
Each index is converted to fixed point,
shifted left or right depending on the value and sign of %f3GL_INDEX_SHIFTfP,
and added to %f3GL_INDEX_OFFSETfP.
Indices are then replaced by the red,
green,
blue,
and alpha values obtained by indexing the tables
%f3GL_PIXEL_MAP_I_TO_RfP,
%f3GL_PIXEL_MAP_I_TO_GfP,
%f3GL_PIXEL_MAP_I_TO_BfP, and
%f3GL_PIXEL_MAP_I_TO_AfP.
Each table must be of size $2 sup n$, but $n$ may be different for
different tables.
Before an index is used to look up a value in a table of
size $2 sup n$, it must be masked against $2 sup n - 1$.

If RGBA color components are stored in the color buffers,
they are read from the color buffer selected by %f3glReadBufferfP.
Each color component is converted to floating point such that zero intensity
maps to 0.0 and full intensity maps to 1.0.
Each component is then multiplied by %f3GL_c_SCALEfP and
added to %f3GL_c_BIASfP,
where f2cfP is RED, GREEN, BLUE, or ALPHA.
Finally,
if %f3GL_MAP_COLORfP is %f3GL_TRUEfP,
each component is clamped to the range [0, 1],
scaled to the size of its corresponding table, and is then
replaced by its mapping in the table
%f3GL_PIXEL_MAP_c_TO_cfP,
where f2cfP is R, G, B, or A.

Unneeded data is then discarded.
For example,
%f3GL_REDfP discards the green, blue, and alpha components,
while %f3GL_RGBfP discards only the alpha component.
%f3GL_LUMINANCEfP computes a single-component value as the sum of
the red,
green,
and blue components,
and %f3GL_LUMINANCE_ALPHAfP does the same,
while keeping alpha as a second value.
The final values are clamped to the range [0, 1].
The shift,
scale,
bias,
and lookup factors just described are all specified by
%f3glPixelTransferfP.
The lookup table contents themselves are specified by %f3glPixelMapfP.
Finally, the indices or components
are converted to the proper ,
as specified by f2typefP.
If f2formatfP is %f3GL_COLOR_INDEXfP or %f3GL_STENCIL_INDEXfP
and f2typefP is not %f3GL_FLOATfP,
each index is masked with the mask value given in the following table.
If f2typefP is %f3GL_FLOATfP, then each integer index is converted to
single-precision floating-point .
If f2formatfP is
%f3GL_REDfP,
%f3GL_GREENfP,
%f3GL_BLUEfP,
%f3GL_ALPHAfP,
%f3GL_RGBfP,
%f3GL_BGRfP,
%f3GL_RGBAfP,
%f3GL_BGRAfP,
%f3GL_LUMINANCEfP, or
%f3GL_LUMINANCE_ALPHAfP and f2typefP is not %f3GL_FLOATfP,
each component is multiplied by the multiplier shown in the following table.
If type is %f3GL_FLOATfP, then each component is passed as is
(or converted to the client's single-precision floating-point if
it is different from the one used by the GL).

f2typefP

index mask

component conversion

%f3GL_UNSIGNED_BYTEfP

$2"^"8 - 1$

$(2"^"8 - 1) c$

%f3GL_BYTEfP

$2"^"7 - 1$

$[(2"^"8 - 1) c - 1] / 2$

%f3GL_BITMAPfP

$1$

$1$

%f3GL_UNSIGNED_SHORTfP

$2"^"16 - 1$

$(2"^"16 - 1) c$

%f3GL_SHORTfP

$2"^"15 - 1$

$[(2"^"16 - 1) c - 1] / 2$

%f3GL_UNSIGNED_INTfP

$2"^"32 - 1$

$(2"^"32 - 1) c$

%f3GL_INTfP

$2"^"31 - 1$

$[(2"^"32 - 1) c - 1] / 2$

%f3GL_FLOATfP

none

$c$

Return values are placed in memory as follows.
If f2formatfP is
%f3GL_COLOR_INDEXfP,
%f3GL_STENCIL_INDEXfP,
%f3GL_DEPTH_COMPONENTfP,
%f3GL_REDfP,
%f3GL_GREENfP,
%f3GL_BLUEfP,
%f3GL_ALPHAfP, or
%f3GL_LUMINANCEfP,
a single value is returned and the data for the $i$th pixel in the $j$th row
is placed in location $(j)~"width"~+~i$.
%f3GL_RGBfP and %f3GL_BGRfP return three values,
%f3GL_RGBAfP and %f3GL_BGRAfP return four values,
and %f3GL_LUMINANCE_ALPHAfP returns two values for each pixel,
with all values corresponding to a single pixel occupying contiguous space
in f2pixelsfP.
Storage parameters set by %f3glPixelStorefP,
such as %f3GL_PACK_LSB_FIRSTfP and %f3GL_PACK_SWAP_BYTESfP,
affect the way that data is written into memory.
See %f3glPixelStorefP for a description.

NOTES

Values for pixels that lie outside the window
connected to the current GL context are undefined.
If an error is generated,
no change is made to the contents of f2pixelsfP.

ERRORS

%f3GL_INVALID_ENUMfP is generated if f2formatfP or f2typefP is not an
accepted value.
%f3GL_INVALID_ENUMfP is generated if f2typefP is %f3GL_BITMAPfP and f2formatfP is
not %f3GL_COLOR_INDEXfP or %f3GL_STENCIL_INDEXfP.
%f3GL_INVALID_VALUEfP is generated if either f2widthfP or f2heightfP is negative.
%f3GL_INVALID_OPERATIONfP is generated if f2formatfP is %f3GL_COLOR_INDEXfP
and the color buffers store RGBA color components.
%f3GL_INVALID_OPERATIONfP is generated if f2formatfP is %f3GL_STENCIL_INDEXfP
and there is no stencil buffer.
%f3GL_INVALID_OPERATIONfP is generated if f2formatfP is %f3GL_DEPTH_COMPONENTfP
and there is no depth buffer.
%f3GL_INVALID_OPERATIONfP is generated if %f3glReadPixelsfP
is executed between the execution of %f3glBeginfP
and the corresponding execution of %f3glEndfP.
%f3GL_INVALID_OPERATIONfP is generated if f2typefP is one of
%f3GL_UNSIGNED_BYTE_3_3_2fP,
%f3GL_UNSIGNED_BYTE_2_3_3_REVfP,
%f3GL_UNSIGNED_SHORT_5_6_5fP, or
%f3GL_UNSIGNED_SHORT_5_6_5_REVfP
and f2formatfP is not %f3GL_RGBfP.
%f3GL_INVALID_OPERATIONfP is generated if f2typefP is one of
%f3GL_UNSIGNED_SHORT_4_4_4_4fP,
%f3GL_UNSIGNED_SHORT_4_4_4_4_REVfP,
%f3GL_UNSIGNED_SHORT_5_5_5_1fP,
%f3GL_UNSIGNED_SHORT_1_5_5_5_REVfP,
%f3GL_UNSIGNED_INT_8_8_8_8fP,
%f3GL_UNSIGNED_INT_8_8_8_8_REVfP,
%f3GL_UNSIGNED_INT_10_10_10_2fP, or
%f3GL_UNSIGNED_INT_2_10_10_10_REVfP
and f2formatfP is neither %f3GL_RGBAfP nor %f3GL_BGRAfP.
The formats %f3GL_BGRfP, and %f3GL_BGRAfP and types
%f3GL_UNSIGNED_BYTE_3_3_2fP,
%f3GL_UNSIGNED_BYTE_2_3_3_REVfP,
%f3GL_UNSIGNED_SHORT_5_6_5fP,
%f3GL_UNSIGNED_SHORT_5_6_5_REVfP,
%f3GL_UNSIGNED_SHORT_4_4_4_4fP,
%f3GL_UNSIGNED_SHORT_4_4_4_4_REVfP,
%f3GL_UNSIGNED_SHORT_5_5_5_1fP,
%f3GL_UNSIGNED_SHORT_1_5_5_5_REVfP,
%f3GL_UNSIGNED_INT_8_8_8_8fP,
%f3GL_UNSIGNED_INT_8_8_8_8_REVfP,
%f3GL_UNSIGNED_INT_10_10_10_2fP, and
%f3GL_UNSIGNED_INT_2_10_10_10_REVfP are available only if the GL version
is 1.2 or greater.