diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-03-05 19:55:43 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-03-12 15:37:21 +0100 |
commit | e1d0846e060d2b3faedfe1a5877303037d8cf4d6 (patch) | |
tree | c232b6fcc14b77ff1022a3bc42277c9827324d17 /include | |
parent | e286bd791bfaa00746ea143303761f76e0af1f0d (diff) |
drop PNGReader and use only PngImageReader
PNGReader is a home-made PNG reader that does not use libpng,
so it's more code, presumably less optimized and it apparently also
doesn't always map colors properly.
The only two features it has that PngImageReader doesn't are explicit
chunk reading (used only for reading Microsoft's GIF in PNG, I
implemented that for PngImageReader in a previous commit), and it
loads paletted images as BitmapEx with a palette instead of
converting to direct-color 24/32bpp or 8bpp-gray. The latter is even
questional if nowadays that's feature or a misfeature, as it saves
memory at the expense of speed. I can implement that if somebody
misses it.
I had to adjust some tests:
- CVE-2016-0952-1.png - invalid CRC of the PNG header, neither Gimp
nor Gwenview can display that, it should fail
- afl-sample-Z_NEED_DICT.png - failure while decompressing data,
but the loader considers that only a partially broken image since
the header is correct, so it "passes" (like in Gimp or Gwenview)
- SdImportTest::testTdf134210() and
testPictureWithSchemeColor::Load_Verify_Reload_Verify()
need the colors tested changed, because apparently gamma correction
or something is now applied correctly, and it wasn't before (again
checked the loaded images with Gimp)
Change-Id: Id46f8d8a01256daf48ca64264b47c4e609183837
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112042
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/filter/PngImageReader.hxx | 4 | ||||
-rw-r--r-- | include/vcl/pngread.hxx | 59 |
2 files changed, 4 insertions, 59 deletions
diff --git a/include/vcl/filter/PngImageReader.hxx b/include/vcl/filter/PngImageReader.hxx index 2cd57549cf49..2615fd961bd4 100644 --- a/include/vcl/filter/PngImageReader.hxx +++ b/include/vcl/filter/PngImageReader.hxx @@ -33,7 +33,11 @@ class VCL_DLLPUBLIC PngImageReader public: PngImageReader(SvStream& rStream); + // Returns true if image was successfully read without errors. + // A usable bitmap may be returned even if there were errors (e.g. incomplete image). bool read(BitmapEx& rBitmap); + // Returns a bitmap without indicating if there were errors. + BitmapEx read(); // Returns the contents of the msOG chunk (containing a Gif image), if it exists. // Does not change position in the stream. diff --git a/include/vcl/pngread.hxx b/include/vcl/pngread.hxx deleted file mode 100644 index d3fa1942ee57..000000000000 --- a/include/vcl/pngread.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * 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 . - */ - -#ifndef INCLUDED_VCL_PNGREAD_HXX -#define INCLUDED_VCL_PNGREAD_HXX - -#include <vcl/dllapi.h> -#include <vcl/bitmapex.hxx> -#include <memory> -#include <vector> - -namespace vcl -{ -class PNGReaderImpl; - -class VCL_DLLPUBLIC PNGReader -{ - std::unique_ptr<PNGReaderImpl> mpImpl; - -public: - /* the PNG chunks are read within the c'tor, so the stream will - be positioned at the end of the PNG */ - explicit PNGReader(SvStream& rStream); - ~PNGReader(); - - /* an empty preview size hint (=default) will read the whole image - */ - BitmapEx Read(); - - // retrieve every chunk that resides inside the PNG - struct ChunkData - { - sal_uInt32 nType = 0; - std::vector<sal_uInt8> aData; - }; - const std::vector<ChunkData>& GetChunks() const; -}; - -} // end namespace vcl - -#endif // INCLUDED_VCL_PNGREAD_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |