blob: ec62f172214e494f8880d9b705542d8af89fcce9 [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 III712476e2018-10-03 15:47:00 -040031 bool conversionSupported(const SkImageInfo& dst, bool srcIsOpaque,
32 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:
msarette6dd0042015-10-09 11:07:34 -070036 SkSampler* getSampler(bool createIfNecessary) override {
37 SkASSERT(fSwizzler || !createIfNecessary);
Ben Wagner145dbcd2016-11-03 14:40:50 -040038 return fSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070039 }
msarett99f567e2015-08-05 12:58:26 -070040
41 /*
42 * Read a src row from the encoded stream
43 */
msarette6dd0042015-10-09 11:07:34 -070044 bool readRow(uint8_t* row);
msarett99f567e2015-08-05 12:58:26 -070045
Leon Scroggins III36f7e322018-08-27 11:55:46 -040046 SkWbmpCodec(SkEncodedInfo&&, std::unique_ptr<SkStream>);
msarett99f567e2015-08-05 12:58:26 -070047
Hal Canary67b39de2016-11-07 11:47:44 -050048 const size_t fSrcRowBytes;
msarett99f567e2015-08-05 12:58:26 -070049
scroggo46c57472015-09-30 08:57:13 -070050 // Used for scanline decodes:
Hal Canary67b39de2016-11-07 11:47:44 -050051 std::unique_ptr<SkSwizzler> fSwizzler;
Hal Canary67b39de2016-11-07 11:47:44 -050052 SkAutoTMalloc<uint8_t> fSrcBuffer;
scroggo46c57472015-09-30 08:57:13 -070053
msarette6dd0042015-10-09 11:07:34 -070054 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
msarett9b9497e2016-02-11 13:29:36 -080055 bool onSkipScanlines(int count) override;
Leon Scroggins571b30f2017-07-11 17:35:31 +000056 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
57 const Options& options) override;
scroggo46c57472015-09-30 08:57:13 -070058
halcanarya096d7a2015-03-27 12:16:53 -070059 typedef SkCodec INHERITED;
60};
61
62#endif // SkCodec_wbmp_DEFINED