2013-11-13 19:09:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/* Generated by tools/bookmaker from include/core/SkImageInfo.h and docs/SkImageInfo_Reference.bmh
|
|
|
|
on 2018-06-08 11:48:28. Additional documentation and examples can be found at:
|
|
|
|
https://skia.org/user/api/SkImageInfo_Reference
|
|
|
|
|
|
|
|
You may edit either file directly. Structural changes to public interfaces require
|
|
|
|
editing both files. After editing docs/SkImageInfo_Reference.bmh, run:
|
|
|
|
bookmaker -b docs -i include/core/SkImageInfo.h -p
|
|
|
|
to create an updated version of this file.
|
|
|
|
*/
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
#ifndef SkImageInfo_DEFINED
|
|
|
|
#define SkImageInfo_DEFINED
|
|
|
|
|
2016-05-27 14:39:02 +00:00
|
|
|
#include "SkColorSpace.h"
|
2014-02-11 18:21:45 +00:00
|
|
|
#include "SkMath.h"
|
2014-10-24 19:54:53 +00:00
|
|
|
#include "SkRect.h"
|
2014-01-15 02:38:22 +00:00
|
|
|
#include "SkSize.h"
|
2017-09-20 15:56:00 +00:00
|
|
|
#include "../private/SkTFitsIn.h"
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
class SkReadBuffer;
|
2014-10-24 19:54:53 +00:00
|
|
|
class SkWriteBuffer;
|
2013-12-09 22:01:03 +00:00
|
|
|
|
2018-04-03 15:49:10 +00:00
|
|
|
/** \enum SkImageInfo::SkAlphaType
|
|
|
|
Describes how to interpret the alpha component of a pixel. A pixel may
|
2018-05-30 13:20:29 +00:00
|
|
|
be opaque, or alpha, describing multiple levels of transparency.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
In simple blending, alpha weights the draw color and the destination
|
|
|
|
color to create a new color. If alpha describes a weight from zero to one:
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
new color = draw color * alpha + destination color * (1 - alpha)
|
|
|
|
|
|
|
|
In practice alpha is encoded in two or more bits, where 1.0 equals all bits set.
|
|
|
|
|
|
|
|
RGB may have alpha included in each component value; the stored
|
|
|
|
value is the original RGB multiplied by alpha. Premultiplied color
|
2018-04-03 15:49:10 +00:00
|
|
|
components improve performance.
|
|
|
|
*/
|
2013-11-13 19:09:13 +00:00
|
|
|
enum SkAlphaType {
|
2018-05-30 13:20:29 +00:00
|
|
|
kUnknown_SkAlphaType, //!< uninitialized
|
|
|
|
kOpaque_SkAlphaType, //!< pixel is opaque
|
|
|
|
kPremul_SkAlphaType, //!< pixel components are premultiplied by alpha
|
|
|
|
kUnpremul_SkAlphaType, //!< pixel components are independent of alpha
|
|
|
|
kLastEnum_SkAlphaType = kUnpremul_SkAlphaType, //!< last valid value
|
2013-11-13 19:09:13 +00:00
|
|
|
};
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns true if SkAlphaType equals kOpaque_SkAlphaType. kOpaque_SkAlphaType is a
|
2018-05-30 13:20:29 +00:00
|
|
|
hint that the SkColorType is opaque, or that all alpha values are set to
|
2018-04-03 19:24:12 +00:00
|
|
|
their 1.0 equivalent. If SkAlphaType is kOpaque_SkAlphaType, and SkColorType is not
|
2018-05-30 13:20:29 +00:00
|
|
|
opaque, then the result of drawing any pixel with a alpha value less than
|
2018-04-03 19:24:12 +00:00
|
|
|
1.0 is undefined.
|
|
|
|
|
|
|
|
@param at one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@return true if at equals kOpaque_SkAlphaType
|
|
|
|
*/
|
2013-11-13 19:09:13 +00:00
|
|
|
static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
|
2015-02-27 18:23:00 +00:00
|
|
|
return kOpaque_SkAlphaType == at;
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-01-25 19:07:47 +00:00
|
|
|
/** Temporary macro that allows us to add new color types without breaking Chrome compile. */
|
|
|
|
#define SK_EXTENDED_COLOR_TYPES
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** \enum SkImageInfo::SkColorType
|
|
|
|
Describes how pixel bits encode color. A pixel may be an alpha mask, a
|
2018-05-30 13:20:29 +00:00
|
|
|
grayscale, RGB, or ARGB.
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
kN32_SkColorType selects the native 32-bit ARGB format. On Little_Endian
|
|
|
|
processors, pixels containing 8-bit ARGB components pack into 32-bit
|
|
|
|
kBGRA_8888_SkColorType. On Big_Endian processors, pixels pack into 32-bit
|
|
|
|
kRGBA_8888_SkColorType.
|
|
|
|
*/
|
|
|
|
enum SkColorType {
|
2018-05-30 13:20:29 +00:00
|
|
|
kUnknown_SkColorType, //!< uninitialized
|
|
|
|
kAlpha_8_SkColorType, //!< pixel with alpha in 8-bit byte
|
|
|
|
kRGB_565_SkColorType, //!< pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
|
|
|
|
kARGB_4444_SkColorType, //!< pixel with 4 bits for alpha, red, green, blue; in 16-bit word
|
|
|
|
kRGBA_8888_SkColorType, //!< pixel with 8 bits for red, green, blue, alpha; in 32-bit word
|
|
|
|
kRGB_888x_SkColorType, //!< pixel with 8 bits each for red, green, blue; in 32-bit word
|
|
|
|
kBGRA_8888_SkColorType, //!< pixel with 8 bits for blue, green, red, alpha; in 32-bit word
|
|
|
|
kRGBA_1010102_SkColorType, //!< 10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
|
|
|
|
kRGB_101010x_SkColorType, //!< pixel with 10 bits each for red, green, blue; in 32-bit word
|
|
|
|
kGray_8_SkColorType, //!< pixel with grayscale level in 8-bit byte
|
|
|
|
kRGBA_F16_SkColorType, //!< pixel with half floats for red, green, blue, alpha; in 64-bit word
|
|
|
|
kLastEnum_SkColorType = kRGBA_F16_SkColorType,//!< last valid value
|
2018-04-03 15:49:10 +00:00
|
|
|
|
|
|
|
#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
|
2018-05-30 13:20:29 +00:00
|
|
|
kN32_SkColorType = kBGRA_8888_SkColorType,//!< native ARGB 32-bit encoding
|
2018-04-03 15:49:10 +00:00
|
|
|
|
|
|
|
#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
|
2018-05-30 13:20:29 +00:00
|
|
|
kN32_SkColorType = kRGBA_8888_SkColorType,//!< native ARGB 32-bit encoding
|
2018-04-03 15:49:10 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#error "SK_*32_SHIFT values must correspond to BGRA or RGBA byte order"
|
|
|
|
#endif
|
2018-04-03 19:24:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Returns the number of bytes required to store a pixel, including unused padding.
|
|
|
|
Returns zero if ct is kUnknown_SkColorType or invalid.
|
|
|
|
|
|
|
|
@param ct one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
|
|
|
@return bytes per pixel
|
|
|
|
*/
|
|
|
|
SK_API int SkColorTypeBytesPerPixel(SkColorType ct);
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Returns true if SkColorType always decodes alpha to 1.0, making the pixel
|
|
|
|
fully opaque. If true, SkColorType does not reserve bits to encode alpha.
|
2018-04-03 19:24:12 +00:00
|
|
|
|
|
|
|
@param ct one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
2018-05-30 13:20:29 +00:00
|
|
|
@return true if alpha is always set to 1.0
|
2018-04-03 19:24:12 +00:00
|
|
|
*/
|
|
|
|
SK_API bool SkColorTypeIsAlwaysOpaque(SkColorType ct);
|
|
|
|
|
|
|
|
/** Returns true if canonical can be set to a valid SkAlphaType for colorType. If
|
|
|
|
there is more than one valid canonical SkAlphaType, set to alphaType, if valid.
|
|
|
|
If true is returned and canonical is not nullptr, store valid SkAlphaType.
|
|
|
|
|
|
|
|
Returns false only if alphaType is kUnknown_SkAlphaType, color type is not
|
|
|
|
kUnknown_SkColorType, and SkColorType is not always opaque. If false is returned,
|
|
|
|
canonical is ignored.
|
|
|
|
|
|
|
|
For kUnknown_SkColorType: set canonical to kUnknown_SkAlphaType and return true.
|
|
|
|
For kAlpha_8_SkColorType: set canonical to kPremul_SkAlphaType or
|
|
|
|
kOpaque_SkAlphaType and return true if alphaType is not kUnknown_SkAlphaType.
|
|
|
|
For kRGB_565_SkColorType, kRGB_888x_SkColorType, kRGB_101010x_SkColorType, and
|
|
|
|
kGray_8_SkColorType: set canonical to kOpaque_SkAlphaType and return true.
|
|
|
|
For kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
|
|
|
|
kRGBA_1010102_SkColorType, and kRGBA_F16_SkColorType: set canonical to alphaType
|
|
|
|
and return true if alphaType is not kUnknown_SkAlphaType.
|
|
|
|
|
|
|
|
@param colorType one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
|
|
|
@param alphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@param canonical storage for SkAlphaType
|
|
|
|
@return true if valid SkAlphaType can be associated with colorType
|
|
|
|
*/
|
|
|
|
SK_API bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
2018-04-03 15:49:10 +00:00
|
|
|
SkAlphaType* canonical = nullptr);
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** \enum SkImageInfo::SkYUVColorSpace
|
|
|
|
Describes color range of YUV pixels. The color mapping from YUV to RGB varies
|
|
|
|
depending on the source. YUV pixels may be generated by JPEG images, standard
|
|
|
|
video streams, or high definition video streams. Each has its own mapping from
|
|
|
|
YUV and RGB.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
JPEG YUV values encode the full range of 0 to 255 for all three components.
|
|
|
|
Video YUV values range from 16 to 235 for all three components. Details of
|
|
|
|
encoding and conversion to RGB are described in YCbCr color space.
|
|
|
|
*/
|
|
|
|
enum SkYUVColorSpace {
|
2018-05-30 13:20:29 +00:00
|
|
|
kJPEG_SkYUVColorSpace, //!< describes full range
|
|
|
|
kRec601_SkYUVColorSpace, //!< describes SDTV range
|
|
|
|
kRec709_SkYUVColorSpace, //!< describes HDTV range
|
|
|
|
kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace, //!< last valid value
|
2018-04-03 19:24:12 +00:00
|
|
|
};
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** \struct SkImageInfo
|
|
|
|
Describes pixel dimensions and encoding. SkBitmap, SkImage, PixMap, and SkSurface
|
|
|
|
can be created from SkImageInfo. SkImageInfo can be retrieved from SkBitmap and
|
|
|
|
SkPixmap, but not from SkImage and SkSurface. For example, SkImage and SkSurface
|
|
|
|
implementations may defer pixel depth, so may not completely specify SkImageInfo.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
SkImageInfo contains dimensions, the pixel integral width and height. It encodes
|
2018-05-30 13:20:29 +00:00
|
|
|
how pixel bits describe alpha, transparency; color components red, blue,
|
2018-04-03 19:24:12 +00:00
|
|
|
and green; and SkColorSpace, the range and linearity of colors.
|
|
|
|
*/
|
|
|
|
struct SK_API SkImageInfo {
|
2014-09-03 18:54:58 +00:00
|
|
|
public:
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType,
|
|
|
|
a width and height of zero, and no SkColorSpace.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return empty SkImageInfo
|
|
|
|
*/
|
|
|
|
SkImageInfo()
|
2016-05-27 14:39:02 +00:00
|
|
|
: fColorSpace(nullptr)
|
|
|
|
, fWidth(0)
|
2014-09-03 18:54:58 +00:00
|
|
|
, fHeight(0)
|
|
|
|
, fColorType(kUnknown_SkColorType)
|
2015-02-27 18:23:00 +00:00
|
|
|
, fAlphaType(kUnknown_SkAlphaType)
|
2014-09-03 18:54:58 +00:00
|
|
|
{}
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, SkColorType ct,
|
|
|
|
SkAlphaType at, and optionally SkColorSpace cs.
|
|
|
|
|
|
|
|
If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
|
|
|
|
defaults to sRGB, mapping into SkSurface SkColorSpace.
|
|
|
|
|
|
|
|
Parameters are not validated to see if their values are legal, or that the
|
|
|
|
combination is supported.
|
|
|
|
|
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param ct one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
|
|
|
@param at one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@param cs range of colors; may be nullptr
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
|
2016-06-17 16:26:41 +00:00
|
|
|
sk_sp<SkColorSpace> cs = nullptr) {
|
|
|
|
return SkImageInfo(width, height, ct, at, std::move(cs));
|
2014-01-15 02:38:22 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
|
|
|
|
SkAlphaType at, and optionally SkColorSpace cs. kN32_SkColorType will equal either
|
|
|
|
kBGRA_8888_SkColorType or kRGBA_8888_SkColorType, whichever is optimal.
|
|
|
|
|
|
|
|
If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
|
|
|
|
defaults to sRGB, mapping into SkSurface SkColorSpace.
|
|
|
|
|
|
|
|
Parameters are not validated to see if their values are legal, or that the
|
|
|
|
combination is supported.
|
|
|
|
|
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param at one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@param cs range of colors; may be nullptr
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeN32(int width, int height, SkAlphaType at,
|
2016-06-17 16:26:41 +00:00
|
|
|
sk_sp<SkColorSpace> cs = nullptr) {
|
|
|
|
return Make(width, height, kN32_SkColorType, at, cs);
|
2014-01-15 02:38:22 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
|
|
|
|
SkAlphaType at, with sRGB SkColorSpace.
|
2014-01-15 07:01:43 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Parameters are not validated to see if their values are legal, or that the
|
|
|
|
combination is supported.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param at one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeS32(int width, int height, SkAlphaType at);
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
|
|
|
|
kPremul_SkAlphaType, with optional SkColorSpace.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
If SkColorSpace cs is nullptr and SkImageInfo is part of drawing source: SkColorSpace
|
|
|
|
defaults to sRGB, mapping into SkSurface SkColorSpace.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Parameters are not validated to see if their values are legal, or that the
|
|
|
|
combination is supported.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@param cs range of colors; may be nullptr
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) {
|
2016-06-21 17:28:14 +00:00
|
|
|
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs);
|
2014-01-15 02:38:22 +00:00
|
|
|
}
|
2014-01-15 07:01:43 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kN32_SkColorType,
|
|
|
|
kPremul_SkAlphaType, with SkColorSpace set to nullptr.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
If SkImageInfo is part of drawing source: SkColorSpace defaults to sRGB, mapping
|
|
|
|
into SkSurface SkColorSpace.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Parameters are not validated to see if their values are legal, or that the
|
|
|
|
combination is supported.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param size width and height, each must be zero or greater
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeN32Premul(const SkISize& size) {
|
2016-06-17 16:26:41 +00:00
|
|
|
return MakeN32Premul(size.width(), size.height());
|
|
|
|
}
|
2016-06-02 19:40:22 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kAlpha_8_SkColorType,
|
|
|
|
kPremul_SkAlphaType, with SkColorSpace set to nullptr.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeA8(int width, int height) {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(width, height, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr);
|
2014-01-15 02:38:22 +00:00
|
|
|
}
|
2014-01-15 07:01:43 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height, kUnknown_SkColorType,
|
|
|
|
kUnknown_SkAlphaType, with SkColorSpace set to nullptr.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Returned SkImageInfo as part of source does not draw, and as part of destination
|
|
|
|
can not be drawn to.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param width pixel column count; must be zero or greater
|
|
|
|
@param height pixel row count; must be zero or greater
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeUnknown(int width, int height) {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(width, height, kUnknown_SkColorType, kUnknown_SkAlphaType, nullptr);
|
2014-02-20 20:55:37 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo from integral dimensions width and height set to zero,
|
|
|
|
kUnknown_SkColorType, kUnknown_SkAlphaType, with SkColorSpace set to nullptr.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Returned SkImageInfo as part of source does not draw, and as part of destination
|
|
|
|
can not be drawn to.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeUnknown() {
|
2016-06-17 16:26:41 +00:00
|
|
|
return MakeUnknown(0, 0);
|
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns pixel count in each row.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return pixel width
|
|
|
|
*/
|
|
|
|
int width() const { return fWidth; }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns pixel row count.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return pixel height
|
|
|
|
*/
|
|
|
|
int height() const { return fHeight; }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns SkColorType, one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType.
|
2016-05-27 14:39:02 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return SkColorType
|
|
|
|
*/
|
|
|
|
SkColorType colorType() const { return fColorType; }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns SkAlphaType, one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return SkAlphaType
|
|
|
|
*/
|
|
|
|
SkAlphaType alphaType() const { return fAlphaType; }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns SkColorSpace, the range of colors. The reference count of
|
|
|
|
SkColorSpace is unchanged. The returned SkColorSpace is immutable.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return SkColorSpace, or nullptr
|
|
|
|
*/
|
|
|
|
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns smart pointer to SkColorSpace, the range of colors. The smart pointer
|
|
|
|
tracks the number of objects sharing this SkColorSpace reference so the memory
|
|
|
|
is released when the owners destruct.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
The returned SkColorSpace is immutable.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return SkColorSpace wrapped in a smart pointer
|
|
|
|
*/
|
|
|
|
sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns if SkImageInfo describes an empty area of pixels by checking if either
|
|
|
|
width or height is zero or smaller.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return true if either dimension is zero or smaller
|
|
|
|
*/
|
|
|
|
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns true if SkAlphaType is set to hint that all pixels are opaque; their
|
2018-05-30 13:20:29 +00:00
|
|
|
alpha value is implicitly or explicitly 1.0. If true, and all pixels are
|
2018-04-03 19:24:12 +00:00
|
|
|
not opaque, Skia may draw incorrectly.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Does not check if SkColorType allows alpha, or if any pixel value has
|
|
|
|
transparency.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return true if SkAlphaType is kOpaque_SkAlphaType
|
|
|
|
*/
|
|
|
|
bool isOpaque() const {
|
2013-11-13 19:09:13 +00:00
|
|
|
return SkAlphaTypeIsOpaque(fAlphaType);
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns SkISize { width(), height() }.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return integral size of width() and height()
|
|
|
|
*/
|
|
|
|
SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns SkIRect { 0, 0, width(), height() }.
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return integral rectangle from origin to width() and height()
|
|
|
|
*/
|
|
|
|
SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns true if associated SkColorSpace is not nullptr, and SkColorSpace gamma
|
|
|
|
is approximately the same as sRGB.
|
|
|
|
This includes the
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return true if SkColorSpace gamma is approximately the same as sRGB
|
|
|
|
*/
|
|
|
|
bool gammaCloseToSRGB() const {
|
2016-06-17 16:26:41 +00:00
|
|
|
return fColorSpace && fColorSpace->gammaCloseToSRGB();
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo with the same SkColorType, SkColorSpace, and SkAlphaType,
|
|
|
|
with dimensions set to width and height.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param newWidth pixel column count; must be zero or greater
|
|
|
|
@param newHeight pixel row count; must be zero or greater
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
SkImageInfo makeWH(int newWidth, int newHeight) const {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(newWidth, newHeight, fColorType, fAlphaType, fColorSpace);
|
2014-06-02 20:07:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo with same SkColorType, SkColorSpace, width, and height,
|
|
|
|
with SkAlphaType set to newAlphaType.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Created SkImageInfo contains newAlphaType even if it is incompatible with
|
|
|
|
SkColorType, in which case SkAlphaType in SkImageInfo is ignored.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param newAlphaType one of:
|
|
|
|
kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType,
|
|
|
|
kUnpremul_SkAlphaType
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(fWidth, fHeight, fColorType, newAlphaType, fColorSpace);
|
2014-09-03 18:54:58 +00:00
|
|
|
}
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo with same SkAlphaType, SkColorSpace, width, and height,
|
|
|
|
with SkColorType set to newColorType.
|
|
|
|
|
|
|
|
@param newColorType one of:
|
|
|
|
kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType,
|
|
|
|
kGray_8_SkColorType, kRGBA_F16_SkColorType
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
SkImageInfo makeColorType(SkColorType newColorType) const {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(fWidth, fHeight, newColorType, fAlphaType, fColorSpace);
|
2014-09-03 18:54:58 +00:00
|
|
|
}
|
2014-11-10 16:57:21 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates SkImageInfo with same SkAlphaType, SkColorType, width, and height,
|
|
|
|
with SkColorSpace set to cs.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param cs range of colors; may be nullptr
|
|
|
|
@return created SkImageInfo
|
|
|
|
*/
|
|
|
|
SkImageInfo makeColorSpace(sk_sp<SkColorSpace> cs) const {
|
2016-06-17 16:26:41 +00:00
|
|
|
return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
|
2016-06-09 18:03:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns number of bytes per pixel required by SkColorType.
|
|
|
|
Returns zero if colorType( is kUnknown_SkColorType.
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return bytes in pixel
|
|
|
|
*/
|
|
|
|
int bytesPerPixel() const;
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns bit shift converting row bytes to row pixels.
|
|
|
|
Returns zero for kUnknown_SkColorType.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return one of: 0, 1, 2, 3; left shift to convert pixels to bytes
|
|
|
|
*/
|
|
|
|
int shiftPerPixel() const;
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns minimum bytes per row, computed from pixel width() and SkColorType, which
|
2018-05-30 13:20:29 +00:00
|
|
|
specifies bytesPerPixel(). SkBitmap maximum value for row bytes must fit
|
|
|
|
in 31 bits.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return width() times bytesPerPixel() as unsigned 64-bit integer
|
|
|
|
*/
|
|
|
|
uint64_t minRowBytes64() const {
|
2014-02-11 18:21:45 +00:00
|
|
|
return sk_64_mul(fWidth, this->bytesPerPixel());
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns minimum bytes per row, computed from pixel width() and SkColorType, which
|
2018-05-30 13:20:29 +00:00
|
|
|
specifies bytesPerPixel(). SkBitmap maximum value for row bytes must fit
|
|
|
|
in 31 bits.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return width() times bytesPerPixel() as signed 32-bit integer
|
|
|
|
*/
|
|
|
|
size_t minRowBytes() const {
|
2016-10-17 18:32:46 +00:00
|
|
|
uint64_t minRowBytes = this->minRowBytes64();
|
2017-09-20 15:56:00 +00:00
|
|
|
if (!SkTFitsIn<int32_t>(minRowBytes)) {
|
2016-10-17 18:32:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-09-20 15:56:00 +00:00
|
|
|
return SkTo<int32_t>(minRowBytes);
|
2013-12-09 22:01:03 +00:00
|
|
|
}
|
2014-02-11 03:02:13 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns byte offset of pixel from pixel base address.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Asserts in debug build if x or y is outside of bounds. Does not assert if
|
|
|
|
rowBytes is smaller than minRowBytes(), even though result may be incorrect.
|
2015-05-22 15:06:21 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param x column index, zero or greater, and less than width()
|
|
|
|
@param y row index, zero or greater, and less than height()
|
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@return offset within pixel array
|
|
|
|
*/
|
|
|
|
size_t computeOffset(int x, int y, size_t rowBytes) const;
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Compares SkImageInfo with other, and returns true if width, height, SkColorType,
|
|
|
|
SkAlphaType, and SkColorSpace are equivalent.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param other SkImageInfo to compare
|
|
|
|
@return true if SkImageInfo equals other
|
|
|
|
*/
|
|
|
|
bool operator==(const SkImageInfo& other) const {
|
2016-05-27 14:39:02 +00:00
|
|
|
return fWidth == other.fWidth && fHeight == other.fHeight &&
|
|
|
|
fColorType == other.fColorType && fAlphaType == other.fAlphaType &&
|
2016-08-01 16:43:08 +00:00
|
|
|
SkColorSpace::Equals(fColorSpace.get(), other.fColorSpace.get());
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Compares SkImageInfo with other, and returns true if width, height, SkColorType,
|
2018-05-30 13:20:29 +00:00
|
|
|
SkAlphaType, and SkColorSpace are not equivalent.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param other SkImageInfo to compare
|
|
|
|
@return true if SkImageInfo is not equal to other
|
|
|
|
*/
|
|
|
|
bool operator!=(const SkImageInfo& other) const {
|
2016-08-01 16:43:08 +00:00
|
|
|
return !(*this == other);
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
2013-12-09 22:01:03 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns storage required by pixel array, given SkImageInfo dimensions, SkColorType,
|
|
|
|
and rowBytes. rowBytes is assumed to be at least as large as minRowBytes().
|
2017-09-29 17:41:58 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Returns zero if height is zero.
|
|
|
|
Returns SK_MaxSizeT if answer exceeds the range of size_t.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@return memory required by pixel buffer
|
|
|
|
*/
|
|
|
|
size_t computeByteSize(size_t rowBytes) const;
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns storage required by pixel array, given SkImageInfo dimensions, and
|
|
|
|
SkColorType. Uses minRowBytes() to compute bytes for pixel row.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
Returns zero if height is zero.
|
|
|
|
Returns SK_MaxSizeT if answer exceeds the range of size_t.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@return least memory required by pixel buffer
|
|
|
|
*/
|
|
|
|
size_t computeMinByteSize() const {
|
2017-09-29 17:41:58 +00:00
|
|
|
return this->computeByteSize(this->minRowBytes());
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns true if byteSize equals SK_MaxSizeT. computeByteSize() and
|
|
|
|
computeMinByteSize() return SK_MaxSizeT if size_t can not hold buffer size.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param byteSize result of computeByteSize() or computeMinByteSize()
|
|
|
|
@return true if computeByteSize() or computeMinByteSize() result exceeds size_t
|
|
|
|
*/
|
|
|
|
static bool ByteSizeOverflowed(size_t byteSize) {
|
2017-10-09 15:37:44 +00:00
|
|
|
return SK_MaxSizeT == byteSize;
|
2017-10-09 14:42:51 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Returns true if rowBytes is smaller than width times pixel size.
|
2018-04-03 15:49:10 +00:00
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
@param rowBytes size of pixel row or larger
|
|
|
|
@return true if rowBytes is large enough to contain pixel row
|
|
|
|
*/
|
|
|
|
bool validRowBytes(size_t rowBytes) const {
|
2017-10-03 18:47:21 +00:00
|
|
|
uint64_t minRB = sk_64_mul(fWidth, this->bytesPerPixel());
|
|
|
|
return rowBytes >= minRB;
|
2014-02-11 18:21:45 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Creates an empty SkImageInfo with kUnknown_SkColorType, kUnknown_SkAlphaType,
|
|
|
|
a width and height of zero, and no SkColorSpace.
|
|
|
|
*/
|
|
|
|
void reset() {
|
2016-06-17 16:26:41 +00:00
|
|
|
fColorSpace = nullptr;
|
2016-05-27 14:39:02 +00:00
|
|
|
fWidth = 0;
|
|
|
|
fHeight = 0;
|
|
|
|
fColorType = kUnknown_SkColorType;
|
|
|
|
fAlphaType = kUnknown_SkAlphaType;
|
|
|
|
}
|
|
|
|
|
2018-04-03 19:24:12 +00:00
|
|
|
/** Asserts if internal values are illegal or inconsistent. Only available if
|
|
|
|
SK_DEBUG is defined at compile time.
|
|
|
|
*/
|
|
|
|
SkDEBUGCODE(void validate() const;)
|
2014-09-03 18:54:58 +00:00
|
|
|
|
|
|
|
private:
|
2016-05-27 14:39:02 +00:00
|
|
|
sk_sp<SkColorSpace> fColorSpace;
|
2014-11-10 16:57:21 +00:00
|
|
|
int fWidth;
|
|
|
|
int fHeight;
|
|
|
|
SkColorType fColorType;
|
|
|
|
SkAlphaType fAlphaType;
|
2014-09-03 18:54:58 +00:00
|
|
|
|
2016-06-17 16:26:41 +00:00
|
|
|
SkImageInfo(int width, int height, SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
|
2016-05-27 14:39:02 +00:00
|
|
|
: fColorSpace(std::move(cs))
|
|
|
|
, fWidth(width)
|
2014-09-03 18:54:58 +00:00
|
|
|
, fHeight(height)
|
|
|
|
, fColorType(ct)
|
|
|
|
, fAlphaType(at)
|
|
|
|
{}
|
2013-11-13 19:09:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|