CARLA
Loading...
Searching...
No Matches
ImageSerializer.h
Go to the documentation of this file.
1// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include "carla/Memory.h"
11
12#include <cstdint>
13#include <cstring>
14
15namespace carla {
16namespace sensor {
17
18 class SensorData;
19
20namespace s11n {
21
22 /// Serializes image buffers generated by camera sensors.
24 public:
25
26#pragma pack(push, 1)
27 struct ImageHeader {
28 uint32_t width;
29 uint32_t height;
30 float fov_angle;
31 };
32#pragma pack(pop)
33
34 static_assert (sizeof(ImageHeader) == sizeof(uint32_t) * 3);
35
36 constexpr static auto header_offset = sizeof(ImageHeader);
37
38 static const ImageHeader &DeserializeHeader(const RawData &data) {
39 return *reinterpret_cast<const ImageHeader *>(data.begin());
40 }
41
42 template <typename Sensor>
43 static Buffer Serialize(Sensor&& sensor, Buffer&& bitmap);
44
46 };
47
48 template <typename Sensor>
50 Sensor&& sensor,
51 Buffer&& bitmap)
52 {
53 DEBUG_ASSERT(bitmap.size() > sizeof(ImageHeader));
54
55 ImageHeader header = {
56 sensor.GetImageWidth(),
57 sensor.GetImageHeight(),
58 sensor.GetFOVAngle()
59 };
60
61 std::memcpy(
62 bitmap.data(),
63 reinterpret_cast<const void *>(&header),
64 sizeof(header));
65
66 return std::move(bitmap);
67 }
68
69} // namespace s11n
70} // namespace sensor
71} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
A piece of raw data.
Wrapper around the raw data generated by a sensor plus some useful meta-information.
Definition RawData.h:21
auto begin() noexcept
Begin iterator to the data generated by the sensor.
Definition RawData.h:52
Serializes image buffers generated by camera sensors.
static Buffer Serialize(Sensor &&sensor, Buffer &&bitmap)
static const ImageHeader & DeserializeHeader(const RawData &data)
static SharedPtr< SensorData > Deserialize(RawData &&data)
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
Definition Memory.h:15