📄 type_grayc.cpp
字号:
//for clear memory Int copy_pel=0; Int dst_x=0; Int iBuffXWidth = (int)((rctDst.right - iExpandYRefFrame/iType)/(1<<h_factor_int)); Int iHeightSrcNet = iHeightSrc-iExpandYRefFrame/iType*2; Int iWidthSrcNet = iWidthSrc-iExpandYRefFrame/iType*2; // Int iWidthDstNet = iWidthDst - iExpandYRefFrame/iType*2; // Int iHeightDstNet = iHeightDst - iExpandYRefFrame/iType*2; if(h_factor - h_factor_int > 0.000001 ){ int j; // wmay for(j=0; j<(iHeightSrc-iExpandYRefFrame/iType);j++){ dst_x = 0; copy_pel = 0; Int next_copy_pel = 0; for(int i=0; i<(iWidthSrc-iExpandYRefFrame/iType);i++){ if(i==next_copy_pel){ if(i<iWidthSrcNet && j<iHeightSrcNet) *(ppxlcBuffX+dst_x+j*iBuffXWidth) = (PixelC) *(pict+j*where().width+i); Xcheck1[dst_x] = 0 ; dst_x++; copy_pel++; next_copy_pel = (int)floor( ((double) (iHorizontalSamplingFactorM*(1<<h_factor_int))/(iHorizontalSamplingFactorN-iHorizontalSamplingFactorM*(1<<h_factor_int))*copy_pel)); } if(i<iWidthSrcNet && j<iHeightSrcNet) *(ppxlcBuffX+dst_x+j*iBuffXWidth) = (PixelC) *(pict+j*where().width+i); Xcheck1[dst_x] = 1 ; dst_x++; } } for(j=0; j<(iHeightSrc-iExpandYRefFrame/iType);j++){ for(int i=0; i<iBuffXWidth+iExpandYRefFrame/iType;i++){ dst_x = (1<<h_factor_int); do{ if(i<iBuffXWidth && j<iHeightSrcNet) *(ppxlcBuffX2-(dst_x-1)+(i+1)*(1<<h_factor_int)-1+j*iBuffXWidth*(1<<h_factor_int)) = (PixelC) *(ppxlcBuffX+j*iBuffXWidth+i); if(dst_x !=1) Xcheck2[(i+1)*(1<<h_factor_int)-1-(dst_x-1)] = 0; else Xcheck2[(i+1)*(1<<h_factor_int)-1-(dst_x-1)] = Xcheck1[i]; dst_x--; } while ( dst_x != 0); } } } else { for(int j=0; j<(iHeightSrc-iExpandYRefFrame/iType);j++){ for(int i=0; i<iBuffXWidth+iExpandYRefFrame/iType;i++){ dst_x = (1<<h_factor_int); do{ if(i<iBuffXWidth && j<iHeightSrcNet) *(ppxlcBuffX2-(dst_x-1)+(i+1)*(1<<h_factor_int)-1+j*iBuffXWidth*(1<<h_factor_int)) = (PixelC) *(pict+j*where().width+i); if(dst_x !=1) Xcheck2[(i+1)*(1<<h_factor_int)-1-(dst_x-1)] = 0; else Xcheck2[(i+1)*(1<<h_factor_int)-1-(dst_x-1)] = 1; dst_x--; } while ( dst_x != 0); } } } Int copy_line=0; Int dst_y=0; Int next_copy_line = 0 ; if(v_factor - v_factor_int > 0.000001 ){ int j; // wmay for(j=0; j<(iHeightSrc-iExpandYRefFrame/iType);j++){ if(j == next_copy_line){ if(j<iHeightSrcNet) { for(int i=0; i<rctDst.width - iExpandYRefFrame/iType*2;i++) *(ppxlcBuffY+i+dst_y*iBuffXWidth*(1<<h_factor_int)) = (PixelC) *(ppxlcBuffX2+j*iBuffXWidth*(1<<h_factor_int)+i); } Ycheck1[dst_y] = 0 ; dst_y++; copy_line++; next_copy_line = (int)floor (( (double) (iVerticalSamplingFactorM*(1<<v_factor_int))/(iVerticalSamplingFactorN-iVerticalSamplingFactorM*(1<<v_factor_int)) *copy_line)); } if(j<iHeightSrcNet) { for(int i=0; i<iBuffXWidth*(1<<h_factor_int);i++) *(ppxlcBuffY+i+dst_y*iBuffXWidth*(1<<h_factor_int)) = (PixelC) *(ppxlcBuffX2+j*iBuffXWidth*(1<<h_factor_int)+i); } Ycheck1[dst_y] = 1 ; dst_y++; } for(j=0; j<(iHeightDst-iExpandYRefFrame/iType*2)/(1<<v_factor_int)+iExpandYRefFrame/iType;j++){ dst_y = (1<<v_factor_int); do { if(j<(iHeightDst-iExpandYRefFrame/iType*2)/(1<<v_factor_int)){ for(int i=0; i<iBuffXWidth*(1<<h_factor_int);i++) *(ppxlcDst+(i+iExpandYRefFrame/iType)+((j+1)*(1<<v_factor_int)-1-(dst_y-1)+iExpandYRefFrame/iType)*rctDst.width) = (PixelC) *(ppxlcBuffY+j*iBuffXWidth*(1<<h_factor_int)+i); } if(dst_y !=1) Ycheck2[(j+1)*(1<<v_factor_int)-1-(dst_y-1)] = 0; else Ycheck2[(j+1)*(1<<v_factor_int)-1-(dst_y-1)] = Ycheck1[j]; dst_y--; } while ( dst_y != 0); } } else { for(int j=0; j<(iHeightDst-iExpandYRefFrame/iType*2)/(1<<v_factor_int)+iExpandYRefFrame/iType;j++){ dst_y = (1<<v_factor_int); do { if(j<(iHeightDst-iExpandYRefFrame/iType*2)/(1<<v_factor_int)){ for(int i=0; i<iBuffXWidth*(1<<h_factor_int);i++) *(ppxlcDst+(i+iExpandYRefFrame/iType)+((j+1)*(1<<v_factor_int)-1-(dst_y-1)+iExpandYRefFrame/iType)*rctDst.width) = (PixelC) *(ppxlcBuffX2+j*iBuffXWidth*(1<<h_factor_int)+i); } if(dst_y !=1) Ycheck2[(j+1)*(1<<v_factor_int)-1-(dst_y-1)] = 0; else Ycheck2[(j+1)*(1<<v_factor_int)-1-(dst_y-1)] = 1; dst_y--; } while ( dst_y != 0); } } puciRet->m_pbHorSamplingChk = Xcheck2; puciRet->m_pbVerSamplingChk = Ycheck2; delete puciBuffX; delete puciBuffX2; delete puciBuffY; return puciRet;}//~OBSS_SAIT_FIX000602//~OBSS_SAIT_991015own CU8Image* CU8Image::biInterpolate (UInt accuracy) const // bilinearly interpolate the vframe{ const CoordI left = where ().left * accuracy; const CoordI top = where ().top * accuracy; const CoordI right = where ().right * accuracy; const CoordI bottom = where ().bottom * accuracy; CU8Image* puciRet = new CU8Image (CRct (left, top, right, bottom)); PixelC* ppxlcRet = (PixelC*) puciRet -> pixels (); for (CoordI y = top; y < bottom; y++) { // x-direction interpolation for (CoordI x = left; x < right; x++) { *ppxlcRet = pixel (x, y, accuracy); ppxlcRet++; } } return puciRet;}own CU8Image* CU8Image::transpose () const{ CRct rctDst = where (); rctDst.transpose (); CU8Image* puciDst = new CU8Image (rctDst); const PixelC* ppxlSrc = pixels (); PixelC* ppxlDstRow = (PixelC*) puciDst->pixels (); PixelC* ppxlDst; UInt height = where ().height (); for (CoordI iy = where ().top; iy < where ().bottom; iy++) { ppxlDst = ppxlDstRow; for (CoordI ix = where ().left; ix < where ().right; ix++) { *ppxlDst = *ppxlSrc++; ppxlDst += height; } ppxlDstRow++; } return puciDst;}own CU8Image* CU8Image::warp (const CAffine2D& aff) const // affine warp{ CSiteD stdLeftTopWarp = aff * CSiteD (where ().left, where ().top); CSiteD stdRightTopWarp = aff * CSiteD (where ().right, where ().top); CSiteD stdLeftBottomWarp = aff * CSiteD (where ().left, where ().bottom); CSiteD stdRightBottomWarp = aff * CSiteD (where ().right, where ().bottom); CRct rctWarp (stdLeftTopWarp, stdRightTopWarp, stdLeftBottomWarp, stdRightBottomWarp); CU8Image* puciRet = new CU8Image (rctWarp); PixelC* ppxlcRet = (PixelC*) puciRet -> pixels (); CAffine2D affInv = aff.inverse (); for (CoordI y = rctWarp.top; y < rctWarp.bottom; y++) { for (CoordI x = rctWarp.left; x < rctWarp.right; x++) { CSiteD src = affInv * CSiteD (x, y); CoordI fx = (CoordI) floor (src.x); //.5 is for better truncation CoordI fy = (CoordI) floor (src.y); //.5 is for better truncation CoordI cx = (CoordI) ceil (src.x); //.5 is for better truncation CoordI cy = (CoordI) ceil (src.y); //.5 is for better truncation if ( where ().includes (fx, fy) && where ().includes (fx, cy) && where ().includes (cx, fy) && where ().includes (cx, cy) ) *ppxlcRet = pixel (src); ppxlcRet++; } } return puciRet;}own CU8Image* CU8Image::warp (const CPerspective2D& persp) const // perspective warp{ CSiteD src [4], dest [4]; src [0] = CSiteD (where ().left, where ().top); src [1] = CSiteD (where ().right, where ().top); src [2] = CSiteD (where ().left, where ().bottom); src [3] = CSiteD (where ().right, where ().bottom); for (UInt i = 0; i < 4; i++) { dest [i] = (persp * src [i]).s; } CRct rctWarp (dest [0], dest [1], dest [2], dest [3]); CU8Image* puciRet = new CU8Image (rctWarp); PixelC* ppxlcRet = (PixelC*) puciRet -> pixels (); CPerspective2D perspInv = CPerspective2D (dest, src); for (CoordI y = rctWarp.top; y != rctWarp.bottom; y++) { for (CoordI x = rctWarp.left; x != rctWarp.right; x++) { CSiteD src = (perspInv * CSiteD (x, y)).s; CoordI fx = (CoordI) floor (src.x); //.5 is for better truncation CoordI fy = (CoordI) floor (src.y); //.5 is for better truncation CoordI cx = (CoordI) ceil (src.x); //.5 is for better truncation CoordI cy = (CoordI) ceil (src.y); //.5 is for better truncation if ( where ().includes (fx, fy) && where ().includes (fx, cy) && where ().includes (cx, fy) && where ().includes (cx, cy) ) *ppxlcRet = pixel (src); ppxlcRet++; } } return puciRet;}own CU8Image* CU8Image::warp (const CPerspective2D& persp, const CRct& rctWarp) const // perspective warp{ CU8Image* puciRet = new CU8Image (rctWarp); PixelC* ppxlcRet = (PixelC*) puciRet -> pixels (); CPerspective2D perspInv = persp.inverse (); for (CoordI y = rctWarp.top; y != rctWarp.bottom; y++) { for (CoordI x = rctWarp.left; x != rctWarp.right; x++) { CSiteD src = (perspInv * CSiteD (x, y)).s; CoordI fx = (CoordI) floor (src.x); //.5 is for better truncation CoordI fy = (CoordI) floor (src.y); //.5 is for better truncation CoordI cx = (CoordI) ceil (src.x); //.5 is for better truncation CoordI cy = (CoordI) ceil (src.y); //.5 is for better truncation if ( where ().includes (fx, fy) && where ().includes (fx, cy) && where ().includes (cx, fy) && where ().includes (cx, cy) ) *ppxlcRet = pixel (src); ppxlcRet++; } } return puciRet;}own CU8Image* CU8Image::warp (const CPerspective2D& persp, const CRct& rctWarp, const UInt accuracy) const // perspective warp{ CU8Image* puciRet = new CU8Image (rctWarp); PixelC* ppxlcRet = (PixelC*) puciRet -> pixels (); for (CoordI y = rctWarp.top; y != rctWarp.bottom; y++) { for (CoordI x = rctWarp.left; x != rctWarp.right; x++) { CSite src = (persp * CSite (x, y)).s; CoordI fx = (CoordI) floor ((CoordD) src.x / (CoordD) accuracy); //.5 is for better truncation CoordI fy = (CoordI) floor ((CoordD) src.y / (CoordD) accuracy); //.5 is for better truncation CoordI cx = (CoordI) ceil ((CoordD) src.x / (CoordD) accuracy); //.5 is for better truncation CoordI cy = (CoordI) ceil ((CoordD) src.y / (CoordD) accuracy); //.5 is for better truncation if ( where ().includes (fx, fy) && where ().includes (fx, cy) && where ().includes (cx, fy) && where ().includes (cx, cy) ) *ppxlcRet = pixel (src, accuracy); ppxlcRet++; } } return puciRet;}PixelC CU8Image::pixel (CoordD x, CoordD y) const{ CoordI left = (CoordI) floor (x); // find the coordinates of the four corners CoordI wLeft = where ().left, wRight1 = where ().right - 1, wTop = where ().top, wBottom1 = where ().bottom - 1; left = checkrange (left, wLeft, wRight1); CoordI right = (CoordI) ceil (x); right = checkrange (right, wLeft, wRight1); CoordI top = (CoordI) floor (y); top = checkrange (top, wTop, wBottom1); CoordI bottom = (CoordI) ceil (y); bottom = checkrange (bottom, wTop, wBottom1); const PixelC lt = pixel (left, top); const PixelC rt = pixel (right, top); const PixelC lb = pixel (left, bottom); const PixelC rb = pixel (right, bottom); const Double distX = x - left; const Double distY = y - top; Double x01 = distX * (rt - lt) + lt; // use p.59's notation (Wolberg, Digital Image Warping) Double x23 = distX * (rb - lb) + lb; PixelC pxlRet = checkrangeU8 ((U8) (x01 + (x23 - x01) * distY + .5), 0, 255); return pxlRet;}PixelC CU8Image::pixel (CoordI x, CoordI y, UInt accuracy) const{ UInt uis = 1 << (accuracy + 1); UInt accuracy1 = accuracy + 1; CoordD dx = (CoordD) ((CoordD) x / uis); CoordD dy = (CoordD) ((CoordD) y / uis); CoordI left = (CoordI) floor (dx); // find the coordinates of the four corners CoordI wLeft = where ().left, wRight1 = where ().right - 1, wTop = where ().top, wBottom1 = where ().bottom - 1; left = checkrange (left, wLeft, wRight1); CoordI right = (CoordI) ceil (dx); right = checkrange (right, wLeft, wRight1); CoordI top = (CoordI) floor (dy); top = checkrange (top, wTop, wBottom1); CoordI bottom = (CoordI) ceil (dy); bottom = checkrange (bottom, wTop, wBottom1); UInt accuracy2 = (accuracy << 1) + 2; const PixelC lt = pixel (left, top); const PixelC rt = pixel (right, top); const PixelC lb = pixel (left, bottom); const PixelC rb = pixel (right, bottom); const CoordI distX = x - (left << accuracy1); const CoordI distY = y - (top << accuracy1); Int dRet = ((uis-distY)*((uis-distX)*lt + distX*rt) + distY*((uis-distX)*lb + distX*rb) + (1<<(accuracy2-1))) >> accuracy2; PixelC pxlRet = (U8) checkrange ((PixelC)dRet, 0U, 255U); return pxlRet;}own CU8Image* CU8Image::complement () const{ CU8Image* puciDst = new CU8Image (where(), (PixelC) transpValue); const PixelC* ppxlcSrc = pixels (); PixelC* ppxlcDst = (PixelC*) puciDst->pixels (); for (UInt iPxl = 0; iPxl < where ().area (); iPxl++) *ppxlcDst++ = *ppxlcSrc++ ^ 0xFF; return puciDst;}Void CU8Image::overlay (const CU8Image& uci){ if (!valid () || !uci.valid () || uci.where ().empty ()) return; CRct r = m_rc; r.include (uci.m_rc); // overlay is defined on union of rects where (r); if (!valid ()) return; assert (uci.m_ppxlc != NULL); CRct rctFi = uci.m_rc; Int widthFi = rctFi.width; Int widthCurr = where ().width; PixelC* ppxlcThis = (PixelC*) pixels (rctFi.left, rctFi.top); const PixelC* ppxlcFi = uci.pixels (); for (CoordI y = rctFi.top; y < rctFi.bottom; y++) { // loop through VOP CRct memcpy (ppxlcThis, ppxlcFi, rctFi.width * sizeof (PixelC)); ppxlcThis += widthCurr; ppxlcFi += widthFi; }}Void CU8Image::overlay (const CU8Image& uci, const CRct& rctSrc){ if (!valid () || !uci.valid () || uci.where ().empty () || !rctSrc.valid ()) return; if (!(uci.m_rc >= rctSrc)) return; CRct r = m_rc; r.include (rctSrc); // overlay is defined on union of rects where (r); if (!valid ()) return; assert (uci.m_ppxlc != NULL); Int widthSrc = rctSrc.width; Int widthDst = where ().width; PixelC* ppxlcThis = (PixelC*) pixels (rctSrc.left, rctSrc.top); const PixelC* ppxlcSrc = uci.pixels (rctSrc.left, rctSrc.top); for (CoordI y = rctSrc.top; y < rctSrc.bottom; y++) { // loop through VOP CRct memcpy (ppxlcThis, ppxlcSrc, widthSrc * sizeof (PixelC)); ppxlcThis += widthDst; ppxlcSrc += widthSrc; }}own CU8Image* CU8Image::smooth_ (UInt window) const{ const UInt offset = window >> 1; const UInt offset2 = offset << 1; const UInt size = window * window; // array size to be sorted const UInt med = size >> 1; CU8Image* pfmgRet = new CU8Image (*this); // bound of the image to be filtered. const CoordI left = where ().left + offset; const CoordI top = where ().top + offset; const CoordI right = where ().right - offset; const CoordI bottom = where ().bottom - offset; const Int width = where ().width; const Int dist = offset + offset * width; const Int wwidth = width - window; PixelC* rgValues = new PixelC [size]; PixelC* pRet = (PixelC*) pfmgRet -> pixels (left, top); const PixelC* p = pixels (left, top); for (CoordI y = top; y != bottom; y++) { for (CoordI x = left; x != right; x++) { const PixelC* pp = p - dist; // get correct index UInt numTransp = 0; for (UInt sy = 0; sy < window; sy++) { for (UInt sx = 0; sx < window; sx++) { if (*pp == transpValue) numTransp++; pp++; } pp += wwidth; } *pRet++ = (PixelC) ((numTransp <= med) ? opaqueValue : transpValue); p++; } pRet += offset2; p += offset2; } delete [] rgValues; return pfmgRet;}own CU8Image* CU8Image::smooth (UInt window) const{ UInt offset = window >> 1; CRct rctExp (where ()); rctExp.expand (offset); CU8Image* puciExp = new CU8Image (*this, rctExp); CU8Image* puciSmooth = puciExp -> smooth_ (window); puciSmooth -> where (where ()); delete puciExp; return puciSmooth;}Void CU8Image::CU8Image_xor (const CU8Image& uci){ CRct rctIntersect = m_rc; rctIntersect.clip (uci.where()); if (!rctIntersect.valid () || rctIntersect.empty ()) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -