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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
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
|
|
|
|
2015-08-13 20:32:39 +00:00
|
|
|
/**
|
2015-10-12 17:39:46 +00:00
|
|
|
* Describes how to interpret the alpha component of a pixel.
|
2013-11-13 19:09:13 +00:00
|
|
|
*/
|
|
|
|
enum SkAlphaType {
|
2015-02-27 18:23:00 +00:00
|
|
|
kUnknown_SkAlphaType,
|
2013-11-14 07:02:31 +00:00
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
/**
|
|
|
|
* All pixels are stored as opaque. This differs slightly from kIgnore in
|
|
|
|
* that kOpaque has correct "opaque" values stored in the pixels, while
|
|
|
|
* kIgnore may not, but in both cases the caller should treat the pixels
|
|
|
|
* as opaque.
|
|
|
|
*/
|
|
|
|
kOpaque_SkAlphaType,
|
2013-11-14 07:02:31 +00:00
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
/**
|
|
|
|
* All pixels have their alpha premultiplied in their color components.
|
|
|
|
* This is the natural format for the rendering target pixels.
|
|
|
|
*/
|
|
|
|
kPremul_SkAlphaType,
|
2013-11-14 07:02:31 +00:00
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
/**
|
|
|
|
* All pixels have their color components stored without any regard to the
|
|
|
|
* alpha. e.g. this is the default configuration for PNG images.
|
|
|
|
*
|
|
|
|
* This alpha-type is ONLY supported for input images. Rendering cannot
|
|
|
|
* generate this on output.
|
|
|
|
*/
|
|
|
|
kUnpremul_SkAlphaType,
|
2013-11-14 07:02:31 +00:00
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
kLastEnum_SkAlphaType = kUnpremul_SkAlphaType
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
static inline bool SkAlphaTypeIsValid(unsigned value) {
|
|
|
|
return value <= kLastEnum_SkAlphaType;
|
|
|
|
}
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describes how to interpret the components of a pixel.
|
2014-06-30 19:44:03 +00:00
|
|
|
*
|
|
|
|
* kN32_SkColorType is an alias for whichever 32bit ARGB format is the "native"
|
|
|
|
* form for skia's blitters. Use this if you don't have a swizzle preference
|
|
|
|
* for 32bit pixels.
|
2013-11-13 19:09:13 +00:00
|
|
|
*/
|
|
|
|
enum SkColorType {
|
2014-02-11 18:21:45 +00:00
|
|
|
kUnknown_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
kRGB_565_SkColorType,
|
2013-12-09 22:01:03 +00:00
|
|
|
kARGB_4444_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
kRGBA_8888_SkColorType,
|
|
|
|
kBGRA_8888_SkColorType,
|
2013-12-09 22:01:03 +00:00
|
|
|
kIndex_8_SkColorType,
|
2015-03-18 00:44:06 +00:00
|
|
|
kGray_8_SkColorType,
|
2016-02-05 19:18:39 +00:00
|
|
|
kRGBA_F16_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2016-02-05 19:18:39 +00:00
|
|
|
kLastEnum_SkColorType = kRGBA_F16_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
|
|
|
|
#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
|
2014-04-11 17:15:40 +00:00
|
|
|
kN32_SkColorType = kBGRA_8888_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
|
2014-04-11 17:15:40 +00:00
|
|
|
kN32_SkColorType = kRGBA_8888_SkColorType,
|
2013-11-13 19:09:13 +00:00
|
|
|
#else
|
2014-12-21 22:29:04 +00:00
|
|
|
#error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
|
2014-04-11 17:15:40 +00:00
|
|
|
#endif
|
2013-11-13 19:09:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int SkColorTypeBytesPerPixel(SkColorType ct) {
|
Revert of move static arrays into impl, to avoid multiple copies (patchset #3 id:40001 of https://codereview.chromium.org/1889793007/ )
Reason for revert:
FAILED: if [ ! -e lib/libgfx.so -o ! -e lib/libgfx.so.TOC ]; then /b/build/slave/linux_chromeos/build/src/build/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -pthread -Wl,-z,noexecstack -fPIC -fuse-ld=gold -B/b/build/slave/linux_chromeos/build/src/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=all -o lib/libgfx.so -Wl,-soname=libgfx.so @lib/libgfx.so.rsp && { readelf -d lib/libgfx.so | grep SONAME ; nm -gD -f p lib/libgfx.so | cut -f1-2 -d' '; } > lib/libgfx.so.TOC; else /b/build/slave/linux_chromeos/build/src/build/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -pthread -Wl,-z,noexecstack -fPIC -fuse-ld=gold -B/b/build/slave/linux_chromeos/build/src/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=all -o lib/libgfx.so -Wl,-soname=libgfx.so @lib/libgfx.so.rsp && { readelf -d lib/libgfx.so | grep SONAME ; nm -gD -f p lib/libgfx.so | cut -f1-2 -d' '; } > lib/libgfx.so.tmp && if ! cmp -s lib/libgfx.so.tmp lib/libgfx.so.TOC; then mv lib/libgfx.so.tmp lib/libgfx.so.TOC ; fi; fi
obj/ui/gfx/gfx.blit.o:../../ui/gfx/blit.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/gfx.canvas.o:../../ui/gfx/canvas.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/gfx.canvas_skia.o:../../ui/gfx/canvas_skia.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/codec/gfx.jpeg_codec.o:../../ui/gfx/codec/jpeg_codec.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Original issue's description:
> move static arrays into impl, to avoid multiple copies
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1889793007
>
> Committed: https://skia.googlesource.com/skia/+/6d7cd1f421dbde43dd2db655ca477c05312ec5fd
TBR=fmalita@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1899563002
2016-04-16 19:24:09 +00:00
|
|
|
static const uint8_t gSize[] = {
|
|
|
|
0, // Unknown
|
|
|
|
1, // Alpha_8
|
|
|
|
2, // RGB_565
|
|
|
|
2, // ARGB_4444
|
|
|
|
4, // RGBA_8888
|
|
|
|
4, // BGRA_8888
|
|
|
|
1, // kIndex_8
|
|
|
|
1, // kGray_8
|
|
|
|
8, // kRGBA_F16
|
|
|
|
};
|
|
|
|
static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1),
|
|
|
|
"size_mismatch_with_SkColorType_enum");
|
|
|
|
|
|
|
|
SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize));
|
|
|
|
return gSize[ct];
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 13:59:38 +00:00
|
|
|
static int SkColorTypeShiftPerPixel(SkColorType ct) {
|
Revert of move static arrays into impl, to avoid multiple copies (patchset #3 id:40001 of https://codereview.chromium.org/1889793007/ )
Reason for revert:
FAILED: if [ ! -e lib/libgfx.so -o ! -e lib/libgfx.so.TOC ]; then /b/build/slave/linux_chromeos/build/src/build/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -pthread -Wl,-z,noexecstack -fPIC -fuse-ld=gold -B/b/build/slave/linux_chromeos/build/src/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=all -o lib/libgfx.so -Wl,-soname=libgfx.so @lib/libgfx.so.rsp && { readelf -d lib/libgfx.so | grep SONAME ; nm -gD -f p lib/libgfx.so | cut -f1-2 -d' '; } > lib/libgfx.so.TOC; else /b/build/slave/linux_chromeos/build/src/build/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -pthread -Wl,-z,noexecstack -fPIC -fuse-ld=gold -B/b/build/slave/linux_chromeos/build/src/third_party/binutils/Linux_x64/Release/bin -Wl,--disable-new-dtags -m64 -Wl,--icf=all -o lib/libgfx.so -Wl,-soname=libgfx.so @lib/libgfx.so.rsp && { readelf -d lib/libgfx.so | grep SONAME ; nm -gD -f p lib/libgfx.so | cut -f1-2 -d' '; } > lib/libgfx.so.tmp && if ! cmp -s lib/libgfx.so.tmp lib/libgfx.so.TOC; then mv lib/libgfx.so.tmp lib/libgfx.so.TOC ; fi; fi
obj/ui/gfx/gfx.blit.o:../../ui/gfx/blit.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/gfx.canvas.o:../../ui/gfx/canvas.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/gfx.canvas_skia.o:../../ui/gfx/canvas_skia.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
obj/ui/gfx/codec/gfx.jpeg_codec.o:../../ui/gfx/codec/jpeg_codec.cc:function SkColorTypeBytesPerPixel(SkColorType): error: undefined reference to 'gPrivate_SkColorTypeBytesPerPixel'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Original issue's description:
> move static arrays into impl, to avoid multiple copies
>
> BUG=skia:
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1889793007
>
> Committed: https://skia.googlesource.com/skia/+/6d7cd1f421dbde43dd2db655ca477c05312ec5fd
TBR=fmalita@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1899563002
2016-04-16 19:24:09 +00:00
|
|
|
static const uint8_t gShift[] = {
|
|
|
|
0, // Unknown
|
|
|
|
0, // Alpha_8
|
|
|
|
1, // RGB_565
|
|
|
|
1, // ARGB_4444
|
|
|
|
2, // RGBA_8888
|
|
|
|
2, // BGRA_8888
|
|
|
|
0, // kIndex_8
|
|
|
|
0, // kGray_8
|
|
|
|
3, // kRGBA_F16
|
|
|
|
};
|
|
|
|
static_assert(SK_ARRAY_COUNT(gShift) == (size_t)(kLastEnum_SkColorType + 1),
|
|
|
|
"size_mismatch_with_SkColorType_enum");
|
|
|
|
|
|
|
|
SkASSERT((size_t)ct < SK_ARRAY_COUNT(gShift));
|
|
|
|
return gShift[ct];
|
2016-04-15 13:59:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
|
|
|
|
return width * SkColorTypeBytesPerPixel(ct);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool SkColorTypeIsValid(unsigned value) {
|
|
|
|
return value <= kLastEnum_SkColorType;
|
|
|
|
}
|
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) {
|
2016-04-15 13:59:38 +00:00
|
|
|
if (kUnknown_SkColorType == ct) {
|
|
|
|
return 0;
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
2016-04-15 13:59:38 +00:00
|
|
|
return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
|
2015-05-22 15:06:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-07-01 14:08:19 +00:00
|
|
|
/**
|
|
|
|
* Return true if alphaType is supported by colorType. If there is a canonical
|
|
|
|
* alphaType for this colorType, return it in canonical.
|
|
|
|
*/
|
|
|
|
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
|
|
|
SkAlphaType* canonical = NULL);
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-13 00:45:58 +00:00
|
|
|
/**
|
|
|
|
* Describes the color space a YUV pixel.
|
|
|
|
*/
|
|
|
|
enum SkYUVColorSpace {
|
|
|
|
/** Standard JPEG color space. */
|
|
|
|
kJPEG_SkYUVColorSpace,
|
|
|
|
/** SDTV standard Rec. 601 color space. Uses "studio swing" [16, 235] color
|
|
|
|
range. See http://en.wikipedia.org/wiki/Rec._601 for details. */
|
|
|
|
kRec601_SkYUVColorSpace,
|
2015-07-20 22:00:03 +00:00
|
|
|
/** HDTV standard Rec. 709 color space. Uses "studio swing" [16, 235] color
|
|
|
|
range. See http://en.wikipedia.org/wiki/Rec._709 for details. */
|
|
|
|
kRec709_SkYUVColorSpace,
|
2014-09-13 00:45:58 +00:00
|
|
|
|
2015-07-20 22:00:03 +00:00
|
|
|
kLastEnum_SkYUVColorSpace = kRec709_SkYUVColorSpace
|
2014-09-13 00:45:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-17 16:26:41 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
2014-11-10 16:57:21 +00:00
|
|
|
enum SkColorProfileType {
|
|
|
|
kLinear_SkColorProfileType,
|
|
|
|
kSRGB_SkColorProfileType,
|
|
|
|
|
|
|
|
kLastEnum_SkColorProfileType = kSRGB_SkColorProfileType
|
|
|
|
};
|
2016-06-17 16:26:41 +00:00
|
|
|
#endif
|
2014-11-10 16:57:21 +00:00
|
|
|
|
2016-06-06 20:10:58 +00:00
|
|
|
enum class SkSourceGammaTreatment {
|
|
|
|
kRespect,
|
|
|
|
kIgnore,
|
|
|
|
};
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
/**
|
|
|
|
* Describe an image's dimensions and pixel type.
|
2014-11-10 16:57:21 +00:00
|
|
|
* Used for both src images and render-targets (surfaces).
|
2013-11-13 19:09:13 +00:00
|
|
|
*/
|
2015-01-30 22:54:38 +00:00
|
|
|
struct SK_API SkImageInfo {
|
2014-09-03 18:54:58 +00:00
|
|
|
public:
|
|
|
|
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
|
|
|
|
2014-11-10 16:57:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets colortype to the native ARGB32 type.
|
|
|
|
*/
|
2014-11-10 16:57:21 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-17 16:26:41 +00:00
|
|
|
* Create an ImageInfo marked as SRGB with N32 swizzle.
|
2014-01-15 02:38:22 +00:00
|
|
|
*/
|
2016-06-17 16:26:41 +00:00
|
|
|
static SkImageInfo MakeS32(int width, int height, SkAlphaType at);
|
2014-01-15 07:01:43 +00:00
|
|
|
|
2014-01-15 02:38:22 +00:00
|
|
|
/**
|
|
|
|
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
|
|
|
|
*/
|
2016-06-21 17:28:14 +00:00
|
|
|
static SkImageInfo MakeN32Premul(int width, int height, sk_sp<SkColorSpace> cs = nullptr) {
|
|
|
|
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
|
|
|
|
2016-06-17 16:26:41 +00:00
|
|
|
static SkImageInfo MakeN32Premul(const SkISize& size) {
|
|
|
|
return MakeN32Premul(size.width(), size.height());
|
|
|
|
}
|
2016-06-02 19:40:22 +00:00
|
|
|
|
2014-01-15 02:38:22 +00:00
|
|
|
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
|
|
|
|
2014-02-20 20:55:37 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-06-14 11:24:56 +00:00
|
|
|
static SkImageInfo MakeUnknown() {
|
2016-06-17 16:26:41 +00:00
|
|
|
return MakeUnknown(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_SUPPORT_LEGACY_COLORPROFILETYPE
|
|
|
|
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at,
|
|
|
|
SkColorProfileType pt) {
|
|
|
|
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
|
|
|
|
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
|
|
|
|
return Make(width, height, ct, at, cs);
|
2014-06-14 11:24:56 +00:00
|
|
|
}
|
|
|
|
|
2016-06-17 16:26:41 +00:00
|
|
|
static SkImageInfo MakeN32(int width, int height, SkAlphaType at, SkColorProfileType pt) {
|
|
|
|
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
|
|
|
|
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
|
|
|
|
return SkImageInfo(width, height, kN32_SkColorType, at, cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeN32Premul(int width, int height, SkColorProfileType pt) {
|
|
|
|
sk_sp<SkColorSpace> cs = (kSRGB_SkColorProfileType == pt) ?
|
|
|
|
SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr;
|
|
|
|
return Make(width, height, kN32_SkColorType, kPremul_SkAlphaType, cs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets colortype to the native ARGB32 type, and the alphatype to premul.
|
|
|
|
*/
|
|
|
|
static SkImageInfo MakeN32Premul(const SkISize& size, SkColorProfileType pt) {
|
|
|
|
return MakeN32Premul(size.width(), size.height(), pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkColorProfileType profileType() const;
|
|
|
|
bool isLinear() const { return kLinear_SkColorProfileType == this->profileType(); }
|
|
|
|
bool isSRGB() const { return kSRGB_SkColorProfileType == this->profileType(); }
|
|
|
|
#endif
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
int width() const { return fWidth; }
|
|
|
|
int height() const { return fHeight; }
|
|
|
|
SkColorType colorType() const { return fColorType; }
|
|
|
|
SkAlphaType alphaType() const { return fAlphaType; }
|
2016-05-27 14:39:02 +00:00
|
|
|
SkColorSpace* colorSpace() const { return fColorSpace.get(); }
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
bool isOpaque() const {
|
|
|
|
return SkAlphaTypeIsOpaque(fAlphaType);
|
|
|
|
}
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
SkISize dimensions() const { return SkISize::Make(fWidth, fHeight); }
|
2014-11-10 16:57:21 +00:00
|
|
|
SkIRect bounds() const { return SkIRect::MakeWH(fWidth, fHeight); }
|
2014-02-11 18:21:45 +00:00
|
|
|
|
2016-06-17 16:26:41 +00:00
|
|
|
bool gammaCloseToSRGB() const {
|
|
|
|
return fColorSpace && fColorSpace->gammaCloseToSRGB();
|
|
|
|
}
|
|
|
|
|
2014-06-02 20:07:26 +00:00
|
|
|
/**
|
|
|
|
* Return a new ImageInfo with the same colortype and alphatype as this info,
|
|
|
|
* but with the specified width and height.
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-03 18:54:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2016-06-09 18:03:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-04-15 13:59:38 +00:00
|
|
|
int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
|
|
|
|
|
|
|
|
int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); }
|
2013-11-13 19:09:13 +00:00
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
uint64_t minRowBytes64() const {
|
|
|
|
return sk_64_mul(fWidth, this->bytesPerPixel());
|
|
|
|
}
|
|
|
|
|
2013-12-09 22:01:03 +00:00
|
|
|
size_t minRowBytes() const {
|
2014-02-11 18:21:45 +00:00
|
|
|
return (size_t)this->minRowBytes64();
|
2013-12-09 22:01:03 +00:00
|
|
|
}
|
2014-02-11 03:02:13 +00:00
|
|
|
|
2015-05-22 15:06:21 +00:00
|
|
|
size_t computeOffset(int x, int y, size_t rowBytes) const {
|
|
|
|
SkASSERT((unsigned)x < (unsigned)fWidth);
|
|
|
|
SkASSERT((unsigned)y < (unsigned)fHeight);
|
|
|
|
return SkColorTypeComputeOffset(fColorType, x, y, rowBytes);
|
|
|
|
}
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
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-06-17 16:26:41 +00:00
|
|
|
fColorSpace == other.fColorSpace;
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
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-06-17 16:26:41 +00:00
|
|
|
fColorSpace != other.fColorSpace;
|
2013-11-13 19:09:13 +00:00
|
|
|
}
|
2013-12-09 22:01:03 +00:00
|
|
|
|
2014-01-30 18:58:24 +00:00
|
|
|
void unflatten(SkReadBuffer&);
|
|
|
|
void flatten(SkWriteBuffer&) const;
|
2013-12-09 22:01:03 +00:00
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
int64_t getSafeSize64(size_t rowBytes) const {
|
2013-12-09 22:01:03 +00:00
|
|
|
if (0 == fHeight) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-11 18:21:45 +00:00
|
|
|
return sk_64_mul(fHeight - 1, rowBytes) + fWidth * this->bytesPerPixel();
|
2013-12-09 22:01:03 +00:00
|
|
|
}
|
2014-02-11 18:21:45 +00:00
|
|
|
|
|
|
|
size_t getSafeSize(size_t rowBytes) const {
|
2015-06-18 20:41:40 +00:00
|
|
|
int64_t size = this->getSafeSize64(rowBytes);
|
|
|
|
if (!sk_64_isS32(size)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sk_64_asS32(size);
|
2014-02-11 18:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool validRowBytes(size_t rowBytes) const {
|
|
|
|
uint64_t rb = sk_64_mul(fWidth, this->bytesPerPixel());
|
|
|
|
return rowBytes >= rb;
|
|
|
|
}
|
|
|
|
|
2016-05-27 14:39:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-11 18:21:45 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2016-04-06 14:38:23 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-06-16 20:03:24 +00:00
|
|
|
static inline bool SkColorAndColorSpaceAreGammaCorrect(SkColorType ct, SkColorSpace* cs) {
|
|
|
|
// Anything with a color-space attached is gamma-correct, as is F16.
|
|
|
|
// To get legacy behavior, you need to ask for non-F16, with a nullptr color space.
|
|
|
|
return (cs != nullptr) || kRGBA_F16_SkColorType == ct;
|
2016-04-06 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool SkImageInfoIsGammaCorrect(const SkImageInfo& info) {
|
2016-06-16 20:03:24 +00:00
|
|
|
return SkColorAndColorSpaceAreGammaCorrect(info.colorType(), info.colorSpace());
|
2016-04-06 14:38:23 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 19:09:13 +00:00
|
|
|
#endif
|