st_sample.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 
00029 #include "pipe/p_compiler.h"
00030 #include "pipe/p_format.h"
00031 #include "pipe/p_state.h"
00032 #include "pipe/p_inlines.h"
00033 #include "util/u_tile.h"
00034 #include "util/u_math.h"
00035 #include "util/u_memory.h"
00036 
00037 #include "st_sample.h"
00038 
00039 
00046 static uint32_t st_random(void) {
00047    static uint64_t seed = UINT64_C(0xbb9a063afb0a739d);
00048 
00049    seed = UINT64_C(134775813) * seed + UINT64_C(1);
00050    
00051    return (uint16_t)(seed >> 32); 
00052 }
00053 
00054 
00060 struct dxt_data
00061 {
00062    uint8_t rgba[16*4];
00063    uint8_t raw[16];
00064 };
00065 
00066 
00067 static const struct dxt_data 
00068 dxt1_rgb_data[] = {
00069    {
00070       {
00071          0x99, 0xb0, 0x8e, 0xff,
00072          0x5d, 0x62, 0x89, 0xff,
00073          0x99, 0xb0, 0x8e, 0xff,
00074          0x99, 0xb0, 0x8e, 0xff,
00075          0xd6, 0xff, 0x94, 0xff,
00076          0x5d, 0x62, 0x89, 0xff,
00077          0x99, 0xb0, 0x8e, 0xff,
00078          0xd6, 0xff, 0x94, 0xff,
00079          0x5d, 0x62, 0x89, 0xff,
00080          0x5d, 0x62, 0x89, 0xff,
00081          0x99, 0xb0, 0x8e, 0xff,
00082          0x21, 0x14, 0x84, 0xff,
00083          0x5d, 0x62, 0x89, 0xff,
00084          0x21, 0x14, 0x84, 0xff,
00085          0x21, 0x14, 0x84, 0xff,
00086          0x99, 0xb0, 0x8e, 0xff
00087       },
00088       {0xf2, 0xd7, 0xb0, 0x20, 0xae, 0x2c, 0x6f, 0x97}
00089    },
00090    {
00091       {
00092          0xb5, 0xcf, 0x9c, 0xff,
00093          0x83, 0x8c, 0x8b, 0xff,
00094          0x21, 0x08, 0x6b, 0xff,
00095          0x83, 0x8c, 0x8b, 0xff,
00096          0x52, 0x4a, 0x7b, 0xff,
00097          0x83, 0x8c, 0x8b, 0xff,
00098          0x83, 0x8c, 0x8b, 0xff,
00099          0xb5, 0xcf, 0x9c, 0xff,
00100          0x21, 0x08, 0x6b, 0xff,
00101          0xb5, 0xcf, 0x9c, 0xff,
00102          0x83, 0x8c, 0x8b, 0xff,
00103          0x52, 0x4a, 0x7b, 0xff,
00104          0xb5, 0xcf, 0x9c, 0xff,
00105          0x83, 0x8c, 0x8b, 0xff,
00106          0x52, 0x4a, 0x7b, 0xff,
00107          0x83, 0x8c, 0x8b, 0xff
00108       },
00109       {0x73, 0xb6, 0x4d, 0x20, 0x98, 0x2b, 0xe1, 0xb8}
00110    },
00111    {
00112       {
00113          0x00, 0x2c, 0xff, 0xff,
00114          0x94, 0x8d, 0x7b, 0xff,
00115          0x4a, 0x5c, 0xbd, 0xff,
00116          0x4a, 0x5c, 0xbd, 0xff,
00117          0x4a, 0x5c, 0xbd, 0xff,
00118          0x94, 0x8d, 0x7b, 0xff,
00119          0x94, 0x8d, 0x7b, 0xff,
00120          0x94, 0x8d, 0x7b, 0xff,
00121          0xde, 0xbe, 0x39, 0xff,
00122          0x94, 0x8d, 0x7b, 0xff,
00123          0xde, 0xbe, 0x39, 0xff,
00124          0xde, 0xbe, 0x39, 0xff,
00125          0xde, 0xbe, 0x39, 0xff,
00126          0xde, 0xbe, 0x39, 0xff,
00127          0xde, 0xbe, 0x39, 0xff,
00128          0x94, 0x8d, 0x7b, 0xff
00129       },
00130       {0xe7, 0xdd, 0x7f, 0x01, 0xf9, 0xab, 0x08, 0x80}
00131    },
00132    {
00133       {
00134          0x6b, 0x24, 0x21, 0xff,
00135          0x7b, 0x4f, 0x5d, 0xff,
00136          0x7b, 0x4f, 0x5d, 0xff,
00137          0x8b, 0x7a, 0x99, 0xff,
00138          0x7b, 0x4f, 0x5d, 0xff,
00139          0x7b, 0x4f, 0x5d, 0xff,
00140          0x6b, 0x24, 0x21, 0xff,
00141          0x8b, 0x7a, 0x99, 0xff,
00142          0x9c, 0xa6, 0xd6, 0xff,
00143          0x6b, 0x24, 0x21, 0xff,
00144          0x7b, 0x4f, 0x5d, 0xff,
00145          0x8b, 0x7a, 0x99, 0xff,
00146          0x6b, 0x24, 0x21, 0xff,
00147          0x8b, 0x7a, 0x99, 0xff,
00148          0x7b, 0x4f, 0x5d, 0xff,
00149          0x9c, 0xa6, 0xd6, 0xff
00150       },
00151       {0x3a, 0x9d, 0x24, 0x69, 0xbd, 0x9f, 0xb4, 0x39}
00152    }
00153 };
00154 
00155 
00156 static const struct dxt_data 
00157 dxt1_rgba_data[] = {
00158    {
00159       {
00160          0x00, 0x00, 0x00, 0x00,
00161          0x4e, 0xaa, 0x90, 0xff,
00162          0x4e, 0xaa, 0x90, 0xff,
00163          0x00, 0x00, 0x00, 0x00,
00164          0x4e, 0xaa, 0x90, 0xff,
00165          0x29, 0xff, 0xff, 0xff,
00166          0x00, 0x00, 0x00, 0x00,
00167          0x4e, 0xaa, 0x90, 0xff,
00168          0x73, 0x55, 0x21, 0xff,
00169          0x00, 0x00, 0x00, 0x00,
00170          0x00, 0x00, 0x00, 0x00,
00171          0x4e, 0xaa, 0x90, 0xff,
00172          0x4e, 0xaa, 0x90, 0xff,
00173          0x00, 0x00, 0x00, 0x00,
00174          0x00, 0x00, 0x00, 0x00,
00175          0x4e, 0xaa, 0x90, 0xff
00176       },
00177       {0xff, 0x2f, 0xa4, 0x72, 0xeb, 0xb2, 0xbd, 0xbe}
00178    },
00179    {
00180       {
00181          0xb5, 0xe3, 0x63, 0xff,
00182          0x00, 0x00, 0x00, 0x00,
00183          0x6b, 0x24, 0x84, 0xff,
00184          0xb5, 0xe3, 0x63, 0xff,
00185          0x00, 0x00, 0x00, 0x00,
00186          0xb5, 0xe3, 0x63, 0xff,
00187          0x00, 0x00, 0x00, 0x00,
00188          0x00, 0x00, 0x00, 0x00,
00189          0x00, 0x00, 0x00, 0x00,
00190          0x00, 0x00, 0x00, 0x00,
00191          0x6b, 0x24, 0x84, 0xff,
00192          0x6b, 0x24, 0x84, 0xff,
00193          0x00, 0x00, 0x00, 0x00,
00194          0xb5, 0xe3, 0x63, 0xff,
00195          0x90, 0x83, 0x73, 0xff,
00196          0xb5, 0xe3, 0x63, 0xff
00197       },
00198       {0x30, 0x69, 0x0c, 0xb7, 0x4d, 0xf7, 0x0f, 0x67}
00199    },
00200    {
00201       {
00202          0x00, 0x00, 0x00, 0x00,
00203          0xc6, 0x86, 0x8c, 0xff,
00204          0xc6, 0x86, 0x8c, 0xff,
00205          0x21, 0x65, 0x42, 0xff,
00206          0x21, 0x65, 0x42, 0xff,
00207          0x21, 0x65, 0x42, 0xff,
00208          0x21, 0x65, 0x42, 0xff,
00209          0x00, 0x00, 0x00, 0x00,
00210          0x00, 0x00, 0x00, 0x00,
00211          0x21, 0x65, 0x42, 0xff,
00212          0xc6, 0x86, 0x8c, 0xff,
00213          0x00, 0x00, 0x00, 0x00,
00214          0x00, 0x00, 0x00, 0x00,
00215          0x00, 0x00, 0x00, 0x00,
00216          0x00, 0x00, 0x00, 0x00,
00217          0xc6, 0x86, 0x8c, 0xff
00218       },
00219       {0x28, 0x23, 0x31, 0xc4, 0x17, 0xc0, 0xd3, 0x7f}
00220    },
00221    {
00222       {
00223          0x00, 0x00, 0x00, 0x00,
00224          0x00, 0x00, 0x00, 0x00,
00225          0x00, 0x00, 0x00, 0x00,
00226          0xc6, 0xe3, 0x9c, 0xff,
00227          0x7b, 0x1c, 0x52, 0xff,
00228          0x00, 0x00, 0x00, 0x00,
00229          0x00, 0x00, 0x00, 0x00,
00230          0x00, 0x00, 0x00, 0x00,
00231          0x00, 0x00, 0x00, 0x00,
00232          0x7b, 0x1c, 0x52, 0xff,
00233          0x00, 0x00, 0x00, 0x00,
00234          0x7b, 0x1c, 0x52, 0xff,
00235          0xa0, 0x7f, 0x77, 0xff,
00236          0xc6, 0xe3, 0x9c, 0xff,
00237          0x00, 0x00, 0x00, 0x00,
00238          0xa0, 0x7f, 0x77, 0xff
00239       },
00240       {0xea, 0x78, 0x13, 0xc7, 0x7f, 0xfc, 0x33, 0xb6}
00241    },
00242 };
00243 
00244 
00245 static const struct dxt_data 
00246 dxt3_rgba_data[] = {
00247    {
00248       {
00249          0x6d, 0xc6, 0x96, 0x77,
00250          0x6d, 0xc6, 0x96, 0xee,
00251          0x6d, 0xc6, 0x96, 0xaa,
00252          0x8c, 0xff, 0xb5, 0x44,
00253          0x6d, 0xc6, 0x96, 0xff,
00254          0x6d, 0xc6, 0x96, 0x88,
00255          0x31, 0x55, 0x5a, 0x66,
00256          0x6d, 0xc6, 0x96, 0x99,
00257          0x31, 0x55, 0x5a, 0xbb,
00258          0x31, 0x55, 0x5a, 0x55,
00259          0x31, 0x55, 0x5a, 0x11,
00260          0x6d, 0xc6, 0x96, 0xcc,
00261          0x6d, 0xc6, 0x96, 0xcc,
00262          0x6d, 0xc6, 0x96, 0x11,
00263          0x31, 0x55, 0x5a, 0x44,
00264          0x31, 0x55, 0x5a, 0x88
00265       },
00266       {0xe7, 0x4a, 0x8f, 0x96, 0x5b, 0xc1, 0x1c, 0x84, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
00267    },
00268    {
00269       {
00270          0xad, 0xeb, 0x73, 0x99,
00271          0x97, 0xaa, 0x86, 0x66,
00272          0x6b, 0x28, 0xad, 0x99,
00273          0xad, 0xeb, 0x73, 0x99,
00274          0x6b, 0x28, 0xad, 0x22,
00275          0xad, 0xeb, 0x73, 0xff,
00276          0x97, 0xaa, 0x86, 0x55,
00277          0x6b, 0x28, 0xad, 0x55,
00278          0x6b, 0x28, 0xad, 0x44,
00279          0xad, 0xeb, 0x73, 0x33,
00280          0x6b, 0x28, 0xad, 0xee,
00281          0x6b, 0x28, 0xad, 0x99,
00282          0x97, 0xaa, 0x86, 0x66,
00283          0xad, 0xeb, 0x73, 0xbb,
00284          0x97, 0xaa, 0x86, 0x99,
00285          0xad, 0xeb, 0x73, 0xbb
00286       },
00287       {0x69, 0x99, 0xf2, 0x55, 0x34, 0x9e, 0xb6, 0xb9, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
00288    },
00289    {
00290       {
00291          0x63, 0xd7, 0xd6, 0x00,
00292          0x57, 0x62, 0x5d, 0xdd,
00293          0x57, 0x62, 0x5d, 0xcc,
00294          0x57, 0x62, 0x5d, 0xbb,
00295          0x52, 0x28, 0x21, 0xaa,
00296          0x57, 0x62, 0x5d, 0xcc,
00297          0x57, 0x62, 0x5d, 0xcc,
00298          0x57, 0x62, 0x5d, 0x66,
00299          0x57, 0x62, 0x5d, 0x22,
00300          0x57, 0x62, 0x5d, 0xdd,
00301          0x63, 0xd7, 0xd6, 0xee,
00302          0x57, 0x62, 0x5d, 0x33,
00303          0x63, 0xd7, 0xd6, 0x55,
00304          0x52, 0x28, 0x21, 0x55,
00305          0x57, 0x62, 0x5d, 0x11,
00306          0x5d, 0x9c, 0x99, 0xee
00307       },
00308       {0xd0, 0xbc, 0xca, 0x6c, 0xd2, 0x3e, 0x55, 0xe1, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
00309    },
00310    {
00311       {
00312          0x94, 0x6f, 0x60, 0x22,
00313          0x94, 0x6f, 0x60, 0x22,
00314          0xc5, 0xab, 0x76, 0x11,
00315          0xc5, 0xab, 0x76, 0xee,
00316          0x63, 0x34, 0x4a, 0xdd,
00317          0x63, 0x34, 0x4a, 0x33,
00318          0x94, 0x6f, 0x60, 0x77,
00319          0xf7, 0xe7, 0x8c, 0x00,
00320          0x94, 0x6f, 0x60, 0x33,
00321          0x63, 0x34, 0x4a, 0xaa,
00322          0x94, 0x6f, 0x60, 0x77,
00323          0x63, 0x34, 0x4a, 0xcc,
00324          0x94, 0x6f, 0x60, 0xaa,
00325          0xf7, 0xe7, 0x8c, 0x99,
00326          0x63, 0x34, 0x4a, 0x44,
00327          0xc5, 0xab, 0x76, 0xaa
00328       },
00329       {0x22, 0xe1, 0x3d, 0x07, 0xa3, 0xc7, 0x9a, 0xa4, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
00330    },
00331 };
00332 
00333 
00334 static const struct dxt_data 
00335 dxt5_rgba_data[] = {
00336    {
00337       {
00338          0x6d, 0xc6, 0x96, 0x74,
00339          0x6d, 0xc6, 0x96, 0xf8,
00340          0x6d, 0xc6, 0x96, 0xb6,
00341          0x8c, 0xff, 0xb5, 0x53,
00342          0x6d, 0xc6, 0x96, 0xf8,
00343          0x6d, 0xc6, 0x96, 0x95,
00344          0x31, 0x55, 0x5a, 0x53,
00345          0x6d, 0xc6, 0x96, 0x95,
00346          0x31, 0x55, 0x5a, 0xb6,
00347          0x31, 0x55, 0x5a, 0x53,
00348          0x31, 0x55, 0x5a, 0x11,
00349          0x6d, 0xc6, 0x96, 0xd7,
00350          0x6d, 0xc6, 0x96, 0xb6,
00351          0x6d, 0xc6, 0x96, 0x11,
00352          0x31, 0x55, 0x5a, 0x32,
00353          0x31, 0x55, 0x5a, 0x95
00354       },
00355       {0xf8, 0x11, 0xc5, 0x0c, 0x9a, 0x73, 0xb4, 0x9c, 0xf6, 0x8f, 0xab, 0x32, 0x2a, 0x9a, 0x95, 0x5a}
00356    },
00357    {
00358       {
00359          0xad, 0xeb, 0x73, 0xa1,
00360          0x97, 0xaa, 0x86, 0x65,
00361          0x6b, 0x28, 0xad, 0xa1,
00362          0xad, 0xeb, 0x73, 0xa1,
00363          0x6b, 0x28, 0xad, 0x2a,
00364          0xad, 0xeb, 0x73, 0xfb,
00365          0x97, 0xaa, 0x86, 0x47,
00366          0x6b, 0x28, 0xad, 0x65,
00367          0x6b, 0x28, 0xad, 0x47,
00368          0xad, 0xeb, 0x73, 0x47,
00369          0x6b, 0x28, 0xad, 0xdd,
00370          0x6b, 0x28, 0xad, 0xa1,
00371          0x97, 0xaa, 0x86, 0x65,
00372          0xad, 0xeb, 0x73, 0xbf,
00373          0x97, 0xaa, 0x86, 0xa1,
00374          0xad, 0xeb, 0x73, 0xbf
00375       },
00376       {0xfb, 0x2a, 0x34, 0x19, 0xdc, 0xbf, 0xe8, 0x71, 0x4e, 0xaf, 0x55, 0x69, 0x18, 0x61, 0x51, 0x22}
00377    },
00378    {
00379       {
00380          0x63, 0xd7, 0xd6, 0x00,
00381          0x57, 0x62, 0x5d, 0xf5,
00382          0x57, 0x62, 0x5d, 0xd2,
00383          0x57, 0x62, 0x5d, 0xaf,
00384          0x52, 0x28, 0x21, 0xaf,
00385          0x57, 0x62, 0x5d, 0xd2,
00386          0x57, 0x62, 0x5d, 0xd2,
00387          0x57, 0x62, 0x5d, 0x69,
00388          0x57, 0x62, 0x5d, 0x23,
00389          0x57, 0x62, 0x5d, 0xd2,
00390          0x63, 0xd7, 0xd6, 0xf5,
00391          0x57, 0x62, 0x5d, 0x46,
00392          0x63, 0xd7, 0xd6, 0x46,
00393          0x52, 0x28, 0x21, 0x69,
00394          0x57, 0x62, 0x5d, 0x23,
00395          0x5d, 0x9c, 0x99, 0xf5
00396       },
00397       {0xf5, 0x00, 0x81, 0x36, 0xa9, 0x17, 0xec, 0x1e, 0xba, 0x66, 0x44, 0x51, 0xfc, 0xfd, 0xcf, 0xb4}
00398    },
00399    {
00400       {
00401          0x94, 0x6f, 0x60, 0x25,
00402          0x94, 0x6f, 0x60, 0x25,
00403          0xc5, 0xab, 0x76, 0x05,
00404          0xc5, 0xab, 0x76, 0xe8,
00405          0x63, 0x34, 0x4a, 0xe8,
00406          0x63, 0x34, 0x4a, 0x25,
00407          0x94, 0x6f, 0x60, 0x86,
00408          0xf7, 0xe7, 0x8c, 0x05,
00409          0x94, 0x6f, 0x60, 0x25,
00410          0x63, 0x34, 0x4a, 0xa7,
00411          0x94, 0x6f, 0x60, 0x66,
00412          0x63, 0x34, 0x4a, 0xc7,
00413          0x94, 0x6f, 0x60, 0xa7,
00414          0xf7, 0xe7, 0x8c, 0xa7,
00415          0x63, 0x34, 0x4a, 0x45,
00416          0xc5, 0xab, 0x76, 0xa7
00417       },
00418       {0xe8, 0x05, 0x7f, 0x80, 0x33, 0x5f, 0xb5, 0x79, 0x31, 0xf7, 0xa9, 0x61, 0xaf, 0x35, 0x77, 0x93}
00419    },
00420 };
00421 
00422 
00423 static INLINE void 
00424 st_sample_dxt_pixel_block(enum pipe_format format, 
00425                           const struct pipe_format_block *block,
00426                           uint8_t *raw,
00427                           float *rgba, unsigned rgba_stride, 
00428                           unsigned w, unsigned h)
00429 {
00430    const struct dxt_data *data;
00431    unsigned n;
00432    unsigned i;
00433    unsigned x, y, ch;
00434    
00435    switch(format) {
00436    case PIPE_FORMAT_DXT1_RGB:
00437       data = dxt1_rgb_data;
00438       n = sizeof(dxt1_rgb_data)/sizeof(dxt1_rgb_data[0]);
00439       break;
00440    case PIPE_FORMAT_DXT1_RGBA:
00441       data = dxt1_rgba_data;
00442       n = sizeof(dxt1_rgba_data)/sizeof(dxt1_rgba_data[0]);
00443       break;
00444    case PIPE_FORMAT_DXT3_RGBA:
00445       data = dxt3_rgba_data;
00446       n = sizeof(dxt3_rgba_data)/sizeof(dxt3_rgba_data[0]);
00447       break;
00448    case PIPE_FORMAT_DXT5_RGBA:
00449       data = dxt5_rgba_data;
00450       n = sizeof(dxt5_rgba_data)/sizeof(dxt5_rgba_data[0]);
00451       break;
00452    default:
00453       assert(0);
00454    }
00455    
00456    i = st_random() % n;
00457    
00458    for(y = 0; y < h; ++y)
00459       for(x = 0; x < w; ++x)
00460          for(ch = 0; ch < 4; ++ch)
00461             rgba[y*rgba_stride + x*4 + ch] = (float)(data[i].rgba[y*4*4 + x*4 + ch])/255.0f;
00462    
00463    memcpy(raw, data[i].raw, block->size);
00464 }
00465 
00466 
00467 static INLINE void 
00468 st_sample_generic_pixel_block(enum pipe_format format, 
00469                               const struct pipe_format_block *block,
00470                               uint8_t *raw,
00471                               float *rgba, unsigned rgba_stride,
00472                               unsigned w, unsigned h)
00473 {
00474    unsigned i;
00475    unsigned x, y, ch;
00476    
00477    for(i = 0; i < block->size; ++i)
00478       raw[i] = (uint8_t)st_random();
00479    
00480    
00481    pipe_tile_raw_to_rgba(format,
00482                          raw,
00483                          w, h,
00484                          rgba, rgba_stride);
00485  
00486    if(format == PIPE_FORMAT_YCBCR || format == PIPE_FORMAT_YCBCR_REV) {
00487       for(y = 0; y < h; ++y) {
00488          for(x = 0; x < w; ++x) {
00489             for(ch = 0; ch < 4; ++ch) {
00490                unsigned offset = y*rgba_stride + x*4 + ch;
00491                rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f);
00492             }
00493          }
00494       }
00495    }
00496 }
00497 
00498 
00502 void 
00503 st_sample_pixel_block(enum pipe_format format,
00504                       const struct pipe_format_block *block,
00505                       void *raw,
00506                       float *rgba, unsigned rgba_stride,
00507                       unsigned w, unsigned h)
00508 {
00509    switch(format) {
00510    case PIPE_FORMAT_DXT1_RGB:
00511    case PIPE_FORMAT_DXT1_RGBA:
00512    case PIPE_FORMAT_DXT3_RGBA:
00513    case PIPE_FORMAT_DXT5_RGBA:
00514       st_sample_dxt_pixel_block(format, block, raw, rgba, rgba_stride, w, h);
00515       break;
00516 
00517    default:
00518       st_sample_generic_pixel_block(format, block, raw, rgba, rgba_stride, w, h);
00519       break;
00520    }
00521 }
00522 
00523 
00524 void
00525 st_sample_surface(struct pipe_surface *surface, float *rgba) 
00526 {
00527    const struct pipe_format_block *block = &surface->block;
00528    unsigned rgba_stride = surface->width*4;
00529    void *raw;
00530    unsigned x, y;
00531 
00532    raw = pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_READ);
00533    if(!raw)
00534       return;
00535 
00536    for (y = 0; y < surface->nblocksy; ++y) {
00537       for(x = 0; x < surface->nblocksx; ++x) {
00538          st_sample_pixel_block(surface->format,
00539                                block,
00540                                (uint8_t*)raw + y*surface->stride + x*block->size, 
00541                                rgba + y*block->height*rgba_stride + x*block->width*4,
00542                                rgba_stride,
00543                                MIN2(block->width, surface->width - x*block->width), 
00544                                MIN2(block->height, surface->height - y*block->height));
00545        }
00546    }
00547    
00548    pipe_surface_unmap(surface);
00549 }

Generated on Tue Sep 29 06:25:17 2009 for Gallium3D by  doxygen 1.5.4