Ocean
Loading...
Searching...
No Matches
ImageOcn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_MEDIA_SPECIAL_IMAGE_OCN_H
9#define META_OCEAN_MEDIA_SPECIAL_IMAGE_OCN_H
10
12
13#include "ocean/base/Frame.h"
14
15namespace Ocean
16{
17
18namespace Media
19{
20
21namespace Special
22{
23
24/**
25 * This class implements read and write functions for Ocean frames.
26 * @ingroup mediaspecial
27 */
28class OCEAN_MEDIA_SPECIAL_EXPORT ImageOcn
29{
30 protected:
31
32 /// The size of the magic number header part in bytes.
33 static constexpr size_t headerMagicNumberSize_ = 4;
34
35 /// The size of the pixel format header part in bytes.
36 static constexpr size_t headerPixelFormatSize_ = 40;
37
38 /// The size of the pixel origin header part in bytes.
39 static constexpr size_t headerPixelOriginSize_ = 16;
40
41 /// The size of the data type header part in bytes.
42 static constexpr size_t headerDataTypeSize_ = 32;
43
44 public:
45
46 /**
47 * Decodes a OCN image from a given binary buffer.
48 * @param buffer The buffer from which the image will be loaded, must be valid
49 * @param size The size of the given buffer in bytes, with range [1, infinity)
50 * @return The frame containing the image information, an invalid frame if the image could not be loaded
51 */
52 static Frame decodeImage(const void* buffer, const size_t size);
53
54 /**
55 * Encodes a given frame as OCN image to a resulting buffer.
56 * @param frame The frame to be written, must be valid
57 * @param buffer The resulting buffer storing the binary information of the OCN image
58 * @return True, if succeeded
59 */
60 static bool encodeImage(const Frame& frame, std::vector<uint8_t>& buffer);
61
62 protected:
63
64 /**
65 * Reads a value from memory.
66 * @param data The memory from which the value will be read, will be moved, must be valid
67 * @param remainingSize The remaining size of the memory, in bytes, will be adjusted, with range [sizeof(T), infinity)
68 * @param value The resulting value
69 * @return True, if succeeded
70 * @tparam T The data type of the value
71 */
72 template <typename T>
73 static bool readValue(const uint8_t*& data, size_t& remainingSize, T& value);
74
75 /**
76 * Reads a string from memory.
77 * @param data The memory from which the string will be read, will be moved, must be valid
78 * @param remainingSize The remaining size of the memory, in bytes, will be adjusted, with range [numberCharacters, infinity)
79 * @param numberCharacters The maximal size of the string to read, in bytes, with range [1, remainingSize]
80 * @param value The resulting string
81 * @return True, if succeeded
82 */
83 static bool readValue(const uint8_t*& data, size_t& remainingSize, const size_t numberCharacters, std::string& value);
84
85 /**
86 * Writes a value to memory.
87 * @param value The value to write
88 * @param data The memory receiving the value, will be moved, must be valid
89 * @param remainingSize The remaining size of the memory, in bytes, will be adjusted, with range [sizeof(T), infinity)
90 * @return True, if succeeded
91 * @tparam T The data type of the value
92 */
93 template <typename T>
94 static bool writeValue(const T& value, uint8_t*& data, size_t& remainingSize);
95
96 /**
97 * Writes a string to memory and fills remaining memory with zero values.
98 * @param value The string to write
99 * @param numberCharacters The number of characters that will be written, with range [value.size(), infinity)
100 * @param data The memory receiving the value, will be moved, must be valid
101 * @param remainingSize The remaining size of the memory, in bytes, will be adjusted, with range [numberCharacters, infinity)
102 * @return True, if succeeded
103 */
104 static bool writeValue(const std::string& value, const size_t numberCharacters, uint8_t*& data, size_t& remainingSize);
105};
106
107}
108
109}
110
111}
112
113#endif // META_OCEAN_MEDIA_SPECIAL_IMAGE_OCN_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements read and write functions for Ocean frames.
Definition ImageOcn.h:29
static bool encodeImage(const Frame &frame, std::vector< uint8_t > &buffer)
Encodes a given frame as OCN image to a resulting buffer.
static Frame decodeImage(const void *buffer, const size_t size)
Decodes a OCN image from a given binary buffer.
static bool writeValue(const T &value, uint8_t *&data, size_t &remainingSize)
Writes a value to memory.
static bool readValue(const uint8_t *&data, size_t &remainingSize, T &value)
Reads a value from memory.
static bool readValue(const uint8_t *&data, size_t &remainingSize, const size_t numberCharacters, std::string &value)
Reads a string from memory.
static bool writeValue(const std::string &value, const size_t numberCharacters, uint8_t *&data, size_t &remainingSize)
Writes a string to memory and fills remaining memory with zero values.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15