1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
/*! @file image.h
*
* @brief Declaration of structures and functions for images
*
* @version 1.0.0
*
* (C) Copyright 2018 GoPro Inc (http://gopro.com/).
*
* Licensed under either:
* - Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
* - MIT license, http://opensource.org/licenses/MIT
* at your option.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IMAGE_H
#define IMAGE_H
//! Data type for the values in a component array
typedef uint16_t COMPONENT_VALUE;
/*!
@brief Data structure for an image input to the unpacking process
This data structure is used to represent the image that is the input to the
image unpacking process that unpacks an image into component arrays for encoding.
Unlike the wavelet data structures, an image contains multiple color components,
usually in a packed pixel format.
*/
typedef struct _packed_image
{
DIMENSION width; //!< Width of the frame (in pixels)
DIMENSION height; //!< Height of the frame
size_t pitch; //!< Distance between rows (in bytes)
PIXEL_FORMAT format; //!< Format of the pixels
void *buffer; //!< Address of the buffer for the frame
size_t size; //!< Allocated size of the buffer (in bytes)
size_t offset; //!< Offset to the start of the frame
} PACKED_IMAGE;
/*!
@brief Data structure for an image input to the unpacking process
This data structure is used to represent the image that is the input to the
image unpacking process that unpacks an image into component arrays for encoding.
Unlike the wavelet data structures, an image contains multiple color components,
usually in a packed pixel format.
*/
typedef struct _rgb_image
{
DIMENSION width; //!< Width of the frame (in pixels)
DIMENSION height; //!< Height of the frame
size_t pitch; //!< Distance between rows (in bytes)
void *buffer; //!< Address of the buffer for the frame
size_t size; //!< Allocated size of the buffer (in bytes)
} RGB_IMAGE;
//! Short name for the packed image data type
typedef PACKED_IMAGE IMAGE;
/*!
@brief Data structure for an array that contains a single type of component
This data structure is used to represent the component array output by the image
unpacking process. The image unpacking process unpacks an image into component
arrays for encoding.
*/
typedef struct _component_array
{
DIMENSION width; //!< Width of the frame (in pixels)
DIMENSION height; //!< Height of the frame
size_t pitch; //!< Distance between rows (in bytes)
COMPONENT_VALUE *data; //!< Buffer for the array of component values
//! Number of bits per in each component value
PRECISION bits_per_component;
} COMPONENT_ARRAY;
/*!
@brief Image represented as an ordered set of component arrays
The decoder outputs a set of component arrays that represent an image.
The image repacking process can pack the component arrays output by the
decoder into a packed image.
*/
typedef struct _unpacked_image
{
//! Number of component arrays in the unpacked image
int component_count;
//! Vector of component arrays
COMPONENT_ARRAY *component_array_list;
} UNPACKED_IMAGE;
/*!
@brief Flags that describe the image structure
*/
typedef enum
{
IMAGE_STRUCTURE_INTERLACED = 0x0001, //!< Set the first bit if the image is interlaced
IMAGE_STRUCTURE_BOTTOM_FIELD_FIRST = 0x0002, //!< The bottom field is encoded before the top field
IMAGE_STRUCTURE_BOTTOM_ROW_FIRST = 0x0010, //!< The encoded image is upside down
} IMAGE_STRUCTURE;
#ifdef __cplusplus
extern "C" {
#endif
CODEC_ERROR InitImage(IMAGE *image);
CODEC_ERROR InitRGBImage(RGB_IMAGE *image);
CODEC_ERROR AllocImage(gpr_allocator *allocator, IMAGE *image, DIMENSION width, DIMENSION height, PIXEL_FORMAT format);
CODEC_ERROR ReleaseImage(gpr_allocator *allocator, IMAGE *image);
DIMENSION ImagePitch(DIMENSION width, PIXEL_FORMAT format);
CODEC_ERROR SetImageFormat(IMAGE *image,
DIMENSION width,
DIMENSION height,
DIMENSION pitch,
PIXEL_FORMAT format,
size_t offset);
void *ImageData(IMAGE *image);
void *RowAddress(IMAGE *image, DIMENSION row);
CODEC_ERROR ReleaseComponentArrays(gpr_allocator *allocator,
UNPACKED_IMAGE *image,
int channel_count );
CODEC_ERROR AllocateComponentArrays(gpr_allocator *allocator,
UNPACKED_IMAGE *image,
int channel_count,
DIMENSION max_channel_width,
DIMENSION max_channel_height,
PIXEL_FORMAT format,
int bits_per_component);
CODEC_ERROR AllocateComponentArray(gpr_allocator *allocator,
COMPONENT_ARRAY *component_array,
DIMENSION width,
DIMENSION height,
PRECISION bits_per_component);
CODEC_ERROR InitUnpackedImage(UNPACKED_IMAGE *image);
PRECISION MaxBitsPerComponent(const UNPACKED_IMAGE *image);
#ifdef __cplusplus
}
#endif
#endif // IMAGE_H
|