Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(422)

Side by Side Diff: include/codec/SkScaledCodec.h

Issue 1260673002: SkScaledCodec class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move Jpeg Swizzler to ScanlineDecoder Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 fScanlineDecoder->getEncodedFormat();
62 }
63
64 bool onReallyHasAlpha() const override {
65 return fScanlineDecoder->reallyHasAlpha();
66 }
67
68 private:
69 SkAutoTDelete<SkScanlineDecoder> fScanlineDecoder;
70
71 explicit SkScaledCodec(SkScanlineDecoder*);
72
73 typedef SkCodec INHERITED;
74 };
75 #endif // SkScaledCodec_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698