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