blob: 40f507e9f34c9d49cda81a29b8c1c5e2332e1ef9 [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 */
halcanarya096d7a2015-03-27 12:16:53 -070024 static SkCodec* NewFromStream(SkStream*);
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,
msarette6dd0042015-10-09 11:07:34 -070029 const Options&, SkPMColor[], int*, 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 */
35 SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable,
36 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
msarettc30c4182016-04-20 11:53:35 -070047 SkWbmpCodec(int width, int height, const SkEncodedInfo&, 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;
53 sk_sp<SkColorTable> fColorTable;
54 SkAutoTMalloc<uint8_t> fSrcBuffer;
scroggo46c57472015-09-30 08:57:13 -070055
msarette6dd0042015-10-09 11:07:34 -070056 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
msarett9b9497e2016-02-11 13:29:36 -080057 bool onSkipScanlines(int count) override;
scroggo46c57472015-09-30 08:57:13 -070058 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
59 SkPMColor inputColorTable[], int* inputColorCount) override;
60
halcanarya096d7a2015-03-27 12:16:53 -070061 typedef SkCodec INHERITED;
62};
63
64#endif // SkCodec_wbmp_DEFINED