video::IImage* TextureSource::generateImage(const std::string &name)
{
- /*
- Get the base image
- */
+ // Get the base image
const char separator = '^';
+ const char escape = '\\';
const char paren_open = '(';
const char paren_close = ')';
s32 last_separator_pos = -1;
u8 paren_bal = 0;
for (s32 i = name.size() - 1; i >= 0; i--) {
- switch(name[i]) {
+ if (i > 0 && name[i-1] == escape)
+ continue;
+ switch (name[i]) {
case separator:
if (paren_bal == 0) {
last_separator_pos = i;
return NULL;
}
core::dimension2d<u32> dim = tmp->getDimension();
- if (!baseimg)
- baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
- blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim);
- tmp->drop();
+ if (baseimg) {
+ blit_with_alpha(tmp, baseimg, v2s32(0, 0), v2s32(0, 0), dim);
+ tmp->drop();
+ } else {
+ baseimg = tmp;
+ }
} else if (!generateImagePart(last_part_of_name, baseimg)) {
// Generate image according to part of name
errorstream << "generateImage(): "
#endif
+static std::string unescape_string(const std::string &str, const char esc = '\\')
+{
+ std::string out;
+ size_t pos = 0, cpos;
+ out.reserve(str.size());
+ while (1) {
+ cpos = str.find_first_of(esc, pos);
+ if (cpos == std::string::npos) {
+ out += str.substr(pos);
+ break;
+ }
+ out += str.substr(pos, cpos - pos) + str[cpos + 1];
+ pos = cpos + 2;
+ }
+ return out;
+}
+
bool TextureSource::generateImagePart(std::string part_of_name,
video::IImage *& baseimg)
{
+ const char escape = '\\'; // same as in generateImage()
video::IVideoDriver* driver = m_device->getVideoDriver();
sanity_check(driver);
}
/*
[combine:WxH:X,Y=filename:X,Y=filename2
- Creates a bigger texture from an amount of smaller ones
+ Creates a bigger texture from any amount of smaller ones
*/
else if (str_starts_with(part_of_name, "[combine"))
{
sf.next(":");
u32 w0 = stoi(sf.next("x"));
u32 h0 = stoi(sf.next(":"));
- //infostream<<"combined w="<<w0<<" h="<<h0<<std::endl;
core::dimension2d<u32> dim(w0,h0);
if (baseimg == NULL) {
baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
while (sf.at_end() == false) {
u32 x = stoi(sf.next(","));
u32 y = stoi(sf.next("="));
- std::string filename = sf.next(":");
+ std::string filename = unescape_string(sf.next_esc(":", escape), escape);
infostream<<"Adding \""<<filename
<<"\" to combined ("<<x<<","<<y<<")"
<<std::endl;
- video::IImage *img = m_sourcecache.getOrLoad(filename, m_device);
+ video::IImage *img = generateImage(filename);
if (img) {
core::dimension2d<u32> dim = img->getDimension();
infostream<<"Size "<<dim.Width
}
}
/*
- "[brighten"
+ [brighten
*/
else if (str_starts_with(part_of_name, "[brighten"))
{
brighten(baseimg);
}
/*
- "[noalpha"
+ [noalpha
Make image completely opaque.
Used for the leaves texture when in old leaves mode, so
that the transparent parts don't look completely black
}
}
/*
- "[makealpha:R,G,B"
+ [makealpha:R,G,B
Convert one color to transparent.
*/
else if (str_starts_with(part_of_name, "[makealpha:"))
}
}
/*
- "[transformN"
+ [transformN
Rotates and/or flips the image.
N can be a number (between 0 and 7) or a transform name.
Strfnd sf(part_of_name);
sf.next(":");
u32 percent = stoi(sf.next(":"));
- std::string filename = sf.next(":");
- //infostream<<"power part "<<percent<<"%% of "<<filename<<std::endl;
+ std::string filename = unescape_string(sf.next_esc(":", escape), escape);
if (baseimg == NULL)
baseimg = driver->createImage(video::ECF_A8R8G8B8, v2u32(16,16));
- video::IImage *img = m_sourcecache.getOrLoad(filename, m_device);
+ video::IImage *img = generateImage(filename);
if (img)
{
core::dimension2d<u32> dim = img->getDimension();
}
Strfnd sf(part_of_name);
sf.next(":");
- std::string filename = sf.next(":");
+ std::string filename = unescape_string(sf.next_esc(":", escape), escape);
- video::IImage *img = m_sourcecache.getOrLoad(filename, m_device);
+ video::IImage *img = generateImage(filename);
if (img) {
apply_mask(img, baseimg, v2s32(0, 0), v2s32(0, 0),
img->getDimension());
apply_colorize(baseimg, v2u32(0, 0), baseimg->getDimension(), color, ratio, keep_alpha);
}
+ /*
+ [applyfiltersformesh
+ Internal modifier
+ */
else if (str_starts_with(part_of_name, "[applyfiltersformesh"))
{
// Apply the "clean transparent" filter, if configured.