BinaryDataContainer: hand out shared_ptr's to SvStreams.
Hide the SvMemoryStream implementation detail better - this could be served from a file in future. Also couple lifecycle of the SvMemoryStream to the vector backing it. Change-Id: Ia9b28b57b8df4ce57286effd4d1753bf345fc10e Signed-off-by: Michael Meeks <michael.meeks@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149917 Tested-by: Jenkins
This commit is contained in:
parent
689f0da67b
commit
c55d558630
@ -47,8 +47,10 @@ public:
|
|||||||
const sal_uInt8* getData() const;
|
const sal_uInt8* getData() const;
|
||||||
css::uno::Sequence<sal_Int8> getCopyAsByteSequence() const;
|
css::uno::Sequence<sal_Int8> getCopyAsByteSequence() const;
|
||||||
|
|
||||||
// Returns the data as a stream open for reading
|
// Returns the data as a readonly stream open for reading
|
||||||
SvMemoryStream getMemoryStream();
|
std::shared_ptr<SvStream> getAsStream();
|
||||||
|
|
||||||
|
/// writes the contents to the given stream
|
||||||
std::size_t writeToStream(SvStream& rStream) const;
|
std::size_t writeToStream(SvStream& rStream) const;
|
||||||
|
|
||||||
size_t calculateHash() const;
|
size_t calculateHash() const;
|
||||||
|
@ -38,9 +38,9 @@ struct VCL_DLLPUBLIC ExternalPDFStream
|
|||||||
{
|
{
|
||||||
if (!mpPDFDocument)
|
if (!mpPDFDocument)
|
||||||
{
|
{
|
||||||
SvMemoryStream aPDFStream = maDataContainer.getMemoryStream();
|
std::shared_ptr<SvStream> aPDFStream = maDataContainer.getAsStream();
|
||||||
auto pPDFDocument = std::make_shared<filter::PDFDocument>();
|
auto pPDFDocument = std::make_shared<filter::PDFDocument>();
|
||||||
if (!pPDFDocument->ReadWithPossibleFixup(aPDFStream))
|
if (!pPDFDocument->ReadWithPossibleFixup(*aPDFStream))
|
||||||
{
|
{
|
||||||
SAL_WARN("vcl.pdfwriter",
|
SAL_WARN("vcl.pdfwriter",
|
||||||
"PDFWriterImpl::writeReferenceXObject: reading the PDF document failed");
|
"PDFWriterImpl::writeReferenceXObject: reading the PDF document failed");
|
||||||
|
@ -914,8 +914,8 @@ Graphic GraphicFilter::ImportUnloadedGraphic(SvStream& rIStream, sal_uInt64 size
|
|||||||
Size aLogicSize;
|
Size aLogicSize;
|
||||||
if (eLinkType == GfxLinkType::NativeGif)
|
if (eLinkType == GfxLinkType::NativeGif)
|
||||||
{
|
{
|
||||||
SvMemoryStream aMemoryStream(aGraphicContent.getMemoryStream());
|
std::shared_ptr<SvStream> pMemoryStream = aGraphicContent.getAsStream();
|
||||||
bAnimated = IsGIFAnimated(aMemoryStream, aLogicSize);
|
bAnimated = IsGIFAnimated(*pMemoryStream, aLogicSize);
|
||||||
if (!pSizeHint && aLogicSize.getWidth() && aLogicSize.getHeight())
|
if (!pSizeHint && aLogicSize.getWidth() && aLogicSize.getHeight())
|
||||||
{
|
{
|
||||||
pSizeHint = &aLogicSize;
|
pSizeHint = &aLogicSize;
|
||||||
@ -954,8 +954,8 @@ ErrCode GraphicFilter::readPNG(SvStream & rStream, Graphic & rGraphic, GfxLinkTy
|
|||||||
if (auto aMSGifChunk = vcl::PngImageReader::getMicrosoftGifChunk(rStream);
|
if (auto aMSGifChunk = vcl::PngImageReader::getMicrosoftGifChunk(rStream);
|
||||||
!aMSGifChunk.isEmpty())
|
!aMSGifChunk.isEmpty())
|
||||||
{
|
{
|
||||||
SvMemoryStream aIStrm(aMSGifChunk.getMemoryStream());
|
std::shared_ptr<SvStream> pIStrm(aMSGifChunk.getAsStream());
|
||||||
ImportGIF(aIStrm, rGraphic);
|
ImportGIF(*pIStrm, rGraphic);
|
||||||
rLinkType = GfxLinkType::NativeGif;
|
rLinkType = GfxLinkType::NativeGif;
|
||||||
rpGraphicContent = aMSGifChunk;
|
rpGraphicContent = aMSGifChunk;
|
||||||
return aReturnCode;
|
return aReturnCode;
|
||||||
|
@ -42,9 +42,28 @@ css::uno::Sequence<sal_Int8> BinaryDataContainer::getCopyAsByteSequence() const
|
|||||||
return aData;
|
return aData;
|
||||||
}
|
}
|
||||||
|
|
||||||
SvMemoryStream BinaryDataContainer::getMemoryStream()
|
namespace
|
||||||
{
|
{
|
||||||
return SvMemoryStream(mpData ? mpData->data() : nullptr, getSize(), StreamMode::READ);
|
/*
|
||||||
|
* Hold a reference on the internal state in case we swap out
|
||||||
|
* and free the vector while someone holds an SvStream pointer.
|
||||||
|
*/
|
||||||
|
class ReferencedMemoryStream : public SvMemoryStream
|
||||||
|
{
|
||||||
|
std::shared_ptr<std::vector<sal_uInt8>> mpData;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ReferencedMemoryStream(const std::shared_ptr<std::vector<sal_uInt8>>& rData)
|
||||||
|
: SvMemoryStream(rData ? rData->data() : nullptr, rData->size(), StreamMode::READ)
|
||||||
|
, mpData(rData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<SvStream> BinaryDataContainer::getAsStream()
|
||||||
|
{
|
||||||
|
return std::make_shared<ReferencedMemoryStream>(mpData);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t BinaryDataContainer::writeToStream(SvStream& rStream) const
|
std::size_t BinaryDataContainer::writeToStream(SvStream& rStream) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user