Squashed commit of the following:
[mesa.git] / src / gallium / auxiliary / util / u_tile.c
index 43b45eb92606c6b1332a2d1c91bb754c1cfb8ce9..fe327c302b7a27c2e20e1975faf9cfca75202bc2 100644 (file)
@@ -53,9 +53,9 @@ pipe_get_tile_raw(struct pipe_context *pipe,
    const void *src;
 
    if (dst_stride == 0)
-      dst_stride = util_format_get_stride(pt->texture->format, w);
+      dst_stride = util_format_get_stride(pt->resource->format, w);
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    src = pipe->transfer_map(pipe, pt);
@@ -63,7 +63,7 @@ pipe_get_tile_raw(struct pipe_context *pipe,
    if(!src)
       return;
 
-   util_copy_rect(dst, pt->texture->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
+   util_copy_rect(dst, pt->resource->format, dst_stride, 0, 0, w, h, src, pt->stride, x, y);
 
    pipe->transfer_unmap(pipe, pt);
 }
@@ -79,12 +79,12 @@ pipe_put_tile_raw(struct pipe_context *pipe,
                   const void *src, int src_stride)
 {
    void *dst;
-   enum pipe_format format = pt->texture->format;
+   enum pipe_format format = pt->resource->format;
 
    if (src_stride == 0)
       src_stride = util_format_get_stride(format, w);
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    dst = pipe->transfer_map(pipe, pt);
@@ -137,185 +137,6 @@ z16_get_tile_rgba(const ushort *src,
 
 
 
-/*** PIPE_FORMAT_A8B8G8R8_SRGB ***/
-
-/**
- * Convert an 8-bit sRGB value from non-linear space to a
- * linear RGB value in [0, 1].
- * Implemented with a 256-entry lookup table.
- */
-static INLINE float
-srgb_to_linear(ubyte cs8)
-{
-   static float table[256];
-   static boolean tableReady = FALSE;
-   if (!tableReady) {
-      /* compute lookup table now */
-      uint i;
-      for (i = 0; i < 256; i++) {
-         const float cs = ubyte_to_float(i);
-         if (cs <= 0.04045) {
-            table[i] = cs / 12.92f;
-         }
-         else {
-            table[i] = (float) powf((cs + 0.055) / 1.055, 2.4);
-         }
-      }
-      tableReady = TRUE;
-   }
-   return table[cs8];
-}
-
-
-/**
- * Convert linear float in [0,1] to an srgb ubyte value in [0,255].
- * XXX this hasn't been tested (render to srgb surface).
- * XXX this needs optimization.
- */
-static INLINE ubyte
-linear_to_srgb(float cl)
-{
-   if (cl >= 1.0F)
-      return 255;
-   else if (cl >= 0.0031308F)
-      return float_to_ubyte(1.055F * powf(cl, 0.41666F) - 0.055F);
-   else if (cl > 0.0F)
-      return float_to_ubyte(12.92F * cl);
-   else
-      return 0.0;
-}
-
-
-static void
-a8r8g8b8_srgb_get_tile_rgba(const unsigned *src,
-                            unsigned w, unsigned h,
-                            float *p,
-                            unsigned dst_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      float *pRow = p;
-      for (j = 0; j < w; j++, pRow += 4) {
-         const unsigned pixel = *src++;
-         pRow[0] = srgb_to_linear((pixel >> 16) & 0xff);
-         pRow[1] = srgb_to_linear((pixel >>  8) & 0xff);
-         pRow[2] = srgb_to_linear((pixel >>  0) & 0xff);
-         pRow[3] = ubyte_to_float((pixel >> 24) & 0xff);
-      }
-      p += dst_stride;
-   }
-}
-
-static void
-a8r8g8b8_srgb_put_tile_rgba(unsigned *dst,
-                            unsigned w, unsigned h,
-                            const float *p,
-                            unsigned src_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      const float *pRow = p;
-      for (j = 0; j < w; j++, pRow += 4) {
-         unsigned r, g, b, a;
-         r = linear_to_srgb(pRow[0]);
-         g = linear_to_srgb(pRow[1]);
-         b = linear_to_srgb(pRow[2]);
-         a = float_to_ubyte(pRow[3]);
-         *dst++ = (a << 24) | (r << 16) | (g << 8) | b;
-      }
-      p += src_stride;
-   }
-}
-
-
-/*** PIPE_FORMAT_L8A8_SRGB ***/
-
-static void
-a8l8_srgb_get_tile_rgba(const ushort *src,
-                        unsigned w, unsigned h,
-                        float *p,
-                        unsigned dst_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      float *pRow = p;
-      for (j = 0; j < w; j++, pRow += 4) {
-         ushort p = *src++;
-         pRow[0] =
-         pRow[1] =
-         pRow[2] = srgb_to_linear(p & 0xff);
-         pRow[3] = ubyte_to_float(p >> 8);
-      }
-      p += dst_stride;
-   }
-}
-
-static void
-a8l8_srgb_put_tile_rgba(ushort *dst,
-                        unsigned w, unsigned h,
-                        const float *p,
-                        unsigned src_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      const float *pRow = p;
-      for (j = 0; j < w; j++, pRow += 4) {
-         unsigned r, a;
-         r = linear_to_srgb(pRow[0]);
-         a = float_to_ubyte(pRow[3]);
-         *dst++ = (a << 8) | r;
-      }
-      p += src_stride;
-   }
-}
-
-
-/*** PIPE_FORMAT_L8_SRGB ***/
-
-static void
-l8_srgb_get_tile_rgba(const ubyte *src,
-                      unsigned w, unsigned h,
-                      float *p,
-                      unsigned dst_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      float *pRow = p;
-      for (j = 0; j < w; j++, src++, pRow += 4) {
-         pRow[0] =
-         pRow[1] =
-         pRow[2] = srgb_to_linear(*src);
-         pRow[3] = 1.0;
-      }
-      p += dst_stride;
-   }
-}
-
-static void
-l8_srgb_put_tile_rgba(ubyte *dst,
-                      unsigned w, unsigned h,
-                      const float *p,
-                      unsigned src_stride)
-{
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      const float *pRow = p;
-      for (j = 0; j < w; j++, pRow += 4) {
-         unsigned r;
-         r = linear_to_srgb(pRow[0]);
-         *dst++ = (ubyte) r;
-      }
-      p += src_stride;
-   }
-}
-
-
 /*** PIPE_FORMAT_Z32_UNORM ***/
 
 /**
@@ -423,94 +244,6 @@ z32f_get_tile_rgba(const float *src,
 }
 
 
-/*** PIPE_FORMAT_UYVY / PIPE_FORMAT_YUYV ***/
-
-/**
- * Convert YCbCr (or YCrCb) to RGBA.
- */
-static void
-ycbcr_get_tile_rgba(const ushort *src,
-                    unsigned w, unsigned h,
-                    float *p,
-                    unsigned dst_stride,
-                    boolean rev)
-{
-   const float scale = 1.0f / 255.0f;
-   unsigned i, j;
-
-   for (i = 0; i < h; i++) {
-      float *pRow = p;
-      /* do two texels at a time */
-      for (j = 0; j < (w & ~1); j += 2, src += 2) {
-         const ushort t0 = src[0];
-         const ushort t1 = src[1];
-         const ubyte y0 = (t0 >> 8) & 0xff;  /* luminance */
-         const ubyte y1 = (t1 >> 8) & 0xff;  /* luminance */
-         ubyte cb, cr;
-         float r, g, b;
-
-         if (rev) {
-            cb = t1 & 0xff;         /* chroma U */
-            cr = t0 & 0xff;         /* chroma V */
-         }
-         else {
-            cb = t0 & 0xff;         /* chroma U */
-            cr = t1 & 0xff;         /* chroma V */
-         }
-
-         /* even pixel: y0,cr,cb */
-         r = 1.164f * (y0-16) + 1.596f * (cr-128);
-         g = 1.164f * (y0-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
-         b = 1.164f * (y0-16) + 2.018f * (cb-128);
-         pRow[0] = r * scale;
-         pRow[1] = g * scale;
-         pRow[2] = b * scale;
-         pRow[3] = 1.0f;
-         pRow += 4;
-
-         /* odd pixel: use y1,cr,cb */
-         r = 1.164f * (y1-16) + 1.596f * (cr-128);
-         g = 1.164f * (y1-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
-         b = 1.164f * (y1-16) + 2.018f * (cb-128);
-         pRow[0] = r * scale;
-         pRow[1] = g * scale;
-         pRow[2] = b * scale;
-         pRow[3] = 1.0f;
-         pRow += 4;
-
-      }
-      /* do the last texel */
-      if (w & 1) {
-         const ushort t0 = src[0];
-         const ushort t1 = src[1];
-         const ubyte y0 = (t0 >> 8) & 0xff;  /* luminance */
-         ubyte cb, cr;
-         float r, g, b;
-
-         if (rev) {
-            cb = t1 & 0xff;         /* chroma U */
-            cr = t0 & 0xff;         /* chroma V */
-         }
-         else {
-            cb = t0 & 0xff;         /* chroma U */
-            cr = t1 & 0xff;         /* chroma V */
-         }
-
-         /* even pixel: y0,cr,cb */
-         r = 1.164f * (y0-16) + 1.596f * (cr-128);
-         g = 1.164f * (y0-16) - 0.813f * (cr-128) - 0.391f * (cb-128);
-         b = 1.164f * (y0-16) + 2.018f * (cb-128);
-         pRow[0] = r * scale;
-         pRow[1] = g * scale;
-         pRow[2] = b * scale;
-         pRow[3] = 1.0f;
-         pRow += 4;
-      }
-      p += dst_stride;
-   }
-}
-
-
 void
 pipe_tile_raw_to_rgba(enum pipe_format format,
                       void *src,
@@ -518,15 +251,6 @@ pipe_tile_raw_to_rgba(enum pipe_format format,
                       float *dst, unsigned dst_stride)
 {
    switch (format) {
-   case PIPE_FORMAT_B8G8R8A8_SRGB:
-      a8r8g8b8_srgb_get_tile_rgba((unsigned *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_L8A8_SRGB:
-      a8l8_srgb_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
-      break;
-   case PIPE_FORMAT_L8_SRGB:
-      l8_srgb_get_tile_rgba((ubyte *) src, w, h, dst, dst_stride);
-      break;
    case PIPE_FORMAT_Z16_UNORM:
       z16_get_tile_rgba((ushort *) src, w, h, dst, dst_stride);
       break;
@@ -544,12 +268,6 @@ pipe_tile_raw_to_rgba(enum pipe_format format,
    case PIPE_FORMAT_Z32_FLOAT:
       z32f_get_tile_rgba((float *) src, w, h, dst, dst_stride);
       break;
-   case PIPE_FORMAT_UYVY:
-      ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, FALSE);
-      break;
-   case PIPE_FORMAT_YUYV:
-      ycbcr_get_tile_rgba((ushort *) src, w, h, dst, dst_stride, TRUE);
-      break;
    default:
       util_format_read_4f(format,
                           dst, dst_stride * sizeof(float),
@@ -567,9 +285,9 @@ pipe_get_tile_rgba(struct pipe_context *pipe,
 {
    unsigned dst_stride = w * 4;
    void *packed;
-   enum pipe_format format = pt->texture->format;
+   enum pipe_format format = pt->resource->format;
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
@@ -604,10 +322,10 @@ pipe_get_tile_swizzle(struct pipe_context *pipe,
 {
    unsigned dst_stride = w * 4;
    void *packed;
-   uint i;
+   uint iy;
    float rgba01[6];
 
-   if (pipe_clip_tile(x, y, &w, &h, pt)) {
+   if (u_clip_tile(x, y, &w, &h, &pt->box)) {
       return;
    }
 
@@ -637,16 +355,22 @@ pipe_get_tile_swizzle(struct pipe_context *pipe,
    rgba01[PIPE_SWIZZLE_ZERO] = 0.0f;
    rgba01[PIPE_SWIZZLE_ONE] = 1.0f;
 
-   for (i = 0; i < w * h; i++) {
-      rgba01[PIPE_SWIZZLE_RED] = p[0];
-      rgba01[PIPE_SWIZZLE_GREEN] = p[1];
-      rgba01[PIPE_SWIZZLE_BLUE] = p[2];
-      rgba01[PIPE_SWIZZLE_ALPHA] = p[3];
+   for (iy = 0; iy < h; iy++) {
+      float *row = p;
+      uint ix;
+
+      for (ix = 0; ix < w; ix++) {
+         rgba01[PIPE_SWIZZLE_RED] = row[0];
+         rgba01[PIPE_SWIZZLE_GREEN] = row[1];
+         rgba01[PIPE_SWIZZLE_BLUE] = row[2];
+         rgba01[PIPE_SWIZZLE_ALPHA] = row[3];
 
-      *p++ = rgba01[swizzle_r];
-      *p++ = rgba01[swizzle_g];
-      *p++ = rgba01[swizzle_b];
-      *p++ = rgba01[swizzle_a];
+         *row++ = rgba01[swizzle_r];
+         *row++ = rgba01[swizzle_g];
+         *row++ = rgba01[swizzle_b];
+         *row++ = rgba01[swizzle_a];
+      }
+      p += dst_stride;
    }
 }
 
@@ -659,9 +383,9 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
 {
    unsigned src_stride = w * 4;
    void *packed;
-   enum pipe_format format = pt->texture->format;
+   enum pipe_format format = pt->resource->format;
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    packed = MALLOC(util_format_get_nblocks(format, w, h) * util_format_get_blocksize(format));
@@ -670,15 +394,6 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
       return;
 
    switch (format) {
-   case PIPE_FORMAT_B8G8R8A8_SRGB:
-      a8r8g8b8_srgb_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);
-      break;
-   case PIPE_FORMAT_L8A8_SRGB:
-      a8l8_srgb_put_tile_rgba((ushort *) packed, w, h, p, src_stride);
-      break;
-   case PIPE_FORMAT_L8_SRGB:
-      l8_srgb_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);
-      break;
    case PIPE_FORMAT_Z16_UNORM:
       /*z16_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
       break;
@@ -719,9 +434,9 @@ pipe_get_tile_z(struct pipe_context *pipe,
    ubyte *map;
    uint *pDest = z;
    uint i, j;
-   enum pipe_format format = pt->texture->format;
+   enum pipe_format format = pt->resource->format;
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    map = (ubyte *)pipe->transfer_map(pipe, pt);
@@ -804,9 +519,9 @@ pipe_put_tile_z(struct pipe_context *pipe,
    const uint *ptrc = zSrc;
    ubyte *map;
    uint i, j;
-   enum pipe_format format = pt->texture->format;
+   enum pipe_format format = pt->resource->format;
 
-   if (pipe_clip_tile(x, y, &w, &h, pt))
+   if (u_clip_tile(x, y, &w, &h, &pt->box))
       return;
 
    map = (ubyte *)pipe->transfer_map(pipe, pt);
@@ -829,7 +544,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
-         assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
+         //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z, preserve stencil */
@@ -856,7 +571,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
       {
          uint *pDest = (uint *) (map + y * pt->stride + x*4);
-         assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
+         //assert((pt->usage & PIPE_TRANSFER_READ_WRITE) == PIPE_TRANSFER_READ_WRITE);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z, preserve stencil */