2001-04-02 08:56:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2001-04-02 08:56:18 +04:00
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#ifndef mozilla_image_decoders_nsIconDecoder_h
|
|
|
|
#define mozilla_image_decoders_nsIconDecoder_h
|
2001-04-02 08:56:18 +04:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2015-10-06 00:29:01 +03:00
|
|
|
#include "StreamingLexer.h"
|
2016-03-11 05:45:29 +03:00
|
|
|
#include "SurfacePipe.h"
|
2001-04-02 08:56:18 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2016-03-11 05:45:29 +03:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
class RasterImage;
|
2001-04-02 08:56:18 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// The icon decoder is a decoder specifically tailored for loading icons
|
2001-04-02 08:56:18 +04:00
|
|
|
// from the OS. We've defined our own little format to represent these icons
|
2014-11-14 20:59:00 +03:00
|
|
|
// and this decoder takes that format and converts it into 24-bit RGB with
|
|
|
|
// alpha channel support. It was modeled a bit off the PPM decoder.
|
2001-04-02 08:56:18 +04:00
|
|
|
//
|
2016-03-11 05:45:29 +03:00
|
|
|
// The format of the incoming data is as follows:
|
2001-04-02 08:56:18 +04:00
|
|
|
//
|
2016-03-11 05:45:29 +03:00
|
|
|
// The first two bytes contain the width and the height of the icon.
|
|
|
|
// The remaining bytes contain the icon data, 4 bytes per pixel, in
|
|
|
|
// ARGB order (platform endianness, A in highest bits, B in lowest
|
|
|
|
// bits), row-primary, top-to-bottom, left-to-right, with
|
|
|
|
// premultiplied alpha.
|
2001-04-02 08:56:18 +04:00
|
|
|
//
|
2014-11-14 20:59:00 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-04-02 08:56:18 +04:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class nsIconDecoder : public Decoder {
|
2001-04-02 08:56:18 +04:00
|
|
|
public:
|
|
|
|
virtual ~nsIconDecoder();
|
|
|
|
|
2018-02-28 21:34:52 +03:00
|
|
|
DecoderType GetType() const override { return DecoderType::ICON; }
|
|
|
|
|
2016-07-16 08:27:12 +03:00
|
|
|
LexerResult DoDecode(SourceBufferIterator& aIterator,
|
|
|
|
IResumable* aOnResume) override;
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2015-07-23 08:39:56 +03:00
|
|
|
private:
|
|
|
|
friend class DecoderFactory;
|
|
|
|
|
|
|
|
// Decoders should only be instantiated via DecoderFactory.
|
|
|
|
explicit nsIconDecoder(RasterImage* aImage);
|
|
|
|
|
2015-10-06 00:29:01 +03:00
|
|
|
enum class State { HEADER, ROW_OF_PIXELS, FINISH };
|
|
|
|
|
|
|
|
LexerTransition<State> ReadHeader(const char* aData);
|
|
|
|
LexerTransition<State> ReadRowOfPixels(const char* aData, size_t aLength);
|
|
|
|
LexerTransition<State> Finish();
|
|
|
|
|
|
|
|
StreamingLexer<State> mLexer;
|
2016-03-11 05:45:29 +03:00
|
|
|
SurfacePipe mPipe;
|
2015-10-06 00:29:01 +03:00
|
|
|
uint32_t mBytesPerRow;
|
2001-04-02 08:56:18 +04:00
|
|
|
};
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-23 06:30:46 +04:00
|
|
|
} // namespace mozilla
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#endif // mozilla_image_decoders_nsIconDecoder_h
|