• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SkPixmapPriv_DEFINED
9 #define SkPixmapPriv_DEFINED
10 
11 #include "include/codec/SkEncodedOrigin.h"
12 #include "include/core/SkPixmap.h"
13 #include "src/core/SkAutoPixmapStorage.h"
14 
15 class SkPixmapPriv {
16 public:
17     /**
18      *  Copy the pixels in this pixmap into dst, applying the orientation transformations specified
19      *  by the flags. If the inputs are invalid, this returns false and no copy is made.
20      */
21     static bool Orient(const SkPixmap& dst, const SkPixmap& src, SkEncodedOrigin);
22 
23     static SkImageInfo SwapWidthHeight(const SkImageInfo& info);
24 
25     /**
26      *  Decode an image and then copy into dst, applying origin.
27      *
28      *  @param dst SkPixmap to write the final image, after
29      *      applying the origin.
30      *  @param origin SkEncodedOrigin to apply to the raw pixels.
31      *  @param decode Function for decoding into a pixmap without
32      *      applying the origin.
33      */
34 
35     template <typename Fn>
Orient(const SkPixmap & dst,SkEncodedOrigin origin,Fn && decode)36     static bool Orient(const SkPixmap& dst, SkEncodedOrigin origin, Fn&& decode) {
37         SkAutoPixmapStorage storage;
38         const SkPixmap* tmp = &dst;
39         if (origin != kTopLeft_SkEncodedOrigin) {
40             auto info = dst.info();
41             if (SkEncodedOriginSwapsWidthHeight(origin)) {
42                 info = SwapWidthHeight(info);
43             }
44             if (!storage.tryAlloc(info)) {
45                 return false;
46             }
47             tmp = &storage;
48         }
49         if (!decode(*tmp)) {
50             return false;
51         }
52         if (tmp != &dst) {
53             return Orient(dst, *tmp, origin);
54         }
55         return true;
56     }
57 
ResetPixmapKeepInfo(SkPixmap * pm,const void * address,size_t rowBytes)58     static void ResetPixmapKeepInfo(SkPixmap* pm, const void* address, size_t rowBytes) {
59         pm->fRowBytes = rowBytes;
60         pm->fPixels = address;
61     }
62 };
63 
64 #endif
65