blob: 03287710e0c971cce147f11e51d9c769510ea7fe [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;
halcanarya096d7a2015-03-27 12:16:53 -070031private:
msarett99f567e2015-08-05 12:58:26 -070032 /*
halcanary96fcdcc2015-08-27 07:41:13 -070033 * Returns a swizzler on success, nullptr on failure
msarett99f567e2015-08-05 12:58:26 -070034 */
Leon Scroggins571b30f2017-07-11 17:35:31 +000035 SkSwizzler* initializeSwizzler(const SkImageInfo& info,
msarett99f567e2015-08-05 12:58:26 -070036 const Options& opts);
msarette6dd0042015-10-09 11:07:34 -070037 SkSampler* getSampler(bool createIfNecessary) override {
38 SkASSERT(fSwizzler || !createIfNecessary);
Ben Wagner145dbcd2016-11-03 14:40:50 -040039 return fSwizzler.get();
msarette6dd0042015-10-09 11:07:34 -070040 }
msarett99f567e2015-08-05 12:58:26 -070041
42 /*
43 * Read a src row from the encoded stream
44 */
msarette6dd0042015-10-09 11:07:34 -070045 bool readRow(uint8_t* row);
msarett99f567e2015-08-05 12:58:26 -070046
Mike Reedede7bac2017-07-23 15:30:02 -040047 SkWbmpCodec(int width, int height, const SkEncodedInfo&, std::unique_ptr<SkStream>);
msarett99f567e2015-08-05 12:58:26 -070048
Hal Canary67b39de2016-11-07 11:47:44 -050049 const size_t fSrcRowBytes;
msarett99f567e2015-08-05 12:58:26 -070050
scroggo46c57472015-09-30 08:57:13 -070051 // Used for scanline decodes:
Hal Canary67b39de2016-11-07 11:47:44 -050052 std::unique_ptr<SkSwizzler> fSwizzler;
Hal Canary67b39de2016-11-07 11:47:44 -050053 SkAutoTMalloc<uint8_t> fSrcBuffer;
scroggo46c57472015-09-30 08:57:13 -070054
msarette6dd0042015-10-09 11:07:34 -070055 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
msarett9b9497e2016-02-11 13:29:36 -080056 bool onSkipScanlines(int count) override;
Leon Scroggins571b30f2017-07-11 17:35:31 +000057 Result onStartScanlineDecode(const SkImageInfo& dstInfo,
58 const Options& options) override;
scroggo46c57472015-09-30 08:57:13 -070059
halcanarya096d7a2015-03-27 12:16:53 -070060 typedef SkCodec INHERITED;
61};
62
63#endif // SkCodec_wbmp_DEFINED