/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
switch(mpGdiPlusBitmap->GetPixelFormat())
{ case PixelFormat1bppIndexed:
nRetval /= 8; break; case PixelFormat4bppIndexed:
nRetval /= 4; break; case PixelFormat16bppGrayScale: case PixelFormat16bppRGB555: case PixelFormat16bppRGB565: case PixelFormat16bppARGB1555:
nRetval *= 2; break; case PixelFormat24bppRGB:
nRetval *= 3; break; case PixelFormat32bppRGB: case PixelFormat32bppARGB: case PixelFormat32bppPARGB: case PixelFormat32bppCMYK:
nRetval *= 4; break; case PixelFormat48bppRGB:
nRetval *= 6; break; case PixelFormat64bppARGB: case PixelFormat64bppPARGB:
nRetval *= 8; break; default: case PixelFormat8bppIndexed: break;
}
// try to access buffered data
std::shared_ptr<SystemDependentData_GdiPlusBitmap> pSystemDependentData_GdiPlusBitmap(
getSystemDependentData<SystemDependentData_GdiPlusBitmap>(basegfx::SDD_Type::SDDType_GdiPlusBitmap));
if(pSystemDependentData_GdiPlusBitmap)
{ // check data validity if(pSystemDependentData_GdiPlusBitmap->getAssociatedAlpha() != pAlphaSource
|| 0 == maSize.Width()
|| 0 == maSize.Height())
{ // #122350# if associated alpha with which the GDIPlus was constructed has changed // it is necessary to remove it from buffer, reset reference to it and reconstruct // data invalid, forget
pSystemDependentData_GdiPlusBitmap.reset();
}
}
if(pSystemDependentData_GdiPlusBitmap)
{ // use from buffer
aRetval = pSystemDependentData_GdiPlusBitmap->getGdiPlusBitmap();
} elseif(!maSize.IsEmpty())
{ // create and set data const WinSalBitmap* pAssociatedAlpha(nullptr);
if(!pSalRGB->ImplGethDIB())
{ // we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalRGB.emplace();
pExtraWinSalRGB->Create(*pSalRGB, vcl::bitDepthToPixelFormat(pSalRGB->GetBitCount()));
pSalRGB = &*pExtraWinSalRGB;
}
if (pRGB && ScanlineFormat::N24BitTcBgr != pRGB->meFormat)
{ // convert source bitmap to BMP_FORMAT_24BIT_TC_BGR format if not yet in that format
SalTwoRect aSalTwoRect(0, 0, pRGB->mnWidth, pRGB->mnHeight, 0, 0, pRGB->mnWidth, pRGB->mnHeight);
pExtraRGB = StretchAndConvert(
*pRGB,
aSalTwoRect,
ScanlineFormat::N24BitTcBgr);
// copy data to Gdiplus::Bitmap; format is BGR here in both cases, so memcpy is possible for(sal_uInt32 y(0); y < nH; y++)
{ const sal_uInt32 nYInsert(bTopDown ? y : nH - y - 1);
sal_uInt8* targetPixels = static_cast<sal_uInt8*>(aGdiPlusBitmapData.Scan0) + (nYInsert * aGdiPlusBitmapData.Stride);
if(pExtraRGB)
{ // #i123478# shockingly, BitmapBuffer does not free the memory it is controlling // in its destructor, this *has to be done by hand*. Doing it here now delete[] pExtraRGB->mpBits;
pExtraRGB.reset();
} else
{
pSalRGB->ReleaseBuffer(pRGB, BitmapAccessMode::Read);
}
if(!pSalRGB->ImplGethDIB())
{ // we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalRGB.emplace();
pExtraWinSalRGB->Create(*pSalRGB, vcl::bitDepthToPixelFormat(pSalRGB->GetBitCount()));
pSalRGB = &*pExtraWinSalRGB;
}
if (pRGB && ScanlineFormat::N24BitTcBgr != pRGB->meFormat)
{ // convert source bitmap to canlineFormat::N24BitTcBgr format if not yet in that format
SalTwoRect aSalTwoRect(0, 0, pRGB->mnWidth, pRGB->mnHeight, 0, 0, pRGB->mnWidth, pRGB->mnHeight);
pExtraRGB = StretchAndConvert(
*pRGB,
aSalTwoRect,
ScanlineFormat::N24BitTcBgr);
if(!pSalA->ImplGethDIB())
{ // we need DIB for success with AcquireBuffer, create a replacement WinSalBitmap
pExtraWinSalA.emplace();
pExtraWinSalA->Create(*pSalA, vcl::bitDepthToPixelFormat(pSalA->GetBitCount()));
pSalA = &*pExtraWinSalA;
}
BitmapBuffer* pA = pSalA->AcquireBuffer(BitmapAccessMode::Read);
std::optional<BitmapBuffer> pExtraA;
if (pA && ScanlineFormat::N8BitPal != pA->meFormat)
{ // convert alpha bitmap to ScanlineFormat::N8BitPal format if not yet in that format
SalTwoRect aSalTwoRect(0, 0, pA->mnWidth, pA->mnHeight, 0, 0, pA->mnWidth, pA->mnHeight);
if ( pRetval->GetLastStatus() == Gdiplus::Ok ) // 2nd place to secure with new Gdiplus::Bitmap
{
sal_uInt8* pSrcRGB(pRGB->mpBits);
sal_uInt8* pSrcA(pA->mpBits); const sal_uInt32 nExtraRGB(pRGB->mnScanlineSize - (nW * 3)); const sal_uInt32 nExtraA(pA->mnScanlineSize - nW); constbool bTopDown(pRGB->meDirection == ScanlineDirection::TopDown); const Gdiplus::Rect aAllRect(0, 0, nW, nH);
Gdiplus::BitmapData aGdiPlusBitmapData;
pRetval->LockBits(&aAllRect, Gdiplus::ImageLockModeWrite, PixelFormat32bppARGB, &aGdiPlusBitmapData);
// copy data to Gdiplus::Bitmap; format is BGRA; need to mix BGR from Bitmap and // A from alpha, so inner loop is needed (who invented BitmapEx..?) for(sal_uInt32 y(0); y < nH; y++)
{ const sal_uInt32 nYInsert(bTopDown ? y : nH - y - 1);
sal_uInt8* targetPixels = static_cast<sal_uInt8*>(aGdiPlusBitmapData.Scan0) + (nYInsert * aGdiPlusBitmapData.Stride);
if(pExtraA)
{ // #i123478# shockingly, BitmapBuffer does not free the memory it is controlling // in its destructor, this *has to be done by hand*. Doing it here now delete[] pExtraA->mpBits;
pExtraA.reset();
} else
{
pSalA->ReleaseBuffer(pA, BitmapAccessMode::Read);
}
pExtraWinSalA.reset();
if(pExtraRGB)
{ // #i123478# shockingly, BitmapBuffer does not free the memory it is controlling // in its destructor, this *has to be done by hand*. Doing it here now delete[] pExtraRGB->mpBits;
pExtraRGB.reset();
} else
{
pSalRGB->ReleaseBuffer(pRGB, BitmapAccessMode::Read);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.15Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.