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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (C) 2019, Raspberry Pi Ltd
#
# ctt_ccm.py - camera tuning tool for CCM (colour correction matrix)
from ctt_image_load import *
from ctt_awb import get_alsc_patches
"""
takes 8-bit macbeth chart values, degammas and returns 16 bit
"""
def degamma(x):
x = x / ((2**8)-1)
x = np.where(x < 0.04045, x/12.92, ((x+0.055)/1.055)**2.4)
x = x * ((2**16)-1)
return x
"""
FInds colour correction matrices for list of images
"""
def ccm(Cam, cal_cr_list, cal_cb_list):
imgs = Cam.imgs
"""
standard macbeth chart colour values
"""
m_rgb = np.array([ # these are in sRGB
[116, 81, 67], # dark skin
[199, 147, 129], # light skin
[91, 122, 156], # blue sky
[90, 108, 64], # foliage
[130, 128, 176], # blue flower
[92, 190, 172], # bluish green
[224, 124, 47], # orange
[68, 91, 170], # purplish blue
[198, 82, 97], # moderate red
[94, 58, 106], # purple
[159, 189, 63], # yellow green
[230, 162, 39], # orange yellow
[35, 63, 147], # blue
[67, 149, 74], # green
[180, 49, 57], # red
[238, 198, 20], # yellow
[193, 84, 151], # magenta
[0, 136, 170], # cyan (goes out of gamut)
[245, 245, 243], # white 9.5
[200, 202, 202], # neutral 8
[161, 163, 163], # neutral 6.5
[121, 121, 122], # neutral 5
[82, 84, 86]
* +-------------------------+ .
* / | ... | | entry[n].offset
* | +-------------------------+ <-----ยด
* | | minimum value (#n) | \
* Data | +-------------------------+ |
* section | | maximum value (#n) | | Entry #n
* | +-------------------------+ |
* | | default value (#n) | /
* | +-------------------------+
* \ | ... |
* +-------------------------+
* ~~~~
*
* The minimum, maximum and default values are stored in the platform's native
* data format. The ipa_control_info_entry::offset field stores the offset from
* the beginning of the data section to the info data.
*
* Info data in the data section shall be stored in the same order as the
* entries array, shall be aligned to a multiple of 8 bytes, and shall be
* contiguous in memory.
*
* As for the ControlList packet, empty spaces may be present between the end of
* the entries array and the data section, and after the data section. They
* shall be ignored when parsing the packet.
*/
namespace libcamera {
/**
* \def IPA_CONTROLS_FORMAT_VERSION
* \brief The current control serialization format version
*/
/**
* \var ipa_controls_id_map_type
* \brief Enumerates the different control id map types
*
* Each ControlInfoMap and ControlList refers to a control id map that
* associates the ControlId references to a numerical identifier.
* During the serialization procedure the raw pointers to the ControlId
* instances cannot be transported on the wire, hence their numerical id is
* used to identify them in the serialized data buffer. At deserialization time
* it is required to associate back to the numerical id the ControlId instance
* it represents. This enumeration describes which ControlIdMap should be
* used to perform such operation.
*
* \var ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_CONTROLS
* \brief The numerical control identifier are resolved to a ControlId * using
* the global controls::controls id map
* \var ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_PROPERTIES
* \brief The numerical control identifier are resolved to a ControlId * using
* the global properties::properties id map
* \var ipa_controls_id_map_type::IPA_CONTROL_ID_MAP_V4L2
* \brief ControlId for V4L2 defined controls are created by the video device
* that enumerates them, and are not available across the IPC boundaries. The
* deserializer shall create new ControlId instances for them as well as store
* them in a dedicated ControlIdMap. Only lookup by numerical id can be
* performed on de-serialized ControlInfoMap that represents V4L2 controls.
*/
/**
* \struct ipa_controls_header
* \brief Serialized control packet header
* \var ipa_controls_header::version
* Control packet format version number (shall be IPA_CONTROLS_FORMAT_VERSION)
* \var ipa_controls_header::handle
* For ControlInfoMap packets, this field contains a unique non-zero handle
* generated when the ControlInfoMap is serialized. For ControlList packets,
* this field contains the handle of the corresponding ControlInfoMap.
* \var ipa_controls_header::entries
* Number of entries in the packet
* \var ipa_controls_header::size
* The total packet size
and the ccm matrices will be more accurate.
"""
r_greys, b_greys, g_greys = r[3::4], b[3::4], g[3::4]
r_g = np.mean(r_greys/g_greys)
b_g = np.mean(b_greys/g_greys)
r = r / r_g
b = b / b_g
"""
normalise brightness wrt reference macbeth colours and then average
each channel for each patch
"""
gain
* The number of control array entries for array controls (1 otherwise)
* \var ipa_control_value_entry::offset
* The offset in bytes from the beginning of the data section to the control
* value data (shall be a multiple of 8 bytes).
* \var ipa_control_value_entry::padding
* Padding bytes (shall be set to 0)
*/
static_assert(sizeof(ipa_control_value_entry) == 16,
"Invalid ABI size change for struct ipa_control_value_entry");
/**
* \struct ipa_control_info_entry
* \brief Description of a serialized ControlInfo entry
* \var ipa_control_info_entry::id
* The numerical ID of the control
* \var ipa_control_info_entry::type
* The type of the control (defined by enum ControlType)
* \var ipa_control_info_entry::offset
* The offset in bytes from the beginning of the data section to the control
* info data (shall be a multiple of 8 bytes)
* \var ipa_control_info_entry::padding
* Padding bytes (shall be set to 0)
*/
static_assert(sizeof(ipa_control_info_entry) == 16,
"Invalid ABI size change for struct ipa_control_info_entry");
} /* namespace libcamera */
|