searchwindow.hh
来自「Motion JPEG编解码器源代码」· HH 代码 · 共 1,997 行 · 第 1/5 页
HH
1,997 行
tnSearchWindowPixelTop = m_tnY - m_tnSearchRadiusY; tnSearchWindowPixelBottom = m_tnY + m_tnSearchRadiusY + PIXELINDEX (1); // Then it gets clipped by the frame boundaries. tnSearchWindowPixelLeft = Max (tnSearchWindowPixelLeft, PIXELINDEX (0)); tnSearchWindowPixelRight = Min (tnSearchWindowPixelRight, PIXELINDEX (m_tnWidth - PGW + 1)); tnSearchWindowPixelTop = Max (tnSearchWindowPixelTop, PIXELINDEX (0)); tnSearchWindowPixelBottom = Min (tnSearchWindowPixelBottom, PIXELINDEX (m_tnHeight - PGH + 1)); // If we only have to loop through part of the search window, do // so, to save time. tnSearchLeft = tnSearchWindowPixelLeft; tnSearchRight = tnSearchWindowPixelRight; tnSearchTop = tnSearchWindowPixelTop; tnSearchBottom = tnSearchWindowPixelBottom; if (tnSearchWindowPixelLeft == m_tnSearchWindowPixelLeft && tnSearchWindowPixelRight == m_tnSearchWindowPixelRight) { // We only have to do the bottom line. assert (tnSearchWindowPixelTop == m_tnSearchWindowPixelTop); tnSearchTop = m_tnSearchWindowPixelBottom; } else if (tnSearchWindowPixelTop == m_tnSearchWindowPixelTop && tnSearchWindowPixelBottom == m_tnSearchWindowPixelBottom) { if (tnSearchWindowPixelLeft == m_tnSearchWindowPixelLeft) { // We only have to do the right side. tnSearchLeft = m_tnSearchWindowPixelRight; } else if (tnSearchWindowPixelRight == m_tnSearchWindowPixelRight) { // We only have to do the left side. tnSearchRight = m_tnSearchWindowPixelLeft; } } // Loop through the active portion of the search window, find all // pixel-groups that contain only unresolved pixels, and put those // cells into the pixel-sorter. Skip the already-active part of the // search-window, if any. for (tnY = tnSearchTop; tnY < tnSearchBottom; ++tnY) { PIXELINDEX tnPixelX, tnPixelY; // Used to loop through pixels in the pixel-group. for (tnX = tnSearchLeft; tnX < tnSearchRight; ++tnX) { // Skip any part of the search-window that's already active. if (tnY >= m_tnSearchWindowPixelTop && tnY < m_tnSearchWindowPixelBottom && tnX >= m_tnSearchWindowPixelLeft && tnX < m_tnSearchWindowPixelRight) { // (Skip the rest of the line.) assert (tnX == m_tnSearchWindowPixelLeft); tnX = m_tnSearchWindowPixelRight - PIXELINDEX (1); goto nextXPixel; } // Get the cell that we'll be setting up. pCell = &(m_ppSearchWindow[tnY][tnX]); // If this cell was invalidated previously, skip it. if (pCell->m_eDoneSorting && pCell->m_pSorter == NULL) { assert (pCell->m_pForward == NULL); assert (pCell->m_pBackward == NULL); goto nextXPixel; } // If this cell was set up previously, skip it. if (pCell->m_pForward != NULL) { assert (pCell->m_pBackward != NULL); goto sortCell; } // Now set up the pixels. for (tnPixelY = 0; tnPixelY < PGH; ++tnPixelY) { for (tnPixelX = 0; tnPixelX < PGW; ++tnPixelX) { ReferencePixel_t *pPixel; // The current reference pixel. // Get the current reference pixel. pPixel = m_pReferenceFrame->GetPixel (tnX + tnPixelX, tnY + tnPixelY); // Set up the corresponding pixel in the current // search-window cell. pCell->m_atPixels[tnPixelY][tnPixelX] = pPixel->GetValue(); } } // Set up the cell's location. pCell->m_tnX = tnX; pCell->m_tnY = tnY; // Remember that this cell's pixels are set up (by putting // the cell into a circular list with itself). pCell->m_pForward = pCell->m_pBackward = pCell; sortCell:;#ifndef OPTIONALLY_SORT_PIXEL_GROUPS // Put this cell into the pixel-sorter, if it's not // there already. if (pCell->m_pForward == pCell) { // (Sanity check: the backward pointer should be // circular too.) assert (pCell->m_pBackward == pCell); // Take it out of the list it's in with itself. pCell->Remove(); // Put it into the pixel-sorter. pCell->m_pSorter = PixelSorter_Add (a_reStatus, pCell, pCell->m_pSorter, pCell->m_eDoneSorting); if (a_reStatus != g_kNoError) return; }#endif // OPTIONALLY_SORT_PIXEL_GROUPSnextXPixel:; } } // The search-window now looks like this. m_tnSearchWindowPixelLeft = tnSearchWindowPixelLeft; m_tnSearchWindowPixelRight = tnSearchWindowPixelRight; m_tnSearchWindowPixelTop = tnSearchWindowPixelTop; m_tnSearchWindowPixelBottom = tnSearchWindowPixelBottom;#ifndef OPTIONALLY_SORT_PIXEL_GROUPS // The search-window now looks like this. m_tnSearchWindowSortLeft = tnSearchWindowPixelLeft; m_tnSearchWindowSortRight = tnSearchWindowPixelRight; m_tnSearchWindowSortTop = tnSearchWindowPixelTop; m_tnSearchWindowSortBottom = tnSearchWindowPixelBottom;#else // OPTIONALLY_SORT_PIXEL_GROUPS // Put pixel-groups into the pixel-sorter, if so asked. if (a_bSortPixels) { PIXELINDEX tnSearchWindowSortLeft, tnSearchWindowSortRight, tnSearchWindowSortTop, tnSearchWindowSortBottom; // What the search window should look like when we're done. // The search window starts in a radius around the index of the // current pixel group. tnSearchWindowSortLeft = m_tnX - m_tnSearchRadiusX; tnSearchWindowSortRight = m_tnX + m_tnSearchRadiusX + PIXELINDEX (1); tnSearchWindowSortTop = m_tnY - m_tnSearchRadiusY; tnSearchWindowSortBottom = m_tnY + m_tnSearchRadiusY + PIXELINDEX (1); // Then it gets clipped by the frame boundaries. tnSearchWindowSortLeft = Max (tnSearchWindowSortLeft, PIXELINDEX (0)); tnSearchWindowSortRight = Min (tnSearchWindowSortRight, PIXELINDEX (m_tnWidth - PGW + 1)); tnSearchWindowSortTop = Max (tnSearchWindowSortTop, PIXELINDEX (0)); tnSearchWindowSortBottom = Min (tnSearchWindowSortBottom, PIXELINDEX (m_tnHeight - PGH + 1)); // If we only have to loop through part of the search window, do // so, to save time. tnSearchLeft = tnSearchWindowSortLeft; tnSearchRight = tnSearchWindowSortRight; tnSearchTop = tnSearchWindowSortTop; tnSearchBottom = tnSearchWindowSortBottom; if (tnSearchWindowSortLeft == m_tnSearchWindowSortLeft && tnSearchWindowSortRight == m_tnSearchWindowSortRight) { // We only have to do the bottom line. assert (tnSearchWindowSortTop == m_tnSearchWindowSortTop); tnSearchTop = m_tnSearchWindowSortBottom; } else if (tnSearchWindowSortTop == m_tnSearchWindowSortTop && tnSearchWindowSortBottom == m_tnSearchWindowSortBottom) { if (tnSearchWindowSortLeft == m_tnSearchWindowSortLeft) { // We only have to do the right side. tnSearchLeft = m_tnSearchWindowSortRight; } else if (tnSearchWindowSortRight == m_tnSearchWindowSortRight) { // We only have to do the left side. tnSearchRight = m_tnSearchWindowSortLeft; } } // Loop through the active portion of the search window, find // all pixel-groups that contain only unresolved pixels, and // put those cells into the pixel-sorter. Skip the // already-active part of the search-window, if any. for (tnY = tnSearchTop; tnY < tnSearchBottom; ++tnY) { for (tnX = tnSearchLeft; tnX < tnSearchRight; ++tnX) { // Skip any part of the search-window that's already // active. if (tnY >= m_tnSearchWindowSortTop && tnY < m_tnSearchWindowSortBottom && tnX >= m_tnSearchWindowSortLeft && tnX < m_tnSearchWindowSortRight) { // (Skip the rest of the line.) assert (tnX == m_tnSearchWindowSortLeft); tnX = m_tnSearchWindowSortRight - PIXELINDEX (1); continue; } // Get the cell that we'll be setting up. pCell = &(m_ppSearchWindow[tnY][tnX]); // Put this cell into the pixel-sorter, if it's not // there already. if (pCell->m_pForward == pCell) { // (Sanity check: the backward pointer should be // circular too.) assert (pCell->m_pBackward == pCell); // Take it out of the list it's in with itself. pCell->Remove(); // Put it into the pixel-sorter. pCell->m_pSorter = PixelSorter_Add (a_reStatus, pCell, pCell->m_pSorter, pCell->m_eDoneSorting); if (a_reStatus != g_kNoError) return; } } } // The search-window now looks like this. m_tnSearchWindowSortLeft = tnSearchWindowSortLeft; m_tnSearchWindowSortRight = tnSearchWindowSortRight; m_tnSearchWindowSortTop = tnSearchWindowSortTop; m_tnSearchWindowSortBottom = tnSearchWindowSortBottom; }#endif // OPTIONALLY_SORT_PIXEL_GROUPS}#ifdef OPTIONALLY_SORT_PIXEL_GROUPS// Return the cell at this index.template <class PIXEL_NUM, int DIM, class PIXEL_TOL, class PIXELINDEX, class FRAMESIZE, PIXELINDEX PGW, PIXELINDEX PGH, class SORTERBITMASK, class PIXEL, class REFERENCEPIXEL, class REFERENCEFRAME>template <class REGION>const SearchWindow<PIXEL_NUM,DIM,PIXEL_TOL,PIXELINDEX,FRAMESIZE, PGW,PGH,SORTERBITMASK,PIXEL,REFERENCEPIXEL, REFERENCEFRAME>::SearchWindowCell &SearchWindow<PIXEL_NUM,DIM,PIXEL_TOL,PIXELINDEX,FRAMESIZE, PGW,PGH,SORTERBITMASK,PIXEL,REFERENCEPIXEL, REFERENCEFRAME>:: GetCell (PIXELINDEX a_tnY, PIXELINDEX a_tnX) const{ // Make sure the indices are within range. assert (a_tnX >= 0 && a_tnX < m_tnWidth - PGW + 1 && a_tnY >= 0 && a_tnY < m_tnHeight - PGH + 1); // Easy enough. return m_ppSearchWindow[a_tnY][a_tnX];}#endif // OPTIONALLY_SORT_PIXEL_GROUPS// Prune the search-window, i.e. find all pixel-groups that now// contain used reference-pixels, and remove them from the window// and from the pixel-sorter.template <class PIXEL_NUM, int DIM, class PIXEL_TOL, class PIXELINDEX, class FRAMESIZE, PIXELINDEX PGW, PIXELINDEX PGH, class SORTERBITMASK, class PIXEL, class REFERENCEPIXEL, class REFERENCEFRAME>template <class REGION>voidSearchWindow<PIXEL_NUM,DIM,PIXEL_TOL,PIXELINDEX,FRAMESIZE, PGW,PGH,SORTERBITMASK,PIXEL,REFERENCEPIXEL, REFERENCEFRAME>::Prune (const REGION &a_rAppliedRegion, PIXELINDEX a_tnOffsetX, PIXELINDEX a_tnOffsetY){ typename REGION::ConstIterator itExtent; // Used to loop through applied-region extents. PIXELINDEX tnX, tnY; // Used to loop through search-window cells. // Make sure we have a new frame & reference frame to work with. assert (m_pReferenceFrame != NULL); // Loop through all the extents in the newly-applied region, find // all corresponding search-window cells, and invalidate them. for (itExtent = a_rAppliedRegion.Begin(); itExtent != a_rAppliedRegion.End(); ++itExtent) { PIXELINDEX tnTop, tnBottom, tnLeft, tnRight; // The range of search-window cells invalidated by the // current applied-region extent. // Get the current extent. const typename REGION::Extent &rExtent = *itExtent; // Determine the range of search-window cells invalidated by // this extent. tnTop = rExtent.m_tnY - PGH + PIXELINDEX (1) + a_tnOffsetY; tnBottom = rExtent.m_tnY + PIXELINDEX (1) + a_tnOffsetY; tnLeft = rExtent.m_tnXStart - PGW + PIXELINDEX (1) + a_tnOffsetX; tnRight = rExtent.m_tnXEnd + a_tnOffsetX; if (tnTop < 0) tnTop = 0; if (tnBottom > m_tnHeight - PGH + PIXELINDEX (1)) tnBottom = m_tnHeight - PGH + PIXELINDEX (1); if (tnLeft < 0) tnLeft = 0; if (tnRight > m_tnWidth - PGW + PIXELINDEX (1)) tnRight = m_tnWidth - PGW + PIXELINDEX (1); // Loop through the search-window cells intersected by the // current extent, and invalidate them. for (tnY = tnTop; tnY < tnBottom; ++tnY) { for (tnX = tnLeft; tnX < tnRight; ++tnX) { SearchWindowCell *pCell; // The search-window cell corresponding to the pixel // group being manipulated. // Get the cell. pCell = &(m_ppSearchWindow[tnY][tnX]); // If the cell is in use, remove it from service. if (pCell->m_pForward != NULL) { // (Sanity check.) assert (pCell->m_pBackward != NULL); // Remove this cell from the pixel-sorter, if it's // in there. if (pCell->m_pForward != pCell) PixelSorter_Remove (pCell); // Invalidate this cell. assert (pCell->m_pForward == pCell); pCell->Remove(); } // Mark it as invalid, so that it won't be used again // for the rest of the frame. pCell->m_eDoneSorting = SearchWindowCell::m_knDone; pCell->m_pSorter = NULL; } } }}// Move the window one pixel to the right, removing all pixel// groups on the left side of the window.template <class PIXEL_NUM, int DIM, class PIXEL_TOL, class PIXELINDEX, class FRAMESIZE, PIXELINDEX PGW, PIXELINDEX PGH, class SORTERBITMASK, class PIXEL, class REFERENCEPIXEL, class REFERENCEFRAME>voidSearchWindow<PIXEL_NUM,DIM,PIXEL_TOL,PIXELINDEX,FRAMESIZE, PGW,PGH,SORTERBITMASK,PIXEL,REFERENCEPIXEL, REFERENCEFRAME>::MoveRight (void){ PIXELINDEX tnY; // Used to loop through pixel groups. SearchWindowCell *pCell; // The search-window cell corresponding to the pixel group being // removed from the search-window. // If the leftmost edge of the search-window isn't at the edge of // the active area, we can stop now. if (m_tnX - m_tnSearchRadiusX != m_tnSearchWindowPixelLeft) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?