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 <memory>
11#include <type_traits>
12
13namespace shaka {
14namespace media {
15
16struct RgbaColor {
17 uint8_t r;
18 uint8_t g;
19 uint8_t b;
20 uint8_t a;
21
22 bool operator==(const RgbaColor& other) const {
23 return r == other.r && g == other.g && b == other.b && a == other.a;
24 }
25 bool operator!=(const RgbaColor& other) const { return !(*this == other); }
26};
27// To avoid copying, we pass an RgbaColor array as a uint8_t* pointer to libpng
28// for RGBA.
29static_assert(std::is_pod<RgbaColor>::value, "RgbaColor must be POD");
30static_assert(sizeof(RgbaColor) == 4, "RgbaColor not packed correctly");
31
32enum class BitDepth : uint8_t {
33 k2Bit,
34 k4Bit,
35 k8Bit,
36};
37
48 public:
51
53 DvbImageColorSpace& operator=(const DvbImageColorSpace&) = delete;
54
55 RgbaColor GetColor(BitDepth bit_depth, uint8_t entry_id) const;
56
57 void SetColor(BitDepth bit_depth, uint8_t entry_id, RgbaColor color);
59 void Set2To4BitDepthMap(const uint8_t* map);
61 void Set2To8BitDepthMap(const uint8_t* map);
63 void Set4To8BitDepthMap(const uint8_t* map);
64
65 private:
66 RgbaColor GetColorRaw(BitDepth bit_depth, uint8_t entry_id) const;
67
68 // These hold the colors for each entry ID. Each value is initialized to the
69 // special value kNoColor meaning there isn't a value present.
70 RgbaColor color_map_2_[4];
71 RgbaColor color_map_4_[16];
72 RgbaColor color_map_8_[256];
73 // See ETSI EN 300 743 Sections 10.4, 10.5, 10.6 for defaults.
74 uint8_t bit_depth_2_to_4_[4] = {0x0, 0x7, 0x8, 0xf};
75 uint8_t bit_depth_2_to_8_[4] = {0x0, 0x77, 0x88, 0xff};
76 uint8_t bit_depth_4_to_8_[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
77 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
78 0xcc, 0xdd, 0xee, 0xff};
79};
80
90 public:
91 DvbImageBuilder(const DvbImageColorSpace* color_space,
92 const RgbaColor& default_color,
93 uint16_t max_width,
94 uint16_t max_height);
96
97 DvbImageBuilder(const DvbImageBuilder&) = delete;
98 DvbImageBuilder& operator=(const DvbImageBuilder&) = delete;
99
100 uint16_t max_width() const { return max_width_; }
101 uint16_t max_height() const { return max_height_; }
102
103 bool AddPixel(BitDepth bit_depth, uint8_t byte_code, bool is_top_rows);
104 void NewRow(bool is_top_rows);
106 void MirrorToBottomRows();
107
117 bool GetPixels(const RgbaColor** pixels,
118 uint16_t* width,
119 uint16_t* height) const;
120
121 private:
122 struct Position {
123 uint16_t x, y;
124 };
125
126 const std::unique_ptr<RgbaColor[]> pixels_;
127 const DvbImageColorSpace* const color_space_;
128 Position top_pos_, bottom_pos_;
129 const uint16_t max_width_;
130 const uint16_t max_height_;
131 uint16_t width_;
132};
133
134} // namespace media
135} // namespace shaka
136
137#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.