Shaka Packager SDK
Loading...
Searching...
No Matches
dvb_image.h
1// Copyright 2020 Google LLC. All rights reserved.
2//
3// Use of this source code is governed by a BSD-style
4// license that can be found in the LICENSE file or at
5// https://developers.google.com/open-source/licenses/bsd
6
7#ifndef PACKAGER_MEDIA_DVB_DVB_IMAGE_H_
8#define PACKAGER_MEDIA_DVB_DVB_IMAGE_H_
9
10#include <cstdint>
11#include <memory>
12#include <type_traits>
13
14namespace shaka {
15namespace media {
16
17struct RgbaColor {
18 uint8_t r;
19 uint8_t g;
20 uint8_t b;
21 uint8_t a;
22
23 bool operator==(const RgbaColor& other) const {
24 return r == other.r && g == other.g && b == other.b && a == other.a;
25 }
26 bool operator!=(const RgbaColor& other) const { return !(*this == other); }
27};
28// To avoid copying, we pass an RgbaColor array as a uint8_t* pointer to libpng
29// for RGBA.
30static_assert(std::is_pod<RgbaColor>::value, "RgbaColor must be POD");
31static_assert(sizeof(RgbaColor) == 4, "RgbaColor not packed correctly");
32
33enum class BitDepth : uint8_t {
34 k2Bit,
35 k4Bit,
36 k8Bit,
37};
38
49 public:
52
54 DvbImageColorSpace& operator=(const DvbImageColorSpace&) = delete;
55
56 RgbaColor GetColor(BitDepth bit_depth, uint8_t entry_id) const;
57
58 void SetColor(BitDepth bit_depth, uint8_t entry_id, RgbaColor color);
60 void Set2To4BitDepthMap(const uint8_t* map);
62 void Set2To8BitDepthMap(const uint8_t* map);
64 void Set4To8BitDepthMap(const uint8_t* map);
65
66 private:
67 RgbaColor GetColorRaw(BitDepth bit_depth, uint8_t entry_id) const;
68
69 // These hold the colors for each entry ID. Each value is initialized to the
70 // special value kNoColor meaning there isn't a value present.
71 RgbaColor color_map_2_[4];
72 RgbaColor color_map_4_[16];
73 RgbaColor color_map_8_[256];
74 // See ETSI EN 300 743 Sections 10.4, 10.5, 10.6 for defaults.
75 uint8_t bit_depth_2_to_4_[4] = {0x0, 0x7, 0x8, 0xf};
76 uint8_t bit_depth_2_to_8_[4] = {0x0, 0x77, 0x88, 0xff};
77 uint8_t bit_depth_4_to_8_[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
78 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
79 0xcc, 0xdd, 0xee, 0xff};
80};
81
91 public:
92 DvbImageBuilder(const DvbImageColorSpace* color_space,
93 const RgbaColor& default_color,
94 uint16_t max_width,
95 uint16_t max_height);
97
98 DvbImageBuilder(const DvbImageBuilder&) = delete;
99 DvbImageBuilder& operator=(const DvbImageBuilder&) = delete;
100
101 uint16_t max_width() const { return max_width_; }
102 uint16_t max_height() const { return max_height_; }
103
104 bool AddPixel(BitDepth bit_depth, uint8_t byte_code, bool is_top_rows);
105 void NewRow(bool is_top_rows);
107 void MirrorToBottomRows();
108
118 bool GetPixels(const RgbaColor** pixels,
119 uint16_t* width,
120 uint16_t* height) const;
121
122 private:
123 struct Position {
124 uint16_t x, y;
125 };
126
127 const std::unique_ptr<RgbaColor[]> pixels_;
128 const DvbImageColorSpace* const color_space_;
129 Position top_pos_, bottom_pos_;
130 const uint16_t max_width_;
131 const uint16_t max_height_;
132 uint16_t width_;
133};
134
135} // namespace media
136} // namespace shaka
137
138#endif // PACKAGER_MEDIA_DVB_DVB_IMAGE_H_
bool GetPixels(const RgbaColor **pixels, uint16_t *width, uint16_t *height) const
Definition dvb_image.cc:245
void MirrorToBottomRows()
Copies the top-rows to the bottom rows.
Definition dvb_image.cc:233
void Set4To8BitDepthMap(const uint8_t *map)
Must pass a 16-element array; elements are copied over.
Definition dvb_image.cc:176
void Set2To8BitDepthMap(const uint8_t *map)
Must pass a 4-element array; elements are copied over.
Definition dvb_image.cc:172
void Set2To4BitDepthMap(const uint8_t *map)
Must pass a 4-element array; elements are copied over.
Definition dvb_image.cc:168
All the methods that are virtual are virtual for mocking.