From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- image/decoders/nsICODecoder.h | 106 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 image/decoders/nsICODecoder.h (limited to 'image/decoders/nsICODecoder.h') diff --git a/image/decoders/nsICODecoder.h b/image/decoders/nsICODecoder.h new file mode 100644 index 0000000000..0b103e657d --- /dev/null +++ b/image/decoders/nsICODecoder.h @@ -0,0 +1,106 @@ +/* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=2: */ +/* 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/. */ + +#ifndef mozilla_image_decoders_nsICODecoder_h +#define mozilla_image_decoders_nsICODecoder_h + +#include "StreamingLexer.h" +#include "Decoder.h" +#include "Downscaler.h" +#include "imgFrame.h" +#include "mozilla/gfx/2D.h" +#include "nsBMPDecoder.h" +#include "nsPNGDecoder.h" +#include "ICOFileHeaders.h" + +namespace mozilla { +namespace image { + +class RasterImage; + +enum class ICOState { + HEADER, + DIR_ENTRY, + FINISHED_DIR_ENTRY, + ITERATE_UNSIZED_DIR_ENTRY, + SKIP_TO_RESOURCE, + FOUND_RESOURCE, + SNIFF_RESOURCE, + READ_RESOURCE, + PREPARE_FOR_MASK, + READ_MASK_ROW, + FINISH_MASK, + SKIP_MASK, + FINISHED_RESOURCE +}; + +class nsICODecoder : public Decoder { + public: + virtual ~nsICODecoder() {} + + /// @return The offset from the beginning of the ICO to the first resource. + size_t FirstResourceOffset() const; + + DecoderType GetType() const override { return DecoderType::ICO; } + LexerResult DoDecode(SourceBufferIterator& aIterator, + IResumable* aOnResume) override; + nsresult FinishInternal() override; + nsresult FinishWithErrorInternal() override; + + private: + friend class DecoderFactory; + + // Decoders should only be instantiated via DecoderFactory. + explicit nsICODecoder(RasterImage* aImage); + + // Flushes the contained decoder to read all available data and sets the + // appropriate errors. Returns true if there are no errors. + bool FlushContainedDecoder(); + + // Gets decoder state from the contained decoder so it's visible externally. + nsresult GetFinalStateFromContainedDecoder(); + + // Obtains the number of colors from the BPP, mBPP must be filled in + uint16_t GetNumColors(); + + LexerTransition ReadHeader(const char* aData); + LexerTransition ReadDirEntry(const char* aData); + LexerTransition IterateUnsizedDirEntry(); + LexerTransition FinishDirEntry(); + LexerTransition SniffResource(const char* aData); + LexerTransition ReadResource(); + LexerTransition ReadBIH(const char* aData); + LexerTransition PrepareForMask(); + LexerTransition ReadMaskRow(const char* aData); + LexerTransition FinishMask(); + LexerTransition FinishResource(); + + struct IconDirEntryEx : public IconDirEntry { + gfx::IntSize mSize; + }; + + StreamingLexer mLexer; // The lexer. + Maybe mDownscaler; // The downscaler used for the mask. + RefPtr mContainedDecoder; // Either a BMP or PNG decoder. + Maybe + mReturnIterator; // Iterator to save return point. + UniquePtr mMaskBuffer; // A temporary buffer for the alpha mask. + nsTArray mDirEntries; // Valid dir entries with a size. + nsTArray mUnsizedDirEntries; // Dir entries without a size. + IconDirEntryEx* mDirEntry; // The dir entry for the selected resource. + uint16_t mNumIcons; // Stores the number of icons in the ICO file. + uint16_t mCurrIcon; // Stores the current dir entry index we are processing. + uint16_t mBPP; // The BPP of the resource we're decoding. + uint32_t + mMaskRowSize; // The size in bytes of each row in the BMP alpha mask. + uint32_t mCurrMaskLine; // The line of the BMP alpha mask we're processing. + bool mIsCursor; // Is this ICO a cursor? + bool mHasMaskAlpha; // Did the BMP alpha mask have any transparency? +}; + +} // namespace image +} // namespace mozilla + +#endif // mozilla_image_decoders_nsICODecoder_h -- cgit v1.2.3