本文整理汇总了C++中SkImageInfo::alphaType方法的典型用法代码示例。如果您正苦于以下问题:C++ SkImageInfo::alphaType方法的具体用法?C++ SkImageInfo::alphaType怎么用?C++ SkImageInfo::alphaType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkImageInfo
的用法示例。
在下文中一共展示了SkImageInfo::alphaType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initializeSwizzler
SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
const Options& options,
SkPMColor ctable[],
int* ctableCount) {
// FIXME: Could we use the return value of setjmp to specify the type of
// error?
if (setjmp(png_jmpbuf(fPng_ptr))) {
SkCodecPrintf("setjmp long jump!\n");
return kInvalidInput;
}
png_read_update_info(fPng_ptr, fInfo_ptr);
if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) {
if (!this->createColorTable(requestedInfo.colorType(),
kPremul_SkAlphaType == requestedInfo.alphaType(), ctableCount)) {
return kInvalidInput;
}
}
// Copy the color table to the client if they request kIndex8 mode
copy_color_table(requestedInfo, 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, requestedInfo,
options));
SkASSERT(fSwizzler);
return kSuccess;
}
示例2: fillIncompleteImage
void SkCodec::fillIncompleteImage(const SkImageInfo& info, void* dst, size_t rowBytes,
ZeroInitialized zeroInit, int linesRequested, int linesDecoded) {
void* fillDst;
const uint32_t fillValue = this->getFillValue(info.colorType(), info.alphaType());
const int linesRemaining = linesRequested - linesDecoded;
SkSampler* sampler = this->getSampler(false);
switch (this->getScanlineOrder()) {
case kTopDown_SkScanlineOrder:
case kNone_SkScanlineOrder: {
const SkImageInfo fillInfo = info.makeWH(info.width(), linesRemaining);
fillDst = SkTAddOffset<void>(dst, linesDecoded * rowBytes);
fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler);
break;
}
case kBottomUp_SkScanlineOrder: {
fillDst = dst;
const SkImageInfo fillInfo = info.makeWH(info.width(), linesRemaining);
fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler);
break;
}
case kOutOfOrder_SkScanlineOrder: {
SkASSERT(1 == linesRequested || this->getInfo().height() == linesRequested);
const SkImageInfo fillInfo = info.makeWH(info.width(), 1);
for (int srcY = linesDecoded; srcY < linesRequested; srcY++) {
fillDst = SkTAddOffset<void>(dst, this->outputScanline(srcY) * rowBytes);
fill_proc(fillInfo, fillDst, rowBytes, fillValue, zeroInit, sampler);
}
break;
}
}
}
示例3: initializeSwizzler
bool SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
const Options& options,
SkPMColor ctable[],
int* ctableCount) {
if (setjmp(png_jmpbuf(fPng_ptr))) {
return false;
}
png_read_update_info(fPng_ptr, fInfo_ptr);
if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) {
if (!this->createColorTable(requestedInfo.colorType(),
kPremul_SkAlphaType == requestedInfo.alphaType(), ctableCount)) {
return false;
}
}
// Copy the color table to the client if they request kIndex8 mode
copy_color_table(requestedInfo, 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, requestedInfo,
options));
SkASSERT(fSwizzler);
return true;
}
示例4: test_peek
static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectPeekSuccess) {
SkImageInfo info;
size_t rowBytes;
const void* addr = image->peekPixels(&info, &rowBytes);
bool success = SkToBool(addr);
REPORTER_ASSERT(reporter, expectPeekSuccess == success);
if (success) {
REPORTER_ASSERT(reporter, 20 == info.width());
REPORTER_ASSERT(reporter, 20 == info.height());
REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
kOpaque_SkAlphaType == info.alphaType());
REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes);
REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *(const SkPMColor*)addr);
}
}
示例5: NewFromBitmap
SkImage* SkImage::NewFromBitmap(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()) {
const bool notBudgeted = false;
tex = GrDeepCopyTexture(tex, notBudgeted);
if (nullptr == tex) {
return nullptr;
}
unrefCopy.reset(tex);
}
const SkImageInfo info = bm.info();
return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID(), info.alphaType(),
tex, 0, SkSurface::kNo_Budgeted);
}
#endif
// This will check for immutable (share or copy)
return SkNewImageFromRasterBitmap(bm, nullptr);
}
示例6: decode
/*
* Performs the decoding
*/
SkCodec::Result SkBmpMaskCodec::decode(const SkImageInfo& dstInfo,
void* dst, size_t dstRowBytes,
const Options& opts) {
// Set constant values
const int width = dstInfo.width();
const int height = dstInfo.height();
const size_t rowBytes = SkAlign4(compute_row_bytes(width, this->bitsPerPixel()));
// Iterate over rows of the image
uint8_t* srcRow = fSrcBuffer.get();
for (int y = 0; y < height; y++) {
// Read a row of the input
if (this->stream()->read(srcRow, rowBytes) != rowBytes) {
SkCodecPrintf("Warning: incomplete input stream.\n");
// Fill the destination image on failure
SkPMColor fillColor = dstInfo.alphaType() == kOpaque_SkAlphaType ?
SK_ColorBLACK : SK_ColorTRANSPARENT;
if (kNo_ZeroInitialized == opts.fZeroInitialized || 0 != fillColor) {
void* dstStart = this->getDstStartRow(dst, dstRowBytes, y);
SkSwizzler::Fill(dstStart, dstInfo, dstRowBytes, dstInfo.height() - y, fillColor,
nullptr);
}
return kIncompleteInput;
}
// Decode the row in destination format
int row = SkBmpCodec::kBottomUp_RowOrder == this->rowOrder() ? height - 1 - y : y;
void* dstRow = SkTAddOffset<void>(dst, row * dstRowBytes);
fMaskSwizzler->swizzle(dstRow, srcRow);
}
// Finished decoding the entire image
return kSuccess;
}
示例7: 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;
}
示例8: onGetPixels
virtual Result onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options&,
SkPMColor ctableEntries[], int* ctableCount) override {
SkMemoryStream stream(fData->data(), fData->size(), false);
SkAutoTUnref<BareMemoryAllocator> allocator(SkNEW_ARGS(BareMemoryAllocator,
(info, pixels, rowBytes)));
fDecoder->setAllocator(allocator);
fDecoder->setRequireUnpremultipliedColors(kUnpremul_SkAlphaType == info.alphaType());
SkBitmap bm;
const SkImageDecoder::Result result = fDecoder->decode(&stream, &bm, info.colorType(),
SkImageDecoder::kDecodePixels_Mode);
if (SkImageDecoder::kFailure == result) {
return kInvalidInput;
}
SkASSERT(info.colorType() == bm.info().colorType());
if (kIndex_8_SkColorType == info.colorType()) {
SkASSERT(ctableEntries);
SkColorTable* ctable = bm.getColorTable();
if (NULL == ctable) {
return kInvalidConversion;
}
const int count = ctable->count();
memcpy(ctableEntries, ctable->readColors(), count * sizeof(SkPMColor));
*ctableCount = count;
}
if (SkImageDecoder::kPartialSuccess == result) {
return kIncompleteInput;
}
return kSuccess;
}
示例9: make_premul
static SkImageInfo make_premul(const SkImageInfo& info) {
if (kUnpremul_SkAlphaType == info.alphaType()) {
return info.makeAlphaType(kPremul_SkAlphaType);
}
return info;
}
示例10: 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);
}
示例11: compatibleInfo
static bool compatibleInfo(const SkImageInfo& src, const SkImageInfo& dst)
{
if (src == dst)
return true;
// It is legal to write kOpaque_SkAlphaType pixels into a kPremul_SkAlphaType buffer.
// This can happen when DeferredImageDecoder allocates an kOpaque_SkAlphaType image
// generator based on cached frame info, while the ImageFrame-allocated dest bitmap
// stays kPremul_SkAlphaType.
if (src.alphaType() == kOpaque_SkAlphaType && dst.alphaType() == kPremul_SkAlphaType) {
const SkImageInfo& tmp = src.makeAlphaType(kPremul_SkAlphaType);
return tmp == dst;
}
return false;
}
示例12: SkAssertResult
bool SkAnimatedImage::Frame::init(const SkImageInfo& info, OnInit onInit) {
if (fBitmap.getPixels()) {
if (fBitmap.pixelRef()->unique()) {
SkAssertResult(fBitmap.setAlphaType(info.alphaType()));
return true;
}
// An SkCanvas provided to onDraw is still holding a reference.
// Copy before we decode to ensure that we don't overwrite the
// expected contents of the image.
if (OnInit::kRestoreIfNecessary == onInit) {
SkBitmap tmp;
if (!tmp.tryAllocPixels(info)) {
return false;
}
memcpy(tmp.getPixels(), fBitmap.getPixels(), fBitmap.computeByteSize());
using std::swap;
swap(tmp, fBitmap);
return true;
}
}
return fBitmap.tryAllocPixels(info);
}
示例13: ico_conversion_possible
static bool ico_conversion_possible(const SkImageInfo& dstInfo) {
// We only support kN32_SkColorType.
// This makes sense for BMP-in-ICO. The presence of an AND
// mask (which changes colors and adds transparency) means that
// we cannot use k565 or kIndex8.
// FIXME: For PNG-in-ICO, we could technically support whichever
// color types that the png supports.
if (kN32_SkColorType != dstInfo.colorType()) {
return false;
}
// We only support transparent alpha types. This is necessary for
// BMP-in-ICOs since there will be an AND mask.
// FIXME: For opaque PNG-in-ICOs, we should be able to support kOpaque.
return kPremul_SkAlphaType == dstInfo.alphaType() ||
kUnpremul_SkAlphaType == dstInfo.alphaType();
}
示例14: readRows
int readRows(const SkImageInfo& dstInfo, void* dst, size_t rowBytes, int count, int startRow)
override {
if (setjmp(png_jmpbuf(fPng_ptr))) {
SkCodecPrintf("Failed to get scanlines.\n");
// FIXME (msarett): Returning 0 is pessimistic. If we can complete a single pass,
// we may be able to report that all of the memory has been initialized. Even if we
// fail on the first pass, we can still report than some scanlines are initialized.
return 0;
}
SkAutoTMalloc<uint8_t> storage(count * fSrcRowBytes);
uint8_t* srcRow;
for (int i = 0; i < fNumberPasses; i++) {
// Discard rows that we planned to skip.
for (int y = 0; y < startRow; y++){
png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
}
// Read rows we care about into storage.
srcRow = storage.get();
for (int y = 0; y < count; y++) {
png_read_row(fPng_ptr, srcRow, nullptr);
srcRow += fSrcRowBytes;
}
// Discard rows that we don't need.
for (int y = 0; y < this->getInfo().height() - startRow - count; y++) {
png_read_row(fPng_ptr, fSwizzlerSrcRow, nullptr);
}
}
// Swizzle and xform the rows we care about
void* swizzlerDstRow = dst;
size_t swizzlerDstRowBytes = rowBytes;
bool colorXform = fColorXform &&
apply_xform_on_decode(dstInfo.colorType(), this->getEncodedInfo().color());
if (colorXform) {
swizzlerDstRow = fColorXformSrcRow;
swizzlerDstRowBytes = 0;
}
SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
this->getInfo().alphaType());
srcRow = storage.get();
for (int y = 0; y < count; y++) {
fSwizzler->swizzle(swizzlerDstRow, srcRow);
srcRow = SkTAddOffset<uint8_t>(srcRow, fSrcRowBytes);
if (colorXform) {
fColorXform->apply(dst, (const uint32_t*) swizzlerDstRow, fSwizzler->swizzleWidth(),
dstInfo.colorType(), xformAlphaType);
dst = SkTAddOffset<void>(dst, rowBytes);
}
swizzlerDstRow = SkTAddOffset<void>(swizzlerDstRow, swizzlerDstRowBytes);
}
return count;
}
示例15: getPixels
SkCodec::Result SkCodec::getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
const Options* options, SkPMColor ctable[], int* ctableCount) {
if (kUnknown_SkColorType == info.colorType()) {
return kInvalidConversion;
}
if (NULL == pixels) {
return kInvalidParameters;
}
if (rowBytes < info.minRowBytes()) {
return kInvalidParameters;
}
if (kIndex_8_SkColorType == info.colorType()) {
if (NULL == ctable || NULL == ctableCount) {
return kInvalidParameters;
}
} else {
if (ctableCount) {
*ctableCount = 0;
}
ctableCount = NULL;
ctable = NULL;
}
{
SkAlphaType canonical;
if (!SkColorTypeValidateAlphaType(info.colorType(), info.alphaType(), &canonical)
|| canonical != info.alphaType())
{
return kInvalidConversion;
}
}
// Default options.
Options optsStorage;
if (NULL == options) {
options = &optsStorage;
}
const Result result = this->onGetPixels(info, pixels, rowBytes, *options, ctable, ctableCount);
if ((kIncompleteInput == result || kSuccess == result) && ctableCount) {
SkASSERT(*ctableCount >= 0 && *ctableCount <= 256);
}
return result;
}