Optimize the editor icon generation

Icons are no longer upsampled when using an integer editor scale.
This makes some icons slightly less crisp, but the icons themselves
can be adjusted to mitigate this. When using a non-integer editor
scale setting, upsampling is kept as it improves crispness in a
far more visible manner.

When upsampling is disabled, this speeds up the theme generation
by about 100 ms on average, making the project manager and editor
start slightly faster. This also speeds up switching between themes.
This commit is contained in:
Hugo Locurcio
2020-01-19 23:21:49 +01:00
parent 62d656ea06
commit 9e3393a624
2 changed files with 64 additions and 48 deletions

View File

@ -103,15 +103,17 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t
ERR_PRINT("SVG Corrupted");
return ERR_FILE_CORRUPT;
}
if (convert_colors)
if (convert_colors) {
_convert_colors(svg_image);
}
float upscale = upsample ? 2.0 : 1.0;
const float upscale = upsample ? 2.0 : 1.0;
int w = (int)(svg_image->width * p_scale * upscale);
const int w = (int)(svg_image->width * p_scale * upscale);
ERR_FAIL_COND_V_MSG(w > Image::MAX_WIDTH, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max width.", rtos(p_scale)));
int h = (int)(svg_image->height * p_scale * upscale);
const int h = (int)(svg_image->height * p_scale * upscale);
ERR_FAIL_COND_V_MSG(h > Image::MAX_HEIGHT, ERR_PARAMETER_RANGE_ERROR, vformat("Can't create image from SVG with scale %s, the resulting image size exceeds max height.", rtos(p_scale)));
PoolVector<uint8_t> dst_image;
@ -123,8 +125,9 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const PoolVector<uint8_t
dw.release();
p_image->create(w, h, false, Image::FORMAT_RGBA8, dst_image);
if (upsample)
if (upsample) {
p_image->shrink_x2();
}
nsvgDelete(svg_image);