blob: faa955ca28a8676c66449e84aceb7e1fc173eb8b [file] [log] [blame]
msarett3d9d7a72015-10-21 10:27:10 -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#ifndef SkSampledCodec_DEFINED
8#define SkSampledCodec_DEFINED
9
10#include "SkAndroidCodec.h"
11#include "SkCodec.h"
12
13/**
14 * This class implements the functionality of SkAndroidCodec. Scaling will
15 * be provided by sampling if it cannot be provided by fCodec.
16 */
17class SkSampledCodec : public SkAndroidCodec {
18public:
Leon Scroggins IIIda3e9ad2018-01-26 15:48:26 -050019 explicit SkSampledCodec(SkCodec*, ExifOrientationBehavior);
msarett3d9d7a72015-10-21 10:27:10 -070020
Brian Salomond3b65972017-03-22 12:05:03 -040021 ~SkSampledCodec() override {}
msarett3d9d7a72015-10-21 10:27:10 -070022
23protected:
24
msarett3d9d7a72015-10-21 10:27:10 -070025 SkISize onGetSampledDimensions(int sampleSize) const override;
26
27 bool onGetSupportedSubset(SkIRect* desiredSubset) const override { return true; }
28
29 SkCodec::Result onGetAndroidPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
scroggoe95a0682015-11-04 04:31:12 -080030 const AndroidOptions& options) override;
msarett3d9d7a72015-10-21 10:27:10 -070031
32private:
scroggo501b7342015-11-03 07:55:11 -080033 /**
34 * Find the best way to account for native scaling.
35 *
36 * Return a size that fCodec can scale to, and adjust sampleSize to finish scaling.
37 *
38 * @param sampleSize As an input, the requested sample size.
39 * As an output, sampling needed after letting fCodec
40 * scale to the returned dimensions.
41 * @param nativeSampleSize Optional output parameter. Will be set to the
42 * effective sample size done by fCodec.
43 * @return SkISize The size that fCodec should scale to.
44 */
45 SkISize accountForNativeScaling(int* sampleSize, int* nativeSampleSize = nullptr) const;
msarett3d9d7a72015-10-21 10:27:10 -070046
47 /**
48 * This fulfills the same contract as onGetAndroidPixels().
49 *
50 * We call this function from onGetAndroidPixels() if we have determined
51 * that fCodec does not support the requested scale, and we need to
52 * provide the scale by sampling.
53 */
54 SkCodec::Result sampledDecode(const SkImageInfo& info, void* pixels, size_t rowBytes,
scroggoe95a0682015-11-04 04:31:12 -080055 const AndroidOptions& options);
msarett3d9d7a72015-10-21 10:27:10 -070056
msarett3d9d7a72015-10-21 10:27:10 -070057 typedef SkAndroidCodec INHERITED;
58};
59#endif // SkSampledCodec_DEFINED