From 7fcfb621998648ba018e3b89e2cab3135bd46a1f Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Fri, 9 Feb 2018 13:26:46 -0500 Subject: move a bunch of helpers from SkImageInfo.h into priv Bug: skia: Change-Id: I8c91cfdb89e4f22448d1201d391556fe43d86dca Reviewed-on: https://skia-review.googlesource.com/105289 Commit-Queue: Mike Reed Reviewed-by: Mike Klein Reviewed-by: Cary Clark --- src/core/SkImageInfo.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/core/SkImageInfo.cpp') diff --git a/src/core/SkImageInfo.cpp b/src/core/SkImageInfo.cpp index a3d352f05f..b684cdfcf4 100644 --- a/src/core/SkImageInfo.cpp +++ b/src/core/SkImageInfo.cpp @@ -5,11 +5,28 @@ * found in the LICENSE file. */ -#include "SkImageInfo.h" +#include "SkImageInfoPriv.h" #include "SkSafeMath.h" #include "SkReadBuffer.h" #include "SkWriteBuffer.h" +int SkColorTypeBytesPerPixel(SkColorType ct) { + switch (ct) { + case kUnknown_SkColorType: return 0; + case kAlpha_8_SkColorType: return 1; + case kRGB_565_SkColorType: return 2; + case kARGB_4444_SkColorType: return 2; + case kRGBA_8888_SkColorType: return 4; + case kBGRA_8888_SkColorType: return 4; + case kRGB_888x_SkColorType: return 4; + case kRGBA_1010102_SkColorType: return 4; + case kRGB_101010x_SkColorType: return 4; + case kGray_8_SkColorType: return 1; + case kRGBA_F16_SkColorType: return 8; + } + return 0; +} + // These values must be constant over revisions, though they can be renamed to reflect if/when // they are deprecated. enum Stored_SkColorType { @@ -64,6 +81,16 @@ static SkColorType stored_to_live(unsigned stored) { /////////////////////////////////////////////////////////////////////////////////////////////////// +int SkImageInfo::bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); } + +int SkImageInfo::shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); } + +size_t SkImageInfo::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); +} + size_t SkImageInfo::computeByteSize(size_t rowBytes) const { if (0 == fHeight) { return 0; -- cgit v1.2.3