本文整理汇总了C++中SkBitmap::eraseColor方法的典型用法代码示例。如果您正苦于以下问题:C++ SkBitmap::eraseColor方法的具体用法?C++ SkBitmap::eraseColor怎么用?C++ SkBitmap::eraseColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkBitmap
的用法示例。
在下文中一共展示了SkBitmap::eraseColor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: doDecode
//.........这里部分代码省略.........
}
jint scaledBounds[4];
if (willScale) {
for (int i=0; i<4; i++) {
scaledBounds[i] = (jint)((((jint*)peeker.fLayoutBounds)[i]*scale) + .5f);
}
} else {
memcpy(scaledBounds, (jint*)peeker.fLayoutBounds, sizeof(scaledBounds));
}
env->SetIntArrayRegion(layoutBounds, 0, 4, scaledBounds);
if (javaBitmap != NULL) {
env->SetObjectField(javaBitmap, gBitmap_layoutBoundsFieldID, layoutBounds);
}
}
if (willScale) {
// This is weird so let me explain: we could use the scale parameter
// directly, but for historical reasons this is how the corresponding
// Dalvik code has always behaved. We simply recreate the behavior here.
// The result is slightly different from simply using scale because of
// the 0.5f rounding bias applied when computing the target image size
const float sx = scaledWidth / float(decoded->width());
const float sy = scaledHeight / float(decoded->height());
SkBitmap::Config config = decoded->config();
switch (config) {
case SkBitmap::kNo_Config:
case SkBitmap::kIndex8_Config:
case SkBitmap::kRLE_Index8_Config:
config = SkBitmap::kARGB_8888_Config;
break;
default:
break;
}
bitmap->setConfig(config, scaledWidth, scaledHeight);
bitmap->setIsOpaque(decoded->isOpaque());
if (!bitmap->allocPixels(&javaAllocator, NULL)) {
return nullObjectReturn("allocation failed for scaled bitmap");
}
bitmap->eraseColor(0);
SkPaint paint;
paint.setFilterBitmap(true);
SkCanvas canvas(*bitmap);
canvas.scale(sx, sy);
canvas.drawBitmap(*decoded, 0.0f, 0.0f, &paint);
// Save off the unscaled version of bitmap to be used in later
// transformations if it would reduce memory pressure. Only do
// so if it is being upscaled more than 50%, is bigger than
// 256x256, and not too big to be keeping a copy of (<1MB).
const int numUnscaledPixels = decoded->width() * decoded->height();
if (sx > 1.5 && numUnscaledPixels > 65536 && numUnscaledPixels < 262144) {
bitmap->setUnscaledBitmap(decoded);
adb2.detach(); //responsibility for freeing decoded's memory is
//transferred to bitmap's destructor
}
}
if (padding) {
if (peeker.fPatch != NULL) {
GraphicsJNI::set_jrect(env, padding,
peeker.fPatch->paddingLeft, peeker.fPatch->paddingTop,
peeker.fPatch->paddingRight, peeker.fPatch->paddingBottom);
} else {
GraphicsJNI::set_jrect(env, padding, -1, -1, -1, -1);
}
}
SkPixelRef* pr;
if (isPurgeable) {
pr = installPixelRef(bitmap, stream, sampleSize, doDither);
} else {
// if we get here, we're in kDecodePixels_Mode and will therefore
// already have a pixelref installed.
pr = bitmap->pixelRef();
}
if (pr == NULL) {
return nullObjectReturn("Got null SkPixelRef");
}
if (!isMutable) {
// promise we will never change our pixels (great for sharing and pictures)
pr->setImmutable();
}
// detach bitmap from its autodeleter, since we want to own it now
adb.detach();
if (javaBitmap != NULL) {
// If a java bitmap was passed in for reuse, pass it back
return javaBitmap;
}
// now create the java bitmap
return GraphicsJNI::createBitmap(env, bitmap, javaAllocator.getStorageObj(),
isMutable, ninePatchChunk, layoutBounds, -1);
}
示例2: Bitmap_erase
static void Bitmap_erase(JNIEnv* env, jobject, jlong bitmapHandle, jint color) {
SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
bitmap->eraseColor(color);
}
示例3: check
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
bool supportsScanlineDecoding,
bool supportsSubsetDecoding,
bool supports565 = true) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to decode '%s'", path);
return;
}
// This test is used primarily to verify rewinding works properly. Using kN32 allows
// us to test this without the added overhead of creating different bitmaps depending
// on the color type (ex: building a color table for kIndex8). DM is where we test
// decodes to all possible destination color types.
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
REPORTER_ASSERT(r, info.dimensions() == size);
{
// Test decoding to 565
SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType);
SkCodec::Result expected = (supports565 && info.alphaType() == kOpaque_SkAlphaType) ?
SkCodec::kSuccess : SkCodec::kInvalidConversion;
test_info(r, codec, info565, expected, nullptr);
}
SkBitmap bm;
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
SkCodec::Result result =
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), nullptr, nullptr, nullptr);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
SkMD5::Digest digest;
md5(bm, &digest);
// verify that re-decoding gives the same result.
test_info(r, codec, info, SkCodec::kSuccess, &digest);
{
// Check alpha type conversions
if (info.alphaType() == kOpaque_SkAlphaType) {
test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr);
test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
SkCodec::kInvalidConversion, nullptr);
} else {
// Decoding to opaque should fail
test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType),
SkCodec::kInvalidConversion, nullptr);
SkAlphaType otherAt = info.alphaType();
if (kPremul_SkAlphaType == otherAt) {
otherAt = kUnpremul_SkAlphaType;
} else {
otherAt = kPremul_SkAlphaType;
}
// The other non-opaque alpha type should always succeed, but not match.
test_info(r, codec, info.makeAlphaType(otherAt), SkCodec::kSuccess, nullptr);
}
}
// Scanline decoding follows.
stream.reset(resource(path));
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(
SkScanlineDecoder::NewFromStream(stream.detach()));
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, scanlineDecoder);
REPORTER_ASSERT(r, scanlineDecoder->start(info) == SkCodec::kSuccess);
for (int y = 0; y < info.height(); y++) {
result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
}
// verify that scanline decoding gives the same result.
if (SkScanlineDecoder::kTopDown_SkScanlineOrder == scanlineDecoder->getScanlineOrder()) {
compare_to_good_digest(r, digest, bm);
}
} else {
REPORTER_ASSERT(r, !scanlineDecoder);
}
// The rest of this function tests decoding subsets, and will decode an arbitrary number of
// random subsets.
// Do not attempt to decode subsets of an image of only once pixel, since there is no
// meaningful subset.
if (size.width() * size.height() == 1) {
return;
}
SkRandom rand;
SkIRect subset;
//.........这里部分代码省略.........
示例4: iter
CanvasLayer::CanvasLayer(const CanvasLayer& layer)
: LayerAndroid(layer)
, m_canvas(0)
, m_bitmap(0)
, m_gpuCanvas(0)
{
init();
if (!layer.m_canvas) {
// The canvas has already been destroyed - this shouldn't happen
ALOGW("Creating a CanvasLayer for a destroyed canvas!");
m_visibleContentRect = IntRect();
m_offsetFromRenderer = IntSize();
m_texture->setHwAccelerated(false);
return;
}
// We are making a copy for the UI, sync the interesting bits
m_visibleContentRect = layer.visibleContentRect();
m_offsetFromRenderer = layer.offsetFromRenderer();
bool previousState = m_texture->hasValidTexture();
if(layer.m_canvas->isUsingGpuRendering())
return;
ImageBuffer* imageBuffer = layer.m_canvas->buffer();
if (!previousState && layer.m_dirtyCanvas.isEmpty() && imageBuffer && !(imageBuffer->drawsUsingRecording())) {
// We were previously in software and don't have anything new to draw,
// so stay in software
m_bitmap = layer.bitmap();
SkSafeRef(m_bitmap);
} else {
if(imageBuffer && imageBuffer->drawsUsingRecording() && !layer.m_canvas->isUsingGpuRendering())
{
bool canUseGpuRendering = imageBuffer->canUseGpuRendering();
if(canUseGpuRendering && layer.m_canvas->canUseGpuRendering())
{
layer.m_canvas->enableGpuRendering();
CanvasLayer::setGpuCanvasStatus(layer.uniqueId(), true);
}
}
// If recording is being used
if(imageBuffer && imageBuffer->drawsUsingRecording())
{
GraphicsContext* gc = imageBuffer->context();
//SkPicture* canvasRecording = gc->platformContext()->getRecordingPicture();
SkPicture* canvasRecording = CanvasLayer::getRecordingPicture(this);
SkBitmap* bitmap = CanvasLayer::getRecordingBitmap(this);
SkCanvas* canvas = CanvasLayer::getRecordingCanvas(this);
if(canvasRecording == NULL)
return;
if(bitmap == NULL || bitmap->width() != canvasRecording->width()
|| bitmap->height() != canvasRecording->height())
{
SkBitmap* newBitmap = new SkBitmap();
newBitmap->setConfig(SkBitmap::kARGB_8888_Config, canvasRecording->width(), canvasRecording->height());
newBitmap->allocPixels();
newBitmap->eraseColor(0);
CanvasLayer::setRecordingBitmap(newBitmap, this);
bitmap = newBitmap;
if(canvas != NULL)
canvas->setBitmapDevice(*bitmap);
}
if(canvas == NULL)
{
canvas = new SkCanvas();
canvas->setBitmapDevice(*bitmap);
CanvasLayer::setRecordingCanvas(canvas, this);
}
canvas->drawARGB(0, 0, 0, 0, SkXfermode::kClear_Mode);
canvasRecording->draw(canvas);
if (!m_texture->uploadImageBitmap(bitmap)) {
//SLOGD("+++++++++++++++++++++ Didn't upload bitmap .. fall back to software");
// TODO:: Fix this
}
}
else
{
if (!m_texture->uploadImageBuffer(layer.m_canvas->buffer())) {
// Blargh, no surface texture or ImageBuffer - fall back to software
m_bitmap = layer.bitmap();
SkSafeRef(m_bitmap);
// Merge the canvas invals with the layer's invals to repaint the needed
// tiles.
SkRegion::Iterator iter(layer.m_dirtyCanvas);
const IntPoint& offset = m_visibleContentRect.location();
for (; !iter.done(); iter.next()) {
SkIRect diff = iter.rect();
diff.fLeft += offset.x();
diff.fRight += offset.x();
diff.fTop += offset.y();
diff.fBottom += offset.y();
//.........这里部分代码省略.........
示例5: canvas
/**
* This test case is a mirror of the Android CTS tests for MatrixColorFilter
* found in the android.graphics.ColorMatrixColorFilterTest class.
*/
static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
SkBitmap bitmap;
bitmap.allocN32Pixels(1,1);
SkCanvas canvas(bitmap);
SkPaint paint;
SkScalar blueToCyan[20] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f };
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(blueToCyan));
paint.setColor(SK_ColorBLUE);
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
paint.setColor(SK_ColorGREEN);
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorGREEN, bitmap.getColor(0, 0));
paint.setColor(SK_ColorRED);
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorRED, bitmap.getColor(0, 0));
// color components are clipped, not scaled
paint.setColor(SK_ColorMAGENTA);
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorWHITE, bitmap.getColor(0, 0));
SkScalar transparentRedAddBlue[20] = {
1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f, 64.0f,
-0.5f, 0.0f, 0.0f, 1.0f, 0.0f
};
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
bitmap.eraseColor(SK_ColorTRANSPARENT);
paint.setColor(SK_ColorRED);
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SkColorSetARGB(128, 255, 0, 64), bitmap.getColor(0, 0), 2);
paint.setColor(SK_ColorCYAN);
canvas.drawPoint(0, 0, paint);
// blue gets clipped
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
// change array to filter out green
REPORTER_ASSERT(reporter, 1.0f == transparentRedAddBlue[6]);
transparentRedAddBlue[6] = 0.0f;
// check that changing the array has no effect
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
// create a new filter with the changed matrix
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
canvas.drawPoint(0, 0, paint);
assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0));
}
示例6: autoLockPixels
// Test interlaced PNG in stripes, similar to DM's kStripe_Mode
DEF_TEST(Codec_stripes, r) {
const char * path = "plane_interlaced.png";
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
REPORTER_ASSERT(r, codec);
if (!codec) {
return;
}
switch (codec->getScanlineOrder()) {
case SkCodec::kBottomUp_SkScanlineOrder:
case SkCodec::kOutOfOrder_SkScanlineOrder:
ERRORF(r, "This scanline order will not match the original.");
return;
default:
break;
}
// Baseline for what the image should look like, using N32.
const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
SkBitmap bm;
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
SkMD5::Digest digest;
md5(bm, &digest);
// Now decode in stripes
const int height = info.height();
const int numStripes = 4;
int stripeHeight;
int remainingLines;
SkTDivMod(height, numStripes, &stripeHeight, &remainingLines);
bm.eraseColor(SK_ColorYELLOW);
result = codec->startScanlineDecode(info);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
// Odd stripes
for (int i = 1; i < numStripes; i += 2) {
// Skip the even stripes
bool skipResult = codec->skipScanlines(stripeHeight);
REPORTER_ASSERT(r, skipResult);
int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
bm.rowBytes());
REPORTER_ASSERT(r, linesDecoded == stripeHeight);
}
// Even stripes
result = codec->startScanlineDecode(info);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
for (int i = 0; i < numStripes; i += 2) {
int linesDecoded = codec->getScanlines(bm.getAddr(0, i * stripeHeight), stripeHeight,
bm.rowBytes());
REPORTER_ASSERT(r, linesDecoded == stripeHeight);
// Skip the odd stripes
if (i + 1 < numStripes) {
bool skipResult = codec->skipScanlines(stripeHeight);
REPORTER_ASSERT(r, skipResult);
}
}
// Remainder at the end
if (remainingLines > 0) {
result = codec->startScanlineDecode(info);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
bool skipResult = codec->skipScanlines(height - remainingLines);
REPORTER_ASSERT(r, skipResult);
int linesDecoded = codec->getScanlines(bm.getAddr(0, height - remainingLines),
remainingLines, bm.rowBytes());
REPORTER_ASSERT(r, linesDecoded == remainingLines);
}
compare_to_good_digest(r, digest, bm);
}
示例7: make_bm
static SkBitmap make_bm() {
SkBitmap bm;
bm.allocN32Pixels(WW, HH);
bm.eraseColor(SK_ColorTRANSPARENT);
return bm;
}
示例8: create_bm
static SkBitmap create_bm() {
SkBitmap bm;
bm.allocN32Pixels(kFullSize, kFullSize, true);
bm.eraseColor(SK_ColorTRANSPARENT);
return bm;
}
示例9: check
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
bool supportsScanlineDecoding,
bool supportsSubsetDecoding) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to decode '%s'", path);
return;
}
// This test is used primarily to verify rewinding works properly. Using kN32 allows
// us to test this without the added overhead of creating different bitmaps depending
// on the color type (ex: building a color table for kIndex8). DM is where we test
// decodes to all possible destination color types.
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
REPORTER_ASSERT(r, info.dimensions() == size);
SkBitmap bm;
bm.allocPixels(info);
SkAutoLockPixels autoLockPixels(bm);
SkCodec::Result result =
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
SkMD5::Digest digest;
md5(bm, &digest);
bm.eraseColor(SK_ColorYELLOW);
result =
codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
// verify that re-decoding gives the same result.
compare_to_good_digest(r, digest, bm);
SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(codec->getScanlineDecoder(info));
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, scanlineDecoder);
// Regular decodes should not be affected by creating a scanline decoder
result = codec->getPixels(info, bm.getPixels(), bm.rowBytes(), NULL, NULL, NULL);
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
compare_to_good_digest(r, digest, bm);
bm.eraseColor(SK_ColorYELLOW);
for (int y = 0; y < info.height(); y++) {
result = scanlineDecoder->getScanlines(bm.getAddr(0, y), 1, 0);
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
}
// verify that scanline decoding gives the same result.
compare_to_good_digest(r, digest, bm);
} else {
REPORTER_ASSERT(r, !scanlineDecoder);
}
// The rest of this function tests decoding subsets, and will decode an arbitrary number of
// random subsets.
// Do not attempt to decode subsets of an image of only once pixel, since there is no
// meaningful subset.
if (size.width() * size.height() == 1) {
return;
}
SkRandom rand;
SkIRect subset;
SkCodec::Options opts;
opts.fSubset = ⊂
for (int i = 0; i < 5; i++) {
subset = generate_random_subset(&rand, size.width(), size.height());
SkASSERT(!subset.isEmpty());
const bool supported = codec->getValidSubset(&subset);
REPORTER_ASSERT(r, supported == supportsSubsetDecoding);
SkImageInfo subsetInfo = info.makeWH(subset.width(), subset.height());
SkBitmap bm;
bm.allocPixels(subsetInfo);
const SkCodec::Result result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes(),
&opts, NULL, NULL);
if (supportsSubsetDecoding) {
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
// Webp is the only codec that supports subsets, and it will have modified the subset
// to have even left/top.
REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop));
} else {
// No subsets will work.
REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
}
}
}
示例10: main
int main (int argc, char * const argv[]) {
SkAutoGraphics ag;
const char* writePath = NULL; // if non-null, where we write the originals
const char* readPath = NULL; // if non-null, were we read from to compare
char* const* stop = argv + argc;
for (++argv; argv < stop; ++argv) {
if (strcmp(*argv, "-w") == 0) {
argv++;
if (argv < stop && **argv) {
writePath = *argv;
}
} else if (strcmp(*argv, "-r") == 0) {
argv++;
if (argv < stop && **argv) {
readPath = *argv;
}
}
}
Iter iter;
GM* gm;
while ((gm = iter.next()) != NULL) {
SkISize size = gm->getISize();
SkDebugf("creating... %s [%d %d]\n", gm->shortName(),
size.width(), size.height());
SkBitmap bitmap;
for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
bitmap.setConfig(gRec[i].fConfig, size.width(), size.height());
bitmap.allocPixels();
bitmap.eraseColor(0);
SkCanvas canvas(bitmap);
gm->draw(&canvas);
SkString name = make_name(gm->shortName(), gRec[i].fName);
if (writePath) {
SkString path = make_filename(writePath, name);
bool success = write_bitmap(path, bitmap);
if (!success) {
fprintf(stderr, "FAILED to write %s\n", path.c_str());
}
} else if (readPath) {
SkString path = make_filename(readPath, name);
SkBitmap orig;
bool success = SkImageDecoder::DecodeFile(path.c_str(), &orig,
SkBitmap::kARGB_8888_Config,
SkImageDecoder::kDecodePixels_Mode, NULL);
if (success) {
compare(bitmap, orig, name);
} else {
fprintf(stderr, "FAILED to read %s\n", path.c_str());
}
}
}
SkDELETE(gm);
}
return 0;
}
示例11: onDelayedSetup
void onDelayedSetup() override {
fBitmap.allocN32Pixels(fW, fH, true);
fBitmap.eraseColor(SK_ColorWHITE); // so we don't read uninitialized memory
}
示例12: doDecode
//.........这里部分代码省略.........
jintArray layoutBounds = NULL;
if (peeker.fLayoutBounds != NULL) {
layoutBounds = env->NewIntArray(4);
if (layoutBounds == NULL) {
return nullObjectReturn("layoutBounds == null");
}
jint scaledBounds[4];
if (willScale) {
for (int i=0; i<4; i++) {
scaledBounds[i] = (jint)((((jint*)peeker.fLayoutBounds)[i]*scale) + .5f);
}
} else {
memcpy(scaledBounds, (jint*)peeker.fLayoutBounds, sizeof(scaledBounds));
}
env->SetIntArrayRegion(layoutBounds, 0, 4, scaledBounds);
if (javaBitmap != NULL) {
env->SetObjectField(javaBitmap, gBitmap_layoutBoundsFieldID, layoutBounds);
}
}
if (willScale) {
// This is weird so let me explain: we could use the scale parameter
// directly, but for historical reasons this is how the corresponding
// Dalvik code has always behaved. We simply recreate the behavior here.
// The result is slightly different from simply using scale because of
// the 0.5f rounding bias applied when computing the target image size
const float sx = scaledWidth / float(decodingBitmap.width());
const float sy = scaledHeight / float(decodingBitmap.height());
// TODO: avoid copying when scaled size equals decodingBitmap size
SkBitmap::Config config = configForScaledOutput(decodingBitmap.config());
outputBitmap->setConfig(config, scaledWidth, scaledHeight);
outputBitmap->setIsOpaque(decodingBitmap.isOpaque());
if (!outputBitmap->allocPixels(outputAllocator, NULL)) {
return nullObjectReturn("allocation failed for scaled bitmap");
}
// If outputBitmap's pixels are newly allocated by Java, there is no need
// to erase to 0, since the pixels were initialized to 0.
if (outputAllocator != &javaAllocator) {
outputBitmap->eraseColor(0);
}
SkPaint paint;
paint.setFilterBitmap(true);
SkCanvas canvas(*outputBitmap);
canvas.scale(sx, sy);
canvas.drawBitmap(decodingBitmap, 0.0f, 0.0f, &paint);
} else {
outputBitmap->swap(decodingBitmap);
}
if (padding) {
if (peeker.fPatch != NULL) {
GraphicsJNI::set_jrect(env, padding,
peeker.fPatch->paddingLeft, peeker.fPatch->paddingTop,
peeker.fPatch->paddingRight, peeker.fPatch->paddingBottom);
} else {
GraphicsJNI::set_jrect(env, padding, -1, -1, -1, -1);
}
}
SkPixelRef* pr;
if (isPurgeable) {
pr = installPixelRef(outputBitmap, stream, sampleSize, doDither);
} else {
// if we get here, we're in kDecodePixels_Mode and will therefore
// already have a pixelref installed.
pr = outputBitmap->pixelRef();
}
if (pr == NULL) {
return nullObjectReturn("Got null SkPixelRef");
}
if (!isMutable && javaBitmap == NULL) {
// promise we will never change our pixels (great for sharing and pictures)
pr->setImmutable();
}
// detach bitmap from its autodeleter, since we want to own it now
adb.detach();
if (javaBitmap != NULL) {
bool isPremultiplied = !requireUnpremultiplied;
GraphicsJNI::reinitBitmap(env, javaBitmap, outputBitmap, isPremultiplied);
outputBitmap->notifyPixelsChanged();
// If a java bitmap was passed in for reuse, pass it back
return javaBitmap;
}
int bitmapCreateFlags = 0x0;
if (isMutable) bitmapCreateFlags |= GraphicsJNI::kBitmapCreateFlag_Mutable;
if (!requireUnpremultiplied) bitmapCreateFlags |= GraphicsJNI::kBitmapCreateFlag_Premultiplied;
// now create the java bitmap
return GraphicsJNI::createBitmap(env, outputBitmap, javaAllocator.getStorageObj(),
bitmapCreateFlags, ninePatchChunk, layoutBounds, -1);
}
示例13: onDraw
virtual void onDraw(SkCanvas* canvas)
{
if (true) {
SkRect r = { 0, 0, 1 << 30, 1 << 30 };
bool open = canvas->clipRect(r);
SkDebugf("---- giant clip is %d\n", open);
}
this->drawBG(canvas);
if (false) {
SkPaint paint;
paint.setAntiAlias(true);
SkBitmap bm;
bm.setConfig(SkBitmap::kA8_Config, 100, 100);
bm.allocPixels();
bm.eraseColor(0);
SkCanvas c(bm);
c.drawCircle(50, 50, 50, paint);
paint.setColor(SK_ColorBLUE);
canvas->drawBitmap(bm, 0, 0, &paint);
canvas->scale(SK_Scalar1/2, SK_Scalar1/2);
paint.setColor(SK_ColorRED);
canvas->drawBitmap(bm, 0, 0, &paint);
return;
}
#ifdef SK_DEBUG
if (true) {
SkRegion a, b, c;
test_union_bug_1505668(&a, &b, &c);
if (false) { // draw the result of the test
SkPaint paint;
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
paint.setColor(SK_ColorRED);
paint_rgn(canvas, a, paint);
paint.setColor(0x800000FF);
paint_rgn(canvas, b, paint);
paint.setColor(SK_ColorBLACK);
paint.setStyle(SkPaint::kStroke_Style);
// paint_rgn(canvas, c, paint);
return;
}
}
#endif
static const struct {
SkColor fColor;
const char* fName;
SkRegion::Op fOp;
} gOps[] = {
{ SK_ColorBLACK, "Difference", SkRegion::kDifference_Op },
{ SK_ColorRED, "Intersect", SkRegion::kIntersect_Op },
{ 0xFF008800, "Union", SkRegion::kUnion_Op },
{ SK_ColorBLUE, "XOR", SkRegion::kXOR_Op }
};
SkPaint textPaint;
textPaint.setAntiAlias(true);
textPaint.setTextSize(SK_Scalar1*24);
this->drawOrig(canvas, false);
canvas->save();
canvas->translate(SkIntToScalar(200), 0);
this->drawRgnOped(canvas, SkRegion::kUnion_Op, SK_ColorBLACK);
canvas->restore();
canvas->translate(0, SkIntToScalar(200));
for (int op = 0; op < SK_ARRAY_COUNT(gOps); op++)
{
canvas->drawText(gOps[op].fName, strlen(gOps[op].fName), SkIntToScalar(75), SkIntToScalar(50), textPaint);
this->drawRgnOped(canvas, gOps[op].fOp, gOps[op].fColor);
if (true)
{
canvas->save();
canvas->translate(0, SkIntToScalar(200));
this->drawPathOped(canvas, gOps[op].fOp, gOps[op].fColor);
canvas->restore();
}
canvas->translate(SkIntToScalar(200), 0);
}
}
示例14: check
static void check(skiatest::Reporter* r,
const char path[],
SkISize size,
bool supportsScanlineDecoding,
bool supportsSubsetDecoding,
bool supportsIncomplete = true) {
SkAutoTDelete<SkStream> stream(resource(path));
if (!stream) {
SkDebugf("Missing resource '%s'\n", path);
return;
}
SkAutoTDelete<SkCodec> codec(nullptr);
bool isIncomplete = supportsIncomplete;
if (isIncomplete) {
size_t size = stream->getLength();
sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
codec.reset(SkCodec::NewFromData(data.get()));
} else {
codec.reset(SkCodec::NewFromStream(stream.release()));
}
if (!codec) {
ERRORF(r, "Unable to decode '%s'", path);
return;
}
// Test full image decodes with SkCodec
SkMD5::Digest codecDigest;
const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
SkBitmap bm;
SkCodec::Result expectedResult = isIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nullptr);
// Scanline decoding follows.
// Need to call startScanlineDecode() first.
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
== 0);
const SkCodec::Result startResult = codec->startScanlineDecode(info);
if (supportsScanlineDecoding) {
bm.eraseColor(SK_ColorYELLOW);
REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
for (int y = 0; y < info.height(); y++) {
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, 1 == lines);
}
}
// verify that scanline decoding gives the same result.
if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) {
compare_to_good_digest(r, codecDigest, bm);
}
// Cannot continue to decode scanlines beyond the end
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
// Interrupting a scanline decode with a full decode starts from
// scratch
REPORTER_ASSERT(r, codec->startScanlineDecode(info) == SkCodec::kSuccess);
const int lines = codec->getScanlines(bm.getAddr(0, 0), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, lines == 1);
}
REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes())
== expectedResult);
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
== 0);
REPORTER_ASSERT(r, codec->skipScanlines(1)
== 0);
// Test partial scanline decodes
if (supports_partial_scanlines(path) && info.width() >= 3) {
SkCodec::Options options;
int width = info.width();
int height = info.height();
SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, height);
options.fSubset = ⊂
const SkCodec::Result partialStartResult = codec->startScanlineDecode(info, &options,
nullptr, nullptr);
REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
for (int y = 0; y < height; y++) {
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
if (!isIncomplete) {
REPORTER_ASSERT(r, 1 == lines);
}
}
}
} else {
REPORTER_ASSERT(r, startResult == SkCodec::kUnimplemented);
}
// The rest of this function tests decoding subsets, and will decode an arbitrary number of
//.........这里部分代码省略.........
示例15: initBitmap
static void initBitmap(SkBitmap& bitmap, uint32_t width, uint32_t height) {
bitmap.allocPixels(SkImageInfo::MakeA8(width, height));
bitmap.eraseColor(0);
}