@@ -537,6 +537,10 @@ static void blit_with_alpha(video::IImage *src, video::IImage *dst,
537
537
static void blit_with_alpha_overlay (video::IImage *src, video::IImage *dst,
538
538
v2s32 src_pos, v2s32 dst_pos, v2u32 size);
539
539
540
+ // Apply a mask to an image
541
+ static void apply_mask (video::IImage *mask, video::IImage *dst,
542
+ v2s32 mask_pos, v2s32 dst_pos, v2u32 size);
543
+
540
544
// Draw or overlay a crack
541
545
static void draw_crack (video::IImage *crack, video::IImage *dst,
542
546
bool use_overlay, s32 frame_count, s32 progression,
@@ -1557,6 +1561,31 @@ bool TextureSource::generateImagePart(std::string part_of_name,
1557
1561
baseimg->drop ();
1558
1562
baseimg = img;
1559
1563
}
1564
+ /*
1565
+ [mask:filename
1566
+ Applies a mask to an image
1567
+ */
1568
+ else if (part_of_name.substr (0 ,6 ) == " [mask:" )
1569
+ {
1570
+ if (baseimg == NULL ) {
1571
+ errorstream << " generateImage(): baseimg == NULL "
1572
+ << " for part_of_name=\" " << part_of_name
1573
+ << " \" , cancelling." << std::endl;
1574
+ return false ;
1575
+ }
1576
+ Strfnd sf (part_of_name);
1577
+ sf.next (" :" );
1578
+ std::string filename = sf.next (" :" );
1579
+
1580
+ video::IImage *img = m_sourcecache.getOrLoad (filename, m_device);
1581
+ if (img) {
1582
+ apply_mask (img, baseimg, v2s32 (0 , 0 ), v2s32 (0 , 0 ),
1583
+ img->getDimension ());
1584
+ } else {
1585
+ errorstream << " generateImage(): Failed to load \" "
1586
+ << filename << " \" ." ;
1587
+ }
1588
+ }
1560
1589
else
1561
1590
{
1562
1591
errorstream<<" generateImagePart(): Invalid "
@@ -1615,6 +1644,26 @@ static void blit_with_alpha_overlay(video::IImage *src, video::IImage *dst,
1615
1644
}
1616
1645
}
1617
1646
1647
+ /*
1648
+ Apply mask to destination
1649
+ */
1650
+ static void apply_mask (video::IImage *mask, video::IImage *dst,
1651
+ v2s32 mask_pos, v2s32 dst_pos, v2u32 size)
1652
+ {
1653
+ for (u32 y0 = 0 ; y0 < size.Y ; y0 ++) {
1654
+ for (u32 x0 = 0 ; x0 < size.X ; x0++) {
1655
+ s32 mask_x = x0 + mask_pos.X ;
1656
+ s32 mask_y = y0 + mask_pos.Y ;
1657
+ s32 dst_x = x0 + dst_pos.X ;
1658
+ s32 dst_y = y0 + dst_pos.Y ;
1659
+ video::SColor mask_c = mask->getPixel (mask_x, mask_y);
1660
+ video::SColor dst_c = dst->getPixel (dst_x, dst_y);
1661
+ dst_c.color &= mask_c.color ;
1662
+ dst->setPixel (dst_x, dst_y, dst_c);
1663
+ }
1664
+ }
1665
+ }
1666
+
1618
1667
static void draw_crack (video::IImage *crack, video::IImage *dst,
1619
1668
bool use_overlay, s32 frame_count, s32 progression,
1620
1669
video::IVideoDriver *driver)
0 commit comments