本文整理汇总了C++中SkImageInfo::colorSpace方法的典型用法代码示例。如果您正苦于以下问题:C++ SkImageInfo::colorSpace方法的具体用法?C++ SkImageInfo::colorSpace怎么用?C++ SkImageInfo::colorSpace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkImageInfo
的用法示例。
在下文中一共展示了SkImageInfo::colorSpace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildCacheInfo
SkImageInfo SkImage_Lazy::buildCacheInfo(CachedFormat format) const {
switch (format) {
case kLegacy_CachedFormat:
return fInfo.makeColorSpace(nullptr);
case kLinearF16_CachedFormat:
return fInfo.makeColorType(kRGBA_F16_SkColorType)
.makeColorSpace(fInfo.colorSpace()->makeLinearGamma());
case kSRGB8888_CachedFormat:
// If the transfer function is nearly (but not exactly) sRGB, we don't want the codec
// to bother trans-coding. It would be slow, and do more harm than good visually,
// so we make sure to leave the colorspace as-is.
if (fInfo.colorSpace()->gammaCloseToSRGB()) {
return fInfo.makeColorType(kRGBA_8888_SkColorType);
} else {
return fInfo.makeColorType(kRGBA_8888_SkColorType)
.makeColorSpace(fInfo.colorSpace()->makeSRGBGamma());
}
case kSBGR8888_CachedFormat:
// See note above about not-quite-sRGB transfer functions.
if (fInfo.colorSpace()->gammaCloseToSRGB()) {
return fInfo.makeColorType(kBGRA_8888_SkColorType);
} else {
return fInfo.makeColorType(kBGRA_8888_SkColorType)
.makeColorSpace(fInfo.colorSpace()->makeSRGBGamma());
}
default:
SkDEBUGFAIL("Invalid cached format");
return fInfo;
}
}
示例2: Valid
bool SkSurface_Gpu::Valid(const SkImageInfo& info) {
switch (info.colorType()) {
case kRGBA_F16_SkColorType:
return (!info.colorSpace()) || info.colorSpace()->gammaIsLinear();
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
return !info.colorSpace() || info.colorSpace()->gammaCloseToSRGB();
default:
return !info.colorSpace();
}
}
示例3: setColorSpace
bool SkPngEncoderMgr::setColorSpace(const SkImageInfo& info) {
if (setjmp(png_jmpbuf(fPngPtr))) {
return false;
}
if (info.colorSpace() && info.colorSpace()->isSRGB()) {
png_set_sRGB(fPngPtr, fInfoPtr, PNG_sRGB_INTENT_PERCEPTUAL);
} else {
set_icc(fPngPtr, fInfoPtr, info);
}
return true;
}
示例4:
DEF_TEST(ColorSpace_Named, r) {
const struct {
SkColorSpace::Named fNamed;
bool fExpectedToSucceed;
bool fIsSRGB;
} recs[] {
{ SkColorSpace::kUnknown_Named, false, false },
{ SkColorSpace::kSRGB_Named, true, true },
{ SkColorSpace::kAdobeRGB_Named, true, false },
};
for (auto rec : recs) {
auto cs = SkColorSpace::NewNamed(rec.fNamed);
REPORTER_ASSERT(r, !cs == !rec.fExpectedToSucceed);
if (cs) {
if (rec.fIsSRGB) {
REPORTER_ASSERT(r, SkColorSpace::kSRGB_GammaNamed == cs->gammaNamed());
} else {
REPORTER_ASSERT(r, SkColorSpace::k2Dot2Curve_GammaNamed == cs->gammaNamed());
}
}
}
SkImageInfo info = SkImageInfo::MakeS32(10, 10, kPremul_SkAlphaType);
REPORTER_ASSERT(r, kSRGB_SkColorProfileType == info.profileType());
REPORTER_ASSERT(r, SkColorSpace::kSRGB_GammaNamed == info.colorSpace()->gammaNamed());
}
示例5: SkASSERT
sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) {
GrRenderTarget* rt = fDevice->accessDrawContext()->accessRenderTarget();
SkASSERT(rt);
GrTexture* tex = rt->asTexture();
SkAutoTUnref<GrTexture> copy;
// If the original render target is a buffer originally created by the client, then we don't
// want to ever retarget the SkSurface at another buffer we create. Force a copy now to avoid
// copy-on-write.
if (kYes_ForceCopyMode == forceCopyMode || !tex || rt->resourcePriv().refsWrappedObjects()) {
GrSurfaceDesc desc = fDevice->accessDrawContext()->desc();
GrContext* ctx = fDevice->context();
desc.fFlags = desc.fFlags & ~kRenderTarget_GrSurfaceFlag;
copy.reset(ctx->textureProvider()->createTexture(desc, budgeted));
if (!copy) {
return nullptr;
}
if (!ctx->copySurface(copy, rt)) {
return nullptr;
}
tex = copy;
}
const SkImageInfo info = fDevice->imageInfo();
sk_sp<SkImage> image;
if (tex) {
image = sk_make_sp<SkImage_Gpu>(info.width(), info.height(), kNeedNewImageUniqueID,
info.alphaType(), tex, sk_ref_sp(info.colorSpace()),
budgeted);
}
return image;
}
示例6: SkMakeImageFromRasterBitmap
sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
SkPixelRef* pr = bm.pixelRef();
if (nullptr == pr) {
return nullptr;
}
#if SK_SUPPORT_GPU
if (GrTexture* tex = pr->getTexture()) {
SkAutoTUnref<GrTexture> unrefCopy;
if (!bm.isImmutable()) {
tex = GrDeepCopyTexture(tex, SkBudgeted::kNo);
if (nullptr == tex) {
return nullptr;
}
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenerationID(),
info.alphaType(), tex, sk_ref_sp(info.colorSpace()),
SkBudgeted::kNo);
}
#endif
// This will check for immutable (share or copy)
return SkMakeImageFromRasterBitmap(bm);
}
示例7: onReadPixels
bool SkImage_Lazy::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
int srcX, int srcY, CachingHint chint) const {
SkColorSpace* dstColorSpace = dstInfo.colorSpace();
SkBitmap bm;
if (kDisallow_CachingHint == chint) {
CachedFormat cacheFormat = this->chooseCacheFormat(dstColorSpace);
SkImageInfo genPixelsInfo = dstInfo;
SkTransferFunctionBehavior behavior = getGeneratorBehaviorAndInfo(&genPixelsInfo);
if (this->lockAsBitmapOnlyIfAlreadyCached(&bm, cacheFormat)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
} else {
// Try passing the caller's buffer directly down to the generator. If this fails we
// may still succeed in the general case, as the generator may prefer some other
// config, which we could then convert via SkBitmap::readPixels.
if (this->directGeneratePixels(genPixelsInfo, dstPixels, dstRB, srcX, srcY, behavior)) {
return true;
}
// else fall through
}
}
if (this->getROPixels(&bm, dstColorSpace, chint)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
}
return false;
}
示例8: createCharacterization
SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization(
size_t cacheMaxResourceBytes,
const SkImageInfo& ii, const GrBackendFormat& backendFormat,
int sampleCnt, GrSurfaceOrigin origin,
const SkSurfaceProps& surfaceProps,
bool isMipMapped, bool willUseGLFBO0, bool isTextureable) {
if (!backendFormat.isValid()) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
if (GrBackendApi::kOpenGL != backendFormat.backend() && willUseGLFBO0) {
// The willUseGLFBO0 flags can only be used for a GL backend.
return SkSurfaceCharacterization(); // return an invalid characterization
}
if (!this->caps()->mipMapSupport()) {
isMipMapped = false;
}
GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendFormat, ii.colorType());
if (config == kUnknown_GrPixelConfig) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
if (!SkSurface_Gpu::Valid(this->caps(), config, ii.colorSpace())) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, config);
if (!sampleCnt) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
GrFSAAType FSAAType = GrFSAAType::kNone;
if (sampleCnt > 1) {
FSAAType = this->caps()->usesMixedSamples() ? GrFSAAType::kMixedSamples
: GrFSAAType::kUnifiedMSAA;
}
if (willUseGLFBO0 && isTextureable) {
return SkSurfaceCharacterization(); // return an invalid characterization
}
if (isTextureable && !this->caps()->isConfigTexturable(config)) {
// Skia doesn't agree that this is textureable.
return SkSurfaceCharacterization(); // return an invalid characterization
}
return SkSurfaceCharacterization(sk_ref_sp<GrContextThreadSafeProxy>(this),
cacheMaxResourceBytes, ii,
origin, config, FSAAType, sampleCnt,
SkSurfaceCharacterization::Textureable(isTextureable),
SkSurfaceCharacterization::MipMapped(isMipMapped),
SkSurfaceCharacterization::UsesGLFBO0(willUseGLFBO0),
SkSurfaceCharacterization::VulkanSecondaryCBCompatible(false),
surfaceProps);
}
示例9: initializeColorXform
bool SkJpegCodec::initializeColorXform(const SkImageInfo& dstInfo, bool needsColorXform) {
if (needsColorXform) {
fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
return false;
}
}
return true;
}
示例10: MakeRenderTarget
sk_sp<SkSpecialSurface> onMakeSurface(const SkImageInfo& info) const override {
if (!fTexture->getContext()) {
return nullptr;
}
GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *fTexture->getContext()->caps());
return SkSpecialSurface::MakeRenderTarget(fTexture->getContext(),
info.width(), info.height(),
config, sk_ref_sp(info.colorSpace()));
}
示例11: initializeXforms
bool SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const Options& options,
SkPMColor ctable[], int* ctableCount) {
if (setjmp(png_jmpbuf(fPng_ptr))) {
SkCodecPrintf("Failed on png_read_update_info.\n");
return false;
}
png_read_update_info(fPng_ptr, fInfo_ptr);
// It's important to reset fColorXform to nullptr. We don't do this on rewinding
// because the interlaced scanline decoder may need to rewind.
fColorXform = nullptr;
SkImageInfo swizzlerInfo = dstInfo;
bool needsColorXform = needs_color_xform(dstInfo, this->getInfo());
if (needsColorXform) {
switch (dstInfo.colorType()) {
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
case kRGBA_F16_SkColorType:
swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType);
if (kPremul_SkAlphaType == dstInfo.alphaType()) {
swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaType);
}
break;
case kIndex_8_SkColorType:
break;
default:
return false;
}
fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
sk_ref_sp(dstInfo.colorSpace()));
if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) {
return false;
}
}
if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) {
if (!this->createColorTable(dstInfo, ctableCount)) {
return false;
}
}
// Copy the color table to the client if they request kIndex8 mode
copy_color_table(swizzlerInfo, fColorTable, ctable, ctableCount);
// Create the swizzler. SkPngCodec retains ownership of the color table.
const SkPMColor* colors = get_color_ptr(fColorTable.get());
fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colors, swizzlerInfo,
options));
SkASSERT(fSwizzler);
return true;
}
示例12: texture
sk_sp<SkImage> SkImage::MakeTextureFromMipMap(GrContext* ctx, const SkImageInfo& info,
const GrMipLevel* texels, int mipLevelCount,
SkBudgeted budgeted,
SkSourceGammaTreatment gammaTreatment) {
if (!ctx) {
return nullptr;
}
sk_sp<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, mipLevelCount));
if (!texture) {
return nullptr;
}
texture->texturePriv().setGammaTreatment(gammaTreatment);
return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNewImageUniqueID,
info.alphaType(), std::move(texture),
sk_ref_sp(info.colorSpace()), budgeted);
}
示例13: setOutputColorFormat
/*
* Checks if the conversion between the input image and the requested output
* image has been implemented
* Sets the output color format
*/
bool SkHeifCodec::setOutputColorFormat(const SkImageInfo& dstInfo) {
if (kUnknown_SkAlphaType == dstInfo.alphaType()) {
return false;
}
if (kOpaque_SkAlphaType != dstInfo.alphaType()) {
SkCodecPrintf("Warning: an opaque image should be decoded as opaque "
"- it is being decoded as non-opaque, which will draw slower\n");
}
switch (dstInfo.colorType()) {
case kRGBA_8888_SkColorType:
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
case kBGRA_8888_SkColorType:
return fHeifDecoder->setOutputColor(kHeifColorFormat_BGRA_8888);
case kRGB_565_SkColorType:
if (this->colorXform()) {
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
} else {
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGB565);
}
case kRGBA_F16_SkColorType:
SkASSERT(this->colorXform());
if (!dstInfo.colorSpace()->gammaIsLinear()) {
return false;
}
return fHeifDecoder->setOutputColor(kHeifColorFormat_RGBA_8888);
default:
return false;
}
}
示例14: generator
/*
* We have 4 ways to try to return a texture (in sorted order)
*
* 1. Check the cache for a pre-existing one
* 2. Ask the generator to natively create one
* 3. Ask the generator to return YUV planes, which the GPU can convert
* 4. Ask the generator to return RGB(A) data, which the GPU can convert
*/
sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
const GrUniqueKey& origKey,
SkImage::CachingHint chint,
bool willBeMipped,
SkColorSpace* dstColorSpace,
GrTextureMaker::AllowedTexGenType genType) {
// Values representing the various texture lock paths we can take. Used for logging the path
// taken to a histogram.
enum LockTexturePath {
kFailure_LockTexturePath,
kPreExisting_LockTexturePath,
kNative_LockTexturePath,
kCompressed_LockTexturePath, // Deprecated
kYUV_LockTexturePath,
kRGBA_LockTexturePath,
};
enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 };
// Determine which cached format we're going to use (which may involve decoding to a different
// info than the generator provides).
CachedFormat format = this->chooseCacheFormat(dstColorSpace, ctx->caps());
// Fold the cache format into our texture key
GrUniqueKey key;
this->makeCacheKeyFromOrigKey(origKey, format, &key);
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
sk_sp<GrTextureProxy> proxy;
// 1. Check the cache for a pre-existing one
if (key.isValid()) {
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin);
if (proxy) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexturePath,
kLockTexturePathCount);
if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
return proxy;
}
}
}
// The CachedFormat is both an index for which cache "slot" we'll use to store this particular
// decoded variant of the encoded data, and also a recipe for how to transform the original
// info to get the one that we're going to decode to.
const SkImageInfo cacheInfo = this->buildCacheInfo(format);
SkImageInfo genPixelsInfo = cacheInfo;
SkTransferFunctionBehavior behavior = getGeneratorBehaviorAndInfo(&genPixelsInfo);
// 2. Ask the generator to natively create one
if (!proxy) {
ScopedGenerator generator(fSharedGenerator);
if (GrTextureMaker::AllowedTexGenType::kCheap == genType &&
SkImageGenerator::TexGenType::kCheap != generator->onCanGenerateTexture()) {
return nullptr;
}
if ((proxy = generator->generateTexture(ctx, genPixelsInfo, fOrigin, behavior,
willBeMipped))) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
return proxy;
}
}
}
// 3. Ask the generator to return YUV planes, which the GPU can convert. If we will be mipping
// the texture we fall through here and have the CPU generate the mip maps for us.
if (!proxy && !willBeMipped && !ctx->contextPriv().disableGpuYUVConversion()) {
const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(cacheInfo, *ctx->caps());
ScopedGenerator generator(fSharedGenerator);
Generator_GrYUVProvider provider(generator);
// The pixels in the texture will be in the generator's color space. If onMakeColorSpace
// has been called then this will not match this image's color space. To correct this, apply
// a color space conversion from the generator's color space to this image's color space.
const SkColorSpace* generatorColorSpace =
fSharedGenerator->fGenerator->getInfo().colorSpace();
const SkColorSpace* thisColorSpace = fInfo.colorSpace();
// TODO: Update to create the mipped surface in the YUV generator and draw the base layer
// directly into the mipped surface.
proxy = provider.refAsTextureProxy(ctx, desc, generatorColorSpace, thisColorSpace);
if (proxy) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
kLockTexturePathCount);
set_key_on_proxy(proxyProvider, proxy.get(), nullptr, key);
return proxy;
}
}
//.........这里部分代码省略.........
示例15: SkImageInfo2GrPixelConfig
GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& caps) {
return SkImageInfo2GrPixelConfig(info.colorType(), info.colorSpace(), caps);
}