📄 grayc.cpp
字号:
else *ppxlc1 = (PixelC) opaqueValue; ppxlc1++; ppxlc2++; } ppxlcRowStart1 += where ().width; ppxlcRowStart2 += uci.where ().width; }}Void CU8Image::CU8Image_or (const CU8Image& uci){ CRct rctIntersect = m_rc; rctIntersect.clip (uci.where()); if (!rctIntersect.valid () || rctIntersect.empty ()) return; PixelC* ppxlcRowStart1 = (PixelC*) pixels (rctIntersect.left, rctIntersect.top); const PixelC* ppxlcRowStart2 = uci.pixels (rctIntersect.left, rctIntersect.top); for (CoordI iy = rctIntersect.top; iy < rctIntersect.bottom; iy++) { PixelC* ppxlc1 = ppxlcRowStart1; const PixelC* ppxlc2 = ppxlcRowStart2; for (CoordI ix = rctIntersect.left; ix < rctIntersect.right; ix++) { assert (*ppxlc1 == transpValue || *ppxlc1 == opaqueValue); assert (*ppxlc2 == transpValue || *ppxlc2 == opaqueValue); if (*ppxlc2 == opaqueValue) *ppxlc1 = opaqueValue; ppxlc1++; ppxlc2++; } ppxlcRowStart1 += where ().width; ppxlcRowStart2 += uci.where ().width; }}Void CU8Image::CU8Image_and (const CU8Image& uci){ CRct rctIntersect = m_rc; rctIntersect.clip (uci.where()); if (!rctIntersect.valid () || rctIntersect.empty ()) return; PixelC* ppxlcRowStart1 = (PixelC*) pixels (rctIntersect.left, rctIntersect.top); const PixelC* ppxlcRowStart2 = uci.pixels (rctIntersect.left, rctIntersect.top); for (CoordI iy = rctIntersect.top; iy < rctIntersect.bottom; iy++) { PixelC* ppxlc1 = ppxlcRowStart1; const PixelC* ppxlc2 = ppxlcRowStart2; for (CoordI ix = rctIntersect.left; ix < rctIntersect.right; ix++) { assert (*ppxlc1 == transpValue || *ppxlc1 == opaqueValue); assert (*ppxlc2 == transpValue || *ppxlc2 == opaqueValue); if (*ppxlc2 == transpValue) *ppxlc1 = transpValue; ppxlc1++; ppxlc2++; } ppxlcRowStart1 += where ().width; ppxlcRowStart2 += uci.where ().width; }}Void CU8Image::maskOut (const CU8Image& uci){ CRct rctIntersect = m_rc; rctIntersect.clip (uci.where()); if (!rctIntersect.valid () || rctIntersect.empty ()) return; PixelC* ppxlcRowStart = (PixelC*) pixels (rctIntersect.left, rctIntersect.top); const PixelC* ppxlcRowStartMask = uci.pixels (rctIntersect.left, rctIntersect.top); for (CoordI iy = rctIntersect.top; iy < rctIntersect.bottom; iy++) { PixelC* ppxlc = ppxlcRowStart; const PixelC* ppxlcMask = ppxlcRowStartMask; for (CoordI ix = rctIntersect.left; ix < rctIntersect.right; ix++) { assert (*ppxlcMask == transpValue || *ppxlcMask == opaqueValue); assert (*ppxlc == transpValue || *ppxlc == opaqueValue); if (*ppxlcMask != transpValue) *ppxlc = transpValue; ppxlc++; ppxlcMask++; } ppxlcRowStart += where ().width; ppxlcRowStartMask += uci.where ().width; }}Void CU8Image::mutiplyAlpha (const CU8Image& uci){ CRct rctIntersect = m_rc; rctIntersect.clip (uci.where()); if (!rctIntersect.valid () || rctIntersect.empty ()) return; PixelC* ppxlcRowStart = (PixelC*) pixels (rctIntersect.left, rctIntersect.top); const PixelC* ppxlcRowStartMask = uci.pixels (rctIntersect.left, rctIntersect.top); for (CoordI iy = rctIntersect.top; iy < rctIntersect.bottom; iy++) { PixelC* ppxlc = ppxlcRowStart; const PixelC* ppxlcMask = ppxlcRowStartMask; for (CoordI ix = rctIntersect.left; ix < rctIntersect.right; ix++) { assert (*ppxlcMask == transpValue || *ppxlcMask == opaqueValue); if (*ppxlcMask == transpValue) *ppxlc = transpValue; else *ppxlc = (PixelC) ((*ppxlc * *ppxlcMask + 127) / opaqueValueF); //normalize ppxlc++; ppxlcMask++; } ppxlcRowStart += where ().width; ppxlcRowStartMask += uci.where ().width; }}Void CU8Image::cropOnAlpha (){ CRct rctVisible = whereVisible (); where (rctVisible); }Void CU8Image::operator = (const CU8Image& uci){ delete [] m_ppxlc; copyConstruct (uci, uci.where ());}Void CU8Image::decimateBinaryShapeFrom (const CU8Image& uciSrc) // decimate by rateX and rateY in a conservative way{ const CoordI left = uciSrc.where ().left / 2; const CoordI top = uciSrc.where ().top / 2; Int roundR = (uciSrc.where ().right >= 0) ? 1 : -1; Int roundB = (uciSrc.where ().bottom >= 0) ? 1 : -1; const CoordI right = (uciSrc.where ().right + roundR) / 2; const CoordI bottom = (uciSrc.where ().bottom + roundB) / 2; assert (where () == CRct (left, top, right, bottom)); PixelC* ppxlc = (PixelC*) pixels (); const PixelC* ppxlcSrc11 = uciSrc.pixels (); const PixelC* ppxlcSrc12 = ppxlcSrc11 + 1; const PixelC* ppxlcSrc21 = ppxlcSrc11 + uciSrc.where ().width; const PixelC* ppxlcSrc22 = ppxlcSrc21 + 1; CoordI x, y; for (y = top; y < bottom; y++) { for (x = left; x < right; x++) { assert (*ppxlcSrc11 == transpValue || *ppxlcSrc11 == opaqueValue); assert (*ppxlcSrc12 == transpValue || *ppxlcSrc12 == opaqueValue); assert (*ppxlcSrc21 == transpValue || *ppxlcSrc21 == opaqueValue); assert (*ppxlcSrc22 == transpValue || *ppxlcSrc22 == opaqueValue); *ppxlc++ = *ppxlcSrc11 | *ppxlcSrc12 | *ppxlcSrc21 | *ppxlcSrc22; ppxlcSrc11 += 2; ppxlcSrc12 += 2; ppxlcSrc21 += 2; ppxlcSrc22 += 2; } ppxlcSrc11 += uciSrc.where ().width; ppxlcSrc12 += uciSrc.where ().width; ppxlcSrc21 += uciSrc.where ().width; ppxlcSrc22 += uciSrc.where ().width; }}Bool CU8Image::operator == (const CU8Image& uci) const{ if (uci.where () != where ()) return FALSE; UInt area = where ().area (); const PixelC* ppxlc = uci.pixels (); const PixelC* ppxlcThis = pixels (); for (UInt ip = 0; ip < area; ip++, ppxlc++, ppxlcThis++) if (*ppxlc != *ppxlcThis) return FALSE; return TRUE;}Double CU8Image::mse (const CU8Image& uciCompare) const{ assert (uciCompare.where () == where ()); Int sqr = 0; const PixelC* ppxlcThis = pixels (); const PixelC* ppxlcCompare = uciCompare.pixels (); UInt area = where ().area (); for (UInt i = 0; i < area; i++) { Int diffR = *ppxlcThis - *ppxlcCompare; sqr += diffR * diffR; ppxlcThis++; ppxlcCompare++; } return ((Double) sqr / area);}Double CU8Image::mse (const CU8Image& uciCompare, const CU8Image& uciMsk) const{ assert (uciCompare.where () == where () && uciMsk.where () == where ()); Int sqr = 0; const PixelC* ppxlcThis = pixels (); const PixelC* ppxlcCompare = uciCompare.pixels (); const PixelC* ppxlcMsk = uciMsk.pixels (); UInt area = where ().area (); UInt uiNonTransp = 0; for (UInt i = 0; i < area; i++) { if (*ppxlcMsk != transpValue) { Int diffR = *ppxlcThis - *ppxlcCompare; sqr += diffR * diffR; uiNonTransp++; } ppxlcThis++; ppxlcCompare++; ppxlcMsk++; } if (uiNonTransp == 0) return 0.0; return ((Double) sqr / area);}Double CU8Image::snr (const CU8Image& uciCompare) const{ Double msError = mse (uciCompare); if (msError == 0.0) return 1000000.0; else return (log10 (255 * 255 / msError) * 10.0);}Double CU8Image::snr (const CU8Image& uciCompare, const CU8Image& uciMsk) const{ CU8Image* puciMskOp = NULL; Double msError = 0; if (&uciMsk == NULL) { puciMskOp = new CU8Image (where (), (PixelC) opaqueValue); msError = mse (uciCompare, *puciMskOp); delete puciMskOp; } else msError = mse (uciCompare, uciMsk); if (msError == 0.0) return 1000000.0; else return (log10 (255 * 255 / msError) * 10.0);}// vdldump doesnt work for >8bit videoVoid CU8Image::vdlDump (const Char* fileName, const CRct& rct) const{ CRct rctRegionOfInterest = (!rct.valid ()) ? where () : rct; assert (rctRegionOfInterest <= where ()); if (rctRegionOfInterest == where ()) { CVideoObjectPlane vop (where (), opaquePixel); CPixel* ppxl = (CPixel*) vop.pixels (); const PixelC* ppxlc = pixels (); UInt area = where ().area (); for (UInt ip = 0; ip < area; ip++, ppxl++, ppxlc++) *ppxl = CPixel ((U8)*ppxlc, (U8)*ppxlc, (U8)*ppxlc, opaqueValue); vop.vdlDump (fileName); } else { CVideoObjectPlane vop (rct, opaquePixel); Int offset = where ().width - rct.width; CPixel* ppxl = (CPixel*) vop.pixels (); const PixelC* ppxlc = pixels (rctRegionOfInterest.left, rctRegionOfInterest.top); for (CoordI y = rctRegionOfInterest.top; y < rctRegionOfInterest.bottom; y++) { for (CoordI x = rctRegionOfInterest.left; x < rctRegionOfInterest.right; x++, ppxl++, ppxlc++) { *ppxl = CPixel ((U8)*ppxlc, (U8)*ppxlc, (U8)*ppxlc, opaqueValue); } ppxlc += offset; } vop.vdlDump (fileName); }} Void CU8Image::dump (FILE* pf, const CRct& rct, Int iScale) const{ CRct rctRegionOfInterest = (!rct.valid ()) ? where () : rct; assert (rctRegionOfInterest <= where ()); iScale++; if(iScale!=256) { Int i,j; PixelC pxlTmp; const PixelC* ppxlc = pixels (rctRegionOfInterest.left, rctRegionOfInterest.top); for (i = rctRegionOfInterest.top; i < rctRegionOfInterest.bottom; i++) { for(j = 0; j <rctRegionOfInterest.width; j++) { pxlTmp = (ppxlc[j]*iScale)>>8; fwrite(&pxlTmp, sizeof(PixelC), 1, pf); } ppxlc += where ().width; } } else { if (rctRegionOfInterest == where ()) { /* NBIT: change U8 to PixelC fwrite (m_ppxlc, sizeof (U8), where ().area (), pf); */ fwrite (m_ppxlc, sizeof (PixelC), where ().area (), pf); } else { const PixelC* ppxlc = pixels (rctRegionOfInterest.left, rctRegionOfInterest.top); for (Int i = rctRegionOfInterest.top; i < rctRegionOfInterest.bottom; i++) { /* NBIT: change U8 to PixelC fwrite (ppxlc, sizeof (U8), rctRegionOfInterest.width, pf); */ fwrite (ppxlc, sizeof (PixelC), rctRegionOfInterest.width, pf); ppxlc += where ().width; } } }}Void CU8Image::dumpWithMask (FILE* pf, const CU8Image *puciMask, const CRct& rct, Int iScale) const{ PixelC pxlZero = 0; // NBIT PixelC pxlTmp; CRct rctRegionOfInterest = (!rct.valid ()) ? where () : rct; assert (rctRegionOfInterest <= where ()); assert (rctRegionOfInterest <= puciMask->where ()); Int x; const PixelC* ppxlc = pixels (rctRegionOfInterest.left, rctRegionOfInterest.top); const PixelC* ppxlcMask = puciMask->pixels(rctRegionOfInterest.left, rctRegionOfInterest.top); iScale++; for (Int i = rctRegionOfInterest.top; i < rctRegionOfInterest.bottom; i++) { for(x = 0; x<rctRegionOfInterest.width; x++) if(ppxlcMask[x] == 0)/* NBIT: change fputc(0, pf);*/ fwrite(&pxlZero, sizeof(PixelC), 1, pf); else if(iScale==256)/* NBIT: change fputc(ppxlc[x], pf);*/ fwrite(&ppxlc[x], sizeof(PixelC), 1, pf); else { pxlTmp = (ppxlc[x] * iScale)>>8; fwrite(&pxlTmp, sizeof(PixelC), 1, pf); } ppxlc += where ().width; ppxlcMask += puciMask->where().width; }}Void CU8Image::txtDump (const Char* fileName) const{ FILE* pfTxt; const PixelC* ppxlc = pixels (); if (fileName != NULL) pfTxt = fopen (fileName, "w"); else pfTxt = NULL; for (CoordI y = 0; y < where ().height (); y++) { for (CoordI x = 0; x < where ().width; x++) { if (pfTxt != NULL) fprintf (pfTxt, "%3d ", *ppxlc); else printf ("%3d ", *ppxlc); ppxlc++; } if (pfTxt != NULL) fprintf (pfTxt, "\n"); else printf ("\n"); } if (pfTxt != NULL) fclose (pfTxt);}Void CU8Image::txtDump (FILE *pf) const{ const PixelC *ppxlc = pixels(); for (CoordI y = 0; y < where ().height (); y++) { for (CoordI x = 0; x < where ().width; x++) { fprintf (pf, "%3d ", *ppxlc); ppxlc++; } fprintf (pf,"\n"); } fprintf (pf,"\n");}Void CU8Image::txtDumpMask (FILE *pf) const{ const PixelC *ppxlc = pixels (); for (CoordI y = 0; y < where ().height (); y++) { for (CoordI x = 0; x < where ().width; x++) { if (*ppxlc == transpValue) fprintf (pf, ".."); else fprintf (pf, "[]"); ppxlc++; } fprintf (pf,"\n"); } fprintf (pf,"\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -