blob: b9df0b9a7dc1affa54498b47b8a09a7b2ea5e43c [file] [log] [blame]
halcanarya096d7a2015-03-27 12:16:53 -07001/*
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
8#ifndef SkCodec_wbmp_DEFINED
9#define SkCodec_wbmp_DEFINED
10
11#include "SkCodec.h"
msarettad8bcfe2016-03-07 07:09:03 -080012#include "SkColorSpace.h"
msarett99f567e2015-08-05 12:58:26 -070013#include "SkSwizzler.h"
halcanarya096d7a2015-03-27 12:16:53 -070014
15class SkWbmpCodec final : public SkCodec {
16public:
scroggodb30be22015-12-08 18:54:13 -080017 static bool IsWbmp(const void*, size_t);
msarett99f567e2015-08-05 12:58:26 -070018
19 /*
20 * Assumes IsWbmp was called and returned true
21 * Creates a wbmp codec
22 * Takes ownership of the stream
23 */
Mike Reedede7bac2017-07-23 15:30:02 -040024 static std::unique_ptr<SkCodec> MakeFromStream(std::unique_ptr<SkStream>, Result*);
msarett99f567e2015-08-05 12:58:26 -070025
halcanarya096d7a2015-03-27 12:16:53 -070026protected:
Hal Canarydb683012016-11-23 08:55:18 -070027 SkEncodedImageFormat onGetEncodedFormat() const override;
halcanarya096d7a2015-03-27 12:16:53 -070028 Result onGetPixels(const SkImageInfo&, void*, size_t,
Leon Scroggins571b30f2017-07-11 17:35:31 +000029 const Options&, int*) override;
scroggob427db12015-08-12 07:24:13 -070030 bool onRewind() override;
Leon Scroggins IIIc8037dc2017-12-05 13:55:24 -050031 bool conversionSupported(const SkImageInfo& dst, SkColorType srcColor,
Leon Scroggins III36f7e322018-08-27 11:55:46 -040032 bool srcIsOpaque, bool needsXform) override;
Leon Scroggins IIIae79f322017-08-18 10:53:24 -040033 // No need to Xform; all pixels are either black or white.
34 bool usesColorXform() const override { return false; }
halcanarya096d7a2015-03-27 12:16:53 -070035private:
msarett99f567e2015-08-05 12:58:26 -070036 /*
halcanary96fcdcc2015-08-27 07:41:13 -070037 * Returns a swizzler on success, nullptr on failure
msarett99f567e2015-08-05 12:58:26 -070038 */
Leon Scroggins571b30f2017-07-11 17:35:31 +000039 SkSwizzler* initializeSwizzler(const SkImageInfo& info,
msarett99f567e2015-08-05 12:58:26 -070040 const Options& opts);
msarette6dd0042015-10-09 11:07:34 -070041 SkSampler* getSampler(bool createIfNecessary) override {
42 SkASSERT(fSwizzler || !createIfNecessary);
Ben Wagner145dbcd2016-11-03 14:40:50 -040043 return fSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070044 }
msarett99f567e2015-08-05 12:58:26 -070045
46 /*
47 * Read a src row from the encoded stream
48 */
msarette6dd0042015-10-09 11:07:34 -070049 bool readRow(uint8_t* row);
msarett99f567e2015-08-05 12:58:26 -070050
Leon Scroggins III36f7e322018-08-27 11:55:46 -040051 SkWbmpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>);
msarett99f567e2015-08-05 12:58:26 -070052
Hal Canary67b39de2016-11-07 11:47:44 -050053 const size_t fSrcRowBytes;
msarett99f567e2015-08-05 12:58:26 -070054
scroggo46c57472015-09-30 08:57:13 -070055 // Used for scanline decodes:
Hal Canary67b39de2016-11-07 11:47:44 -050056 std::unique_ptr<SkSwizzler> fSwizzler;
Hal Canary67b39de2016-11-07 11:47:44 -050057 SkAutoTMalloc<uint8_t> fSrcBuffer;
scroggo46c57472015-09-30 08:57:13 -070058
msarette6dd0042015-10-09 11:07:34 -070059 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
msarett9b9497e2016-02-11 13:29:36 -080060 bool onSkipScanlines(int count) override;
Leon Scroggins571b30f2017-07-11 17:35:31 +000061 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
62 const Options& options) override;
scroggo46c57472015-09-30 08:57:13 -070063
halcanarya096d7a2015-03-27 12:16:53 -070064 typedef SkCodec INHERITED;
65};
66
67#endif // SkCodec_wbmp_DEFINED