Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/decoders/nsIconDecoder.h
Line
Count
Source (jump to first uncovered line)
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 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.
32
//
33
////////////////////////////////////////////////////////////////////////////////
34
35
class nsIconDecoder : public Decoder
36
{
37
public:
38
  virtual ~nsIconDecoder();
39
40
0
  DecoderType GetType() const override { return DecoderType::ICON; }
41
42
  LexerResult DoDecode(SourceBufferIterator& aIterator,
43
                       IResumable* aOnResume) override;
44
45
private:
46
  friend class DecoderFactory;
47
48
  // Decoders should only be instantiated via DecoderFactory.
49
  explicit nsIconDecoder(RasterImage* aImage);
50
51
  enum class State {
52
    HEADER,
53
    ROW_OF_PIXELS,
54
    FINISH
55
  };
56
57
  LexerTransition<State> ReadHeader(const char* aData);
58
  LexerTransition<State> ReadRowOfPixels(const char* aData, size_t aLength);
59
  LexerTransition<State> Finish();
60
61
  StreamingLexer<State> mLexer;
62
  SurfacePipe mPipe;
63
  uint32_t mBytesPerRow;
64
};
65
66
} // namespace image
67
} // namespace mozilla
68
69
#endif // mozilla_image_decoders_nsIconDecoder_h