Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPixmapUtils.cpp
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
9
21
22#include <utility>
23
24static bool draw_orientation(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin) {
25 auto surf = SkSurfaces::WrapPixels(dst.info(), dst.writable_addr(), dst.rowBytes());
26 if (!surf) {
27 return false;
28 }
29
30 SkBitmap bm;
31 bm.installPixels(src);
32
33 SkMatrix m = SkEncodedOriginToMatrix(origin, dst.width(), dst.height());
34
35 SkPaint p;
36 p.setBlendMode(SkBlendMode::kSrc);
37 surf->getCanvas()->concat(m);
38 surf->getCanvas()->drawImage(SkImages::RasterFromBitmap(bm), 0, 0, SkSamplingOptions(), &p);
39 return true;
40}
41
42namespace SkPixmapUtils {
43
44bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin origin) {
45 if (src.colorType() != dst.colorType()) {
46 return false;
47 }
48 // note: we just ignore alphaType and colorSpace for this transformation
49
50 int w = src.width();
51 int h = src.height();
53 using std::swap;
54 swap(w, h);
55 }
56 if (dst.width() != w || dst.height() != h) {
57 return false;
58 }
59 if (w == 0 || h == 0) {
60 return true;
61 }
62
63 // check for aliasing to self
64 if (src.addr() == dst.addr()) {
65 return kTopLeft_SkEncodedOrigin == origin;
66 }
67 return draw_orientation(dst, src, origin);
68}
69
71 return info.makeWH(info.height(), info.width());
72}
73
74}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
SkEncodedOrigin
@ kTopLeft_SkEncodedOrigin
static bool SkEncodedOriginSwapsWidthHeight(SkEncodedOrigin origin)
static SkMatrix SkEncodedOriginToMatrix(SkEncodedOrigin origin, int w, int h)
static bool draw_orientation(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition SkRefCnt.h:341
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
Definition SkBitmap.cpp:323
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
SK_API bool Orient(const SkPixmap &dst, const SkPixmap &src, SkEncodedOrigin origin)
SK_API SkImageInfo SwapWidthHeight(const SkImageInfo &info)
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
SkScalar w
SkScalar h
SkImageInfo makeWH(int newWidth, int newHeight) const