diff --git a/include/bimg/decode.h b/include/bimg/decode.h index 09d389c..89b6f6d 100644 --- a/include/bimg/decode.h +++ b/include/bimg/decode.h @@ -35,9 +35,10 @@ namespace bimg /// /// @remarks /// Aspect ratio is always preserved. When both `_width` and `_height` are given the image is - /// scaled to fit inside of them. When both are 0 the image is rasterized at the size stated - /// in the document, scaled down if needed to fit inside of 4096x4096, which is also what - /// `bimg::imageParse` does. + /// scaled to fit inside of them. When both are 0 documents that fit inside of 4096x4096 are + /// rasterized at native scale, with pixel dimensions rounded to the nearest integer (half + /// up). Dimensions rounding to 0 are rejected. Larger documents are scaled down to fit + /// inside of 4096x4096. `bimg::imageParse` and `bimg::imageParseInfo` use the same size policy. /// ImageContainer* imageParseSvg( bx::AllocatorI* _allocator diff --git a/src/image_decode.cpp b/src/image_decode.cpp index 4e0ad56..e8fcae1 100644 --- a/src/image_decode.cpp +++ b/src/image_decode.cpp @@ -1599,14 +1599,19 @@ namespace bimg if (0 == _width && 0 == _height) { - _width = uint32_t(bx::ceil(bx::min(width, float(kSvgMaxSize) ) ) ); - _height = uint32_t(bx::ceil(bx::min(height, float(kSvgMaxSize) ) ) ); - if (width <= float(kSvgMaxSize) && height <= float(kSvgMaxSize) ) { - _outWidth = _width; - _outHeight = _height; + _outWidth = uint32_t(bx::floor(width + 0.5f) ); + _outHeight = uint32_t(bx::floor(height + 0.5f) ); + if (0 == _outWidth + || 0 == _outHeight) + { + nsvgDelete(image); + BX_ERROR_SET(_err, BIMG_ERROR, "SVG: Unsupported dimensions."); + return NULL; + } + _outScale = 1.0f; return image;