1 /* 2 * Copyright 2016 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 SkYUVASizeInfo_DEFINED 9 #define SkYUVASizeInfo_DEFINED 10 11 #include "SkEncodedOrigin.h" 12 #include "SkImageInfo.h" 13 #include "SkSize.h" 14 15 struct SK_API SkYUVASizeInfo { 16 static constexpr auto kMaxCount = 4; 17 18 SkISize fSizes[kMaxCount]; 19 20 /** 21 * While the widths of the Y, U, V and A planes are not restricted, the 22 * implementation often requires that the width of the memory allocated 23 * for each plane be a multiple of 8. 24 * 25 * This struct allows us to inform the client how many "widthBytes" 26 * that we need. Note that we use the new idea of "widthBytes" 27 * because this idea is distinct from "rowBytes" (used elsewhere in 28 * Skia). "rowBytes" allow the last row of the allocation to not 29 * include any extra padding, while, in this case, every single row of 30 * the allocation must be at least "widthBytes". 31 */ 32 size_t fWidthBytes[kMaxCount]; 33 34 /** 35 * YUVA data often comes from formats like JPEG that support EXIF orientation. 36 * Code that operates on the raw YUV data often needs to know that orientation. 37 */ 38 SkEncodedOrigin fOrigin = kDefault_SkEncodedOrigin; 39 40 bool operator==(const SkYUVASizeInfo& that) const { 41 for (int i = 0; i < kMaxCount; ++i) { 42 SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) || 43 (fSizes[i].isEmpty() && !fWidthBytes[i])); 44 if (fSizes[i] != that.fSizes[i] || fWidthBytes[i] != that.fWidthBytes[i]) { 45 return false; 46 } 47 } 48 49 return true; 50 } 51 computeTotalBytesSkYUVASizeInfo52 size_t computeTotalBytes() const { 53 size_t totalBytes = 0; 54 55 for (int i = 0; i < kMaxCount; ++i) { 56 SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) || 57 (fSizes[i].isEmpty() && !fWidthBytes[i])); 58 totalBytes += fWidthBytes[i] * fSizes[i].height(); 59 } 60 61 return totalBytes; 62 } 63 64 void computePlanes(void* base, void* planes[kMaxCount]) const; 65 66 }; 67 68 #endif // SkYUVASizeInfo_DEFINED 69