/* * Copyright 2014 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file.
*/ #include"src/core/SkConvertPixels.h"
staticbool rect_memcpy(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, const SkImageInfo& srcInfo, constvoid* srcPixels, size_t srcRB, const SkColorSpaceXformSteps& steps) { // We can copy the pixels when no color type, alpha type, or color space changes. if (dstInfo.colorType() != srcInfo.colorType()) { returnfalse;
} if (dstInfo.colorType() != kAlpha_8_SkColorType
&& steps.flags.mask() != 0b00000) { returnfalse;
}
switch (srcInfo.colorType()) { case kUnknown_SkColorType: case kAlpha_8_SkColorType: { // Unknown should never happen. // Alpha8 should have been handled by rect_memcpy().
SkASSERT(false); returnfalse;
}
case kA16_unorm_SkColorType: { auto src16 = (const uint16_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = src16[x] >> 8;
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src16 = SkTAddOffset<const uint16_t>(src16, srcRB);
} returntrue;
}
case kGray_8_SkColorType: case kRGB_565_SkColorType: case kR8G8_unorm_SkColorType: case kR16G16_unorm_SkColorType: case kR16G16_float_SkColorType: case kRGB_888x_SkColorType: case kRGB_101010x_SkColorType: case kBGR_101010x_SkColorType: case kBGR_101010x_XR_SkColorType: case kRGB_F16F16F16x_SkColorType: case kR8_unorm_SkColorType: { for (int y = 0; y < srcInfo.height(); ++y) {
memset(dst, 0xFF, srcInfo.width());
dst = SkTAddOffset<uint8_t>(dst, dstRB);
} returntrue;
}
case kARGB_4444_SkColorType: { auto src16 = (const uint16_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = SkPacked4444ToA32(src16[x]);
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src16 = SkTAddOffset<const uint16_t>(src16, srcRB);
} returntrue;
}
case kBGRA_8888_SkColorType: case kRGBA_8888_SkColorType: case kSRGBA_8888_SkColorType: { auto src32 = (const uint32_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = src32[x] >> 24;
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src32 = SkTAddOffset<const uint32_t>(src32, srcRB);
} returntrue;
}
case kRGBA_1010102_SkColorType: case kBGRA_1010102_SkColorType: { auto src32 = (const uint32_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = (src32[x] >> 30) * 0x55;
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src32 = SkTAddOffset<const uint32_t>(src32, srcRB);
} returntrue;
}
case kRGBA_F16Norm_SkColorType: case kRGBA_F16_SkColorType: { auto src64 = (const uint64_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = (uint8_t) (255.0f * SkHalfToFloat(src64[x] >> 48));
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src64 = SkTAddOffset<const uint64_t>(src64, srcRB);
} returntrue;
}
case kRGBA_F32_SkColorType: { auto rgba = (constfloat*)src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = (uint8_t)(255.0f * rgba[4*x+3]);
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
rgba = SkTAddOffset<constfloat>(rgba, srcRB);
} returntrue;
}
case kA16_float_SkColorType: { auto srcF16 = (const uint16_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = (uint8_t) (255.0f * SkHalfToFloat(srcF16[x]));
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
srcF16 = SkTAddOffset<const uint16_t>(srcF16, srcRB);
} returntrue;
}
case kBGRA_10101010_XR_SkColorType: { auto src64 = (const uint64_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) { static constexpr int64_t kZero = 384; static constexpr int64_t kRange = 510; static constexpr int64_t kMaxU8 = 0xff; static constexpr int64_t kMinU8 = 0x00; static constexpr int64_t kDivisor = kRange / kMaxU8;
int64_t raw_alpha = src64[x] >> 54; // f(384) = 0 // f(894) = 255
int64_t alpha =
SkTPin((raw_alpha - kZero) / kDivisor, kMinU8, kMaxU8);
dst[x] = static_cast<uint8_t>(alpha);
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src64 = SkTAddOffset<const uint64_t>(src64, srcRB);
} returntrue;
} case kRGBA_10x6_SkColorType: case kR16G16B16A16_unorm_SkColorType: { auto src64 = (const uint64_t*) src; for (int y = 0; y < srcInfo.height(); y++) { for (int x = 0; x < srcInfo.width(); x++) {
dst[x] = (src64[x] >> 48) >> 8;
}
dst = SkTAddOffset<uint8_t>(dst, dstRB);
src64 = SkTAddOffset<const uint64_t>(src64, srcRB);
} returntrue;
}
} returnfalse;
}
// Default: Use the pipeline. staticvoid convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, int dstStride, const SkImageInfo& srcInfo, constvoid* srcRow, int srcStride, const SkColorSpaceXformSteps& steps) {
SkRasterPipeline_MemoryCtx src = { const_cast<void*>(srcRow), srcStride },
dst = { dstRow, dstStride };
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.