1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_image_decoders_nsIconDecoder_h
8 #define mozilla_image_decoders_nsIconDecoder_h
11 #include "StreamingLexer.h"
12 #include "SurfacePipe.h"
19 ////////////////////////////////////////////////////////////////////////////////
20 // The icon decoder is a decoder specifically tailored for loading icons
21 // from the OS. We've defined our own little format to represent these icons
22 // and this decoder takes that format and converts it into 24-bit RGB with
23 // alpha channel support. It was modeled a bit off the PPM decoder.
25 // The format of the incoming data is as follows:
27 // The first two bytes contain the width and the height of the icon.
28 // The remaining bytes contain the icon data, 4 bytes per pixel, in
29 // ARGB order (platform endianness, A in highest bits, B in lowest
30 // bits), row-primary, top-to-bottom, left-to-right, with
31 // premultiplied alpha.
33 ////////////////////////////////////////////////////////////////////////////////
35 class nsIconDecoder
: public Decoder
{
37 virtual ~nsIconDecoder();
39 DecoderType
GetType() const override
{ return DecoderType::ICON
; }
41 LexerResult
DoDecode(SourceBufferIterator
& aIterator
,
42 IResumable
* aOnResume
) override
;
45 friend class DecoderFactory
;
47 // Decoders should only be instantiated via DecoderFactory.
48 explicit nsIconDecoder(RasterImage
* aImage
);
50 enum class State
{ HEADER
, ROW_OF_PIXELS
, FINISH
};
52 LexerTransition
<State
> ReadHeader(const char* aData
);
53 LexerTransition
<State
> ReadRowOfPixels(const char* aData
, size_t aLength
);
54 LexerTransition
<State
> Finish();
56 StreamingLexer
<State
> mLexer
;
58 uint32_t mBytesPerRow
;
62 } // namespace mozilla
64 #endif // mozilla_image_decoders_nsIconDecoder_h