SkWbmpCodec.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 SkCodec_wbmp_DEFINED
  8. #define SkCodec_wbmp_DEFINED
  9. #include "include/codec/SkCodec.h"
  10. #include "include/core/SkColorSpace.h"
  11. #include "src/codec/SkSwizzler.h"
  12. class SkWbmpCodec final : public SkCodec {
  13. public:
  14. static bool IsWbmp(const void*, size_t);
  15. /*
  16. * Assumes IsWbmp was called and returned true
  17. * Creates a wbmp codec
  18. * Takes ownership of the stream
  19. */
  20. static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
  21. protected:
  22. SkEncodedImageFormat onGetEncodedFormat() const override;
  23. Result onGetPixels(const SkImageInfo&, void*, size_t,
  24. const Options&, int*) override;
  25. bool onRewind() override;
  26. bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque,
  27. bool needsXform) override;
  28. // No need to Xform; all pixels are either black or white.
  29. bool usesColorXform() const override { return false; }
  30. private:
  31. SkSampler* getSampler(bool createIfNecessary) override {
  32. SkASSERT(fSwizzler || !createIfNecessary);
  33. return fSwizzler.get();
  34. }
  35. /*
  36. * Read a src row from the encoded stream
  37. */
  38. bool readRow(uint8_t* row);
  39. SkWbmpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>);
  40. const size_t fSrcRowBytes;
  41. // Used for scanline decodes:
  42. std::unique_ptr<SkSwizzler> fSwizzler;
  43. SkAutoTMalloc<uint8_t> fSrcBuffer;
  44. int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
  45. bool onSkipScanlines(int count) override;
  46. Result onStartScanlineDecode(const SkImageInfo& dstInfo,
  47. const Options& options) override;
  48. typedef SkCodec INHERITED;
  49. };
  50. #endif // SkCodec_wbmp_DEFINED