Overte C++ Documentation
FrameIO.h
1 //
2 // Created by Bradley Austin Davis on 2018/10/14
3 // Copyright 2013-2018 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 #pragma once
9 #ifndef hifi_gpu_FrameIO_h
10 #define hifi_gpu_FrameIO_h
11 
12 #include "Forward.h"
13 #include "Format.h"
14 
15 #include <shared/Storage.h>
16 
17 #include <functional>
18 
19 namespace gpu {
20 
21 using TextureCapturer = std::function<storage::StoragePointer(const TexturePointer&)>;
22 //using TextureLoader = std::function<void(const storage::StoragePointer& storage, const TexturePointer&)>;
23 void writeFrame(const std::string& filename, const FramePointer& frame, const TextureCapturer& capturer = nullptr);
24 FramePointer readFrame(const std::string& filename, uint32_t externalTexture);
25 
26 namespace hfb {
27 
28 using Storage = storage::Storage;
29 using StoragePointer = storage::Pointer;
30 using StorageBuilders = storage::Builders;
31 
32 constexpr const char* const EXTENSION{ ".hfb" };
33 constexpr uint32_t HEADER_SIZE{ sizeof(uint32_t) * 3 };
34 constexpr uint32_t CHUNK_HEADER_SIZE = sizeof(uint32_t) * 2;
35 constexpr uint32_t MAGIC{ 0x49464948 };
36 constexpr uint32_t VERSION{ 0x01 };
37 constexpr uint32_t CHUNK_TYPE_JSON{ 0x4E4F534A };
38 constexpr uint32_t CHUNK_TYPE_KTX{ 0x0058544b };
39 constexpr uint32_t CHUNK_TYPE_BIN{ 0x004E4942 };
40 constexpr uint32_t CHUNK_TYPE_PNG{ 0x00474E50 };
41 
42 using Buffer = std::vector<uint8_t>;
43 
44 struct Header {
45  uint32_t magic{ 0 };
46  uint32_t version{ 0 };
47  uint32_t length{ 0 };
48 };
49 
50 struct ChunkHeader {
51  uint32_t length{ 0 };
52  uint32_t type{ 0 };
53 };
54 
55 struct Chunk : public ChunkHeader {
56  uint32_t offset{ 0 };
57 
58  size_t end() const;
59 };
60 
61 using Chunks = std::vector<Chunk>;
62 
63 struct Descriptor {
64  using Pointer = std::shared_ptr<Descriptor>;
65 
66  Header header;
67  Chunks chunks;
68  StoragePointer storage;
69 
70  Descriptor(const StoragePointer& storage);
71  operator bool() const { return header.magic == MAGIC; }
72  StoragePointer getChunk(uint32_t chunk) const;
73 };
74 
75 void writeFrame(const std::string& filename,
76  const std::string& json,
77  const Buffer& binaryBuffer,
78  const StorageBuilders& pngBuffers);
79 
80 } // namespace hfb
81 
82 } // namespace gpu
83 
84 #endif