1fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/* 2fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Copyright 2013 Google Inc. 3fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 4fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Use of this source code is governed by a BSD-style license that can be 5fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * found in the LICENSE file. 6fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 7fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 8fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#ifndef SkImageInfo_DEFINED 9fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#define SkImageInfo_DEFINED 10fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 11fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkColorSpace.h" 12fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkMath.h" 13fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkRect.h" 14fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkSize.h" 15fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 16fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotclass SkReadBuffer; 17fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotclass SkWriteBuffer; 18fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 19fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** 20fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Describes how to interpret the alpha component of a pixel. 21fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 22fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotenum SkAlphaType { 23fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kUnknown_SkAlphaType, 24fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 25fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 26fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * All pixels are stored as opaque. This differs slightly from kIgnore in 27fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * that kOpaque has correct "opaque" values stored in the pixels, while 28fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * kIgnore may not, but in both cases the caller should treat the pixels 29fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * as opaque. 30fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 31fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kOpaque_SkAlphaType, 32fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 33fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 34fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * All pixels have their alpha premultiplied in their color components. 35fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * This is the natural format for the rendering target pixels. 36fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 37fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kPremul_SkAlphaType, 38fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 39fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 40fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * All pixels have their color components stored without any regard to the 41fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * alpha. e.g. this is the default configuration for PNG images. 42fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 43fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * This alpha-type is ONLY supported for input images. Rendering cannot 44fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * generate this on output. 45fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 46fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kUnpremul_SkAlphaType, 47fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 48fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kLastEnum_SkAlphaType = kUnpremul_SkAlphaType, 49fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}; 50fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 51fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool SkAlphaTypeIsOpaque(SkAlphaType at) { 52fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return kOpaque_SkAlphaType == at; 53fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 54fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 55fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool SkAlphaTypeIsValid(unsigned value) { 56fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return value <= kLastEnum_SkAlphaType; 57fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 58fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 59fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/////////////////////////////////////////////////////////////////////////////// 60fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 61fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** Temporary macro that allows us to add new color types without breaking Chrome compile. */ 62fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#define SK_EXTENDED_COLOR_TYPES 63fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 64fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** 65fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Describes how to interpret the components of a pixel. 66fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 67fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * kN32_SkColorType is an alias for whichever 32bit ARGB format is the "native" 68fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * form for skia's blitters. Use this if you don't have a swizzle preference 69fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * for 32bit pixels. 70fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 71fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotenum SkColorType { 72fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kUnknown_SkColorType, 73fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kAlpha_8_SkColorType, 74fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGB_565_SkColorType, 75fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kARGB_4444_SkColorType, 76fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGBA_8888_SkColorType, 77fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGB_888x_SkColorType, 78fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kBGRA_8888_SkColorType, 79fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGBA_1010102_SkColorType, 80fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGB_101010x_SkColorType, 81fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kGray_8_SkColorType, 82fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRGBA_F16_SkColorType, 83fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 84fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kLastEnum_SkColorType = kRGBA_F16_SkColorType, 85fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 86fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A) 87fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kN32_SkColorType = kBGRA_8888_SkColorType, 88fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A) 89fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kN32_SkColorType = kRGBA_8888_SkColorType, 90fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#else 91fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot #error "SK_*32_SHIFT values must correspond to BGRA or RGBA byte order" 92fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#endif 93fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}; 94fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 95fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic int SkColorTypeBytesPerPixel(SkColorType ct) { 96fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot switch (ct) { 97fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kUnknown_SkColorType: return 0; 98fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kAlpha_8_SkColorType: return 1; 99fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_565_SkColorType: return 2; 100fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kARGB_4444_SkColorType: return 2; 101fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_8888_SkColorType: return 4; 102fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kBGRA_8888_SkColorType: return 4; 103fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_888x_SkColorType: return 4; 104fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_1010102_SkColorType: return 4; 105fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_101010x_SkColorType: return 4; 106fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kGray_8_SkColorType: return 1; 107fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_F16_SkColorType: return 8; 108fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 109fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return 0; 110fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 111fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 112fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic int SkColorTypeShiftPerPixel(SkColorType ct) { 113fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot switch (ct) { 114fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kUnknown_SkColorType: return 0; 115fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kAlpha_8_SkColorType: return 0; 116fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_565_SkColorType: return 1; 117fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kARGB_4444_SkColorType: return 1; 118fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_8888_SkColorType: return 2; 119fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_888x_SkColorType: return 2; 120fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kBGRA_8888_SkColorType: return 2; 121fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_1010102_SkColorType: return 2; 122fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGB_101010x_SkColorType: return 2; 123fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kGray_8_SkColorType: return 0; 124fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot case kRGBA_F16_SkColorType: return 3; 125fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 126fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return 0; 127fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 128fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 129fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) { 130fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return width * SkColorTypeBytesPerPixel(ct); 131fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 132fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 133fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline bool SkColorTypeIsValid(unsigned value) { 134fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return value <= kLastEnum_SkColorType; 135fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 136fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 137fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstatic inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) { 138fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot if (kUnknown_SkColorType == ct) { 139fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return 0; 140fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 141fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct)); 142fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 143fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 144fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/////////////////////////////////////////////////////////////////////////////// 145fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 146fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** 147fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Return true if alphaType is supported by colorType. If there is a canonical 148fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * alphaType for this colorType, return it in canonical. 149fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 150fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotbool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType, 151fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkAlphaType* canonical = nullptr); 152fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 153fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/////////////////////////////////////////////////////////////////////////////// 154fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 155fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** 156fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Describes the color space a YUV pixel. 157fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 158fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotenum SkYUVColorSpace { 159fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** Standard JPEG color space. */ 160fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kJPEG_SkYUVColorSpace, 161fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** SDTV standard Rec. 601 color space. Uses "studio swing" [16, 235] color 162fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot range. See http://en.wikipedia.org/wiki/Rec._601 for details. */ 163fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRec601_SkYUVColorSpace, 164fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color 165fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot range. See http://en.wikipedia.org/wiki/Rec._709 for details. */ 166fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kRec709_SkYUVColorSpace, 167fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 168fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace, 169fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}; 170fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 171fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/////////////////////////////////////////////////////////////////////////////// 172fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 173fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotenum class SkDestinationSurfaceColorMode { 174fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kLegacy, 175fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot kGammaAndColorSpaceAware, 176fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}; 177fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 178fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/** 179fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Describe an image's dimensions and pixel type. 180fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Used for both src images and render-targets (surfaces). 181fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 182fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotstruct SK_API SkImageInfo { 183fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotpublic: 184fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo() 185fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot : fColorSpace(nullptr) 186fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fWidth(0) 187fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fHeight(0) 188fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fColorType(kUnknown_SkColorType) 189fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fAlphaType(kUnknown_SkAlphaType) 190fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot {} 191fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 192fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at, 193fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot sk_sp<SkColorSpace> cs = nullptr) { 194fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return SkImageInfo(width, height, ct, at, std::move(cs)); 195fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 196fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 197fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 198fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Sets colortype to the native ARGB32 type. 199fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 200fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeN32(int width, int height, SkAlphaType at, 201fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot sk_sp<SkColorSpace> cs = nullptr) { 202fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(width, height, kN32_SkColorType, at, cs); 203fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 204fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 205fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 206fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Create an ImageInfo marked as SRGB with N32 swizzle. 207fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 208fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeS32(int width, int height, SkAlphaType at); 209fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 210fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 211fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Sets colortype to the native ARGB32 type, and the alphatype to premul. 212fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 213fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) { 214fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs); 215fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 216fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 217fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeN32Premul(const SkISize& size) { 218fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return MakeN32Premul(size.width(), size.height()); 219fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 220fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 221fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeA8(int width, int height) { 222fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr); 223fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 224fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 225fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeUnknown(int width, int height) { 226fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, nullptr); 227fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 228fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 229fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static SkImageInfo MakeUnknown() { 230fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return MakeUnknown(0, 0); 231fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 232fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 233fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int width() const { return fWidth; } 234fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int height() const { return fHeight; } 235fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkColorType colorType() const { return fColorType; } 236fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkAlphaType alphaType() const { return fAlphaType; } 237fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkColorSpace* colorSpace() const { return fColorSpace.get(); } 238fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; } 239fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 240fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } 241fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 242fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool isOpaque() const { 243fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return SkAlphaTypeIsOpaque(fAlphaType); 244fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 245fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 246fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); } 247fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); } 248fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 249fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool gammaCloseToSRGB() const { 250fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return fColorSpace && fColorSpace->gammaCloseToSRGB(); 251fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 252fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 253fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 254fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Return a new ImageInfo with the same colortype and alphatype as this info, 255fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * but with the specified width and height. 256fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 257fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo makeWH(int newWidth, int newHeight) const { 258fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace); 259fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 260fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 261fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const { 262fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace); 263fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 264fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 265fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo makeColorType(SkColorType newColorType) const { 266fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace); 267fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 268fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 269fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const { 270fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs)); 271fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 272fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 273fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } 274fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 275fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } 276fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 277fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot uint64_t minRowBytes64() const { 278fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return sk_64_mul(fWidth, this->bytesPerPixel()); 279fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 280fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 281fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot size_t minRowBytes() const { 282fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot uint64_t minRowBytes = this->minRowBytes64(); 283fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot if (!sk_64_isS32(minRowBytes)) { 284fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return 0; 285fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 286fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return sk_64_asS32(minRowBytes); 287fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 288fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 289fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot size_t computeOffset(int x, int y, size_t rowBytes) const { 290fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkASSERT((unsigned)x < (unsigned)fWidth); 291fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkASSERT((unsigned)y < (unsigned)fHeight); 292fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return SkColorTypeComputeOffset(fColorType, x, y, rowBytes); 293fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 294fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 295fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool operator==(const SkImageInfo& other) const { 296fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return fWidth == other.fWidth && fHeight == other.fHeight && 297fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fColorType == other.fColorType && fAlphaType == other.fAlphaType && 298fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkColorSpace::Equals(fColorSpace.get(), other.fColorSpace.get()); 299fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 300fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool operator!=(const SkImageInfo& other) const { 301fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return !(*this == other); 302fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 303fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 304fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot void unflatten(SkReadBuffer& buffer); 305fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot void flatten(SkWriteBuffer& buffer) const; 306fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 307fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 308fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Returns the size (in bytes) of the image buffer that this info needs, given the specified 309fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * rowBytes. The rowBytes must be >= this->minRowBytes(). 310fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 311fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * if (height == 0) { 312fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * return 0; 313fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * } else { 314fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * return (height - 1) * rowBytes + width * bytes_per_pixel; 315fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * } 316fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 317fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * If the calculation overflows this returns SK_MaxSizeT 318fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 319fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot size_t computeByteSize(size_t rowBytes) const; 320fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 321fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot /** 322fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Returns the minimum size (in bytes) of the image buffer that this info needs. 323fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * If the calculation overflows, or if the height is 0, this returns 0. 324fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 325fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot size_t computeMinByteSize() const { 326fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return this->computeByteSize(this->minRowBytes()); 327fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 328fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 329fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot // Returns true if the result of computeByteSize (or computeMinByteSize) overflowed 330fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot static bool ByteSizeOverflowed(size_t byteSize) { 331fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return SK_MaxSizeT == byteSize; 332fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 333fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 334fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot bool validRowBytes(size_t rowBytes) const { 335fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot uint64_t minRB = sk_64_mul(fWidth, this->bytesPerPixel()); 336fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return rowBytes >= minRB; 337fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 338fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 339fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot void reset() { 340fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fColorSpace = nullptr; 341fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fWidth = 0; 342fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fHeight = 0; 343fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fColorType = kUnknown_SkColorType; 344fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fAlphaType = kUnknown_SkAlphaType; 345fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 346fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 347fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkDEBUGCODE(void validate() const;) 348fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 349fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotprivate: 350fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot sk_sp<SkColorSpace> fColorSpace; 351fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int fWidth; 352fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot int fHeight; 353fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkColorType fColorType; 354fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkAlphaType fAlphaType; 355fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 356fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs) 357fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot : fColorSpace(std::move(cs)) 358fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fWidth(width) 359fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fHeight(height) 360fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fColorType(ct) 361fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fAlphaType(at) 362fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot {} 363fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot}; 364fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 365fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#endif 366