+ /*
+ [resize:WxH
+ Resizes the base image to the given dimensions
+ */
+ else if (str_starts_with(part_of_name, "[resize"))
+ {
+ if (baseimg == NULL) {
+ errorstream << "generateImagePart(): baseimg == NULL "
+ << "for part_of_name=\""<< part_of_name
+ << "\", cancelling." << std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name);
+ sf.next(":");
+ u32 width = stoi(sf.next("x"));
+ u32 height = stoi(sf.next(""));
+ core::dimension2d<u32> dim(width, height);
+
+ video::IImage *image = RenderingEngine::get_video_driver()->
+ createImage(video::ECF_A8R8G8B8, dim);
+ baseimg->copyToScaling(image);
+ baseimg->drop();
+ baseimg = image;
+ }
+ /*
+ [opacity:R
+ Makes the base image transparent according to the given ratio.
+ R must be between 0 and 255.
+ 0 means totally transparent.
+ 255 means totally opaque.
+ */
+ else if (str_starts_with(part_of_name, "[opacity:")) {
+ if (baseimg == NULL) {
+ errorstream << "generateImagePart(): baseimg == NULL "
+ << "for part_of_name=\"" << part_of_name
+ << "\", cancelling." << std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name);
+ sf.next(":");
+
+ u32 ratio = mystoi(sf.next(""), 0, 255);
+
+ core::dimension2d<u32> dim = baseimg->getDimension();
+
+ for (u32 y = 0; y < dim.Height; y++)
+ for (u32 x = 0; x < dim.Width; x++)
+ {
+ video::SColor c = baseimg->getPixel(x, y);
+ c.setAlpha(floor((c.getAlpha() * ratio) / 255 + 0.5));
+ baseimg->setPixel(x, y, c);
+ }
+ }
+ /*
+ [invert:mode
+ Inverts the given channels of the base image.
+ Mode may contain the characters "r", "g", "b", "a".
+ Only the channels that are mentioned in the mode string
+ will be inverted.
+ */
+ else if (str_starts_with(part_of_name, "[invert:")) {
+ if (baseimg == NULL) {
+ errorstream << "generateImagePart(): baseimg == NULL "
+ << "for part_of_name=\"" << part_of_name
+ << "\", cancelling." << std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name);
+ sf.next(":");
+
+ std::string mode = sf.next("");
+ u32 mask = 0;
+ if (mode.find('a') != std::string::npos)
+ mask |= 0xff000000UL;
+ if (mode.find('r') != std::string::npos)
+ mask |= 0x00ff0000UL;
+ if (mode.find('g') != std::string::npos)
+ mask |= 0x0000ff00UL;
+ if (mode.find('b') != std::string::npos)
+ mask |= 0x000000ffUL;
+
+ core::dimension2d<u32> dim = baseimg->getDimension();
+
+ for (u32 y = 0; y < dim.Height; y++)
+ for (u32 x = 0; x < dim.Width; x++)
+ {
+ video::SColor c = baseimg->getPixel(x, y);
+ c.color ^= mask;
+ baseimg->setPixel(x, y, c);
+ }
+ }
+ /*
+ [sheet:WxH:X,Y
+ Retrieves a tile at position X,Y (in tiles)
+ from the base image it assumes to be a
+ tilesheet with dimensions W,H (in tiles).
+ */
+ else if (part_of_name.substr(0,7) == "[sheet:") {
+ if (baseimg == NULL) {
+ errorstream << "generateImagePart(): baseimg != NULL "
+ << "for part_of_name=\"" << part_of_name
+ << "\", cancelling." << std::endl;
+ return false;
+ }
+
+ Strfnd sf(part_of_name);
+ sf.next(":");
+ u32 w0 = stoi(sf.next("x"));
+ u32 h0 = stoi(sf.next(":"));
+ u32 x0 = stoi(sf.next(","));
+ u32 y0 = stoi(sf.next(":"));
+
+ core::dimension2d<u32> img_dim = baseimg->getDimension();
+ core::dimension2d<u32> tile_dim(v2u32(img_dim) / v2u32(w0, h0));
+
+ video::IImage *img = driver->createImage(
+ video::ECF_A8R8G8B8, tile_dim);
+ if (!img) {
+ errorstream << "generateImagePart(): Could not create image "
+ << "for part_of_name=\"" << part_of_name
+ << "\", cancelling." << std::endl;
+ return false;
+ }
+
+ img->fill(video::SColor(0,0,0,0));
+ v2u32 vdim(tile_dim);
+ core::rect<s32> rect(v2s32(x0 * vdim.X, y0 * vdim.Y), tile_dim);
+ baseimg->copyToWithAlpha(img, v2s32(0), rect,
+ video::SColor(255,255,255,255), NULL);
+
+ // Replace baseimg
+ baseimg->drop();
+ baseimg = img;
+ }