Flutter Engine
The Flutter Engine
SkScalingCodec.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 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 SkScalingCodec_DEFINED
8#define SkScalingCodec_DEFINED
9
13#include "include/core/SkSize.h"
16
17#include <algorithm>
18#include <memory>
19#include <utility>
20
21// Helper class for an SkCodec that supports arbitrary downscaling.
22class SkScalingCodec : public SkCodec {
23protected:
24 SkScalingCodec(SkEncodedInfo&& info, XformFormat srcFormat, std::unique_ptr<SkStream> stream,
26 : SkCodec(std::move(info), srcFormat, std::move(stream), origin) {}
27
28 SkISize onGetScaledDimensions(float desiredScale) const override {
29 SkISize dim = this->dimensions();
30 // SkCodec treats zero dimensional images as errors, so the minimum size
31 // that we will recommend is 1x1.
32 dim.fWidth = std::max(1, SkScalarRoundToInt(desiredScale * dim.fWidth));
33 dim.fHeight = std::max(1, SkScalarRoundToInt(desiredScale * dim.fHeight));
34 return dim;
35 }
36
37 bool onDimensionsSupported(const SkISize& requested) override {
38 SkISize dim = this->dimensions();
39 int w = requested.width();
40 int h = requested.height();
41 return 1 <= w && w <= dim.width() && 1 <= h && h <= dim.height();
42 }
43};
44
45#endif // SkScalingCodec_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkEncodedOrigin
@ kTopLeft_SkEncodedOrigin
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:37
SkISize dimensions() const
Definition: SkCodec.h:230
SkStream * stream()
Definition: SkCodec.h:865
SkISize onGetScaledDimensions(float desiredScale) const override
SkScalingCodec(SkEncodedInfo &&info, XformFormat srcFormat, std::unique_ptr< SkStream > stream, SkEncodedOrigin origin=kTopLeft_SkEncodedOrigin)
bool onDimensionsSupported(const SkISize &requested) override
static float max(float r, float g, float b)
Definition: hsl.cpp:49
Definition: ref_ptr.h:256
SkScalar w
SkScalar h
skcms_PixelFormat
Definition: skcms_public.h:273
Definition: SkSize.h:16
int32_t fHeight
Definition: SkSize.h:18
int32_t fWidth
Definition: SkSize.h:17
constexpr int32_t width() const
Definition: SkSize.h:36
constexpr int32_t height() const
Definition: SkSize.h:37