home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- uvtempbuffer.cpp
-
- 03/02/08 Xiaohong
- *************************************************************************/
- #include "uvtempbuffers.h"
- #include "macros.h"
- /**********************************************************
- UVTEMPBUFFERS é╠âüâôâoè╓Éöé╠ÉΘî╛
- **********************************************************/
- UVTEMPBUFFERS::UVTEMPBUFFERS()
- {
- pUBuffer = NULL;
- pVBuffer = NULL;
- pUBuffer422 = NULL;
- pVBuffer422 = NULL;
- pTempFilterBuffer = NULL;
- m_nSize = 0;
- }
-
- UVTEMPBUFFERS::~UVTEMPBUFFERS()
- {
- Clear();
- }
-
- bool UVTEMPBUFFERS::Alloc(int size,bool filter)
- {
- Clear();
- if (!(pUBuffer = (unsigned char *)_malloc(size)))
- return false;
-
- if (!(pVBuffer = (unsigned char *)_malloc(size)))
- return false;
-
- if (!(pUBuffer422 = (unsigned char *)_malloc(size)))
- return false;
-
- if (!(pVBuffer422 = (unsigned char *)_malloc(size)))
- return false;
-
- if(filter)
- if (!(pTempFilterBuffer = (unsigned char *)_malloc(size)))
- return false;
-
- m_nSize = size;
-
- return true;
- }
- void UVTEMPBUFFERS::Clear(void)
- {
- if(pUBuffer!=NULL)
- {
- _free(pUBuffer);
- }
- if(pVBuffer!=NULL)
- {
- _free(pVBuffer);
- }
- if(pUBuffer422!=NULL)
- {
- _free(pUBuffer422);
- }
- if(pVBuffer422!=NULL)
- {
- _free(pVBuffer422);
- }
- if(pTempFilterBuffer!=NULL)
- {
- _free(pTempFilterBuffer);
- }
- m_nSize = 0;
- }
-
- void UVTEMPBUFFERS::conv444to422(const unsigned char* src,
- unsigned char* dst,
- const PICTURESTRUCT* pPictureStruct,
- const SEQUENCEDATA* pSequenceData)
- {
- const int width = pSequenceData->stHeader.nWidth;
- const int height = pSequenceData->stHeader.nHeight;
-
- int i, j, im5, im4, im3, im2, im1, ip1, ip2, ip3, ip4, ip5, ip6;
-
-
- for (j=0; j<height; j++)
- {
- for (i=0; i<width; i+=2)
- {
- im5 = (i<5) ? 0 : i-5;
- im4 = (i<4) ? 0 : i-4;
- im3 = (i<3) ? 0 : i-3;
- im2 = (i<2) ? 0 : i-2;
- im1 = (i<1) ? 0 : i-1;
- ip1 = (i<width-1) ? i+1 : width-1;
- ip2 = (i<width-2) ? i+2 : width-1;
- ip3 = (i<width-3) ? i+3 : width-1;
- ip4 = (i<width-4) ? i+4 : width-1;
- ip5 = (i<width-5) ? i+5 : width-1;
- ip6 = (i<width-5) ? i+6 : width-1;
-
- // FIR filter with 0.5 sample interval phase shift
- dst[i>>1] = pPictureStruct->pClippingTable[(int)(228*(src[i]+src[ip1])
- +70*(src[im1]+src[ip2])
- -37*(src[im2]+src[ip3])
- -21*(src[im3]+src[ip4])
- +11*(src[im4]+src[ip5])
- + 5*(src[im5]+src[ip6])+256)>>9];
- }
- src+= width;
- dst+= width>>1;
- }
- }
-
- void UVTEMPBUFFERS::conv422to420(unsigned char* src,
- unsigned char* dst,
- const PICTURESTRUCT* pPictureStruct,
- const SEQUENCEDATA* pSequenceData)
- {
- const int width = pSequenceData->stHeader.nWidth;
- const int height = pSequenceData->stHeader.nHeight;
- int w, i, j, jm5, jm4, jm3, jm2, jm1;
- int jp1, jp2, jp3, jp4, jp5, jp6;
- int height_div2 = height >> 1;
-
- w = width>>1;
-
- for (i=0; i<w; i++)
- {
- for (j=0; j<height; j+=2)
- {
- jm5 = (j<5) ? 0 : j-5;
- jm4 = (j<4) ? 0 : j-4;
- jm3 = (j<3) ? 0 : j-3;
- jm2 = (j<2) ? 0 : j-2;
- jm1 = (j<1) ? 0 : j-1;
- jp1 = (j<height-1) ? j+1 : height-1;
- jp2 = (j<height-2) ? j+2 : height-1;
- jp3 = (j<height-3) ? j+3 : height-1;
- jp4 = (j<height-4) ? j+4 : height-1;
- jp5 = (j<height-5) ? j+5 : height-1;
- jp6 = (j<height-5) ? j+6 : height-1;
-
- // FIR filter with 0.5 sample interval phase shift
- dst[w*(j>>1)] = pPictureStruct->pClippingTable[(int)(228*(src[w*j]+src[w*jp1])
- +70*(src[w*jm1]+src[w*jp2])
- -37*(src[w*jm2]+src[w*jp3])
- -21*(src[w*jm3]+src[w*jp4])
- +11*(src[w*jm4]+src[w*jp5])
- + 5*(src[w*jm5]+src[w*jp6])+256)>>9];
- }
- src++;
- dst++;
- }
- }
- void UVTEMPBUFFERS::SoftFilter(unsigned char* frame[],const int width,const int height)
- {
- if(pTempFilterBuffer != NULL)
- {
- SoftFilter(pTempFilterBuffer, frame[0], width, height);
- memcpy(frame[0], pTempFilterBuffer, width*height);
-
- SoftFilter(pTempFilterBuffer, frame[1], width/2, height/2);
- memcpy(frame[1], pTempFilterBuffer, width*height/4);
-
- SoftFilter(pTempFilterBuffer, frame[2], width/2, height/2);
- memcpy(frame[2], pTempFilterBuffer, width*height/4);
- }
- }
- /*---------------------------------------------------------
- âtâBâïâ^é≡é⌐é»é▄é╖
- ---------------------------------------------------------*/
- void UVTEMPBUFFERS::SoftFilter(unsigned char* dest, unsigned char* src,const int width,const int height)
- {
- const int Tolerance = 10;
- const int Filtersize = 6;
-
- int refval, aktval, upperval, lowerval, numvalues, sum, rowindex;
- int x, y, fx, fy, fy1, fy2, fx1, fx2;
-
- for(y = 0; y < height; y++)
- {
- for(x = 0; x < width; x++)
- {
- refval = src[x+y*width];
- upperval = refval + Tolerance;
- lowerval = refval - Tolerance;
-
- numvalues = 1;
- sum = refval;
-
- fy1 = MAX(y-Filtersize, 0);
- fy2 = MIN(y+Filtersize+1, height);
-
- for (fy = fy1; fy<fy2; fy++)
- {
- rowindex = fy*width;
- fx1 = MAX(x-Filtersize, 0) + rowindex;
- fx2 = MIN(x+Filtersize+1, width) + rowindex;
-
- for (fx = fx1; fx<fx2; fx++)
- {
- aktval = src[fx];
- if ((lowerval-aktval)*(upperval-aktval)<0)
- {
- numvalues ++;
- sum += aktval;
- }
- } //for fx
- } //for fy
-
- dest[x+y*width] = sum/numvalues;
- }
- }
- }
-