SkBmpStandardCodec.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkBmpStandardCodec_DEFINED
  8. #define SkBmpStandardCodec_DEFINED
  9. #include "include/core/SkImageInfo.h"
  10. #include "include/core/SkTypes.h"
  11. #include "src/codec/SkBmpBaseCodec.h"
  12. #include "src/codec/SkColorTable.h"
  13. #include "src/codec/SkSwizzler.h"
  14. /*
  15. * This class implements the decoding for bmp images that use "standard" modes,
  16. * which essentially means they do not contain bit masks or RLE codes.
  17. */
  18. class SkBmpStandardCodec : public SkBmpBaseCodec {
  19. public:
  20. /*
  21. * Creates an instance of the decoder
  22. *
  23. * Called only by SkBmpCodec::MakeFromStream
  24. * There should be no other callers despite this being public
  25. *
  26. * @param info contains properties of the encoded data
  27. * @param stream the stream of encoded image data
  28. * @param bitsPerPixel the number of bits used to store each pixel
  29. * @param numColors the number of colors in the color table
  30. * @param bytesPerColor the number of bytes in the stream used to represent
  31. each color in the color table
  32. * @param offset the offset of the image pixel data from the end of the
  33. * headers
  34. * @param rowOrder indicates whether rows are ordered top-down or bottom-up
  35. * @param isOpaque indicates if the bmp itself is opaque (before applying
  36. * the icp mask, if there is one)
  37. * @param inIco indicates if the bmp is embedded in an ico file
  38. */
  39. SkBmpStandardCodec(SkEncodedInfo&& info, std::unique_ptr<SkStream> stream,
  40. uint16_t bitsPerPixel, uint32_t numColors, uint32_t bytesPerColor,
  41. uint32_t offset, SkCodec::SkScanlineOrder rowOrder,
  42. bool isOpaque, bool inIco);
  43. protected:
  44. Result onGetPixels(const SkImageInfo& dstInfo, void* dst,
  45. size_t dstRowBytes, const Options&,
  46. int*) override;
  47. bool onInIco() const override {
  48. return fInIco;
  49. }
  50. SkCodec::Result onPrepareToDecode(const SkImageInfo& dstInfo,
  51. const SkCodec::Options& options) override;
  52. SkSampler* getSampler(bool createIfNecessary) override {
  53. SkASSERT(fSwizzler);
  54. return fSwizzler.get();
  55. }
  56. private:
  57. bool createColorTable(SkColorType colorType, SkAlphaType alphaType);
  58. SkEncodedInfo swizzlerInfo() const;
  59. void initializeSwizzler(const SkImageInfo& dstInfo, const Options& opts);
  60. int decodeRows(const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes,
  61. const Options& opts) override;
  62. /*
  63. * @param stream This may be a pointer to the stream owned by the parent SkCodec
  64. * or a sub-stream of the stream owned by the parent SkCodec.
  65. * Either way, this stream is unowned.
  66. */
  67. void decodeIcoMask(SkStream* stream, const SkImageInfo& dstInfo, void* dst, size_t dstRowBytes);
  68. sk_sp<SkColorTable> fColorTable;
  69. // fNumColors is the number specified in the header, or 0 if not present in the header.
  70. const uint32_t fNumColors;
  71. const uint32_t fBytesPerColor;
  72. const uint32_t fOffset;
  73. std::unique_ptr<SkSwizzler> fSwizzler;
  74. const bool fIsOpaque;
  75. const bool fInIco;
  76. const size_t fAndMaskRowBytes; // only used for fInIco decodes
  77. typedef SkBmpBaseCodec INHERITED;
  78. };
  79. #endif // SkBmpStandardCodec_DEFINED