Skip to content

Commit

Permalink
libagl: add 10:10:10 color space
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Mar 25, 2013
1 parent 10f9d16 commit db94788
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
3 changes: 1 addition & 2 deletions agg_test.cpp
Expand Up @@ -72,7 +72,7 @@ void agg_test(void)
agg::rendering_buffer rbuf(buf, width, height, width * 4);

// Create the renderer and the rasterizer
agg::renderer<agg::span_rgba32> ren(rbuf);
agg::renderer<agg::span_rgb101010> ren(rbuf);
agg::rasterizer ras;

// Setup the rasterizer
Expand Down Expand Up @@ -138,4 +138,3 @@ void agg_test(void)

delete [] buf;
}

54 changes: 53 additions & 1 deletion libagl/include/agg.h
Expand Up @@ -1262,8 +1262,60 @@ namespace agg
};


}

//========================================================================
struct span_rgb101010
{
//--------------------------------------------------------------------
static void render(unsigned char* ptr,
int x,
unsigned count,
const unsigned char* covers,
const rgba8& c)
{
unsigned int* p = (unsigned int *)ptr + x;
do
{
int alpha = (*covers++) * c.a;
int r = (*p >> 20) & 0x3ff;
int g = (*p >> 10) & 0x3ff;
int b = *p & 0x3ff;
int cr = c.r << 2;
int cg = c.g << 2;
int cb = c.b << 2;
int dr = (((cr - r) * alpha) + (r << 16)) >> 16;
int dg = (((cg - g) * alpha) + (g << 16)) >> 16;
int db = (((cb - b) * alpha) + (b << 16)) >> 16;
*p++ = (dr << 20) | (dg << 10) | db;
}
while(--count);
}

//--------------------------------------------------------------------
static void hline(unsigned char* ptr,
int x,
unsigned count,
const rgba8& c)
{
unsigned int* p = (unsigned int *)ptr + x;
unsigned int c10 = (c.r << 22) | (c.g << 12) | (c.b << 2);
do { *p++ = c10; } while(--count);
}

//--------------------------------------------------------------------
static rgba8 get(unsigned char* ptr, int x)
{
unsigned int* p = (unsigned int *)ptr + x;
rgba8 c;
c.r = (*p >> 22) & 0xff;
c.g = (*p >> 12) & 0xff;
c.b = (*p >> 2) & 0xff;
c.a = 255;
return c;
}
};

}


#endif
Expand Down

0 comments on commit db94788

Please sign in to comment.