OLD | NEW |
---|---|
(Empty) | |
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 #ifndef SkScaledCodec_DEFINED | |
8 #define SkScaledCodec_DEFINED | |
9 | |
10 #include "SkCodec.h" | |
11 #include "SkScanlineDecoder.h" | |
12 | |
13 class SkScanlineDecoder; | |
14 class SkStream; | |
15 | |
16 /** | |
17 * This class implements scaling, by sampling scanlines in the y direction. | |
18 * x-wise sampling is implemented in the swizzler, when getScanlines() is called . | |
19 */ | |
20 class SkScaledCodec : public SkCodec { | |
21 public: | |
22 static SkCodec* NewFromStream(SkStream*); | |
23 static SkCodec* NewFromData(SkData*); | |
24 | |
25 virtual ~SkScaledCodec(); | |
26 | |
27 /** | |
28 * returns a sample size based on the input src and dst dimensions | |
29 * can only down sample, so dstDimension must be <= than srcDimension | |
30 */ | |
31 static int GetSampleSize(int srcDimension, int dstDimension) { | |
32 SkASSERT(dstDimension <= srcDimension); | |
33 return srcDimension / dstDimension; | |
34 } | |
35 | |
36 /** | |
37 * returns whether a destination's dimensions are supported for down samplin g | |
38 */ | |
39 static bool DimensionsSupportedForSampling(const SkImageInfo& srcInfo, | |
40 const SkImageInfo& dstInfo) { | |
41 // heights must be equal as no native y sampling is supported | |
42 if (dstInfo.height() != srcInfo.height()) { | |
43 return false; | |
44 } | |
45 // only support down sampling, dstWidth cannot be larger that srcWidth | |
46 if(dstInfo.width() > srcInfo.width()) { | |
47 return false; | |
48 } | |
49 return true; | |
50 } | |
51 | |
52 protected: | |
53 /** | |
54 * Recommend a set of destination dimensions given a requested scale | |
55 */ | |
56 SkISize onGetScaledDimensions(float desiredScale) const override; | |
57 | |
58 Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, SkPMCo lor*, int*) | |
59 override; | |
60 SkEncodedFormat onGetEncodedFormat() const override { | |
61 return fCodec->getEncodedFormat(); | |
62 } | |
63 | |
64 SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, const Op tions& options, | |
65 SkPMColor ctable[], int* ctableCount ) override { | |
66 return fCodec->getScanlineDecoder(dstInfo, &options, ctable, ctableCount ); | |
67 } | |
68 | |
69 bool onReallyHasAlpha() const override { | |
70 return fCodec->reallyHasAlpha(); | |
71 } | |
72 | |
73 private: | |
74 SkAutoTDelete<SkCodec> fCodec; | |
75 | |
76 SkScaledCodec(SkCodec*); | |
scroggo
2015/08/03 19:16:20
nit: Please label this constructor as explicit
emmaleer
2015/08/04 18:56:53
Acknowledged.
| |
77 | |
78 typedef SkCodec INHERITED; | |
79 }; | |
80 #endif // SkScaledCodec_DEFINED | |
OLD | NEW |