diff options
author | Luc Verhaegen <libv@skynet.be> | 2005-08-30 19:11:38 +0000 |
---|---|---|
committer | Luc Verhaegen <libv@skynet.be> | 2005-08-30 19:11:38 +0000 |
commit | 408a572c47cdc7cf3ae425de35791274d681fdc0 (patch) | |
tree | e4ea1a80cd899639f0d08f7a5f322a90f986d13a | |
parent | ad02479d946564c071ee24f81997e9f1afbc3d2c (diff) |
[devel-swov_Attributes]
- clean up Attribute handling.
- introduce some superficial sanity to viaCalculateVideoColor
-rw-r--r-- | src/via_video.c | 281 |
1 files changed, 108 insertions, 173 deletions
diff --git a/src/via_video.c b/src/via_video.c index 3090437..251eade 100644 --- a/src/via_video.c +++ b/src/via_video.c @@ -449,66 +449,43 @@ static unsigned vPackFloat(float val, float hiLimit, float loLimit, float mult, } - -typedef float colorCoeff[5]; -static colorCoeff colorCTable[] = {{1.1875,1.625,0.875,0.375,2.0}, - {1.164,1.596,0.54,0.45,2.2}}; - /* + * HORRIBLE + * * This function is a partial rewrite of the overlay.c file of the original VIA drivers, * which was extremely nasty and difficult to follow. Coefficient for new chipset models should * be added in the table above and, if needed, implemented in the model switch below. */ - static void -viaCalculateVideoColor(VIAPtr pVia, int hue, int saturation, int brightness, - int contrast,Bool reset,CARD32 *col1,CARD32 *col2) +viaCalculateVideoColor(VIAPtr pVia, CARD32 *col1, CARD32 *col2) { + struct ViaXvPort *Port = pVia->Swov->Port; + float fA,fB1,fC1,fD,fB2,fC2,fB3,fC3; float fPI,fContrast,fSaturation,fHue,fBrightness; - const float *mCoeff; + + float ColorCoefficientCLE266Ax[5] = {1.164, 1.596, 0.54, 0.45, 2.2}; + float ColorCoefficientOther[5] = {1.1875, 1.625, 0.875, 0.375, 2.0}; + const float *mCoeff; + unsigned long dwA,dwB1,dwC1,dwD,dwB2,dwC2,dwB3,dwC3,dwS; unsigned long dwD_Int,dwD_Dec; int intD; - int model; - fPI = (float)(M_PI/180.); - - if ( reset ) { - saturation = 10000; - brightness = 5000; - contrast = 10000; - } - switch ( pVia->ChipId ) - { - case PCI_CHIP_VT3205: - case PCI_CHIP_VT3204: - model = 0; - break; - case PCI_CHIP_CLE3122: - model = (CLE266_REV_IS_CX(pVia->ChipRev) ? 0 : 1); - break; - default: - ErrorF("Unknown Chip ID\n"); - model = 0; - } + fPI = (float)(M_PI/180.); - switch( model ) - { - case 0: - fBrightness = rangeEqualize(0.,10000.,-128.,128.,-16.,(float) brightness); - fContrast = rangeEqualize(0.,20000.,0.,1.6645,1.0,(float) contrast); - fSaturation = rangeEqualize(0.,20000,0.,2.,1.,(float) saturation); - break; - default: - fBrightness = rangeEqualize(0.,10000.,-128.,128.,-12.,(float) brightness); - fContrast = rangeEqualize(0.,20000.,0.,1.6645,1.1,(float) contrast); - fSaturation = rangeEqualize(0.,20000,0.,2.,1.15,(float) saturation); - break; + if ((pVia->Chipset == VIA_CLE266) && CLE266_REV_IS_AX(pVia->ChipRev)) { + fBrightness = rangeEqualize(0.,10000.,-128.,128.,-12.,(float) Port->brightness); + fContrast = rangeEqualize(0.,20000.,0.,1.6645,1.1,(float) Port->contrast); + fSaturation = rangeEqualize(0.,20000,0.,2.,1.15,(float) Port->saturation); + mCoeff = ColorCoefficientCLE266Ax; + } else { + fBrightness = rangeEqualize(0.,10000.,-128.,128.,-16.,(float) Port->brightness); + fContrast = rangeEqualize(0.,20000.,0.,1.6645,1.0,(float) Port->contrast); + fSaturation = rangeEqualize(0.,20000,0.,2.,1.,(float) Port->saturation); + mCoeff = ColorCoefficientOther; } - fHue = (float)hue; - - mCoeff = colorCTable[model]; + fHue = (float)Port->hue; fA = (float)(mCoeff[0]*fContrast); fB1 = (float)(-mCoeff[1]*fContrast*fSaturation*sin(fHue*fPI)); @@ -521,40 +498,7 @@ viaCalculateVideoColor(VIAPtr pVia, int hue, int saturation, int brightness, fB3 = (float)(mCoeff[4]*fContrast*fSaturation*cos(fHue*fPI)); fC3 = (float)(mCoeff[4]*fContrast*fSaturation*sin(fHue*fPI)); - switch(model) - { - case 0: - dwA = vPackFloat(fA,1.9375,0.,32.,5,0); - dwB1 = vPackFloat(fB1,2.125,-2.125,16.,5,1); - dwC1 = vPackFloat(fC1,2.125,-2.125,16.,5,1); - - if (fD>=0) { - intD=(int)fD; - if (intD>127) - intD = 127; - dwD_Int = ((unsigned long)intD)&0xff; - dwD = ((unsigned long)(fD*16+1))>>1; - dwD_Dec= dwD&0x7; - } else { - intD=(int)fD; - if (intD< -128) - intD = -128; - intD = intD+256; - dwD_Int = ((unsigned long)intD)&0xff; - fD = -fD; - dwD = ((unsigned long)(fD*16+1))>>1; - dwD_Dec= dwD&0x7; - } - - dwB2 = vPackFloat(fB2,1.875,-1.875,16,4,1); - dwC2 = vPackFloat(fC2,1.875,-1.875,16,4,1); - dwB3 = vPackFloat(fB3,3.875,-3.875,16,5,1); - dwC3 = vPackFloat(fC3,3.875,-3.875,16,5,1); - *col1 = (dwA<<24)|(dwB1<<16)|(dwC1<<8)|dwD_Int; - *col2 = (dwD_Dec<<29|dwB2<<24)|(dwC2<<16)|(dwB3<<8)|(dwC3); - break; - - default: + if ((pVia->Chipset == VIA_CLE266) && CLE266_REV_IS_AX(pVia->ChipRev)) { dwA = vPackFloat(fA,1.9375,-0.,32,5,0); dwB1 = vPackFloat(fB1,0.75,-0.75,8.,2,1); dwC1 = vPackFloat(fC1,2.875,1.,16.,5,0); @@ -586,23 +530,47 @@ viaCalculateVideoColor(VIAPtr pVia, int hue, int saturation, int brightness, dwC3 = vPackFloat(fC3,1.25,-1.25,8.,3,1); *col1 = (dwA<<24)|(dwB1<<18)|(dwC1<<9)|dwD; *col2 = (dwB2<<25)|(dwC2<<17)|(dwB3<<10)|(dwC3<<2); - break; + } else { + dwA = vPackFloat(fA,1.9375,0.,32.,5,0); + dwB1 = vPackFloat(fB1,2.125,-2.125,16.,5,1); + dwC1 = vPackFloat(fC1,2.125,-2.125,16.,5,1); + + if (fD>=0) { + intD=(int)fD; + if (intD>127) + intD = 127; + dwD_Int = ((unsigned long)intD)&0xff; + dwD = ((unsigned long)(fD*16+1))>>1; + dwD_Dec= dwD&0x7; + } else { + intD=(int)fD; + if (intD< -128) + intD = -128; + intD = intD+256; + dwD_Int = ((unsigned long)intD)&0xff; + fD = -fD; + dwD = ((unsigned long)(fD*16+1))>>1; + dwD_Dec= dwD&0x7; + } + + dwB2 = vPackFloat(fB2,1.875,-1.875,16,4,1); + dwC2 = vPackFloat(fC2,1.875,-1.875,16,4,1); + dwB3 = vPackFloat(fB3,3.875,-3.875,16,5,1); + dwC3 = vPackFloat(fC3,3.875,-3.875,16,5,1); + *col1 = (dwA<<24)|(dwB1<<16)|(dwC1<<8)|dwD_Int; + *col2 = (dwD_Dec<<29|dwB2<<24)|(dwC2<<16)|(dwB3<<8)|(dwC3); } } /* * - * */ static void -VIASetColorSpace(VIAPtr pVia, int hue, int saturation, int brightness, - int contrast, Bool reset) +VIASetColorSpace(VIAPtr pVia) { CARD32 col1,col2; - viaCalculateVideoColor(pVia,hue,saturation,brightness, contrast,reset,&col1,&col2); - - DBG_DD(ErrorF("%s: Col1 0x%08X, Col2 0x%08X\n", __FUNCTION__, col1, col2)); + viaCalculateVideoColor(pVia, &col1, &col2); pVia->Swov->Video->Video3ColorSpace1 = col1; pVia->Swov->Video->Video3ColorSpace2 = col2; @@ -1436,7 +1404,7 @@ ViaVideoInit(ScrnInfoPtr pScrn, ScreenPtr pScreen) if (num_adaptors) { xf86XVScreenInit(pScreen, allAdaptors, num_adaptors); - VIASetColorSpace(pVia,0,0,0,0,TRUE); + VIASetColorSpace(pVia); } } @@ -1534,63 +1502,43 @@ viaSetPortAttribute(ScrnInfoPtr pScrn, Atom attribute, INT32 value, pointer data { VIAPtr pVia = VIAPTR(pScrn); struct ViaXvPort *Port = (struct ViaXvPort *) data; - int attr, avalue; - - DBG_DD(ErrorF(" via_video.c : viaSetPortAttribute : \n")); - /* Color Key */ - if(attribute == xvColorKey) { - DBG_DD(ErrorF(" V4L Disable xvColorKey = %08lx\n",value)); - - Port->colorKey = value; + if (attribute == xvColorKey) { + Port->colorKey = value; /* All assume color depth is 16 */ value &= 0x00FFFFFF; pVia->Swov->Video->ColorKey = value; pVia->Swov->Video->ColorKeySecond = value; REGION_EMPTY(pScrn->pScreen, &Port->clip); - DBG_DD(ErrorF(" V4L Disable done xvColorKey = %08lx\n",value)); - + return Success; } else if (attribute == xvAutoPaint) { - Port->autoPaint = value; - DBG_DD(ErrorF(" xvAutoPaint = %08lx\n",value)); - /* Color Control */ - } else if (attribute == xvBrightness || - attribute == xvContrast || - attribute == xvSaturation || - attribute == xvHue) { - if (attribute == xvBrightness) - { - DBG_DD(ErrorF(" xvBrightness = %08ld\n",value)); - Port->brightness = value; - } - if (attribute == xvContrast) - { - DBG_DD(ErrorF(" xvContrast = %08ld\n",value)); - Port->contrast = value; - } - if (attribute == xvSaturation) - { - DBG_DD(ErrorF(" xvSaturation = %08ld\n",value)); - Port->saturation = value; - } - if (attribute == xvHue) - { - DBG_DD(ErrorF(" xvHue = %08ld\n",value)); - Port->hue = value; - } - VIASetColorSpace(pVia, Port->hue, Port->saturation, - Port->brightness, Port->contrast, FALSE); - }else{ - DBG_DD(ErrorF(" via_video.c : viaSetPortAttribute : is not supported the attribute")); - return BadMatch; + if (value) + Port->autoPaint = TRUE; + else + Port->autoPaint = FALSE; + return Success; + } else if (attribute == xvBrightness) { + Port->brightness = value; + VIASetColorSpace(pVia); + return Success; + } else if (attribute == xvContrast) { + Port->contrast = value; + VIASetColorSpace(pVia); + return Success; + } else if (attribute == xvSaturation) { + Port->saturation = value; + VIASetColorSpace(pVia); + return Success; + } else if (attribute == xvHue) { + Port->hue = value; + VIASetColorSpace(pVia); + return Success; } - - /* attr,avalue hardware processing goes here */ - (void)attr; - (void)avalue; - - return Success; + + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: Unhandled attribute.\n", + __FUNCTION__); + return BadMatch; } static int @@ -1598,46 +1546,33 @@ viaGetPortAttribute(ScrnInfoPtr pScrn, Atom attribute, INT32 *value, pointer dat { struct ViaXvPort *Port = (struct ViaXvPort *) data; - DBG_DD(ErrorF(" via_video.c : viaGetPortAttribute : port %d %ld\n", - Port->xv_portnum, attribute)); + if (attribute == xvColorKey) { + *value =(INT32) Port->colorKey; + return Success; + } else if (attribute == xvAutoPaint) { + if (Port->autoPaint) + *value = 1; + else + *value = 0; + return Success; + } else if (attribute == xvBrightness) { + *value = Port->brightness; + return Success; + } else if (attribute == xvContrast) { + *value = Port->contrast; + return Success; + } else if (attribute == xvSaturation) { + *value = Port->saturation; + return Success; + } else if (attribute == xvHue) { + *value = Port->hue; + return Success; + } + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "%s: Unhandled attribute.\n", + __FUNCTION__); *value = 0; - if (attribute == xvColorKey ) { - *value =(INT32) Port->colorKey; - DBG_DD(ErrorF(" via_video.c : ColorKey 0x%lx\n",Port->colorKey)); - } else if (attribute == xvAutoPaint ) { - *value = (INT32) Port->autoPaint; - DBG_DD(ErrorF(" AutoPaint = %08ld\n", *value)); - /* Color Control */ - } else if (attribute == xvBrightness || - attribute == xvContrast || - attribute == xvSaturation || - attribute == xvHue) { - if (attribute == xvBrightness) - { - *value = Port->brightness; - DBG_DD(ErrorF(" xvBrightness = %08ld\n", *value)); - } - if (attribute == xvContrast) - { - *value = Port->contrast; - DBG_DD(ErrorF(" xvContrast = %08ld\n", *value)); - } - if (attribute == xvSaturation) - { - *value = Port->saturation; - DBG_DD(ErrorF(" xvSaturation = %08ld\n", *value)); - } - if (attribute == xvHue) - { - *value = Port->hue; - DBG_DD(ErrorF(" xvHue = %08ld\n", *value)); - } - - }else { - /*return BadMatch*/ ; - } - return Success; + return BadMatch; } static void |