main/pack: use _mesa_format_from_format_and_type() in _mesa_pack_rgba_span_from_*()

We had previously added the needed mesa formats, so we can simplify more
the code.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
main: Fix bugs in _mesa_swizzle_and_convert for different size conversions

Fix various conversion paths that were not clamping conversions properly.
Also, there was a typo for the value of "one" in one of the paths.

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
main: Fix RGBA8888_UINT direct unpack path in _mesa_format_convert.

A direct unpack to this format from a signed format won't clamp so we should
not resolve converts of this kind via the unpack fast path.
main: Add RGBA to Luminance conversion helpers

For glReadPixels Luminance values are computed from RGBA as L=R+G+B.
This, however, requires ad-hoc implementation, since pack/unpack functions
or _mesa_swizzle_and_convert won't do this (and thus, neither will
_mesa_format_convert). This patch adds helpers to do this computation so
they can be used to support conversion to these formats.

The current implementation of glReadPixels does this computation as part
of the span functions in pack.c (see _mesa_pack_rgba_span_float), that do
this together with other things like type conversion, etc. We do not want
to use these functions, we want to use _mesa_format_convert instead, so we
need to extract this functionality as helper functions.
main: use _mesa_format_convert to implement glReadPixels.
main: Let _mesa_get_format_base_format also handle mesa_array_format

When we needed the base format for a mesa_array_format we had to find
the matching mesa_format first. This is expensive because it requires
to loop through all existing mesa formats until we find the right match.

We can resolve the base format of an array format directly by looking
at its swizzle information. Also, we can have _mesa_get_format_base_format
accept an uint32_t which can pack either a mesa_format or a mesa_array_format
and resolve the base format for either type. This way clients do not need to
check if they have a mesa_format or a mesa_array_format and call different
functions depending on the case.

Another reason to resolve the base format for array formats directly is that
we don't have matching mesa_format enums for every possible array format, so
for some GL format/type combinations we will produce array formats that don't
have a corresponding mesa format, in which case we would not be able to
find the base format. Example format=GL_RGB, type=GL_UNSIGNED_SHORT. This type
would map to something like MESA_FORMAT_RGB_UNORM16, but we don't have that.
mesa/main/texgetimage: use master conversion function in get_tex_rgba_uncompressed()

Updates get_tex_rgba_uncompressed() to use always use the master
conversion function.

It fixes 22 tests in piglit for i965 driver (SandyBridge)

Signed-off-by: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Signed-off-by: Eduardo Lima Mitev <elima@igalia.com>
main: Unify rebase logic for glReadPixels and glGetTexImage.

Both glReadPixels and glGetTexImage have RGBA rebasing logic that is almost
the same, so move that logic to a separate helper function
_mesa_get_rebase_format_for_color_read_back and call this from
both implementations.
main: Removes _mesa_unpack_bitmap() in favor of the more generic func _mesa_unpack_image()

Signed-off-by: Eduardo Lima Mitev <elima@igalia.com>
main: Remove unused code from texstore.c
main: Remove unused code from readpix.c
main.c: Remove _mesa_unpack_color_span_uint

This is no longer used.
main: Add helpers to extract GL_COLOR_INDEX to RGBA float/ubyte

We only use _mesa_make_temp_ubyte_image in texstore.c to convert
GL_COLOR_INDEX to RGBA, but this helper does more stuff than this.
All uses of this helper can be replaced with calls to
_mesa_format_convert except for this GL_COLOR_INDEX conversion.

This patch extracts the GL_COLOR_INDEX to RGBA logic to a separate
helper so we can use that instead from texstore.c.

The idea is that we will replace all remaining calls to
_mesa_make_temp_ubyte_image in the repository (related to compressed
formats) with calls to _mesa_format_convert, so we can remove
_mesa_make_temp_ubyte_image and related functions.
main: Remove _mesa_make_temp_ubyte_image

Now that we have _mesa_format_convert we don't need this.

texstore_rgba will use the GL_COLOR_INDEX to RGBA conversion
helpers instead and compressed formats that used
_mesa_make_temp_ubyte_image to create an ubyte RGBA temporary
image can call _mesa_texstore with a RGBA/ubyte dst to
achieve the same goal.
main: Remove _mesa_make_temp_float_image

Now that we have _mesa_format_convert we don't need this.

This was only used to create temporary RGBA float images in the process
of storing some compressed formats. These can call _mesa_texstore
with a RGBA/float dst to achieve the same goal.
main: Remove _mesa_unpack_color_span_ubyte

This is no longer used anywhere after moving to _mesa_format_convert.
main: Remove (signed) integer pack and span functions.

These are no longer used now that we moved to _mesa_format_convert.
swrast: Replace _mesa_unpack_color_span_float with _mesa_format_convert
swrast: Remove unused variable.
main: fix get_texbuffer_format().

It has wrongly assigned the mesa formats for GL_LUMINANCE_ALPHA16I_EXT
and GL_LUMINANCE_ALPHA32I_EXT internal formats.

This fixes a piglit regression in Gallium drivers because of clamping in
_mesa_swizzle_and_convert(). The affected test was:

   bin/arb_clear_buffer_object-formats

Signed-off-by: Samuel Iglesias Gonsalvez <correo@samuelig.es>