From c1d4644f487a3ff4dcb3ef32995fed30cd72eeba Mon Sep 17 00:00:00 2001 From: George Sapountzis Date: Fri, 23 May 2008 22:54:54 +0300 Subject: [PATCH] dri/swrast: add support for r3g3b2 --- src/mesa/drivers/dri/swrast/swrast.c | 30 +++++++++- src/mesa/drivers/dri/swrast/swrast_priv.h | 1 + src/mesa/drivers/dri/swrast/swrast_span.c | 68 +++++++++++++++++++++++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index 2622935af93..6a9eb1573b6 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -145,7 +145,11 @@ swrastFillInModes(__DRIscreen *psp, depth_buffer_factor = 4; back_buffer_factor = 2; - if (pixel_bits == 16) { + if (pixel_bits == 8) { + fb_format = GL_RGB; + fb_type = GL_UNSIGNED_BYTE_2_3_3_REV; + } + else if (pixel_bits == 16) { fb_format = GL_RGB; fb_type = GL_UNSIGNED_SHORT_5_6_5; } @@ -173,6 +177,7 @@ driCreateNewScreen(int scrn, const __DRIextension **extensions, { static const __DRIextension *emptyExtensionList[] = { NULL }; __DRIscreen *psp; + __DRIconfig **configs8, **configs16, **configs32; (void) data; @@ -187,8 +192,13 @@ driCreateNewScreen(int scrn, const __DRIextension **extensions, psp->num = scrn; psp->extensions = emptyExtensionList; - *driver_configs = driConcatConfigs(swrastFillInModes(psp, 16, 16, 0, 1), - swrastFillInModes(psp, 32, 24, 8, 1)); + configs8 = swrastFillInModes(psp, 8, 8, 0, 1); + configs16 = swrastFillInModes(psp, 16, 16, 0, 1); + configs32 = swrastFillInModes(psp, 32, 24, 8, 1); + + configs16 = (__DRIconfig **)driConcatConfigs(configs8, configs16); + + *driver_configs = driConcatConfigs(configs16, configs32); driInitExtensions( NULL, card_extensions, GL_FALSE ); @@ -235,6 +245,11 @@ choose_pixel_format(const GLvisual *v) && v->greenMask == 0x07e0 && v->blueMask == 0x001f) return PF_R5G6B5; + else if (bpp == 8 + && v->redMask == 0x07 + && v->greenMask == 0x38 + && v->blueMask == 0xc0) + return PF_R3G3B2; } else { if (v->indexBits == 8) @@ -347,6 +362,15 @@ swrast_new_renderbuffer(const GLvisual *visual, GLboolean front) xrb->Base.BlueBits = 5 * sizeof(GLubyte); xrb->Base.AlphaBits = 0; break; + case PF_R3G3B2: + xrb->Base.InternalFormat = GL_RGB; + xrb->Base._BaseFormat = GL_RGB; + xrb->Base.DataType = GL_UNSIGNED_BYTE; + xrb->Base.RedBits = 3 * sizeof(GLubyte); + xrb->Base.GreenBits = 3 * sizeof(GLubyte); + xrb->Base.BlueBits = 2 * sizeof(GLubyte); + xrb->Base.AlphaBits = 0; + break; case PF_CI8: xrb->Base.InternalFormat = GL_COLOR_INDEX8_EXT; xrb->Base._BaseFormat = GL_COLOR_INDEX; diff --git a/src/mesa/drivers/dri/swrast/swrast_priv.h b/src/mesa/drivers/dri/swrast/swrast_priv.h index d801f88f072..e12743bd563 100644 --- a/src/mesa/drivers/dri/swrast/swrast_priv.h +++ b/src/mesa/drivers/dri/swrast/swrast_priv.h @@ -111,6 +111,7 @@ swrast_renderbuffer(struct gl_renderbuffer *rb) #define PF_CI8 1 /**< Color Index mode */ #define PF_A8R8G8B8 2 /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B bits */ #define PF_R5G6B5 3 /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */ +#define PF_R3G3B2 4 /**< 8-bit TrueColor: 3-R, 3-G, 2-B bits */ /* swrast_span.c */ diff --git a/src/mesa/drivers/dri/swrast/swrast_span.c b/src/mesa/drivers/dri/swrast/swrast_span.c index d11d1d36aef..4613a121131 100644 --- a/src/mesa/drivers/dri/swrast/swrast_span.c +++ b/src/mesa/drivers/dri/swrast/swrast_span.c @@ -71,6 +71,24 @@ } while(0) +/* 8-bit BGR */ +#define STORE_PIXEL_R3G3B2(DST, X, Y, VALUE) \ + do { \ + GLubyte *p = (GLubyte *)DST; \ + *p = ( (((VALUE[RCOMP]) & 0xe0) >> 5) | \ + (((VALUE[GCOMP]) & 0xe0) >> 2) | \ + (((VALUE[BCOMP]) & 0xc0) >> 0) ); \ + } while(0) +#define FETCH_PIXEL_R3G3B2(DST, SRC) \ + do { \ + GLubyte p = *(GLubyte *)SRC; \ + DST[ACOMP] = 0xff; \ + DST[RCOMP] = ((p << 5) & 0xe0) * 255 / 0xe0; \ + DST[GCOMP] = ((p << 2) & 0xe0) * 255 / 0xe0; \ + DST[BCOMP] = ((p << 0) & 0xc0) * 255 / 0xc0; \ + } while(0) + + /* * Generate code for image span functions. */ @@ -109,6 +127,22 @@ #include "swrast/s_spantemp.h" +/* 8-bit BGR */ +#define NAME(FUNC) FUNC##_R3G3B2 +#define RB_TYPE GLubyte +#define SPAN_VARS \ + struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb); +#define INIT_PIXEL_PTR(P, X, Y) \ + GLubyte *P = (GLubyte *)xrb->Base.Data + YFLIP(xrb, Y) * xrb->pitch + (X) * 1; +#define INC_PIXEL_PTR(P) P += 1 +#define STORE_PIXEL(DST, X, Y, VALUE) \ + STORE_PIXEL_R3G3B2(DST, X, Y, VALUE) +#define FETCH_PIXEL(DST, SRC) \ + FETCH_PIXEL_R3G3B2(DST, SRC) + +#include "swrast/s_spantemp.h" + + /* 8-bit color index */ #define NAME(FUNC) FUNC##_CI8 #define CI_MODE @@ -164,6 +198,22 @@ #include "swrast_spantemp.h" +/* 8-bit BGR */ +#define NAME(FUNC) FUNC##_R3G3B2_pixmap +#define RB_TYPE GLubyte +#define SPAN_VARS \ + struct swrast_renderbuffer *xrb = swrast_renderbuffer(rb); +#define INIT_PIXEL_PTR(P, X, Y) \ + GLubyte *P = (GLubyte *)row; +#define INC_PIXEL_PTR(P) P += 1 +#define STORE_PIXEL(DST, X, Y, VALUE) \ + STORE_PIXEL_R3G3B2(DST, X, Y, VALUE) +#define FETCH_PIXEL(DST, SRC) \ + FETCH_PIXEL_R3G3B2(DST, SRC) + +#include "swrast_spantemp.h" + + /* 8-bit color index */ #define NAME(FUNC) FUNC##_CI8_pixmap #define CI_MODE @@ -210,6 +260,15 @@ swrast_set_span_funcs_ximage(struct swrast_renderbuffer *xrb, xrb->Base.PutValues = put_values_R5G6B5; xrb->Base.PutMonoValues = put_mono_values_R5G6B5; break; + case PF_R3G3B2: + xrb->Base.GetRow = get_row_R3G3B2; + xrb->Base.GetValues = get_values_R3G3B2; + xrb->Base.PutRow = put_row_R3G3B2; + xrb->Base.PutRowRGB = put_row_rgb_R3G3B2; + xrb->Base.PutMonoRow = put_mono_row_R3G3B2; + xrb->Base.PutValues = put_values_R3G3B2; + xrb->Base.PutMonoValues = put_mono_values_R3G3B2; + break; case PF_CI8: xrb->Base.GetRow = get_row_CI8; xrb->Base.GetValues = get_values_CI8; @@ -256,6 +315,15 @@ swrast_set_span_funcs_pixmap(struct swrast_renderbuffer *xrb, xrb->Base.PutValues = put_values_R5G6B5_pixmap; xrb->Base.PutMonoValues = put_mono_values_R5G6B5_pixmap; break; + case PF_R3G3B2: + xrb->Base.GetRow = get_row_R3G3B2_pixmap; + xrb->Base.GetValues = get_values_R3G3B2_pixmap; + xrb->Base.PutRow = put_row_R3G3B2_pixmap; + xrb->Base.PutRowRGB = put_row_rgb_R3G3B2_pixmap; + xrb->Base.PutMonoRow = put_mono_row_R3G3B2_pixmap; + xrb->Base.PutValues = put_values_R3G3B2_pixmap; + xrb->Base.PutMonoValues = put_mono_values_R3G3B2_pixmap; + break; case PF_CI8: xrb->Base.GetRow = get_row_CI8_pixmap; xrb->Base.GetValues = get_values_CI8_pixmap; -- 2.30.2