st_sample.c File Reference

Include dependency graph for st_sample.c:

Go to the source code of this file.

Data Structures

struct  dxt_data
 We don't want to include the patent-encumbered DXT code here, so instead we store several uncompressed/compressed data pairs for hardware testing purposes. More...

Functions

static uint32_t st_random (void)
 Use our own pseudo random generator to ensure consistent runs among multiple runs and platforms.
static void st_sample_dxt_pixel_block (enum pipe_format format, const struct pipe_format_block *block, uint8_t *raw, float *rgba, unsigned rgba_stride, unsigned w, unsigned h)
static void st_sample_generic_pixel_block (enum pipe_format format, const struct pipe_format_block *block, uint8_t *raw, float *rgba, unsigned rgba_stride, unsigned w, unsigned h)
void st_sample_pixel_block (enum pipe_format format, const struct pipe_format_block *block, void *raw, float *rgba, unsigned rgba_stride, unsigned w, unsigned h)
 Randomly sample pixels.
void st_sample_surface (struct pipe_surface *surface, float *rgba)

Variables

static struct dxt_data dxt1_rgb_data []
static struct dxt_data dxt1_rgba_data []
static struct dxt_data dxt3_rgba_data []
static struct dxt_data dxt5_rgba_data []


Function Documentation

static uint32_t st_random ( void   )  [static]

Use our own pseudo random generator to ensure consistent runs among multiple runs and platforms.

See also:
http://en.wikipedia.org/wiki/Linear_congruential_generator

Definition at line 46 of file st_sample.c.

00046                                 {
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 }

static void st_sample_dxt_pixel_block ( enum pipe_format  format,
const struct pipe_format_block block,
uint8_t *  raw,
float *  rgba,
unsigned  rgba_stride,
unsigned  w,
unsigned  h 
) [static]

Definition at line 424 of file st_sample.c.

References assert, PIPE_FORMAT_DXT1_RGB, PIPE_FORMAT_DXT1_RGBA, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT5_RGBA, dxt_data::rgba, pipe_format_block::size, and st_random().

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 }

static void st_sample_generic_pixel_block ( enum pipe_format  format,
const struct pipe_format_block block,
uint8_t *  raw,
float *  rgba,
unsigned  rgba_stride,
unsigned  w,
unsigned  h 
) [static]

Definition at line 468 of file st_sample.c.

References CLAMP, offset(), PIPE_FORMAT_YCBCR, PIPE_FORMAT_YCBCR_REV, pipe_tile_raw_to_rgba(), pipe_format_block::size, and st_random().

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 }

void st_sample_pixel_block ( enum pipe_format  format,
const struct pipe_format_block block,
void *  raw,
float *  rgba,
unsigned  rgba_stride,
unsigned  w,
unsigned  h 
)

Randomly sample pixels.

Definition at line 503 of file st_sample.c.

References PIPE_FORMAT_DXT1_RGB, PIPE_FORMAT_DXT1_RGBA, PIPE_FORMAT_DXT3_RGBA, PIPE_FORMAT_DXT5_RGBA, st_sample_dxt_pixel_block(), and st_sample_generic_pixel_block().

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 }

void st_sample_surface ( struct pipe_surface surface,
float *  rgba 
)

Definition at line 525 of file st_sample.c.

References pipe_surface::block, block(), pipe_surface::format, pipe_surface::height, pipe_format_block::height, MIN2, pipe_surface::nblocksx, pipe_surface::nblocksy, PIPE_BUFFER_USAGE_CPU_READ, pipe_surface_map(), pipe_surface_unmap(), pipe_format_block::size, st_sample_pixel_block(), pipe_surface::stride, pipe_format_block::width, and pipe_surface::width.

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 }


Variable Documentation

struct dxt_data dxt1_rgb_data[] [static]

Definition at line 68 of file st_sample.c.

struct dxt_data dxt1_rgba_data[] [static]

Definition at line 157 of file st_sample.c.

struct dxt_data dxt3_rgba_data[] [static]

Definition at line 246 of file st_sample.c.

struct dxt_data dxt5_rgba_data[] [static]

Definition at line 335 of file st_sample.c.


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