OGLplus  (0.59.0) a C++ wrapper for rendering APIs

image_file_io.hpp
Go to the documentation of this file.
1 
9 #ifndef OGLPLUS_UTILS_IMAGE_FILE_IO_HPP
10 #define OGLPLUS_UTILS_IMAGE_FILE_IO_HPP
11 
12 #include "image_file_hdr.hpp"
13 #include <eagine/memory/align.hpp>
14 #include <eagine/memory/block.hpp>
15 #include <eagine/types.hpp>
16 #include <iostream>
17 
18 namespace eagine::oglp {
19 
20 inline void write_and_pad_texture_image_data_header(
21  std::ostream& output,
22  image_data_header& header,
23  span_size_t pixel_data_size,
24  span_size_t& spos) {
26  while(!is_aligned_as<image_data_header>(spos)) {
27  output.put('\0');
28  ++spos;
29  }
30 
31  const span_size_t size = 64;
32  span_size_t done = 0;
33  static_assert(size >= span_size(sizeof(image_data_header)));
34 
35  eagine::memory::const_address hdraddr(&header);
36 
37  header.pixels.reset(hdraddr + size, pixel_data_size);
38 
39  output.write(static_cast<const char*>(hdraddr), sizeof(header));
40  spos += sizeof(header);
41  done += sizeof(header);
42 
43  while(done < size) {
44  output.put('\0');
45  ++spos;
46  ++done;
47  }
48 }
49 
50 inline void write_and_pad_texture_image_data_header(
51  std::ostream& output,
52  image_data_header& header,
53  span_size_t pixel_data_size) {
54  span_size_t spos = 0;
55 
56  if(output.tellp() >= 0) {
57  spos = span_size_t(output.tellp());
58  }
59 
60  write_and_pad_texture_image_data_header(
61  output, header, pixel_data_size, spos);
62 }
63 
64 inline void write_texture_image_data(
65  std::ostream& output,
66  image_data_header& header,
67  const memory::const_block& pixels) {
68  write_and_pad_texture_image_data_header(
69  output, header, span_size(pixels.size()));
70 
71  write_to_stream(output, pixels);
72 }
73 
74 } // namespace eagine::oglp
75 
76 #endif // OGLPLUS_UTILS_IMAGE_FILE_IO_HPP
Class for handling memory addresses as integer values.
Definition: address.hpp:23
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
static constexpr auto is_aligned_as(const_address addr, type_identity< T > tid={}) noexcept
Indicates if a memory address aligned as the specified type T.
Definition: address.hpp:244

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).