nsIconDecoder.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #ifndef mozilla_image_decoders_nsIconDecoder_h
  7. #define mozilla_image_decoders_nsIconDecoder_h
  8. #include "Decoder.h"
  9. #include "StreamingLexer.h"
  10. #include "SurfacePipe.h"
  11. namespace mozilla {
  12. namespace image {
  13. class RasterImage;
  14. ////////////////////////////////////////////////////////////////////////////////
  15. // The icon decoder is a decoder specifically tailored for loading icons
  16. // from the OS. We've defined our own little format to represent these icons
  17. // and this decoder takes that format and converts it into 24-bit RGB with
  18. // alpha channel support. It was modeled a bit off the PPM decoder.
  19. //
  20. // The format of the incoming data is as follows:
  21. //
  22. // The first two bytes contain the width and the height of the icon.
  23. // The remaining bytes contain the icon data, 4 bytes per pixel, in
  24. // ARGB order (platform endianness, A in highest bits, B in lowest
  25. // bits), row-primary, top-to-bottom, left-to-right, with
  26. // premultiplied alpha.
  27. //
  28. ////////////////////////////////////////////////////////////////////////////////
  29. class nsIconDecoder : public Decoder
  30. {
  31. public:
  32. virtual ~nsIconDecoder();
  33. LexerResult DoDecode(SourceBufferIterator& aIterator,
  34. IResumable* aOnResume) override;
  35. private:
  36. friend class DecoderFactory;
  37. // Decoders should only be instantiated via DecoderFactory.
  38. explicit nsIconDecoder(RasterImage* aImage);
  39. enum class State {
  40. HEADER,
  41. ROW_OF_PIXELS,
  42. FINISH
  43. };
  44. LexerTransition<State> ReadHeader(const char* aData);
  45. LexerTransition<State> ReadRowOfPixels(const char* aData, size_t aLength);
  46. LexerTransition<State> Finish();
  47. StreamingLexer<State> mLexer;
  48. SurfacePipe mPipe;
  49. uint32_t mBytesPerRow;
  50. };
  51. } // namespace image
  52. } // namespace mozilla
  53. #endif // mozilla_image_decoders_nsIconDecoder_h