| 463 | } |
| 464 | |
| 465 | BitmapRef Cache::SpriteEffect(const BitmapRef& src_bitmap, const Rect& rect, bool flip_x, bool flip_y, const Tone& tone, const Color& blend) { |
| 466 | std::string id = ToString(src_bitmap->GetId()); |
| 467 | |
| 468 | if (id.empty()) { |
| 469 | // Log causes false positives when empty bitmaps or placeholder (checkerboard) |
| 470 | // bitmaps are used. |
| 471 | //Output::Debug("Bitmap has no ID. Please report a bug!"); |
| 472 | id = fmt::format("{}", (void*)(src_bitmap.get())); |
| 473 | } |
| 474 | |
| 475 | const effect_key_type key { |
| 476 | id, |
| 477 | src_bitmap->GetTransparent(), |
| 478 | rect, |
| 479 | flip_x, |
| 480 | flip_y, |
| 481 | tone, |
| 482 | blend |
| 483 | }; |
| 484 | |
| 485 | const auto it = cache_effects.find(key); |
| 486 | |
| 487 | if (it == cache_effects.end() || it->second.expired()) { |
| 488 | BitmapRef bitmap_effects; |
| 489 | |
| 490 | auto create = [&rect] () -> BitmapRef { |
| 491 | return Bitmap::Create(rect.width, rect.height, true); |
| 492 | }; |
| 493 | |
| 494 | if (tone != Tone()) { |
| 495 | bitmap_effects = create(); |
| 496 | bitmap_effects->ToneBlit(0, 0, *src_bitmap, rect, tone, Opacity::Opaque()); |
| 497 | } |
| 498 | |
| 499 | if (blend != Color()) { |
| 500 | if (bitmap_effects) { |
| 501 | // Tone blit was applied |
| 502 | bitmap_effects->BlendBlit(0, 0, *bitmap_effects, bitmap_effects->GetRect(), blend, Opacity::Opaque()); |
| 503 | } else { |
| 504 | bitmap_effects = create(); |
| 505 | bitmap_effects->BlendBlit(0, 0, *src_bitmap, rect, blend, Opacity::Opaque()); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | if (flip_x || flip_y) { |
| 510 | if (bitmap_effects) { |
| 511 | // Tone or blend blit was applied |
| 512 | bitmap_effects->Flip(flip_x, flip_y); |
| 513 | } else { |
| 514 | bitmap_effects = create(); |
| 515 | bitmap_effects->FlipBlit(0, 0, *src_bitmap, rect, flip_x, flip_y, Opacity::Opaque()); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | assert(bitmap_effects && "Effect cache used but no effect applied!"); |
| 520 | |
| 521 | return(cache_effects[key] = bitmap_effects).lock(); |
| 522 | } else { return it->second.lock(); } |
nothing calls this directly
no test coverage detected