Flutter Engine
The Flutter Engine
SkBmpMaskCodec.cpp
Go to the documentation of this file.
1/*
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
9
12#include "include/core/SkSize.h"
17
18#include <utility>
19
20/*
21 * Creates an instance of the decoder
22 */
24 std::unique_ptr<SkStream> stream,
25 uint16_t bitsPerPixel, SkMasks* masks,
27 : INHERITED(std::move(info), std::move(stream), bitsPerPixel, rowOrder)
28 , fMasks(masks)
29 , fMaskSwizzler(nullptr)
30{}
31
32/*
33 * Initiates the bitmap decode
34 */
36 void* dst, size_t dstRowBytes,
37 const Options& opts,
38 int* rowsDecoded) {
39 if (opts.fSubset) {
40 // Subsets are not supported.
41 return kUnimplemented;
42 }
43 if (dstInfo.dimensions() != this->dimensions()) {
44 SkCodecPrintf("Error: scaling not supported.\n");
45 return kInvalidScale;
46 }
47
48 Result result = this->prepareToDecode(dstInfo, opts);
49 if (kSuccess != result) {
50 return result;
51 }
52
53 int rows = this->decodeRows(dstInfo, dst, dstRowBytes, opts);
54 if (rows != dstInfo.height()) {
55 *rowsDecoded = rows;
56 return kIncompleteInput;
57 }
58 return kSuccess;
59}
60
63 if (this->colorXform()) {
64 this->resetXformBuffer(dstInfo.width());
65 }
66
67 SkImageInfo swizzlerInfo = dstInfo;
68 if (this->colorXform()) {
69 swizzlerInfo = swizzlerInfo.makeColorType(kXformSrcColorType);
71 swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType);
72 }
73 }
74
75 bool srcIsOpaque = this->getEncodedInfo().opaque();
76 fMaskSwizzler.reset(SkMaskSwizzler::CreateMaskSwizzler(swizzlerInfo, srcIsOpaque,
77 fMasks.get(), this->bitsPerPixel(), options));
78 SkASSERT(fMaskSwizzler);
79
80 return SkCodec::kSuccess;
81}
82
83/*
84 * Performs the decoding
85 */
86int SkBmpMaskCodec::decodeRows(const SkImageInfo& dstInfo,
87 void* dst, size_t dstRowBytes,
88 const Options& opts) {
89 // Iterate over rows of the image
90 uint8_t* srcRow = this->srcBuffer();
91 const int height = dstInfo.height();
92 for (int y = 0; y < height; y++) {
93 // Read a row of the input
94 if (this->stream()->read(srcRow, this->srcRowBytes()) != this->srcRowBytes()) {
95 SkCodecPrintf("Warning: incomplete input stream.\n");
96 return y;
97 }
98
99 // Decode the row in destination format
100 uint32_t row = this->getDstRow(y, height);
101 void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
102
103 if (this->colorXform()) {
104 fMaskSwizzler->swizzle(this->xformBuffer(), srcRow);
105 this->applyColorXform(dstRow, this->xformBuffer(), fMaskSwizzler->swizzleWidth());
106 } else {
107 fMaskSwizzler->swizzle(dstRow, srcRow);
108 }
109 }
110
111 // Finished decoding the entire image
112 return height;
113}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
kUnpremul_SkAlphaType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkCodecPrintf(...)
Definition: SkCodecPriv.h:23
static bool read(SkStream *stream, void *buffer, size_t amount)
uint8_t * srcBuffer()
void resetXformBuffer(int count)
Definition: SkBmpCodec.h:105
int32_t getDstRow(int32_t y, int32_t height) const
Definition: SkBmpCodec.cpp:634
SkCodec::Result prepareToDecode(const SkImageInfo &dstInfo, const SkCodec::Options &options)
Definition: SkBmpCodec.cpp:642
size_t srcRowBytes() const
Definition: SkBmpCodec.h:89
uint32_t * xformBuffer() const
Definition: SkBmpCodec.h:104
static constexpr SkColorType kXformSrcColorType
Definition: SkBmpCodec.h:111
SkCodec::Result onPrepareToDecode(const SkImageInfo &dstInfo, const SkCodec::Options &options) override
SkBmpMaskCodec(SkEncodedInfo &&info, std::unique_ptr< SkStream >, uint16_t bitsPerPixel, SkMasks *masks, SkCodec::SkScanlineOrder rowOrder)
Result onGetPixels(const SkImageInfo &dstInfo, void *dst, size_t dstRowBytes, const Options &, int *) override
const SkImageInfo & dstInfo() const
Definition: SkCodec.h:878
SkStream * stream()
Definition: SkCodec.h:865
void applyColorXform(void *dst, const void *src, int count) const
Definition: SkCodec.cpp:853
SkScanlineOrder
Definition: SkCodec.h:575
const SkEncodedInfo & getEncodedInfo() const
Definition: SkCodec.h:788
Result
Definition: SkCodec.h:76
@ kInvalidScale
Definition: SkCodec.h:100
@ kIncompleteInput
Definition: SkCodec.h:84
@ kUnimplemented
Definition: SkCodec.h:123
@ kSuccess
Definition: SkCodec.h:80
bool colorXform() const
Definition: SkCodec.h:906
const Options & options() const
Definition: SkCodec.h:880
static SkMaskSwizzler * CreateMaskSwizzler(const SkImageInfo &dstInfo, bool srcIsOpaque, SkMasks *masks, uint32_t bitsPerPixel, const SkCodec::Options &options)
GAsyncResult * result
double y
dst
Definition: cp.py:12
Definition: ref_ptr.h:256
int32_t height
const SkIRect * fSubset
Definition: SkCodec.h:347
bool opaque() const
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Definition: SkImageInfo.h:466
SkISize dimensions() const
Definition: SkImageInfo.h:421
int width() const
Definition: SkImageInfo.h:365
SkAlphaType alphaType() const
Definition: SkImageInfo.h:375
int height() const
Definition: SkImageInfo.h:371
SkImageInfo makeColorType(SkColorType newColorType) const
Definition: SkImageInfo.h:475