📄 imagemgr.cpp
字号:
HX_RESULT PXImageManager::GetDisplaySubImage(PXImage** ppImage, const HXxRect& rSubRect, BOOL bCopy){ return GetDisplaySubImage(ppImage, rSubRect.left, rSubRect.top, HXxRECT_WIDTH(rSubRect), HXxRECT_HEIGHT(rSubRect), bCopy);}HX_RESULT PXImageManager::GetPresentationSubImage(PXImage** ppImage, UINT32 ulHandle, const PXRect& rSrcRect, const PXRect& rDstRect, BOOL bPreserveAspect){ HX_RESULT retVal = HXR_OK; PXImage* pImage = NULL; PXImage* pSubImage = NULL; PXRect cSrc; PXRect cDst; // Set the rects cSrc.Set(rSrcRect.GetX(), rSrcRect.GetY(), rSrcRect.GetWidth(), rSrcRect.GetHeight()); cDst.Set(rDstRect.GetX(), rDstRect.GetY(), rDstRect.GetWidth(), rDstRect.GetHeight()); if (ppImage && ulHandle) { // Get the presentation image retVal = GetImage(ulHandle, &pImage); if (SUCCEEDED(retVal)) { // Here we check for zero values of width or height in the // src and dst rects. The convention is that a zero for width // means the full width of the image. Same for height. However, // we have to adjust these values to their true values in // order to do comparisons. cSrc.AdjustForZeroValues((UINT32) pImage->GetWidth(), (UINT32) pImage->GetHeight()); cDst.AdjustForZeroValues((UINT32) m_pDisplayImage->GetWidth(), (UINT32) m_pDisplayImage->GetHeight()); if (cSrc.GetWidth() == cDst.GetWidth() && cSrc.GetHeight() == cDst.GetHeight()) { // The src and dst rects are the same, so we don't need to modify // the src image in any way - we can just get a ref to the subimage. retVal = PXImage::CreateObject(&pSubImage); if (SUCCEEDED(retVal)) { // Addref the image pSubImage->AddRef(); // Create the subimage retVal = pSubImage->CreateSubImage(pImage, cSrc); } } else { // Src and dst rects are not the same, so we will have to // do a resize into memory. retVal = GetScratchImage(&pSubImage, cDst.GetWidth(), cDst.GetHeight()); if (SUCCEEDED(retVal)) { // If the presentation image has alpha, then this // image must have alpha too. pSubImage->SetHasAlpha(pImage->GetHasAlpha()); // Do we have to preserve aspect ratio? if (bPreserveAspect) { // First we resolve the rectangles - we currently change the destination // rectangle PXRect cNewDst; PXRect cFill1; PXRect cFill2; retVal = ResolveAspectRatio(cSrc, cDst, cNewDst, cFill1, cFill2, TRUE); if (SUCCEEDED(retVal)) { if (cFill1.GetWidth() > 0 && cFill1.GetHeight() > 0) { PXImage cTmp; retVal = cTmp.CreateSubImage(pSubImage, cFill1); if (SUCCEEDED(retVal)) { // If we have transparency in this image, then fill // with fully transparent. If not, then fill with // background color. if (cTmp.GetHasAlpha()) { retVal = cTmp.Fill32(0xFF000000); // fully transparent } else { retVal = cTmp.Fill32(m_ulBackgroundColor); } } } if (SUCCEEDED(retVal)) { if (cNewDst.GetWidth() > 0 && cNewDst.GetHeight() > 0) { PXImage cTmpDst; retVal = cTmpDst.CreateSubImage(pSubImage, cNewDst); if (SUCCEEDED(retVal)) { PXImage cTmpSrc; retVal = cTmpSrc.CreateSubImage(pImage, cSrc); if (SUCCEEDED(retVal)) { retVal = cTmpDst.ChangeSizeFromNN(&cTmpSrc); } } } if (SUCCEEDED(retVal)) { if (cFill2.GetWidth() > 0 && cFill2.GetHeight() > 0) { PXImage cTmp; retVal = cTmp.CreateSubImage(pSubImage, cFill2); if (SUCCEEDED(retVal)) { // If we have transparency in this image, then fill // with fully transparent. If not, then fill with // background color. if (cTmp.GetHasAlpha()) { retVal = cTmp.Fill32(0xFF000000); // fully transparent } else { retVal = cTmp.Fill32(m_ulBackgroundColor); } } } } } } } else { // We don't have to preserve aspect ratio, so we draw into the // destination rect AS IS. // // Now we get a ref to the src rect PXImage cTmp; retVal = cTmp.CreateSubImage(pImage, cSrc); if (SUCCEEDED(retVal)) { // Now we change sizes into the scratch image retVal = pSubImage->ChangeSizeFromNN(&cTmp); } } } } if (SUCCEEDED(retVal)) { // Assign the out parameter *ppImage = pSubImage; // AddRef it before it goes out (*ppImage)->AddRef(); } } else { HX_ASSERT(FALSE); } } else { retVal = HXR_INVALID_PARAMETER; } HX_RELEASE(pSubImage); HX_RELEASE(pImage);#ifdef XXXMEH_DEBUG_ASSERT // Debug-only assert HX_ASSERT(SUCCEEDED(retVal));#endif return retVal;}HX_RESULT PXImageManager::GetPresentationSubImage(PXImage** ppImage, UINT32 ulHandle, const PXRect& rSrcRect){ HX_RESULT retVal = HXR_OK; PXImage* pImage = NULL; PXImage* pSubImage = NULL; PXRect cSrc; // Set the rects cSrc.Set(rSrcRect.GetX(), rSrcRect.GetY(), rSrcRect.GetWidth(), rSrcRect.GetHeight()); if (ppImage && ulHandle) { // Get the presentation image retVal = GetImage(ulHandle, &pImage); if (SUCCEEDED(retVal)) { retVal = PXImage::CreateObject(&pSubImage); if (SUCCEEDED(retVal)) { // Addref the image pSubImage->AddRef(); // Here we check for zero values of width or height in the // src and dst rects. The convention is that a zero for width // means the full width of the image. Same for height. However, // we have to adjust these values to their true values in // order to do comparisons. cSrc.AdjustForZeroValues((UINT32) pImage->GetWidth(), (UINT32) pImage->GetHeight()); // Adjust for rects that exceed image boundaries if (cSrc.GetWidth() > (UINT32) pImage->GetWidth()) { cSrc.SetWidth(pImage->GetWidth()); } if (cSrc.GetX() + cSrc.GetWidth() > (UINT32) pImage->GetWidth()) { cSrc.SetX(pImage->GetWidth() - cSrc.GetWidth()); } if (cSrc.GetHeight() > (UINT32) pImage->GetHeight()) { cSrc.SetHeight(pImage->GetHeight()); } if (cSrc.GetY() + cSrc.GetHeight() > (UINT32) pImage->GetHeight()) { cSrc.SetY(pImage->GetHeight() - cSrc.GetHeight()); } // Create the subimage retVal = pSubImage->CreateSubImage(pImage, cSrc); if (SUCCEEDED(retVal)) { // Assign the out parameter *ppImage = pSubImage; // AddRef it before it goes out (*ppImage)->AddRef(); } } } else { HX_ASSERT(FALSE); } } else { retVal = HXR_INVALID_PARAMETER; } HX_RELEASE(pSubImage); HX_RELEASE(pImage);#ifdef XXXMEH_DEBUG_ASSERT // Debug-only assert HX_ASSERT(SUCCEEDED(retVal));#endif return retVal;}HX_RESULT PXImageManager::GetScratchImage(PXImage** ppImage, UINT32 ulW, UINT32 ulH){ HX_RESULT retVal = HXR_OK; IHXBuffer* pBuffer = NULL; PXImage* pImage = NULL; if (ppImage && ulW && ulH) { UINT32 ulBytes = ulW * ulH * m_ulDefaultBytesPerPixel; retVal = GetScratchBuffer(ulBytes, &pBuffer); if (SUCCEEDED(retVal)) { retVal = PXImage::CreateObject(&pImage); if (SUCCEEDED(retVal)) { // AddRef the image pImage->AddRef(); // Create the subimage retVal = pImage->CreateFromBuffer((INT32) ulW, (INT32) ulH, m_ulDefaultBitsPerPixel, m_ulDefaultPixelFormat, m_bDefaultRowsInverted, pBuffer); if (SUCCEEDED(retVal)) { // Set the out parameter *ppImage = pImage; // Addref it before it goes out (*ppImage)->AddRef(); } } } } else { retVal = HXR_INVALID_PARAMETER; } HX_RELEASE(pBuffer); HX_RELEASE(pImage);#ifdef XXXMEH_DEBUG_ASSERT // Debug-only assert HX_ASSERT(SUCCEEDED(retVal));#endif return retVal;}HX_RESULT PXImageManager::GetOpaqueDataSize(UINT32 ulHandle, REF(UINT32) rulOpaqueSize){ HX_RESULT retVal = HXR_FAIL; if (ulHandle) { if (m_pHandleToImageMap) { // Check to see if there really is an entry for this handle void* pVoid = NULL; BOOL bEntryPresent = m_pHandleToImageMap->Lookup((LONG32) ulHandle, pVoid); if (bEntryPresent) { // Get the helper object PXImageHelper* pHelper = (PXImageHelper*) pVoid; if (pHelper) { rulOpaqueSize = pHelper->GetOpaqueSize(); retVal = HXR_OK; } } } } return retVal;}HX_RESULT PXImageManager::GetScratchBuffer(UINT32 ulNumBytesNeeded, IHXBuffer** ppBuffer){#ifdef XXXMEH_DEBUG_LOG DEBUG_OUTF("c:\\realpix.log", (s, "PXImageManager::GetScratchBuffer(%lu,0x%08x)\n", ulNumBytesNeeded, ppBuffer));#endif HX_RESULT retVal = HXR_OK; IHXBuffer* pBuffer = NULL; if (ppBuffer) { // Set default *ppBuffer = NULL; // See if we can an unused one with enough bytes BOOL bFound = FALSE; retVal = ChooseScratchBuffer(ulNumBytesNeeded, &pBuffer, &bFound); if (SUCCEEDED(retVal)) { if (!bFound) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -