tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsIconDecoder.h (2225B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      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/. */
      6 
      7 #ifndef mozilla_image_decoders_nsIconDecoder_h
      8 #define mozilla_image_decoders_nsIconDecoder_h
      9 
     10 #include "Decoder.h"
     11 #include "StreamingLexer.h"
     12 #include "SurfacePipe.h"
     13 
     14 namespace mozilla {
     15 namespace image {
     16 
     17 class RasterImage;
     18 
     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.
     24 //
     25 // The format of the incoming data is as follows:
     26 //
     27 // The first two bytes contain the width and the height of the icon.
     28 // The third byte contains the pixel format.
     29 // The fourth byte contains the color transform.
     30 // The remaining bytes contain the icon data, 4 bytes per pixel, in
     31 // ARGB order (platform endianness, A in highest bits, B in lowest
     32 // bits), row-primary, top-to-bottom, left-to-right, with
     33 // premultiplied alpha.
     34 //
     35 ////////////////////////////////////////////////////////////////////////////////
     36 
     37 class nsIconDecoder : public Decoder {
     38 public:
     39  virtual ~nsIconDecoder();
     40 
     41  DecoderType GetType() const override { return DecoderType::ICON; }
     42 
     43  LexerResult DoDecode(SourceBufferIterator& aIterator,
     44                       IResumable* aOnResume) override;
     45 
     46 private:
     47  friend class DecoderFactory;
     48 
     49  // Decoders should only be instantiated via DecoderFactory.
     50  explicit nsIconDecoder(RasterImage* aImage);
     51 
     52  enum class State { HEADER, ROW_OF_PIXELS, FINISH };
     53 
     54  LexerTransition<State> ReadHeader(const char* aData);
     55  LexerTransition<State> ReadRowOfPixels(const char* aData, size_t aLength);
     56  LexerTransition<State> Finish();
     57 
     58  StreamingLexer<State> mLexer;
     59  SurfacePipe mPipe;
     60  uint32_t mBytesPerRow;
     61 };
     62 
     63 }  // namespace image
     64 }  // namespace mozilla
     65 
     66 #endif  // mozilla_image_decoders_nsIconDecoder_h