DitherBitmapView() { fResult = test_pathregion(); fBM8 = make_bitmap(); fBM8.copyTo(&fBM32, kN32_SkColorType); this->setBGColor(0xFFDDDDDD); }
virtual void onDraw(SkCanvas* canvas) { SkBitmap bm; SkIRect center; make_bitmap(&bm, ¢er); // amount of bm that should not be stretched (unless we have to) const SkScalar fixed = SkIntToScalar(bm.width() - center.width()); const SkTSize<SkScalar> size[] = { { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes { fixed * 4 / 5, fixed * 4 }, // shrink in X { fixed * 4, fixed * 4 / 5 }, // shrink in Y { fixed * 4, fixed * 4 } }; canvas->drawBitmap(bm, SkIntToScalar(10), SkIntToScalar(10), NULL); SkScalar x = SkIntToScalar(100); SkScalar y = SkIntToScalar(100); SkPaint paint; paint.setFilterLevel(SkPaint::kLow_FilterLevel); for (int iy = 0; iy < 2; ++iy) { for (int ix = 0; ix < 2; ++ix) { int i = ix * 2 + iy; SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed, size[i].width(), size[i].height()); canvas->drawBitmapNine(bm, center, r, &paint); } } }
virtual void onDrawContent(SkCanvas* canvas) { SkRect srcR; srcR.set(fSrcPts[0], fSrcPts[1]); srcR = SkRect::MakeXYWH(fSrcPts[0].fX, fSrcPts[0].fY, 32, 32); srcR.offset(-srcR.width()/2, -srcR.height()/2); SkPaint paint; paint.setStyle(SkPaint::kStroke_Style); paint.setColor(SK_ColorYELLOW); SkBitmap bitmap; make_bitmap(&bitmap); canvas->translate(20, 20); canvas->drawBitmap(bitmap, 0, 0, &paint); canvas->drawRect(srcR, paint); for (int i = 0; i < 2; ++i) { paint.setFilterLevel(1 == i ? SkPaint::kLow_FilterLevel : SkPaint::kNone_FilterLevel); canvas->drawBitmapRectToRect(bitmap, &srcR, fDstR[i], &paint); canvas->drawRect(fDstR[i], paint); } this->bounce(); this->inval(NULL); }
void onOnceBeforeDraw() override { make_bitmap(); fCheckerboard.allocN32Pixels(80, 80); SkCanvas checkerboardCanvas(fCheckerboard); sk_tool_utils::draw_checkerboard(&checkerboardCanvas, 0xFFA0A0A0, 0xFF404040, 8); }
// https://bug.skia.org/2894 DEF_TEST(BitmapCache_add_rect, reporter) { SkResourceCache::DiscardableFactory factory = SkResourceCache::GetDiscardableFactory(); SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); SkAutoTDelete<SkResourceCache> cache; if (factory) { cache.reset(new SkResourceCache(factory)); } else { const size_t byteLimit = 100 * 1024; cache.reset(new SkResourceCache(byteLimit)); } SkBitmap cachedBitmap; make_bitmap(&cachedBitmap, SkImageInfo::MakeN32Premul(5, 5), allocator); cachedBitmap.setImmutable(); SkBitmap bm; SkIRect rect = SkIRect::MakeWH(5, 5); uint32_t cachedID = cachedBitmap.getGenerationID(); SkPixelRef* cachedPR = cachedBitmap.pixelRef(); // Wrong subset size REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeWH(4, 6), cachedBitmap, cache)); REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); // Wrong offset value REPORTER_ASSERT(reporter, !SkBitmapCache::Add(cachedPR, SkIRect::MakeXYWH(-1, 0, 5, 5), cachedBitmap, cache)); REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); // Should not be in the cache REPORTER_ASSERT(reporter, !SkBitmapCache::Find(cachedID, rect, &bm, cache)); REPORTER_ASSERT(reporter, SkBitmapCache::Add(cachedPR, rect, cachedBitmap, cache)); // Should be in the cache, we just added it REPORTER_ASSERT(reporter, SkBitmapCache::Find(cachedID, rect, &bm, cache)); }
void onPreDraw() override { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } }
DitherBitmapView() { test_pathregion(); fBM8 = make_bitmap(); fBM8.copyTo(&fBM32, SkBitmap::kARGB_8888_Config); this->setBGColor(0xFFDDDDDD); }
static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { canvas->save(); canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(kBitmapSize), SkIntToScalar(kBitmapSize))); canvas->drawBitmap(make_bitmap(), SkIntToScalar(x), SkIntToScalar(y), &paint); canvas->restore(); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; int x = 0, y = 0; for (size_t i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkRect srcRect = SkRect::MakeXYWH(SkIntToScalar(bitmap->width()/4), SkIntToScalar(bitmap->height()/4), SkIntToScalar(bitmap->width()/(i+1)), SkIntToScalar(bitmap->height()/(i+1))); SkRect dstRect = SkRect::MakeXYWH(SkIntToScalar(i * 8), SkIntToScalar(i * 4), SkIntToScalar(bitmap->width() - i * 12), SkIntToScalar(bitmap->height()) - i * 12); SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap)); SkAutoTUnref<SkImageFilter> filter( SkTileImageFilter::Create(srcRect, dstRect, tileInput)); canvas->save(); canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); paint.setImageFilter(filter); canvas->drawBitmap(fBitmap, 0, 0, &paint); canvas->restore(); x += bitmap->width() + MARGIN; if (x + bitmap->width() > WIDTH) { x = 0; y += bitmap->height() + MARGIN; } } }
uint32_t make_new_subseqs(void) { uint32_t i, t_count; assert(subseq_count == 0); subseq_Q = 1; m_low = n_min; m_high = n_max; subseq_count = seq_count; SUBSEQ = xmalloc(subseq_count*sizeof(subseq_t)); for (i = 0, t_count = 0; i < seq_count; i++) { assert(SEQ[i].type == seq_none); SUBSEQ[i].seq = i; SUBSEQ[i].d = 0; SUBSEQ[i].filter = 0; SUBSEQ[i].mcount = n_max-n_min+1; SUBSEQ[i].M = make_bitmap(SUBSEQ[i].mcount); SUBSEQ[i].a = 1; SUBSEQ[i].b = 0; fill_bits(SUBSEQ[i].M,0,SUBSEQ[i].mcount-1); SEQ[i].type = seq_bitmap; t_count += SUBSEQ[i].mcount; } return t_count; }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; for (int i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(i * 12, i * 8, bitmap->width() - i * 8, bitmap->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkBitmapSource::Create(*bitmap)); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter( SkOffsetImageFilter::Create(dx, dy, tileInput, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, *bitmap, paint, SK_Scalar1, cropRect); canvas->translate(SkIntToScalar(bitmap->width() + MARGIN), 0); } SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> filter( SkOffsetImageFilter::Create(SkIntToScalar(-5), SkIntToScalar(-10), NULL, &rect)); paint.setImageFilter(filter); drawClippedBitmap(canvas, fBitmap, paint, SkIntToScalar(2), cropRect); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } canvas->clear(0x00000000); SkPaint paint; int x = 0, y = 0; for (size_t i = 0; i < 4; i++) { SkBitmap* bitmap = (i & 0x01) ? &fCheckerboard : &fBitmap; SkIRect cropRect = SkIRect::MakeXYWH(x + i * 12, y + i * 8, bitmap->width() - i * 8, bitmap->height() - i * 12); SkImageFilter::CropRect rect(SkRect::Make(cropRect)); SkAutoTUnref<SkImageFilter> tileInput(SkNEW_ARGS(SkBitmapSource, (*bitmap))); SkScalar dx = SkIntToScalar(i*5); SkScalar dy = SkIntToScalar(i*10); SkAutoTUnref<SkImageFilter> filter(SkNEW_ARGS( SkOffsetImageFilter, (dx, dy, tileInput, &rect))); paint.setImageFilter(filter); drawClippedBitmap(canvas, *bitmap, paint, SkIntToScalar(x), SkIntToScalar(y)); x += bitmap->width() + MARGIN; if (x + bitmap->width() > WIDTH) { x = 0; y += bitmap->height() + MARGIN; } } }
void onDelayedSetup() override { if (!fInitialized) { make_bitmap(); make_checkerboard(); fInitialized = true; } }
//------------------------------------------------------------------------ bool platform_specific::handle_input() { int16 code = 0; uint32 result = 0; Object* obj = reinterpret_cast<Object*>(m_window_obj); while ( (result = IIntuition->IDoMethod(obj, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG ) { switch ( result & WMHI_CLASSMASK ) { case WMHI_CLOSEWINDOW: return true; break; case WMHI_INTUITICK: if ( !m_support.wait_mode() ) { m_support.on_idle(); } break; case WMHI_NEWSIZE: if ( make_bitmap() ) { m_support.trans_affine_resizing(m_width, m_height); m_support.on_resize(m_width, m_height); m_support.force_redraw(); } break; } } return false; }
static void make_paint(SkPaint* paint, SkShader::TileMode tm) { SkBitmap bm; make_bitmap(&bm); SkShader* shader = SkShader::CreateBitmapShader(bm, tm, tm); paint->setShader(shader)->unref(); }
void onDrawContent(SkCanvas* canvas) override { SkRect srcR; srcR.set(fSrcPts[0], fSrcPts[1]); srcR = SkRect::MakeXYWH(fSrcPts[0].fX, fSrcPts[0].fY, 32, 32); srcR.offset(-srcR.width()/2, -srcR.height()/2); SkPaint paint; paint.setStyle(SkPaint::kStroke_Style); paint.setColor(SK_ColorYELLOW); SkBitmap bitmap; make_bitmap(&bitmap); canvas->translate(20, 20); canvas->drawBitmap(bitmap, 0, 0, &paint); canvas->drawRect(srcR, paint); for (int i = 0; i < 2; ++i) { paint.setFilterQuality(1 == i ? kLow_SkFilterQuality : kNone_SkFilterQuality); canvas->drawBitmapRect(bitmap, srcR, fDstR[i], &paint, SkCanvas::kStrict_SrcRectConstraint); canvas->drawRect(fDstR[i], paint); } }
void init() { if (fInited) { return; } fInited = true; // Create the original bitmap. make_bitmap(quarterWidth, quarterHeight, &origBitmap); }
void make_bitmaps() { make_bitmap(); make_checkerboard(&fCheckerboard, 80, 80); make_checkerboard(&fSmall, 64, 64); make_checkerboard(&fLarge, 96, 96); make_checkerboard(&fLargeW, 96, 64); make_checkerboard(&fLargeH, 64, 96); }
errcode_t ext2fs_allocate_generic_bitmap(__u32 start, __u32 end, __u32 real_end, const char *descr, ext2fs_generic_bitmap *ret) { return make_bitmap(start, end, real_end, descr, 0, ret); }
virtual void onDraw(SkCanvas* canvas) { SkBitmap bm = make_bitmap(); SkShader* s = SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode); SkPaint paint; paint.setAlpha(0x80); paint.setShader(s)->unref(); canvas->drawPaint(paint); }
int main (int argc, char **argv) { SkAutoGraphics ag; SkBitmap bitmap = make_bitmap(80, 80); drawInBitmap(bitmap); if (!save_bitmap("/Users/phryne/Desktop/c0071fce_icon.png", bitmap)) { cout << "Failed to generate image " << endl; } return 0 ; }
errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src, ext2fs_generic_bitmap *dest) { errcode_t retval; ext2fs_generic_bitmap new_map; retval = make_bitmap(src->start, src->end, src->real_end, src->description, src->bitmap, &new_map); if (retval) return retval; new_map->magic = src->magic; new_map->fs = src->fs; new_map->base_error_code = src->base_error_code; *dest = new_map; return 0; }
static void drawSomething(SkCanvas* canvas) { SkPaint paint; canvas->save(); canvas->scale(0.5f, 0.5f); canvas->drawBitmap(make_bitmap(), 0, 0, nullptr); canvas->restore(); paint.setAntiAlias(true); paint.setColor(SK_ColorRED); canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/3), paint); paint.setColor(SK_ColorBLACK); paint.setTextSize(SkIntToScalar(kBitmapSize/3)); canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); fInitialized = true; } canvas->clear(0x00000000); SkIPoint target = SkIPoint::Make(1, 0); for (int x = 10; x < 310; x += 100) { draw(canvas, x, 10, target, SkMatrixConvolutionImageFilter::kClamp_TileMode, true); draw(canvas, x, 110, target, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true); draw(canvas, x, 210, target, SkMatrixConvolutionImageFilter::kRepeat_TileMode, true); target.fY++; } target.fY = 1; draw(canvas, 310, 10, target, SkMatrixConvolutionImageFilter::kClamp_TileMode, false); draw(canvas, 310, 110, target, SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, false); draw(canvas, 310, 210, target, SkMatrixConvolutionImageFilter::kRepeat_TileMode, false); }
static void drawSomething(SkCanvas* canvas) { SkPaint paint; canvas->save(); canvas->scale(0.5f, 0.5f); canvas->drawBitmap(make_bitmap(), 0, 0, NULL); canvas->restore(); const char beforeStr[] = "before circle"; const char afterStr[] = "after circle"; paint.setAntiAlias(true); paint.setColor(SK_ColorRED); canvas->drawData(beforeStr, sizeof(beforeStr)); canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/3), paint); canvas->drawData(afterStr, sizeof(afterStr)); paint.setColor(SK_ColorBLACK); paint.setTextSize(SkIntToScalar(kBitmapSize/3)); canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/4), paint); }
void SwatchView::MouseDown(BPoint where) { if (!IsEnabled()) return; // BMessage *mesg = Window()->CurrentMessage(); // int32 clicks = mesg->FindInt32("clicks"); // if (m_clicks == clicks) // SetColorWindow(ICommon, m_name, m_color, this); BPoint w2; uint32 mods; while(true) { GetMouse(&w2, &mods); if (!mods) //releasing the buttons without moving means no drag { Invoke(); return; } if (w2 != where) break; } snooze(40000); BMessage msg(B_PASTE); msg.AddData("RGBColor",B_RGB_COLOR_TYPE,(const void**)&m_color,sizeof(rgb_color)); BString s = RGBtoText(m_color); msg.AddData("text/plain",B_MIME_DATA,(const void**)s.String(),s.Length()); msg.AddString("be:types", "text/plain"); msg.AddInt32("be:actions", B_COPY_TARGET); msg.AddInt32("be:actions", B_TRASH_TARGET); BBitmap *bitmap = make_bitmap(); BPoint pt(bitmap->Bounds().Width()/2.0, bitmap->Bounds().Height()/2); DragMessage(&msg, bitmap, B_OP_ALPHA, pt, Window()); }
virtual void onDraw(SkCanvas* canvas) { if (!fOnce) { make_bitmap(); fOnce = true; } struct { int fWidth, fHeight; int fRadiusX, fRadiusY; } samples[] = { { 140, 140, 0, 0 }, { 140, 140, 0, 2 }, { 140, 140, 2, 0 }, { 140, 140, 2, 2 }, { 24, 24, 25, 25 }, }; SkPaint paint; for (unsigned j = 0; j < 2; ++j) { for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { SkScalar x = SkIntToScalar(i * 140), y = SkIntToScalar(j * 140); if (j) { paint.setImageFilter(new SkErodeImageFilter( samples[i].fRadiusX, samples[i].fRadiusY))->unref(); } else { paint.setImageFilter(new SkDilateImageFilter( samples[i].fRadiusX, samples[i].fRadiusY))->unref(); } SkRect bounds = SkRect::MakeXYWH( x, y, SkIntToScalar(samples[i].fWidth), SkIntToScalar(samples[i].fHeight)); canvas->saveLayer(&bounds, &paint); canvas->drawBitmap(fBitmap, x, y); canvas->restore(); } } }
DEF_TEST(MipMap, reporter) { SkBitmap bm; SkRandom rand; for (int i = 0; i < 500; ++i) { int width = 1 + rand.nextU() % 1000; int height = 1 + rand.nextU() % 1000; make_bitmap(&bm, width, height); SkAutoTUnref<SkMipMap> mm(SkMipMap::Build(bm, nullptr)); REPORTER_ASSERT(reporter, mm->countLevels() == SkMipMap::ComputeLevelCount(width, height)); REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1, SK_Scalar1), nullptr)); REPORTER_ASSERT(reporter, !mm->extractLevel(SkSize::Make(SK_Scalar1 * 2, SK_Scalar1 * 2), nullptr)); SkMipMap::Level prevLevel; sk_bzero(&prevLevel, sizeof(prevLevel)); SkScalar scale = SK_Scalar1; for (int j = 0; j < 30; ++j) { scale = scale * 2 / 3; SkMipMap::Level level; if (mm->extractLevel(SkSize::Make(scale, scale), &level)) { REPORTER_ASSERT(reporter, level.fPixmap.addr()); REPORTER_ASSERT(reporter, level.fPixmap.width() > 0); REPORTER_ASSERT(reporter, level.fPixmap.height() > 0); REPORTER_ASSERT(reporter, (int)level.fPixmap.rowBytes() >= level.fPixmap.width() * 4); if (prevLevel.fPixmap.addr()) { REPORTER_ASSERT(reporter, level.fPixmap.width() <= prevLevel.fPixmap.width()); REPORTER_ASSERT(reporter, level.fPixmap.height() <= prevLevel.fPixmap.height()); } prevLevel = level; } } } }
virtual void onDraw(SkCanvas* canvas) { if (!fOnce) { make_bitmap(); fOnce = true; } struct { int fWidth, fHeight; int fRadiusX, fRadiusY; } samples[] = { { 140, 140, 0, 0 }, { 140, 140, 0, 2 }, { 140, 140, 2, 0 }, { 140, 140, 2, 2 }, { 24, 24, 25, 25 }, }; SkPaint paint; SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(25, 20, 100, 80)); for (unsigned j = 0; j < 4; ++j) { for (unsigned i = 0; i < SK_ARRAY_COUNT(samples); ++i) { const SkImageFilter::CropRect* cr = j & 0x02 ? &cropRect : NULL; if (j & 0x01) { paint.setImageFilter(SkErodeImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } else { paint.setImageFilter(SkDilateImageFilter::Create( samples[i].fRadiusX, samples[i].fRadiusY, NULL, cr))->unref(); } drawClippedBitmap(canvas, paint, i * 140, j * 140); } } }
virtual void onDraw(SkCanvas* canvas) { if (!fInitialized) { make_bitmap(); fInitialized = true; } canvas->clear(SK_ColorBLACK); SkIPoint kernelOffset = SkIPoint::Make(1, 0); for (int x = 10; x < 310; x += 100) { this->draw(canvas, x, 10, kernelOffset, MCIF::kClamp_TileMode, true); this->draw(canvas, x, 110, kernelOffset, MCIF::kClampToBlack_TileMode, true); this->draw(canvas, x, 210, kernelOffset, MCIF::kRepeat_TileMode, true); kernelOffset.fY++; } kernelOffset.fY = 1; SkImageFilter::CropRect rect(SkRect::MakeXYWH(10, 5, 60, 60)); this->draw(canvas, 310, 10, kernelOffset, MCIF::kClamp_TileMode, true, &rect); this->draw(canvas, 310, 110, kernelOffset, MCIF::kClampToBlack_TileMode, true, &rect); this->draw(canvas, 310, 210, kernelOffset, MCIF::kRepeat_TileMode, true, &rect); this->draw(canvas, 410, 10, kernelOffset, MCIF::kClamp_TileMode, false); this->draw(canvas, 410, 110, kernelOffset, MCIF::kClampToBlack_TileMode, false); this->draw(canvas, 410, 210, kernelOffset, MCIF::kRepeat_TileMode, false); }