blob: fb062c94d597d87e18ca5198ed333dd28aca6fb7 [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"
msarett99f567e2015-08-05 12:58:26 -070012#include "SkSwizzler.h"
halcanarya096d7a2015-03-27 12:16:53 -070013
14class SkWbmpCodec final : public SkCodec {
15public:
scroggodb30be22015-12-08 18:54:13 -080016 static bool IsWbmp(const void*, size_t);
msarett99f567e2015-08-05 12:58:26 -070017
18 /*
19 * Assumes IsWbmp was called and returned true
20 * Creates a wbmp codec
21 * Takes ownership of the stream
22 */
halcanarya096d7a2015-03-27 12:16:53 -070023 static SkCodec* NewFromStream(SkStream*);
msarett99f567e2015-08-05 12:58:26 -070024
halcanarya096d7a2015-03-27 12:16:53 -070025protected:
26 SkEncodedFormat onGetEncodedFormat() const override;
27 Result onGetPixels(const SkImageInfo&, void*, size_t,
msarette6dd0042015-10-09 11:07:34 -070028 const Options&, SkPMColor[], int*, int*) override;
scroggob427db12015-08-12 07:24:13 -070029 bool onRewind() override;
halcanarya096d7a2015-03-27 12:16:53 -070030private:
msarett99f567e2015-08-05 12:58:26 -070031 /*
halcanary96fcdcc2015-08-27 07:41:13 -070032 * Returns a swizzler on success, nullptr on failure
msarett99f567e2015-08-05 12:58:26 -070033 */
34 SkSwizzler* initializeSwizzler(const SkImageInfo& info, const SkPMColor* ctable,
35 const Options& opts);
msarette6dd0042015-10-09 11:07:34 -070036 SkSampler* getSampler(bool createIfNecessary) override {
37 SkASSERT(fSwizzler || !createIfNecessary);
38 return fSwizzler;
39 }
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
halcanarya096d7a2015-03-27 12:16:53 -070046 SkWbmpCodec(const SkImageInfo&, SkStream*);
msarett99f567e2015-08-05 12:58:26 -070047
msarette6dd0042015-10-09 11:07:34 -070048 const size_t fSrcRowBytes;
msarett99f567e2015-08-05 12:58:26 -070049
scroggo46c57472015-09-30 08:57:13 -070050 // Used for scanline decodes:
scroggo46c57472015-09-30 08:57:13 -070051 SkAutoTDelete<SkSwizzler> fSwizzler;
msarette6dd0042015-10-09 11:07:34 -070052 SkAutoTUnref<SkColorTable> fColorTable;
scroggo46c57472015-09-30 08:57:13 -070053 SkAutoTMalloc<uint8_t> fSrcBuffer;
54
55 // FIXME: Override onSkipScanlines to avoid swizzling.
msarette6dd0042015-10-09 11:07:34 -070056 int onGetScanlines(void* dst, int count, size_t dstRowBytes) override;
scroggo46c57472015-09-30 08:57:13 -070057 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& options,
58 SkPMColor inputColorTable[], int* inputColorCount) override;
59
halcanarya096d7a2015-03-27 12:16:53 -070060 typedef SkCodec INHERITED;
61};
62
63#endif // SkCodec_wbmp_DEFINED