void CDitheringView::OnDither4() { // TODO: 여기에 명령 처리기 코드를 추가합니다. CDitheringDoc* pDoc = GetDocument(); CClientDC dc(this); CDC memDC; CSize sizeTotal; // TODO: 이 뷰의 전체 크기를 계산합니다. memDC.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, pDoc->width * 4, pDoc->height * 4 ); memDC.SelectObject( &bitmap ); int i, j, k = 0; for(i = 0; i < pDoc->pixel.GetSize(); i++){ pDoc->ditherPixel.Add(RGBtoGray(pDoc->pixel[i])); pDoc->ditherLevel.Add(dither4Leveling(RGBtoGray(pDoc->pixel[i]))); } for(i = 0; i < pDoc->height * 4; i = i + 4){ for(j = 0; j < pDoc->width * 4; j = j + 4){ dither4SetPx(&memDC, pDoc->ditherLevel[k], pDoc->ditherPixel[k], i, j); k++; } } dc.BitBlt(0, 0, pDoc->width * 4, pDoc->height * 4, &memDC, 0, 0, SRCCOPY); }
void CDitheringView::OnOrdered4() { // TODO: 여기에 명령 처리기 코드를 추가합니다. CDitheringDoc* pDoc = GetDocument(); CClientDC dc(this); int ditherMatrix[4][4] = {0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5}; CDC memDC; memDC.CreateCompatibleDC( &dc ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, pDoc->width, pDoc->height); memDC.SelectObject( &bitmap ); int i, j, x, y, k = 0; for(i = 0; i < pDoc->pixel.GetSize(); i++){ pDoc->ditherPixel.Add(RGBtoGray(pDoc->pixel[i])); pDoc->ditherLevel.Add(dither2Leveling(RGBtoGray(pDoc->pixel[i]))); } for(i = 0; i < pDoc->height; i++){ for(j = 0; j < pDoc->width; j++){ x = i % 4; y = j % 4; if(pDoc->ditherLevel[k] > ditherMatrix[x][y]){ memDC.SetPixel(i, j, pDoc->ditherPixel[k]); }else{ memDC.SetPixel(i, j, RGB(255, 255, 255)); } k++; } } dc.BitBlt(0, 0, pDoc->width, pDoc->height, &memDC, 0, 0, SRCCOPY); }
void CVisPPUSim::DoProcessing() { Int lines; // Copy ids; Uint32 copyRGB; Uint32 copyLUT; Uint32 copyGray; Uint32 copyErodedLUT; // Acquire the image buffers const Uint8 * pLUT = (Uint8*)m_iportLUT.GetBuffer(); const Uint32 * pRGBImage = (const Uint32*)m_iportRGBInput.GetBuffer(); Uint8 * pGrayImage = (Uint8*)m_oportGrayOutput.GetBuffer(); Uint8 * pLUTImage = (Uint8*)m_oportLUTOutput.GetBuffer(); // *************************************************************** // Process the image line by line; First convert to gray and do // the LUT lookup. // *************************************************************** // Prologue; copy the RGB lines from the image copyRGB = StartCopy( (Ptr)m_pRGBLine, (Ptr)pRGBImage, m_unResultWidth * 4 ); copyGray = COPY_DONE; copyLUT = COPY_DONE; // Kernel for ( lines = 0; lines < m_unResultHeight; lines++) { Uint32 offs = lines * m_unResultWidth; // Convert RGB to gray // -> need RGB input // -> need gray WaitCopy( copyRGB ); WaitCopy( copyGray ); RGBtoGray( m_pRGBLine, (Uint32*)(m_pGrayLine), m_unResultWidth ); // Lookup the RGB pixels; but not on first and last lines. // -> done with gray afterwards // -> done with RGB afterwards // -> done with LUT afterwards WaitCopy( copyLUT ); if ( (lines != 0) && (lines != m_unResultHeight-1) ) LookupPixels( m_pRGBLine, m_pLUTData, m_pGrayLine, pLUT, m_unResultWidth ); else MemSet( m_pLUTData, 0, m_unResultWidth ); if ( lines < m_unResultHeight-1) copyRGB = StartCopy( (Ptr)m_pRGBLine, (Ptr)(pRGBImage + offs + m_unResultWidth), m_unResultWidth * 4 ); copyGray = StartCopy( (Ptr)(pGrayImage + offs), m_pGrayLine, m_unResultWidth ); copyLUT = StartCopy( (Ptr)(pLUTImage + offs), m_pLUTData, m_unResultWidth ); } // Epilogue //WaitCopy( copyRGB ); WaitCopy( copyLUT ); WaitCopy( copyGray ); // *************************************************************** // Erode the image. // *************************************************************** for (int i=0; i<m_nNumErosions ; i++) { // To keep things simple, we'd like to do the erosion in place, // that is the input and output port is the same. That behaviour // implies that we have to copy the new input data before writing // the output data back to the image. // Copy the input data. copyLUT = StartCopy( m_pLUTData, (Ptr)(pLUTImage) , m_unResultWidth * 3); WaitCopy( copyLUT ); for ( lines = 1; lines < m_unResultHeight-1; lines++) { // Erode a line ErodeLine_lut( m_pLUTData, m_pErodedLUTData, m_unResultWidth ); // Copy the next input data. copyLUT = StartCopy( m_pLUTData, (Ptr)(pLUTImage + lines * m_unResultWidth) , m_unResultWidth * 3 ); // Wait for the copy to finish, so that the output can then be written. WaitCopy( copyLUT ); // Copy the result data out copyErodedLUT = StartCopy( (Ptr)(pLUTImage + lines*m_unResultWidth) , m_pErodedLUTData, m_unResultWidth ); WaitCopy( copyErodedLUT ); } } // Clear the most left and right rows. for ( lines = 0; lines < m_unResultHeight; lines++) { pLUTImage[ lines*m_unResultWidth ] = 0; pLUTImage[ lines*m_unResultWidth + m_unResultWidth - 1] = 0; } /* // Convert the image to grayscale StartProfileTask( m_nProfile_1 ); RGBtoGray( pRGBImage, (Uint32*)(pGrayImage), m_unResultWidth*m_unResultHeight ); StopProfileTask( m_nProfile_1 ); // do the LUT conversion StartProfileTask( m_nProfile_2 ); LookupPixels( pRGBImage, pLUTImage, m_unResultWidth*m_unResultHeight ); StopProfileTask( m_nProfile_2 ); // Mask out all grayscale pixels where there is background StartProfileTask( m_nProfile_3 ); for ( Uint32 i=0; i<m_unResultWidth*m_unResultHeight; i++) if ( pLUTImage[i] == 0 ) pGrayImage[i] = 0; StopProfileTask( m_nProfile_3 ); */ /* // Do Erosion for ( int er=0; er<CVisCalibHistogram::NUM_EROSIONS; er++) { for ( Uint32 line=1; line<m_unResultHeight-1; line++) { Uint32 offs = line * m_unResultWidth; ErodeLine( pLUTImage + offs, pErodedImage + offs + m_unResultWidth, m_unResultWidth ); } memcpy( pLUTImage, pErodedImage, m_unResultWidth*m_unResultHeight ); } */ }