From d9362fe764c31ffbac1be835d4cb2b23017573a0 Mon Sep 17 00:00:00 2001 From: guptaaarushg Date: Fri, 27 Nov 2026 00:21:21 -0800 Subject: [PATCH] imgcodecs: port PFM locale fix to 5.x --- modules/imgcodecs/src/grfmt_pfm.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_pfm.cpp b/modules/imgcodecs/src/grfmt_pfm.cpp index baa0108081..53ef5d677c 100644 --- a/modules/imgcodecs/src/grfmt_pfm.cpp +++ b/modules/imgcodecs/src/grfmt_pfm.cpp @@ -5,7 +5,7 @@ #include "precomp.hpp" #include "utils.hpp" #include "grfmt_pfm.hpp" -#include +#include #ifdef HAVE_IMGCODEC_PFM @@ -64,11 +64,10 @@ T read_number(cv::RLByteStream& strm) return atoT(str); } -template bool write_anything(cv::WLByteStream& strm, const T& t) +bool write_integer(cv::WLByteStream& strm, int value) { - std::ostringstream ss; - ss << t; - return strm.putBytes(ss.str().c_str(), static_cast(ss.str().size())); + const std::string text = std::to_string(value); + return strm.putBytes(text.c_str(), static_cast(text.size())); } } @@ -220,20 +219,19 @@ bool PFMEncoder::write(const Mat& img, const std::vector& params) CHECK_WRITE(strm.putByte('\n')); - CHECK_WRITE(write_anything(strm, float_img.cols)); + CHECK_WRITE(write_integer(strm, float_img.cols)); CHECK_WRITE(strm.putByte(' ')); - CHECK_WRITE(write_anything(strm, float_img.rows)); + CHECK_WRITE(write_integer(strm, float_img.rows)); CHECK_WRITE(strm.putByte('\n')); #ifdef WORDS_BIGENDIAN - CHECK_WRITE(write_anything(strm, 1.0)); + CHECK_WRITE(write_integer(strm, 1)); #else - CHECK_WRITE(write_anything(strm, -1.0)); + CHECK_WRITE(write_integer(strm, -1)); #endif CHECK_WRITE(strm.putByte('\n')); // Comments are not officially supported in this file format. - // write_anything(strm, "# Generated by OpenCV " CV_VERSION "\n"); for (int y = float_img.rows - 1; y >= 0; --y) {