• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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 SkSamplingPriv_DEFINED
9 #define SkSamplingPriv_DEFINED
10 
11 #include "include/core/SkSamplingOptions.h"
12 
13 class SkReadBuffer;
14 class SkWriteBuffer;
15 
16 // Private copy of SkFilterQuality, just for legacy deserialization
17 // Matches values in SkFilterQuality
18 enum SkLegacyFQ {
19     kNone_SkLegacyFQ   = 0,    //!< nearest-neighbor; fastest but lowest quality
20     kLow_SkLegacyFQ    = 1,    //!< bilerp
21     kMedium_SkLegacyFQ = 2,    //!< bilerp + mipmaps; good for down-scaling
22     kHigh_SkLegacyFQ   = 3,    //!< bicubic resampling; slowest but good quality
23 
24     kLast_SkLegacyFQ = kHigh_SkLegacyFQ,
25 };
26 
27 // Matches values in SkSamplingOptions::MediumBehavior
28 enum SkMediumAs {
29     kNearest_SkMediumAs,
30     kLinear_SkMediumAs,
31 };
32 
33 class SkSamplingPriv {
34 public:
35     enum {
36         kFlatSize = 3 * sizeof(uint32_t)  // bool32 + [2 floats | 2 ints]
37     };
38 
39     // Returns true if the sampling can be ignored when the CTM is identity.
NoChangeWithIdentityMatrix(const SkSamplingOptions & sampling)40     static bool NoChangeWithIdentityMatrix(const SkSamplingOptions& sampling) {
41         // If B == 0, the cubic resampler should have no effect for identity matrices
42         // https://entropymine.com/imageworsener/bicubic/
43         return !sampling.useCubic || sampling.cubic.B == 0;
44     }
45 
46     static SkSamplingOptions Read(SkReadBuffer&);
47     static void Write(SkWriteBuffer&, const SkSamplingOptions&);
48 
49     static SkSamplingOptions FromFQ(SkLegacyFQ, SkMediumAs = kNearest_SkMediumAs);
50 };
51 
52 #endif
53