#include "util/u_memory.h"
#include "util/u_rect.h"
#include "util/u_tile.h"
+#include "lp_tile_cache.h"
#include "lp_tile_soa.h"
#define PIXEL(_p, _x, _y, _c) ((_p)[(_c)*TILE_SIZE*TILE_SIZE + (_y)*TILE_SIZE + (_x)])
-/** Convert short in [-32768,32767] to GLfloat in [-1.0,1.0] */
-#define SHORT_TO_FLOAT(S) ((2.0F * (S) + 1.0F) * (1.0F/65535.0F))
-
-#define UNCLAMPED_FLOAT_TO_SHORT(us, f) \
- us = ( (short) ( CLAMP((f), -1.0, 1.0) * 32767.0F) )
-
-
/*** PIPE_FORMAT_A8R8G8B8_UNORM ***/
static void
a8r8g8b8_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const unsigned pixel = *src++;
- PIXEL(p, j, i, 0) = ubyte_to_float((pixel >> 16) & 0xff);
- PIXEL(p, j, i, 1) = ubyte_to_float((pixel >> 8) & 0xff);
- PIXEL(p, j, i, 2) = ubyte_to_float((pixel >> 0) & 0xff);
- PIXEL(p, j, i, 3) = ubyte_to_float((pixel >> 24) & 0xff);
+ PIXEL(p, j, i, 0) = (pixel >> 16) & 0xff;
+ PIXEL(p, j, i, 1) = (pixel >> 8) & 0xff;
+ PIXEL(p, j, i, 2) = (pixel >> 0) & 0xff;
+ PIXEL(p, j, i, 3) = (pixel >> 24) & 0xff;
}
}
}
static void
a8r8g8b8_put_tile_rgba(unsigned *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, g, b, a;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- g = float_to_ubyte(PIXEL(p, j, i, 1));
- b = float_to_ubyte(PIXEL(p, j, i, 2));
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ r = PIXEL(p, j, i, 0);
+ g = PIXEL(p, j, i, 1);
+ b = PIXEL(p, j, i, 2);
+ a = PIXEL(p, j, i, 3);
*dst++ = (a << 24) | (r << 16) | (g << 8) | b;
}
}
static void
x8r8g8b8_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const unsigned pixel = *src++;
- PIXEL(p, j, i, 0) = ubyte_to_float((pixel >> 16) & 0xff);
- PIXEL(p, j, i, 1) = ubyte_to_float((pixel >> 8) & 0xff);
- PIXEL(p, j, i, 2) = ubyte_to_float((pixel >> 0) & 0xff);
- PIXEL(p, j, i, 3) = ubyte_to_float(0xff);
+ PIXEL(p, j, i, 0) = (pixel >> 16) & 0xff;
+ PIXEL(p, j, i, 1) = (pixel >> 8) & 0xff;
+ PIXEL(p, j, i, 2) = (pixel >> 0) & 0xff;
+ PIXEL(p, j, i, 3) = 0xff;
}
}
}
static void
x8r8g8b8_put_tile_rgba(unsigned *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, g, b;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- g = float_to_ubyte(PIXEL(p, j, i, 1));
- b = float_to_ubyte(PIXEL(p, j, i, 2));
+ r = PIXEL(p, j, i, 0);
+ g = PIXEL(p, j, i, 1);
+ b = PIXEL(p, j, i, 2);
*dst++ = (0xff << 24) | (r << 16) | (g << 8) | b;
}
}
static void
b8g8r8a8_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const unsigned pixel = *src++;
- PIXEL(p, j, i, 0) = ubyte_to_float((pixel >> 8) & 0xff);
- PIXEL(p, j, i, 1) = ubyte_to_float((pixel >> 16) & 0xff);
- PIXEL(p, j, i, 2) = ubyte_to_float((pixel >> 24) & 0xff);
- PIXEL(p, j, i, 3) = ubyte_to_float((pixel >> 0) & 0xff);
+ PIXEL(p, j, i, 0) = (pixel >> 8) & 0xff;
+ PIXEL(p, j, i, 1) = (pixel >> 16) & 0xff;
+ PIXEL(p, j, i, 2) = (pixel >> 24) & 0xff;
+ PIXEL(p, j, i, 3) = (pixel >> 0) & 0xff;
}
}
}
static void
b8g8r8a8_put_tile_rgba(unsigned *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, g, b, a;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- g = float_to_ubyte(PIXEL(p, j, i, 1));
- b = float_to_ubyte(PIXEL(p, j, i, 2));
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ r = PIXEL(p, j, i, 0);
+ g = PIXEL(p, j, i, 1);
+ b = PIXEL(p, j, i, 2);
+ a = PIXEL(p, j, i, 3);
*dst++ = (b << 24) | (g << 16) | (r << 8) | a;
}
}
static void
a1r5g5b5_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const ushort pixel = *src++;
- PIXEL(p, j, i, 0) = ((pixel >> 10) & 0x1f) * (1.0f / 31.0f);
- PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x1f) * (1.0f / 31.0f);
- PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * (1.0f / 31.0f);
- PIXEL(p, j, i, 3) = ((pixel >> 15) ) * 1.0f;
+ PIXEL(p, j, i, 0) = ((pixel >> 10) & 0x1f) * 255 / 31;
+ PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x1f) * 255 / 31;
+ PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * 255 / 31;
+ PIXEL(p, j, i, 3) = ((pixel >> 15) ) * 255;
}
}
}
static void
a1r5g5b5_put_tile_rgba(ushort *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, g, b, a;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- g = float_to_ubyte(PIXEL(p, j, i, 1));
- b = float_to_ubyte(PIXEL(p, j, i, 2));
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ r = PIXEL(p, j, i, 0);
+ g = PIXEL(p, j, i, 1);
+ b = PIXEL(p, j, i, 2);
+ a = PIXEL(p, j, i, 3);
r = r >> 3; /* 5 bits */
g = g >> 3; /* 5 bits */
b = b >> 3; /* 5 bits */
static void
a4r4g4b4_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const ushort pixel = *src++;
- PIXEL(p, j, i, 0) = ((pixel >> 8) & 0xf) * (1.0f / 15.0f);
- PIXEL(p, j, i, 1) = ((pixel >> 4) & 0xf) * (1.0f / 15.0f);
- PIXEL(p, j, i, 2) = ((pixel ) & 0xf) * (1.0f / 15.0f);
- PIXEL(p, j, i, 3) = ((pixel >> 12) ) * (1.0f / 15.0f);
+ PIXEL(p, j, i, 0) = ((pixel >> 8) & 0xf) * 255 / 15;
+ PIXEL(p, j, i, 1) = ((pixel >> 4) & 0xf) * 255 / 15;
+ PIXEL(p, j, i, 2) = ((pixel ) & 0xf) * 255 / 15;
+ PIXEL(p, j, i, 3) = ((pixel >> 12) ) * 255 / 15;
}
}
}
static void
a4r4g4b4_put_tile_rgba(ushort *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, g, b, a;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- g = float_to_ubyte(PIXEL(p, j, i, 1));
- b = float_to_ubyte(PIXEL(p, j, i, 2));
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ r = PIXEL(p, j, i, 0);
+ g = PIXEL(p, j, i, 1);
+ b = PIXEL(p, j, i, 2);
+ a = PIXEL(p, j, i, 3);
r >>= 4;
g >>= 4;
b >>= 4;
static void
r5g6b5_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
const ushort pixel = *src++;
- PIXEL(p, j, i, 0) = ((pixel >> 11) & 0x1f) * (1.0f / 31.0f);
- PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x3f) * (1.0f / 63.0f);
- PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * (1.0f / 31.0f);
- PIXEL(p, j, i, 3) = 1.0f;
+ PIXEL(p, j, i, 0) = ((pixel >> 11) & 0x1f) * 255 / 31;
+ PIXEL(p, j, i, 1) = ((pixel >> 5) & 0x3f) * 255 / 63;
+ PIXEL(p, j, i, 2) = ((pixel ) & 0x1f) * 255 / 31;
+ PIXEL(p, j, i, 3) = 255;
}
}
}
static void
r5g6b5_put_tile_rgba(ushort *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
- uint r = (uint) (CLAMP(PIXEL(p, j, i, 0), 0.0, 1.0) * 31.0);
- uint g = (uint) (CLAMP(PIXEL(p, j, i, 1), 0.0, 1.0) * 63.0);
- uint b = (uint) (CLAMP(PIXEL(p, j, i, 2), 0.0, 1.0) * 31.0);
+ uint r = (uint) PIXEL(p, j, i, 0) * 31 / 255;
+ uint g = (uint) PIXEL(p, j, i, 1) * 63 / 255;
+ uint b = (uint) PIXEL(p, j, i, 2) * 31 / 255;
*dst++ = (r << 11) | (g << 5) | (b);
}
}
static void
z16_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
const float scale = 1.0f / 65535.0f;
unsigned i, j;
static void
l8_get_tile_rgba(const ubyte *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (j = 0; j < w; j++, src++) {
PIXEL(p, j, i, 0) =
PIXEL(p, j, i, 1) =
- PIXEL(p, j, i, 2) = ubyte_to_float(*src);
- PIXEL(p, j, i, 3) = 1.0;
+ PIXEL(p, j, i, 2) = *src;
+ PIXEL(p, j, i, 3) = 255;
}
}
}
static void
l8_put_tile_rgba(ubyte *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
+ r = PIXEL(p, j, i, 0);
*dst++ = (ubyte) r;
}
}
static void
a8_get_tile_rgba(const ubyte *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (j = 0; j < w; j++, src++) {
PIXEL(p, j, i, 0) =
PIXEL(p, j, i, 1) =
- PIXEL(p, j, i, 2) = 0.0;
- PIXEL(p, j, i, 3) = ubyte_to_float(*src);
+ PIXEL(p, j, i, 2) = 0;
+ PIXEL(p, j, i, 3) = *src;
}
}
}
static void
a8_put_tile_rgba(ubyte *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned a;
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ a = PIXEL(p, j, i, 3);
*dst++ = (ubyte) a;
}
}
static void
r16_get_tile_rgba(const short *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++, src++) {
- PIXEL(p, j, i, 0) = SHORT_TO_FLOAT(src[0]);
+ PIXEL(p, j, i, 0) = MAX2(src[0] >> 7, 0);
PIXEL(p, j, i, 1) =
- PIXEL(p, j, i, 2) = 0.0;
- PIXEL(p, j, i, 3) = 1.0;
+ PIXEL(p, j, i, 2) = 0;
+ PIXEL(p, j, i, 3) = 255;
}
}
}
static void
r16_put_tile_rgba(short *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++, dst++) {
- UNCLAMPED_FLOAT_TO_SHORT(dst[0], PIXEL(p, j, i, 0));
+ dst[0] = PIXEL(p, j, i, 0) << 7;
}
}
}
static void
r16g16b16a16_get_tile_rgba(const short *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++, src += 4) {
- PIXEL(p, j, i, 0) = SHORT_TO_FLOAT(src[0]);
- PIXEL(p, j, i, 1) = SHORT_TO_FLOAT(src[1]);
- PIXEL(p, j, i, 2) = SHORT_TO_FLOAT(src[2]);
- PIXEL(p, j, i, 3) = SHORT_TO_FLOAT(src[3]);
+ PIXEL(p, j, i, 0) = src[0] >> 8;
+ PIXEL(p, j, i, 1) = src[1] >> 8;
+ PIXEL(p, j, i, 2) = src[2] >> 8;
+ PIXEL(p, j, i, 3) = src[3] >> 8;
}
}
}
static void
r16g16b16a16_put_tile_rgba(short *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++, dst += 4) {
- UNCLAMPED_FLOAT_TO_SHORT(dst[0], PIXEL(p, j, i, 0));
- UNCLAMPED_FLOAT_TO_SHORT(dst[1], PIXEL(p, j, i, 1));
- UNCLAMPED_FLOAT_TO_SHORT(dst[2], PIXEL(p, j, i, 2));
- UNCLAMPED_FLOAT_TO_SHORT(dst[3], PIXEL(p, j, i, 3));
+ dst[0] = PIXEL(p, j, i, 0) << 8;
+ dst[1] = PIXEL(p, j, i, 1) << 8;
+ dst[2] = PIXEL(p, j, i, 2) << 8;
+ dst[3] = PIXEL(p, j, i, 3) << 8;
}
}
}
static void
i8_get_tile_rgba(const ubyte *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
PIXEL(p, j, i, 0) =
PIXEL(p, j, i, 1) =
PIXEL(p, j, i, 2) =
- PIXEL(p, j, i, 3) = ubyte_to_float(*src);
+ PIXEL(p, j, i, 3) = *src;
}
}
}
static void
i8_put_tile_rgba(ubyte *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
+ r = PIXEL(p, j, i, 0);
*dst++ = (ubyte) r;
}
}
static void
a8l8_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
ushort ra = *src++;
PIXEL(p, j, i, 0) =
PIXEL(p, j, i, 1) =
- PIXEL(p, j, i, 2) = ubyte_to_float(ra & 0xff);
- PIXEL(p, j, i, 3) = ubyte_to_float(ra >> 8);
+ PIXEL(p, j, i, 2) = ra & 0xff;
+ PIXEL(p, j, i, 3) = ra >> 8;
}
}
}
static void
a8l8_put_tile_rgba(ushort *dst,
unsigned w, unsigned h,
- const float *p)
+ const uint8_t *p)
{
unsigned i, j;
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
unsigned r, a;
- r = float_to_ubyte(PIXEL(p, j, i, 0));
- a = float_to_ubyte(PIXEL(p, j, i, 3));
+ r = PIXEL(p, j, i, 0);
+ a = PIXEL(p, j, i, 3);
*dst++ = (a << 8) | r;
}
}
static void
z32_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
const double scale = 1.0 / (double) 0xffffffff;
unsigned i, j;
static void
s8z24_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
const double scale = 1.0 / ((1 << 24) - 1);
unsigned i, j;
static void
z24s8_get_tile_rgba(const unsigned *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
const double scale = 1.0 / ((1 << 24) - 1);
unsigned i, j;
static void
z32f_get_tile_rgba(const float *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
static void
ycbcr_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p,
+ uint8_t *p,
boolean rev)
{
- const float scale = 1.0f / 255.0f;
unsigned i, j;
for (i = 0; i < h; i++) {
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);
- PIXEL(p, j, i, 0) = r * scale;
- PIXEL(p, j, i, 1) = g * scale;
- PIXEL(p, j, i, 2) = b * scale;
- PIXEL(p, j, i, 3) = 1.0f;
+ PIXEL(p, j, i, 0) = r;
+ PIXEL(p, j, i, 1) = g;
+ PIXEL(p, j, i, 2) = b;
+ PIXEL(p, j, i, 3) = 255;
/* 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);
- PIXEL(p, j + 1, i, 0) = r * scale;
- PIXEL(p, j + 1, i, 1) = g * scale;
- PIXEL(p, j + 1, i, 2) = b * scale;
- PIXEL(p, j + 1, i, 3) = 1.0f;
+ PIXEL(p, j + 1, i, 0) = r;
+ PIXEL(p, j + 1, i, 1) = g;
+ PIXEL(p, j + 1, i, 2) = b;
+ PIXEL(p, j + 1, i, 3) = 255;
}
/* do the last texel */
if (w & 1) {
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);
- PIXEL(p, j, i, 0) = r * scale;
- PIXEL(p, j, i, 1) = g * scale;
- PIXEL(p, j, i, 2) = b * scale;
- PIXEL(p, j, i, 3) = 1.0f;
+ PIXEL(p, j, i, 0) = r;
+ PIXEL(p, j, i, 1) = g;
+ PIXEL(p, j, i, 2) = b;
+ PIXEL(p, j, i, 3) = 255;
}
}
}
static void
fake_get_tile_rgba(const ushort *src,
unsigned w, unsigned h,
- float *p)
+ uint8_t *p)
{
unsigned i, j;
PIXEL(p, j, i, 0) =
PIXEL(p, j, i, 1) =
PIXEL(p, j, i, 2) =
- PIXEL(p, j, i, 3) = (i ^ j) & 1 ? 1.0f : 0.0f;
+ PIXEL(p, j, i, 3) = (i ^ j) & 1 ? 255 : 0;
}
}
}
lp_tile_raw_to_rgba_soa(enum pipe_format format,
void *src,
uint w, uint h,
- float *p)
+ uint8_t *p)
{
switch (format) {
case PIPE_FORMAT_A8R8G8B8_UNORM:
void
lp_get_tile_rgba_soa(struct pipe_transfer *pt,
uint x, uint y,
- float *p)
+ uint8_t *p)
{
uint w = TILE_SIZE, h = TILE_SIZE;
void *packed;
void
lp_put_tile_rgba_soa(struct pipe_transfer *pt,
uint x, uint y,
- const float *p)
+ const uint8_t *p)
{
uint w = TILE_SIZE, h = TILE_SIZE;
void *packed;