Flutter Engine
The Flutter Engine
SkPixmapUtilsPriv.h
Go to the documentation of this file.
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
8#ifndef SkPixmapUtilsPriv_DEFINED
9#define SkPixmapUtilsPriv_DEFINED
10
16
17namespace SkPixmapUtils {
18
19/**
20 * Decode an image and then copy into dst, applying origin.
21 *
22 * @param dst SkPixmap to write the final image, after
23 * applying the origin.
24 * @param origin SkEncodedOrigin to apply to the raw pixels.
25 * @param decode Function for decoding into a pixmap without
26 * applying the origin.
27 */
28
29template <typename Fn>
30bool Orient(const SkPixmap& dst, SkEncodedOrigin origin, Fn&& decode) {
31 SkAutoPixmapStorage storage;
32 const SkPixmap* tmp = &dst;
33 if (origin != kTopLeft_SkEncodedOrigin) {
34 auto info = dst.info();
37 }
38 if (!storage.tryAlloc(info)) {
39 return false;
40 }
41 tmp = &storage;
42 }
43 if (!decode(*tmp)) {
44 return false;
45 }
46 if (tmp != &dst) {
47 return Orient(dst, *tmp, origin);
48 }
49 return true;
50}
51
52} // namespace SkPixmapUtils
53
54#endif // SkPixmapUtilsPriv_DEFINED
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkEncodedOrigin
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
bool tryAlloc(const SkImageInfo &)
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
dst
Definition: cp.py:12
static DecodeResult decode(std::string path)
Definition: png_codec.cpp:124