Commit 786e3cf2 authored by mercury233's avatar mercury233

Merge branch 'fh' into patch-image-resize

parents 7442beaf e234c058
......@@ -120,10 +120,12 @@ void ImageManager::ResizeTexture() {
void ImageManager::resizeImage(irr::video::IImage* src, irr::video::IImage* dest, bool use_threading) {
imageResizer.resize(src, dest, use_threading);
}
/** Convert image to texture, resizing if needed.
/**
* Convert image to texture, resizing if needed.
* @param name Texture name (Irrlicht texture key).
* @param srcimg Source image; will be dropped by this function.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`).
*/
irr::video::ITexture* ImageManager::addTexture(const char* name, irr::video::IImage* srcimg, irr::s32 width, irr::s32 height) {
if(srcimg == nullptr)
return nullptr;
......@@ -139,8 +141,10 @@ irr::video::ITexture* ImageManager::addTexture(const char* name, irr::video::IIm
srcimg->drop();
return texture;
}
/** Load image from file and convert to texture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
/**
* Load image from file and convert to texture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`).
*/
irr::video::ITexture* ImageManager::GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height) {
irr::video::IImage* img = driver->createImageFromFile(file);
if(img == nullptr) {
......@@ -150,9 +154,11 @@ irr::video::ITexture* ImageManager::GetTextureFromFile(const char* file, irr::s3
mysnprintf(name, "%s/%d_%d", file, width, height);
return addTexture(name, img, width, height);
}
/** Load card picture from `expansions` or `pics` folder.
/**
* Load card picture from `expansions` or `pics` folder.
* Files in the expansions directory have priority, allowing custom pictures to be loaded without modifying the original files.
* @return Image pointer. Must be dropped after use. */
* @return Image pointer. Must be dropped after use.
*/
irr::video::IImage* ImageManager::GetImage(int code) {
char file[256];
mysnprintf(file, "expansions/pics/%d.jpg", code);
......@@ -163,8 +169,10 @@ irr::video::IImage* ImageManager::GetImage(int code) {
}
return img;
}
/** Load card picture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`). */
/**
* Load card picture.
* @return Texture pointer. Remove via `driver->removeTexture` (do not `drop`).
*/
irr::video::ITexture* ImageManager::GetTexture(int code, irr::s32 width, irr::s32 height) {
irr::video::IImage* img = GetImage(code);
if(img == nullptr) {
......@@ -174,9 +182,11 @@ irr::video::ITexture* ImageManager::GetTexture(int code, irr::s32 width, irr::s3
mysnprintf(name, "pics/%d/%d_%d", code, width, height);
return addTexture(name, img, width, height);
}
/** Load managed card picture texture.
/**
* Load managed card picture texture.
* @param fit Resize to fit scale if true.
* @return Texture pointer. Should NOT be removed nor dropped. */
* @return Texture pointer. Should NOT be removed nor dropped.
*/
irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
if(code == 0)
return fit ? tUnknownFit : tUnknown;
......@@ -200,18 +210,20 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
else
return fit ? tUnknownFit : tUnknown;
}
/** Load managed card picture texture with zoom.
* @return Texture pointer. Should NOT be removed nor dropped. */
/**
* Load managed card picture texture with zoom.
* @return Texture pointer. Should NOT be removed nor dropped.
*/
irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
if(code == 0)
return tUnknown;
return tUnknownFit;
if(tBigPicture != nullptr) {
driver->removeTexture(tBigPicture);
tBigPicture = nullptr;
}
irr::video::IImage* img = GetImage(code);
if(img == nullptr) {
return tUnknown;
return tUnknownFit;
}
char name[256];
mysnprintf(name, "pics/%d/big", code);
......@@ -261,8 +273,10 @@ int ImageManager::LoadThumbThread() {
}
return 0;
}
/** Load managed card thumbnail texture.
* @return Texture pointer. Should NOT be removed nor dropped. */
/**
* Load managed card thumbnail texture.
* @return Texture pointer. Should NOT be removed nor dropped.
*/
irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(code == 0)
return tUnknownThumb;
......@@ -308,8 +322,10 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
else
return tUnknownThumb;
}
/** Load managed duel field texture.
* @return Texture pointer. Should NOT be removed nor dropped. */
/**
* Load managed duel field texture.
* @return Texture pointer. Should NOT be removed nor dropped.
*/
irr::video::ITexture* ImageManager::GetTextureField(int code) {
if(code == 0)
return nullptr;
......
......@@ -43,8 +43,10 @@ struct StbSamplerCache {
}
};
/** Scale image using stb_image_resize2.
* Returns true on success, false on failure or unsupported format. */
/**
* Scale image using stb_image_resize2.
* Returns true on success, false on failure or unsupported format.
*/
bool ImageResizer::imageScaleSTB(irr::video::IImage* src, irr::video::IImage* dest) {
if(!src || !dest)
return false;
......@@ -111,8 +113,10 @@ bool ImageResizer::imageScaleSTB(irr::video::IImage* src, irr::video::IImage* de
return ok != 0;
}
/** Scale image using nearest neighbor anti-aliasing.
* Function by Warr1024, from https://github.com/minetest/minetest/issues/2419, modified. */
/**
* Scale image using nearest neighbor anti-aliasing.
* Function by Warr1024, from https://github.com/minetest/minetest/issues/2419, modified.
*/
void ImageResizer::imageScaleNNAA(irr::video::IImage* src, irr::video::IImage* dest, bool use_threading) {
const auto& srcDim = src->getDimension();
const auto& destDim = dest->getDimension();
......
......@@ -8,8 +8,10 @@
#ifndef _WIN32
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <vector>
#include <algorithm>
#include <string>
#endif
#ifdef _WIN32
......@@ -182,7 +184,7 @@ public:
bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[1024];
int len = mysnprintf(full_path, "%s/%s", dir, name);
int len = std::snprintf(full_path, sizeof(full_path), "%s/%s", dir, name);
if (len < 0 || len >= (int)(sizeof full_path)) {
success = false;
return;
......@@ -228,7 +230,7 @@ public:
while((dirp = readdir(dir)) != nullptr) {
file_unit funit;
char fname[1024];
int len = mysnprintf(fname, "%s/%s", path, dirp->d_name);
int len = std::snprintf(fname, sizeof(fname), "%s/%s", path, dirp->d_name);
if (len < 0 || len >= (int)(sizeof fname))
continue;
stat(fname, &fileStat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment