diff options
Diffstat (limited to 'src/tile.cpp')
-rw-r--r-- | src/tile.cpp | 113 |
1 files changed, 21 insertions, 92 deletions
diff --git a/src/tile.cpp b/src/tile.cpp index f7d577b1f..206d81289 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -1361,14 +1361,14 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, } } /* - "[makealpha:R,G,B:filename.png" - Use an image with converting one color to transparent. + "[makealpha:R,G,B" + Convert one color to transparent. */ else if(part_of_name.substr(0,11) == "[makealpha:") { - if(baseimg != NULL) + if(baseimg == NULL) { - errorstream<<"generate_image(): baseimg!=NULL " + errorstream<<"generate_image(): baseimg==NULL " <<"for part_of_name=\""<<part_of_name <<"\", cancelling."<<std::endl; return false; @@ -1377,99 +1377,28 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg, Strfnd sf(part_of_name.substr(11)); u32 r1 = stoi(sf.next(",")); u32 g1 = stoi(sf.next(",")); - u32 b1 = stoi(sf.next(":")); + u32 b1 = stoi(sf.next("")); std::string filename = sf.next(""); - /*infostream<<"generate_image(): Loading file \""<<filename - <<"\""<<std::endl;*/ - - video::IImage *image = sourcecache->getOrLoad(filename, device); + core::dimension2d<u32> dim = baseimg->getDimension(); - if(image == NULL) - { - errorstream<<"generate_image(): Loading file \"" - <<filename<<"\" failed"<<std::endl; - } - else - { - core::dimension2d<u32> dim = image->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - - // Blit - image->copyTo(baseimg); - - image->drop(); - - for(u32 y=0; y<dim.Height; y++) - for(u32 x=0; x<dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x,y); - u32 r = c.getRed(); - u32 g = c.getGreen(); - u32 b = c.getBlue(); - if(!(r == r1 && g == g1 && b == b1)) - continue; - c.setAlpha(0); - baseimg->setPixel(x,y,c); - } - } - } - /* - "[makealpha2:R,G,B;R2,G2,B2:filename.png" - Use an image with converting two colors to transparent. - */ - else if(part_of_name.substr(0,12) == "[makealpha2:") - { - if(baseimg != NULL) - { - errorstream<<"generate_image(): baseimg!=NULL " - <<"for part_of_name=\""<<part_of_name - <<"\", cancelling."<<std::endl; - return false; - } - - Strfnd sf(part_of_name.substr(12)); - u32 r1 = stoi(sf.next(",")); - u32 g1 = stoi(sf.next(",")); - u32 b1 = stoi(sf.next(";")); - u32 r2 = stoi(sf.next(",")); - u32 g2 = stoi(sf.next(",")); - u32 b2 = stoi(sf.next(":")); - std::string filename = sf.next(""); + /*video::IImage *oldbaseimg = baseimg; + baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); + oldbaseimg->copyTo(baseimg); + oldbaseimg->drop();*/ - /*infostream<<"generate_image(): Loading filename \""<<filename - <<"\""<<std::endl;*/ - - video::IImage *image = sourcecache->getOrLoad(filename, device); - - if(image == NULL) - { - errorstream<<"generate_image(): Loading file \"" - <<filename<<"\" failed"<<std::endl; - } - else + // Set alpha to full + for(u32 y=0; y<dim.Height; y++) + for(u32 x=0; x<dim.Width; x++) { - core::dimension2d<u32> dim = image->getDimension(); - baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); - - // Blit - image->copyTo(baseimg); - - image->drop(); - - for(u32 y=0; y<dim.Height; y++) - for(u32 x=0; x<dim.Width; x++) - { - video::SColor c = baseimg->getPixel(x,y); - u32 r = c.getRed(); - u32 g = c.getGreen(); - u32 b = c.getBlue(); - if(!(r == r1 && g == g1 && b == b1) && - !(r == r2 && g == g2 && b == b2)) - continue; - c.setAlpha(0); - baseimg->setPixel(x,y,c); - } + video::SColor c = baseimg->getPixel(x,y); + u32 r = c.getRed(); + u32 g = c.getGreen(); + u32 b = c.getBlue(); + if(!(r == r1 && g == g1 && b == b1)) + continue; + c.setAlpha(0); + baseimg->setPixel(x,y,c); } } /* |