Skip to content

Commit 0ddbba7

Browse files
committed
DATV modulator: fixed still image timestamp implementation to be portable. Fixes PR #2586
1 parent 005ef99 commit 0ddbba7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

plugins/channeltx/moddatv/tsgenerator.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ extern "C"
3333

3434
#include <opencv2/opencv.hpp> // Add OpenCV for text overlay
3535

36+
#include <QDateTime>
37+
3638
#include "tsgenerator.h"
3739

3840
const double TSGenerator::rate_qpsk[11][4] = {{1.0, 4.0, 12.0, 2}, {1.0, 3.0, 12.0, 2}, {2.0, 5.0, 12.0, 2}, {1.0, 2.0, 12.0, 2}, {3.0, 5.0, 12.0, 2}, {2.0, 3.0, 10.0, 2}, {3.0, 4.0, 12.0, 2}, {4.0, 5.0, 12.0, 2}, {5.0, 6.0, 10.0, 2}, {8.0, 9.0, 8.0, 2}, {9.0, 10.0, 8.0, 1}};
@@ -174,19 +176,19 @@ AVFrame* TSGenerator::load_image_to_yuv_with_opencv(const char* filename, int wi
174176
}
175177

176178
// 2. OPTIONAL: Overlay timestamp
177-
if (overlay_timestamp) {
178-
auto now = std::chrono::system_clock::now();
179-
auto time_t = std::chrono::system_clock::to_time_t(now);
180-
char time_str[32];
181-
struct tm time_buffer; // Your own buffer
182-
std::strftime(time_str, sizeof(time_str), "%H:%M:%S", localtime_r(&time_t, &time_buffer));
179+
if (overlay_timestamp)
180+
{
181+
QString time_str = QDateTime::currentDateTime().toString("HH:mm:ss");
182+
char time_cstr[32];
183+
strncpy(time_cstr, time_str.toStdString().c_str(), sizeof(time_cstr) - 1);
184+
time_cstr[sizeof(time_cstr) - 1] = '\0';
183185

184186
// Draw black background box first
185187
cv::rectangle(rgb_image, cv::Point(15, 28), cv::Point(170, 65),
186188
cv::Scalar(0, 0, 0), -1);
187189

188190
// Draw white timestamp text
189-
cv::putText(rgb_image, time_str, cv::Point(20, 55),
191+
cv::putText(rgb_image, time_cstr, cv::Point(20, 55),
190192
cv::FONT_HERSHEY_SIMPLEX, 1.0, cv::Scalar(255, 255, 255), 2);
191193
}
192194

0 commit comments

Comments
 (0)