Update file name handling
This commit is contained in:
@@ -20,7 +20,6 @@
|
|||||||
#include "Image/JpegWithTagsWriter.hpp"
|
#include "Image/JpegWithTagsWriter.hpp"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
|
||||||
#if __has_include("turbojpeg.h")
|
#if __has_include("turbojpeg.h")
|
||||||
#include <turbojpeg.h>
|
#include <turbojpeg.h>
|
||||||
#define TURBO_JPEG
|
#define TURBO_JPEG
|
||||||
@@ -33,7 +32,7 @@ namespace OpenVulkano::AR
|
|||||||
constexpr int JPEG_QUALITY_DS = 90;
|
constexpr int JPEG_QUALITY_DS = 90;
|
||||||
constexpr int JPEG_QUALITY_FS = 100;
|
constexpr int JPEG_QUALITY_FS = 100;
|
||||||
|
|
||||||
std::filesystem::path GeneratePath(const std::filesystem::path& baseDir, const std::string_view name)
|
std::filesystem::path GeneratePath(const std::filesystem::path& baseDir, const std::string_view& name)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
auto t = std::time(nullptr);
|
auto t = std::time(nullptr);
|
||||||
@@ -90,8 +89,8 @@ namespace OpenVulkano::AR
|
|||||||
void ArRecorder::WriteColorImage(ArFrame* arFrame, IArchiveWriter* colorWriter, JpegWithTagsWriter* jpgWriter, bool highRes) const
|
void ArRecorder::WriteColorImage(ArFrame* arFrame, IArchiveWriter* colorWriter, JpegWithTagsWriter* jpgWriter, bool highRes) const
|
||||||
{
|
{
|
||||||
//BlockProfiler profile("Save AR Frame - Image");
|
//BlockProfiler profile("Save AR Frame - Image");
|
||||||
std::string fileName = GetFileName(arFrame->GetFrameId(), "jpg");
|
|
||||||
#ifndef TURBO_JPEG
|
#ifndef TURBO_JPEG
|
||||||
|
std::string fileName = GetFileName(arFrame->GetFrameId(), "jpg");
|
||||||
if (arFrame->GetCameraImageAsJpeg([&fileName, this](const char* data, size_t len){ m_colorWriter->AddFile(fileName.c_str(), data, len); }))
|
if (arFrame->GetCameraImageAsJpeg([&fileName, this](const char* data, size_t len){ m_colorWriter->AddFile(fileName.c_str(), data, len); }))
|
||||||
return;
|
return;
|
||||||
//TODO stb???
|
//TODO stb???
|
||||||
@@ -135,11 +134,12 @@ namespace OpenVulkano::AR
|
|||||||
else [[likely]]
|
else [[likely]]
|
||||||
{
|
{
|
||||||
if (colorWriter) [[likely]]
|
if (colorWriter) [[likely]]
|
||||||
colorWriter->AddFile(fileName.c_str(), outBuffer, size);
|
|
||||||
if (jpgWriter) [[unlikely]]
|
|
||||||
{
|
{
|
||||||
jpgWriter->WriteImageData({ outBuffer, size }, false); // Keep open, lifetime is managed outside
|
std::string fileName = GetFileName(arFrame->GetFrameId(), "jpg");
|
||||||
|
colorWriter->AddFile(fileName.c_str(), outBuffer, size);
|
||||||
}
|
}
|
||||||
|
if (jpgWriter) [[unlikely]]
|
||||||
|
jpgWriter->WriteImageData({ outBuffer, size }, false); // Keep open, lifetime is managed outside
|
||||||
}
|
}
|
||||||
tjFree(outBuffer);
|
tjFree(outBuffer);
|
||||||
tjDestroy(handle);
|
tjDestroy(handle);
|
||||||
@@ -147,6 +147,13 @@ namespace OpenVulkano::AR
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ArRecorder::WriteDepthImage(ArFrame* arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter)
|
void ArRecorder::WriteDepthImage(ArFrame* arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter)
|
||||||
|
{
|
||||||
|
std::string depthName = GetFileName(arFrame->GetFrameId(), "pfm");
|
||||||
|
std::string confName = GetFileName(arFrame->GetFrameId(), "pgm");
|
||||||
|
WriteDepthImage(arFrame, depthWriter, confWriter, depthName.c_str(), confName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArRecorder::WriteDepthImage(ArFrame* arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter, const char* depthName, const char* confidenceName)
|
||||||
{
|
{
|
||||||
//BlockProfiler profile("Save AR Frame - Depth");
|
//BlockProfiler profile("Save AR Frame - Depth");
|
||||||
if (!depthWriter || !confWriter) return;
|
if (!depthWriter || !confWriter) return;
|
||||||
@@ -161,8 +168,7 @@ namespace OpenVulkano::AR
|
|||||||
buffers[1].first = static_cast<const char *>(depthImg.depth.data);
|
buffers[1].first = static_cast<const char *>(depthImg.depth.data);
|
||||||
buffers[1].second = depthImg.depth.resolution.x * depthImg.depth.resolution.y * sizeof(float);
|
buffers[1].second = depthImg.depth.resolution.x * depthImg.depth.resolution.y * sizeof(float);
|
||||||
|
|
||||||
const std::string fileName = GetFileName(arFrame->GetFrameId(), "pfm");
|
depthWriter->AddFile(depthName, buffers);
|
||||||
depthWriter->AddFile(fileName.c_str(), buffers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (depthImg.confidence.resolution.x > 1 && depthImg.confidence.resolution.y > 1)
|
if (depthImg.confidence.resolution.x > 1 && depthImg.confidence.resolution.y > 1)
|
||||||
@@ -175,17 +181,21 @@ namespace OpenVulkano::AR
|
|||||||
buffers[1].first = static_cast<const char *>(static_cast<void*>(depthImg.confidence.data));
|
buffers[1].first = static_cast<const char *>(static_cast<void*>(depthImg.confidence.data));
|
||||||
buffers[1].second = static_cast<size_t>(depthImg.confidence.resolution.x * depthImg.confidence.resolution.y);
|
buffers[1].second = static_cast<size_t>(depthImg.confidence.resolution.x * depthImg.confidence.resolution.y);
|
||||||
|
|
||||||
const std::string fileName = GetFileName(arFrame->GetFrameId(), "pgm");
|
confWriter->AddFile(confidenceName, buffers);
|
||||||
confWriter->AddFile(fileName.c_str(), buffers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArRecorder::WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter)
|
void ArRecorder::WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter)
|
||||||
|
{
|
||||||
|
std::string fileName = GetFileName(frame->GetFrameId(), "meta");
|
||||||
|
WriteMetadata(frame, metaWriter, fileName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArRecorder::WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter, const char* fileName)
|
||||||
{
|
{
|
||||||
//BlockProfiler profileMeta("Save AR Frame - Meta");
|
//BlockProfiler profileMeta("Save AR Frame - Meta");
|
||||||
std::string metaContent = frame->GetFrameMetadata().ToYaml();
|
std::string metaContent = frame->GetFrameMetadata().ToYaml();
|
||||||
std::string fileName = GetFileName(frame->GetFrameId(), "meta");
|
metaWriter->AddFile(fileName, metaContent.c_str(), metaContent.size());
|
||||||
metaWriter->AddFile(fileName.c_str(), metaContent.c_str(), metaContent.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArRecorder::Write(ArFrame* frame, bool highRes)
|
void ArRecorder::Write(ArFrame* frame, bool highRes)
|
||||||
@@ -307,8 +317,8 @@ namespace OpenVulkano::AR
|
|||||||
if (includeAux)
|
if (includeAux)
|
||||||
{
|
{
|
||||||
ArchiveWriter writer(jpgWriter.GetFilePtr(), ArchiveConfiguration(ArchiveType::ZIP));
|
ArchiveWriter writer(jpgWriter.GetFilePtr(), ArchiveConfiguration(ArchiveType::ZIP));
|
||||||
WriteMetadata(frame.get(), &writer);
|
WriteMetadata(frame.get(), &writer, "metadata.yml");
|
||||||
WriteDepthImage(frame.get(), &writer, &writer);
|
WriteDepthImage(frame.get(), &writer, &writer, "depth.pfm", "confidence.pgm");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,8 +101,10 @@ namespace OpenVulkano::AR
|
|||||||
|
|
||||||
void Write(ArFrame* frame, bool highRes = false);
|
void Write(ArFrame* frame, bool highRes = false);
|
||||||
void WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter);
|
void WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter);
|
||||||
|
void WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter, const char* name);
|
||||||
void WriteColorImage(ArFrame* arFrame, IArchiveWriter* colorWriter, JpegWithTagsWriter* jpgWriter, bool highRes) const;
|
void WriteColorImage(ArFrame* arFrame, IArchiveWriter* colorWriter, JpegWithTagsWriter* jpgWriter, bool highRes) const;
|
||||||
void WriteDepthImage(ArFrame *arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter);
|
void WriteDepthImage(ArFrame *arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter);
|
||||||
|
void WriteDepthImage(ArFrame *arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter, const char* depthName, const char* confidenceName);
|
||||||
void WriteToFile(const std::shared_ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample, bool saveAux);
|
void WriteToFile(const std::shared_ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample, bool saveAux);
|
||||||
|
|
||||||
void SplitWriters();
|
void SplitWriters();
|
||||||
|
|||||||
Reference in New Issue
Block a user