File indexing completed on 2025-09-15 08:59:51
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <string>
0011 #include <vector>
0012
0013 #include "corecel/Config.hh"
0014
0015 #include "corecel/cont/Array.hh"
0016 #include "corecel/cont/Span.hh"
0017 #include "geocel/Types.hh"
0018
0019 #include "Color.hh"
0020
0021 namespace celeritas
0022 {
0023
0024
0025
0026
0027
0028
0029
0030 class ImageWriter
0031 {
0032 public:
0033
0034
0035 using SpanColor = Span<Color>;
0036
0037
0038 public:
0039
0040 ImageWriter(std::string const& filename, Size2 height_width);
0041
0042
0043 inline ~ImageWriter();
0044
0045
0046 void operator()(Span<Color const>);
0047
0048
0049 void close() { this->close_impl( true); }
0050
0051
0052 explicit operator bool() const { return static_cast<bool>(impl_); }
0053
0054 private:
0055 struct Impl;
0056 struct ImplDeleter
0057 {
0058 void operator()(Impl*);
0059 };
0060
0061 std::unique_ptr<Impl, ImplDeleter> impl_;
0062 Size2 size_;
0063 size_type rows_written_{0};
0064 std::vector<char> row_buffer_;
0065
0066 void close_impl(bool validate);
0067 };
0068
0069
0070
0071
0072
0073
0074
0075 ImageWriter::~ImageWriter()
0076 {
0077 if (*this)
0078 {
0079 this->close_impl( false);
0080 }
0081 }
0082
0083
0084 #if !CELERITAS_USE_PNG
0085 inline ImageWriter::ImageWriter(std::string const&, Size2)
0086 {
0087 CELER_DISCARD(size_);
0088 CELER_DISCARD(rows_written_);
0089 CELER_DISCARD(row_buffer_);
0090 CELER_NOT_CONFIGURED("PNG");
0091 }
0092 inline void ImageWriter::operator()(Span<Color const>)
0093 {
0094 CELER_ASSERT_UNREACHABLE();
0095 }
0096 inline void ImageWriter::close_impl(bool) {}
0097 inline void ImageWriter::ImplDeleter::operator()(Impl*) {}
0098 #endif
0099
0100
0101 }