st/python: Allow to sample only in the [0,1] range.
authorJosé Fonseca <jfonseca@vmware.com>
Thu, 1 Apr 2010 16:35:46 +0000 (17:35 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Thu, 1 Apr 2010 16:46:59 +0000 (17:46 +0100)
src/gallium/state_trackers/python/p_context.i
src/gallium/state_trackers/python/st_sample.c
src/gallium/state_trackers/python/st_sample.h

index bccaeead015656eba309f5f8b7c5ecb261a55b81..02ce5647eb6c4c0ba91952ed076cadbccf0baae7 100644 (file)
@@ -589,9 +589,10 @@ error1:
 
    void
    surface_sample_rgba(struct st_surface *surface,
-                       float *rgba)
+                       float *rgba,
+                       int norm = 0)
    {
-      st_sample_surface($self->pipe, surface, rgba);
+      st_sample_surface($self->pipe, surface, rgba, norm != 0);
    }
 
    unsigned
index e2c1e0601747d25ba934afda5a28c3c74c76882d..218a77fb0a1e7e9ad713d69b182e1974343a1b47 100644 (file)
@@ -50,7 +50,7 @@ static uint32_t st_random(void) {
 
    seed = UINT64_C(134775813) * seed + UINT64_C(1);
    
-   return (uint16_t)(seed >> 32); 
+   return (uint32_t)(seed >> 32);
 }
 
 
@@ -470,25 +470,42 @@ static INLINE void
 st_sample_generic_pixel_block(enum pipe_format format, 
                               uint8_t *raw,
                               float *rgba, unsigned rgba_stride,
-                              unsigned w, unsigned h)
+                              unsigned w, unsigned h,
+                              boolean norm)
 {
    unsigned i;
    unsigned x, y, ch;
    int blocksize = util_format_get_blocksize(format);
    
-   for(i = 0; i < blocksize; ++i)
-      raw[i] = (uint8_t)st_random();
-   
-   
-   pipe_tile_raw_to_rgba(format,
-                         raw,
-                         w, h,
-                         rgba, rgba_stride);
-   if(format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
-      for(y = 0; y < h; ++y) {
-         for(x = 0; x < w; ++x) {
-            for(ch = 0; ch < 4; ++ch) {
+   if (norm) {
+      for (y = 0; y < h; ++y) {
+         for (x = 0; x < w; ++x) {
+            for (ch = 0; ch < 4; ++ch) {
+               unsigned offset = y*rgba_stride + x*4 + ch;
+               rgba[offset] = (st_random() & 0xff) / (double)0xff;
+            }
+         }
+      }
+
+      util_format_write_4f(format,
+                           rgba, rgba_stride * sizeof(float),
+                           raw, util_format_get_stride(format, w),
+                           0, 0, w, h);
+
+   } else {
+      for (i = 0; i < blocksize; ++i)
+         raw[i] = (uint8_t)st_random();
+   }
+
+   util_format_read_4f(format,
+                       rgba, rgba_stride * sizeof(float),
+                       raw, util_format_get_stride(format, w),
+                       0, 0, w, h);
+
+   if (format == PIPE_FORMAT_UYVY || format == PIPE_FORMAT_YUYV) {
+      for (y = 0; y < h; ++y) {
+         for (x = 0; x < w; ++x) {
+            for (ch = 0; ch < 4; ++ch) {
                unsigned offset = y*rgba_stride + x*4 + ch;
                rgba[offset] = CLAMP(rgba[offset], 0.0f, 1.0f);
             }
@@ -505,7 +522,8 @@ void
 st_sample_pixel_block(enum pipe_format format,
                       void *raw,
                       float *rgba, unsigned rgba_stride,
-                      unsigned w, unsigned h)
+                      unsigned w, unsigned h,
+                      boolean norm)
 {
    switch(format) {
    case PIPE_FORMAT_DXT1_RGB:
@@ -516,7 +534,7 @@ st_sample_pixel_block(enum pipe_format format,
       break;
 
    default:
-      st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h);
+      st_sample_generic_pixel_block(format, raw, rgba, rgba_stride, w, h, norm);
       break;
    }
 }
@@ -525,7 +543,8 @@ st_sample_pixel_block(enum pipe_format format,
 void
 st_sample_surface(struct pipe_context *pipe,
                   struct st_surface *surface,
-                  float *rgba)
+                  float *rgba,
+                  boolean norm)
 {
    struct pipe_texture *texture = surface->texture;
    unsigned width = u_minify(texture->width0, surface->level);
@@ -564,7 +583,8 @@ st_sample_surface(struct pipe_context *pipe,
                                   rgba + y * blockheight * rgba_stride + x * blockwidth * 4,
                                   rgba_stride,
                                   MIN2(blockwidth, width - x*blockwidth),
-                                  MIN2(blockheight, height - y*blockheight));
+                                  MIN2(blockheight, height - y*blockheight),
+                                  norm);
          }
       }
 
index 6fb8417add8895c1738314548c34e23ae8827129..2fdbb391f368c84b7f51b5e7b9128405db7c7616 100644 (file)
@@ -40,12 +40,14 @@ void
 st_sample_pixel_block(enum pipe_format format,
                       void *raw,
                       float *rgba, unsigned rgba_stride,
-                      unsigned w, unsigned h);
+                      unsigned w, unsigned h,
+                      boolean norm);
 
 void
 st_sample_surface(struct pipe_context *pipe,
                   struct st_surface *surface,
-                  float *rgba);
+                  float *rgba,
+                  boolean norm);
 
 
 #endif /* ST_SAMPLE_H_ */