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 <reed@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org> Reviewed-by: Cary Clark <caryclark@google.com>
This commit is contained in:
parent
47cf048abe
commit
7fcfb62199
@ -26,6 +26,7 @@
|
||||
#include "SkImageGenerator.h"
|
||||
#include "SkImageGeneratorCG.h"
|
||||
#include "SkImageGeneratorWIC.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkLiteDL.h"
|
||||
#include "SkLiteRecorder.h"
|
||||
#include "SkMallocPixelRef.h"
|
||||
@ -455,7 +456,7 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
|
||||
}
|
||||
decodeInfo = decodeInfo.makeWH(size.width(), size.height());
|
||||
|
||||
const int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType());
|
||||
const int bpp = decodeInfo.bytesPerPixel();
|
||||
const size_t rowBytes = size.width() * bpp;
|
||||
const size_t safeSize = decodeInfo.computeByteSize(rowBytes);
|
||||
SkAutoMalloc pixels(safeSize);
|
||||
@ -851,7 +852,7 @@ Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
|
||||
}
|
||||
decodeInfo = decodeInfo.makeWH(size.width(), size.height());
|
||||
|
||||
int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType());
|
||||
int bpp = decodeInfo.bytesPerPixel();
|
||||
size_t rowBytes = size.width() * bpp;
|
||||
SkAutoMalloc pixels(size.height() * rowBytes);
|
||||
|
||||
@ -977,7 +978,7 @@ Error ImageGenSrc::draw(SkCanvas* canvas) const {
|
||||
options.fBehavior = canvas->imageInfo().colorSpace() ?
|
||||
SkTransferFunctionBehavior::kRespect : SkTransferFunctionBehavior::kIgnore;
|
||||
|
||||
int bpp = SkColorTypeBytesPerPixel(decodeInfo.colorType());
|
||||
int bpp = decodeInfo.bytesPerPixel();
|
||||
size_t rowBytes = decodeInfo.width() * bpp;
|
||||
SkAutoMalloc pixels(decodeInfo.height() * rowBytes);
|
||||
if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkJpegEncoder.h"
|
||||
|
||||
#include "Resources.h"
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "SkColorSpaceXformPriv.h"
|
||||
#include "SkHalf.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkPictureRecorder.h"
|
||||
|
||||
static void clamp_if_necessary(const SkImageInfo& info, void* pixels) {
|
||||
|
@ -52,10 +52,6 @@ static inline bool SkAlphaTypeIsOpaque(SkAlphaType at) {
|
||||
return kOpaque_SkAlphaType == at;
|
||||
}
|
||||
|
||||
static inline bool SkAlphaTypeIsValid(unsigned value) {
|
||||
return value <= kLastEnum_SkAlphaType;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/** Temporary macro that allows us to add new color types without breaking Chrome compile. */
|
||||
@ -92,64 +88,32 @@ enum SkColorType {
|
||||
#endif
|
||||
};
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static int SkColorTypeShiftPerPixel(SkColorType ct) {
|
||||
switch (ct) {
|
||||
case kUnknown_SkColorType: return 0;
|
||||
case kAlpha_8_SkColorType: return 0;
|
||||
case kRGB_565_SkColorType: return 1;
|
||||
case kARGB_4444_SkColorType: return 1;
|
||||
case kRGBA_8888_SkColorType: return 2;
|
||||
case kRGB_888x_SkColorType: return 2;
|
||||
case kBGRA_8888_SkColorType: return 2;
|
||||
case kRGBA_1010102_SkColorType: return 2;
|
||||
case kRGB_101010x_SkColorType: return 2;
|
||||
case kGray_8_SkColorType: return 0;
|
||||
case kRGBA_F16_SkColorType: return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
|
||||
return width * SkColorTypeBytesPerPixel(ct);
|
||||
}
|
||||
|
||||
static inline bool SkColorTypeIsValid(unsigned value) {
|
||||
return value <= kLastEnum_SkColorType;
|
||||
}
|
||||
|
||||
static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) {
|
||||
if (kUnknown_SkColorType == ct) {
|
||||
return 0;
|
||||
}
|
||||
return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Returns the number of bytes-per-pixel for the specified colortype, or 0 if invalid.
|
||||
*/
|
||||
SK_API int SkColorTypeBytesPerPixel(SkColorType ct);
|
||||
|
||||
/**
|
||||
* Return true if alphaType is supported by colorType. If there is a canonical
|
||||
* alphaType for this colorType, return it in canonical.
|
||||
* Tries to validate the colortype, alphatype pair. In all cases if it returns true, it
|
||||
* will set canonical to the "canonical" answer if it is non-null, and ignore the parameter if
|
||||
* it is set to null.
|
||||
*
|
||||
* If the specified colortype has only 1 valid alphatype (e.g. 565 must always be opaque) then
|
||||
* canonical will be set to that valid alphatype.
|
||||
*
|
||||
* If the specified colortype treats more than one alphatype the same (e.g. Alpha_8 colortype
|
||||
* treates Premul and Unpremul the same) and the specified alphatype is one of those,
|
||||
* then canonical will be set to the "canonical" answer (Premul in the case of Alpha_8 colortype).
|
||||
*
|
||||
* If the colortype supports multiple alphatypes, and the specified alphatype is one of them,
|
||||
* then canonical will be set to the specified alphatype. If the specified alphatype is not
|
||||
* one of them (e.g. kUnknown_SkAlphaType is not valid for any colortype except
|
||||
* kUnknown_SkColorType), then the function returns false, and canonical's value is undefined.
|
||||
*/
|
||||
bool SkColorTypeValidateAlphaType(SkColorType colorType, SkAlphaType alphaType,
|
||||
SkAlphaType* canonical = nullptr);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
@ -270,9 +234,8 @@ public:
|
||||
return Make(fWidth, fHeight, fColorType, fAlphaType, std::move(cs));
|
||||
}
|
||||
|
||||
int bytesPerPixel() const { return SkColorTypeBytesPerPixel(fColorType); }
|
||||
|
||||
int shiftPerPixel() const { return SkColorTypeShiftPerPixel(fColorType); }
|
||||
int bytesPerPixel() const;
|
||||
int shiftPerPixel() const;
|
||||
|
||||
uint64_t minRowBytes64() const {
|
||||
return sk_64_mul(fWidth, this->bytesPerPixel());
|
||||
@ -286,11 +249,7 @@ public:
|
||||
return sk_64_asS32(minRowBytes);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
size_t computeOffset(int x, int y, size_t rowBytes) const;
|
||||
|
||||
bool operator==(const SkImageInfo& other) const {
|
||||
return fWidth == other.fWidth && fHeight == other.fHeight &&
|
||||
|
@ -279,7 +279,7 @@ public:
|
||||
@return readable unsigned 8-bit pointer to pixels
|
||||
*/
|
||||
const uint8_t* addr8() const {
|
||||
SkASSERT(1 == SkColorTypeBytesPerPixel(fInfo.colorType()));
|
||||
SkASSERT(1 == fInfo.bytesPerPixel());
|
||||
return reinterpret_cast<const uint8_t*>(fPixels);
|
||||
}
|
||||
|
||||
@ -292,7 +292,7 @@ public:
|
||||
@return readable unsigned 16-bit pointer to pixels
|
||||
*/
|
||||
const uint16_t* addr16() const {
|
||||
SkASSERT(2 == SkColorTypeBytesPerPixel(fInfo.colorType()));
|
||||
SkASSERT(2 == fInfo.bytesPerPixel());
|
||||
return reinterpret_cast<const uint16_t*>(fPixels);
|
||||
}
|
||||
|
||||
@ -305,7 +305,7 @@ public:
|
||||
@return readable unsigned 32-bit pointer to pixels
|
||||
*/
|
||||
const uint32_t* addr32() const {
|
||||
SkASSERT(4 == SkColorTypeBytesPerPixel(fInfo.colorType()));
|
||||
SkASSERT(4 == fInfo.bytesPerPixel());
|
||||
return reinterpret_cast<const uint32_t*>(fPixels);
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ public:
|
||||
@return readable unsigned 64-bit pointer to pixels
|
||||
*/
|
||||
const uint64_t* addr64() const {
|
||||
SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType()));
|
||||
SkASSERT(8 == fInfo.bytesPerPixel());
|
||||
return reinterpret_cast<const uint64_t*>(fPixels);
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ public:
|
||||
@return readable unsigned 16-bit pointer to first component of pixels
|
||||
*/
|
||||
const uint16_t* addrF16() const {
|
||||
SkASSERT(8 == SkColorTypeBytesPerPixel(fInfo.colorType()));
|
||||
SkASSERT(8 == fInfo.bytesPerPixel());
|
||||
SkASSERT(kRGBA_F16_SkColorType == fInfo.colorType());
|
||||
return reinterpret_cast<const uint16_t*>(fPixels);
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ static void zero_rect(const SkImageInfo& dstInfo, void* pixels, size_t rowBytes,
|
||||
return;
|
||||
}
|
||||
const auto info = dstInfo.makeWH(frameRect.width(), frameRect.height());
|
||||
const size_t bpp = SkColorTypeBytesPerPixel(dstInfo.colorType());
|
||||
const size_t bpp = dstInfo.bytesPerPixel();
|
||||
const size_t offset = frameRect.x() * bpp + frameRect.y() * rowBytes;
|
||||
auto* eraseDst = SkTAddOffset<void>(pixels, offset);
|
||||
SkSampler::Fill(info, eraseDst, rowBytes, 0, SkCodec::kNo_ZeroInitialized);
|
||||
|
@ -541,7 +541,7 @@ void SkGifCodec::haveDecodedRow(int frameIndex, const unsigned char* rowBegin,
|
||||
|
||||
// Tell the frame to copy the row data if need be.
|
||||
if (repeatCount > 1) {
|
||||
const size_t bytesPerPixel = SkColorTypeBytesPerPixel(this->dstInfo().colorType());
|
||||
const size_t bytesPerPixel = this->dstInfo().bytesPerPixel();
|
||||
const size_t bytesToCopy = fSwizzler->swizzleWidth() * bytesPerPixel;
|
||||
void* copiedLine = SkTAddOffset<void>(dstLine, fSwizzler->swizzleOffsetBytes());
|
||||
void* dst = copiedLine;
|
||||
|
@ -786,7 +786,7 @@ SkSwizzler* SkSwizzler::CreateSwizzler(const SkEncodedInfo& encodedInfo,
|
||||
RowProc fastProc = nullptr;
|
||||
RowProc proc = nullptr;
|
||||
int srcBPP;
|
||||
const int dstBPP = SkColorTypeBytesPerPixel(dstInfo.colorType());
|
||||
const int dstBPP = dstInfo.bytesPerPixel();
|
||||
if (skipFormatConversion) {
|
||||
switch (encodedInfo.color()) {
|
||||
case SkEncodedInfo::kGray_Color:
|
||||
|
@ -617,7 +617,7 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
|
||||
const bool needsSrgbToLinear = dstInfo.gammaCloseToSRGB() &&
|
||||
options.fPremulBehavior == SkTransferFunctionBehavior::kRespect;
|
||||
|
||||
const size_t dstBpp = SkColorTypeBytesPerPixel(dstInfo.colorType());
|
||||
const size_t dstBpp = dstInfo.bytesPerPixel();
|
||||
dst = SkTAddOffset<void>(dst, dstBpp * dstX + rowBytes * dstY);
|
||||
const size_t srcRowBytes = config.output.u.RGBA.stride;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -10,6 +10,42 @@
|
||||
|
||||
#include "SkImageInfo.h"
|
||||
|
||||
static inline bool SkAlphaTypeIsValid(unsigned value) {
|
||||
return value <= kLastEnum_SkAlphaType;
|
||||
}
|
||||
|
||||
static int SkColorTypeShiftPerPixel(SkColorType ct) {
|
||||
switch (ct) {
|
||||
case kUnknown_SkColorType: return 0;
|
||||
case kAlpha_8_SkColorType: return 0;
|
||||
case kRGB_565_SkColorType: return 1;
|
||||
case kARGB_4444_SkColorType: return 1;
|
||||
case kRGBA_8888_SkColorType: return 2;
|
||||
case kRGB_888x_SkColorType: return 2;
|
||||
case kBGRA_8888_SkColorType: return 2;
|
||||
case kRGBA_1010102_SkColorType: return 2;
|
||||
case kRGB_101010x_SkColorType: return 2;
|
||||
case kGray_8_SkColorType: return 0;
|
||||
case kRGBA_F16_SkColorType: return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {
|
||||
return width * SkColorTypeBytesPerPixel(ct);
|
||||
}
|
||||
|
||||
static inline bool SkColorTypeIsValid(unsigned value) {
|
||||
return value <= kLastEnum_SkColorType;
|
||||
}
|
||||
|
||||
static inline size_t SkColorTypeComputeOffset(SkColorType ct, int x, int y, size_t rowBytes) {
|
||||
if (kUnknown_SkColorType == ct) {
|
||||
return 0;
|
||||
}
|
||||
return y * rowBytes + (x << SkColorTypeShiftPerPixel(ct));
|
||||
}
|
||||
|
||||
/**
|
||||
* This contains shared checks on SkImageInfo. Depending on the desired color space behavior,
|
||||
* the caller should choose one of the two versions below.
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "SkBitmap.h"
|
||||
#include "SkColorData.h"
|
||||
#include "SkHalf.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkMathPriv.h"
|
||||
#include "SkNx.h"
|
||||
#include "SkPM4fPriv.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "SkConvertPixels.h"
|
||||
#include "SkDeferredDisplayList.h"
|
||||
#include "SkGr.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkJSONWriter.h"
|
||||
#include "SkMakeUnique.h"
|
||||
#include "SkTaskGroup.h"
|
||||
|
@ -80,7 +80,7 @@ bool SkSurfaceValidateRasterInfo(const SkImageInfo& info, size_t rowBytes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int shift = SkColorTypeShiftPerPixel(info.colorType());
|
||||
int shift = info.shiftPerPixel();
|
||||
|
||||
uint64_t minRB = (uint64_t)info.width() << shift;
|
||||
if (minRB > rowBytes) {
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "SkCanvas.h"
|
||||
#include "SkGraphics.h"
|
||||
#include "SkImageGenerator.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "Test.h"
|
||||
|
||||
static bool gMyFactoryWasCalled;
|
||||
|
@ -5,6 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkSwizzle.h"
|
||||
#include "SkSwizzler.h"
|
||||
#include "Test.h"
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "SkFontMgrPriv.h"
|
||||
#include "SkFontStyle.h"
|
||||
#include "SkGraphics.h"
|
||||
#include "SkImageInfoPriv.h"
|
||||
#include "SkSurface.h"
|
||||
#include "Test.h"
|
||||
#include "gl/GLTestContext.h"
|
||||
|
Loading…
Reference in New Issue
Block a user