blob: 5412cb1102370df2b7346c49d783ceeabb801007 [file] [log] [blame]
Dichen Zhange46f9bb2023-02-23 19:34:53 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <jpegrecoverymap/icc.h>
18#include <jpegrecoverymap/recoverymapmath.h>
19#include <vector>
20#include <utils/Log.h>
21
22#ifndef FLT_MAX
23#define FLT_MAX 0x1.fffffep127f
24#endif
25
26namespace android::jpegrecoverymap {
27static void Matrix3x3_apply(const Matrix3x3* m, float* x) {
28 float y0 = x[0] * m->vals[0][0] + x[1] * m->vals[0][1] + x[2] * m->vals[0][2];
29 float y1 = x[0] * m->vals[1][0] + x[1] * m->vals[1][1] + x[2] * m->vals[1][2];
30 float y2 = x[0] * m->vals[2][0] + x[1] * m->vals[2][1] + x[2] * m->vals[2][2];
31 x[0] = y0;
32 x[1] = y1;
33 x[2] = y2;
34}
35
36bool Matrix3x3_invert(const Matrix3x3* src, Matrix3x3* dst) {
37 double a00 = src->vals[0][0],
38 a01 = src->vals[1][0],
39 a02 = src->vals[2][0],
40 a10 = src->vals[0][1],
41 a11 = src->vals[1][1],
42 a12 = src->vals[2][1],
43 a20 = src->vals[0][2],
44 a21 = src->vals[1][2],
45 a22 = src->vals[2][2];
46
47 double b0 = a00*a11 - a01*a10,
48 b1 = a00*a12 - a02*a10,
49 b2 = a01*a12 - a02*a11,
50 b3 = a20,
51 b4 = a21,
52 b5 = a22;
53
54 double determinant = b0*b5
55 - b1*b4
56 + b2*b3;
57
58 if (determinant == 0) {
59 return false;
60 }
61
62 double invdet = 1.0 / determinant;
63 if (invdet > +FLT_MAX || invdet < -FLT_MAX || !isfinitef_((float)invdet)) {
64 return false;
65 }
66
67 b0 *= invdet;
68 b1 *= invdet;
69 b2 *= invdet;
70 b3 *= invdet;
71 b4 *= invdet;
72 b5 *= invdet;
73
74 dst->vals[0][0] = (float)( a11*b5 - a12*b4 );
75 dst->vals[1][0] = (float)( a02*b4 - a01*b5 );
76 dst->vals[2][0] = (float)( + b2 );
77 dst->vals[0][1] = (float)( a12*b3 - a10*b5 );
78 dst->vals[1][1] = (float)( a00*b5 - a02*b3 );
79 dst->vals[2][1] = (float)( - b1 );
80 dst->vals[0][2] = (float)( a10*b4 - a11*b3 );
81 dst->vals[1][2] = (float)( a01*b3 - a00*b4 );
82 dst->vals[2][2] = (float)( + b0 );
83
84 for (int r = 0; r < 3; ++r)
85 for (int c = 0; c < 3; ++c) {
86 if (!isfinitef_(dst->vals[r][c])) {
87 return false;
88 }
89 }
90 return true;
91}
92
93static Matrix3x3 Matrix3x3_concat(const Matrix3x3* A, const Matrix3x3* B) {
94 Matrix3x3 m = { { { 0,0,0 },{ 0,0,0 },{ 0,0,0 } } };
95 for (int r = 0; r < 3; r++)
96 for (int c = 0; c < 3; c++) {
97 m.vals[r][c] = A->vals[r][0] * B->vals[0][c]
98 + A->vals[r][1] * B->vals[1][c]
99 + A->vals[r][2] * B->vals[2][c];
100 }
101 return m;
102}
103
104static void float_XYZD50_to_grid16_lab(const float* xyz_float, uint8_t* grid16_lab) {
105 float v[3] = {
106 xyz_float[0] / kD50_x,
107 xyz_float[1] / kD50_y,
108 xyz_float[2] / kD50_z,
109 };
110 for (size_t i = 0; i < 3; ++i) {
111 v[i] = v[i] > 0.008856f ? cbrtf(v[i]) : v[i] * 7.787f + (16 / 116.0f);
112 }
113 const float L = v[1] * 116.0f - 16.0f;
114 const float a = (v[0] - v[1]) * 500.0f;
115 const float b = (v[1] - v[2]) * 200.0f;
116 const float Lab_unorm[3] = {
117 L * (1 / 100.f),
118 (a + 128.0f) * (1 / 255.0f),
119 (b + 128.0f) * (1 / 255.0f),
120 };
121 // This will encode L=1 as 0xFFFF. This matches how skcms will interpret the
122 // table, but the spec appears to indicate that the value should be 0xFF00.
123 // https://crbug.com/skia/13807
124 for (size_t i = 0; i < 3; ++i) {
125 reinterpret_cast<uint16_t*>(grid16_lab)[i] =
126 Endian_SwapBE16(float_round_to_unorm16(Lab_unorm[i]));
127 }
128}
129
130std::string IccHelper::get_desc_string(const jpegr_transfer_function tf,
131 const jpegr_color_gamut gamut) {
132 std::string result;
133 switch (gamut) {
134 case JPEGR_COLORGAMUT_BT709:
135 result += "sRGB";
136 break;
137 case JPEGR_COLORGAMUT_P3:
138 result += "Display P3";
139 break;
140 case JPEGR_COLORGAMUT_BT2100:
141 result += "Rec2020";
142 break;
143 default:
144 result += "Unknown";
145 break;
146 }
147 result += " Gamut with ";
148 switch (tf) {
149 case JPEGR_TF_SRGB:
150 result += "sRGB";
151 break;
152 case JPEGR_TF_LINEAR:
153 result += "Linear";
154 break;
155 case JPEGR_TF_PQ:
156 result += "PQ";
157 break;
158 case JPEGR_TF_HLG:
159 result += "HLG";
160 break;
161 default:
162 result += "Unknown";
163 break;
164 }
165 result += " Transfer";
166 return result;
167}
168
169sp<DataStruct> IccHelper::write_text_tag(const char* text) {
170 uint32_t text_length = strlen(text);
171 uint32_t header[] = {
172 Endian_SwapBE32(kTAG_TextType), // Type signature
173 0, // Reserved
174 Endian_SwapBE32(1), // Number of records
175 Endian_SwapBE32(12), // Record size (must be 12)
176 Endian_SwapBE32(SetFourByteTag('e', 'n', 'U', 'S')), // English USA
177 Endian_SwapBE32(2 * text_length), // Length of string in bytes
178 Endian_SwapBE32(28), // Offset of string
179 };
180
181 uint32_t total_length = text_length * 2 + sizeof(header);
182 total_length = (((total_length + 2) >> 2) << 2); // 4 aligned
183 sp<DataStruct> dataStruct = new DataStruct(total_length);
184
185 if (!dataStruct->write(header, sizeof(header))) {
186 ALOGE("write_text_tag(): error in writing data");
187 return dataStruct;
188 }
189
190 for (size_t i = 0; i < text_length; i++) {
191 // Convert ASCII to big-endian UTF-16.
192 dataStruct->write8(0);
193 dataStruct->write8(text[i]);
194 }
195
196 return dataStruct;
197}
198
199sp<DataStruct> IccHelper::write_xyz_tag(float x, float y, float z) {
200 uint32_t data[] = {
201 Endian_SwapBE32(kXYZ_PCSSpace),
202 0,
203 static_cast<uint32_t>(Endian_SwapBE32(float_round_to_fixed(x))),
204 static_cast<uint32_t>(Endian_SwapBE32(float_round_to_fixed(y))),
205 static_cast<uint32_t>(Endian_SwapBE32(float_round_to_fixed(z))),
206 };
207 sp<DataStruct> dataStruct = new DataStruct(sizeof(data));
208 dataStruct->write(&data, sizeof(data));
209 return dataStruct;
210}
211
212sp<DataStruct> IccHelper::write_trc_tag(const int table_entries, const void* table_16) {
213 int total_length = 4 + 4 + 4 + table_entries * 2;
214 total_length = (((total_length + 2) >> 2) << 2); // 4 aligned
215 sp<DataStruct> dataStruct = new DataStruct(total_length);
216 dataStruct->write32(Endian_SwapBE32(kTAG_CurveType)); // Type
217 dataStruct->write32(0); // Reserved
218 dataStruct->write32(Endian_SwapBE32(table_entries)); // Value count
219 for (size_t i = 0; i < table_entries; ++i) {
220 uint16_t value = reinterpret_cast<const uint16_t*>(table_16)[i];
221 dataStruct->write16(value);
222 }
223 return dataStruct;
224}
225
226sp<DataStruct> IccHelper::write_trc_tag_for_linear() {
227 int total_length = 16;
228 sp<DataStruct> dataStruct = new DataStruct(total_length);
229 dataStruct->write32(Endian_SwapBE32(kTAG_ParaCurveType)); // Type
230 dataStruct->write32(0); // Reserved
231 dataStruct->write32(Endian_SwapBE16(kExponential_ParaCurveType));
232 dataStruct->write32(Endian_SwapBE32(float_round_to_fixed(1.0)));
233
234 return dataStruct;
235}
236
237float IccHelper::compute_tone_map_gain(const jpegr_transfer_function tf, float L) {
238 if (L <= 0.f) {
239 return 1.f;
240 }
241 if (tf == JPEGR_TF_PQ) {
242 // The PQ transfer function will map to the range [0, 1]. Linearly scale
243 // it up to the range [0, 10,000/203]. We will then tone map that back
244 // down to [0, 1].
245 constexpr float kInputMaxLuminance = 10000 / 203.f;
246 constexpr float kOutputMaxLuminance = 1.0;
247 L *= kInputMaxLuminance;
248
249 // Compute the tone map gain which will tone map from 10,000/203 to 1.0.
250 constexpr float kToneMapA = kOutputMaxLuminance / (kInputMaxLuminance * kInputMaxLuminance);
251 constexpr float kToneMapB = 1.f / kOutputMaxLuminance;
252 return kInputMaxLuminance * (1.f + kToneMapA * L) / (1.f + kToneMapB * L);
253 }
254 if (tf == JPEGR_TF_HLG) {
255 // Let Lw be the brightness of the display in nits.
256 constexpr float Lw = 203.f;
257 const float gamma = 1.2f + 0.42f * std::log(Lw / 1000.f) / std::log(10.f);
258 return std::pow(L, gamma - 1.f);
259 }
260 return 1.f;
261}
262
263sp<DataStruct> IccHelper::write_cicp_tag(uint32_t color_primaries,
264 uint32_t transfer_characteristics) {
265 int total_length = 12; // 4 + 4 + 1 + 1 + 1 + 1
266 sp<DataStruct> dataStruct = new DataStruct(total_length);
267 dataStruct->write32(Endian_SwapBE32(kTAG_cicp)); // Type signature
268 dataStruct->write32(0); // Reserved
269 dataStruct->write8(color_primaries); // Color primaries
270 dataStruct->write8(transfer_characteristics); // Transfer characteristics
271 dataStruct->write8(0); // RGB matrix
272 dataStruct->write8(1); // Full range
273 return dataStruct;
274}
275
276void IccHelper::compute_lut_entry(const Matrix3x3& src_to_XYZD50, float rgb[3]) {
277 // Compute the matrices to convert from source to Rec2020, and from Rec2020 to XYZD50.
278 Matrix3x3 src_to_rec2020;
279 const Matrix3x3 rec2020_to_XYZD50 = kRec2020;
280 {
281 Matrix3x3 XYZD50_to_rec2020;
282 Matrix3x3_invert(&rec2020_to_XYZD50, &XYZD50_to_rec2020);
283 src_to_rec2020 = Matrix3x3_concat(&XYZD50_to_rec2020, &src_to_XYZD50);
284 }
285
286 // Convert the source signal to linear.
287 for (size_t i = 0; i < kNumChannels; ++i) {
288 rgb[i] = pqOetf(rgb[i]);
289 }
290
291 // Convert source gamut to Rec2020.
292 Matrix3x3_apply(&src_to_rec2020, rgb);
293
294 // Compute the luminance of the signal.
295 float L = bt2100Luminance({{{rgb[0], rgb[1], rgb[2]}}});
296
297 // Compute the tone map gain based on the luminance.
298 float tone_map_gain = compute_tone_map_gain(JPEGR_TF_PQ, L);
299
300 // Apply the tone map gain.
301 for (size_t i = 0; i < kNumChannels; ++i) {
302 rgb[i] *= tone_map_gain;
303 }
304
305 // Convert from Rec2020-linear to XYZD50.
306 Matrix3x3_apply(&rec2020_to_XYZD50, rgb);
307}
308
309sp<DataStruct> IccHelper::write_clut(const uint8_t* grid_points, const uint8_t* grid_16) {
310 uint32_t value_count = kNumChannels;
311 for (uint32_t i = 0; i < kNumChannels; ++i) {
312 value_count *= grid_points[i];
313 }
314
315 int total_length = 20 + 2 * value_count;
316 total_length = (((total_length + 2) >> 2) << 2); // 4 aligned
317 sp<DataStruct> dataStruct = new DataStruct(total_length);
318
319 for (size_t i = 0; i < 16; ++i) {
320 dataStruct->write8(i < kNumChannels ? grid_points[i] : 0); // Grid size
321 }
322 dataStruct->write8(2); // Grid byte width (always 16-bit)
323 dataStruct->write8(0); // Reserved
324 dataStruct->write8(0); // Reserved
325 dataStruct->write8(0); // Reserved
326
327 for (uint32_t i = 0; i < value_count; ++i) {
328 uint16_t value = reinterpret_cast<const uint16_t*>(grid_16)[i];
329 dataStruct->write16(value);
330 }
331
332 return dataStruct;
333}
334
335sp<DataStruct> IccHelper::write_mAB_or_mBA_tag(uint32_t type,
336 bool has_a_curves,
337 const uint8_t* grid_points,
338 const uint8_t* grid_16) {
339 const size_t b_curves_offset = 32;
340 sp<DataStruct> b_curves_data[kNumChannels];
341 sp<DataStruct> a_curves_data[kNumChannels];
342 size_t clut_offset = 0;
343 sp<DataStruct> clut;
344 size_t a_curves_offset = 0;
345
346 // The "B" curve is required.
347 for (size_t i = 0; i < kNumChannels; ++i) {
348 b_curves_data[i] = write_trc_tag_for_linear();
349 }
350
351 // The "A" curve and CLUT are optional.
352 if (has_a_curves) {
353 clut_offset = b_curves_offset;
354 for (size_t i = 0; i < kNumChannels; ++i) {
355 clut_offset += b_curves_data[i]->getLength();
356 }
357 clut = write_clut(grid_points, grid_16);
358
359 a_curves_offset = clut_offset + clut->getLength();
360 for (size_t i = 0; i < kNumChannels; ++i) {
361 a_curves_data[i] = write_trc_tag_for_linear();
362 }
363 }
364
365 int total_length = b_curves_offset;
366 for (size_t i = 0; i < kNumChannels; ++i) {
367 total_length += b_curves_data[i]->getLength();
368 }
369 if (has_a_curves) {
370 total_length += clut->getLength();
371 for (size_t i = 0; i < kNumChannels; ++i) {
372 total_length += a_curves_data[i]->getLength();
373 }
374 }
375 sp<DataStruct> dataStruct = new DataStruct(total_length);
376 dataStruct->write32(Endian_SwapBE32(type)); // Type signature
377 dataStruct->write32(0); // Reserved
378 dataStruct->write8(kNumChannels); // Input channels
379 dataStruct->write8(kNumChannels); // Output channels
380 dataStruct->write16(0); // Reserved
381 dataStruct->write32(Endian_SwapBE32(b_curves_offset)); // B curve offset
382 dataStruct->write32(Endian_SwapBE32(0)); // Matrix offset (ignored)
383 dataStruct->write32(Endian_SwapBE32(0)); // M curve offset (ignored)
384 dataStruct->write32(Endian_SwapBE32(clut_offset)); // CLUT offset
385 dataStruct->write32(Endian_SwapBE32(a_curves_offset)); // A curve offset
386 for (size_t i = 0; i < kNumChannels; ++i) {
387 if (dataStruct->write(b_curves_data[i]->getData(), b_curves_data[i]->getLength())) {
388 return dataStruct;
389 }
390 }
391 if (has_a_curves) {
392 dataStruct->write(clut->getData(), clut->getLength());
393 for (size_t i = 0; i < kNumChannels; ++i) {
394 dataStruct->write(a_curves_data[i]->getData(), a_curves_data[i]->getLength());
395 }
396 }
397 return dataStruct;
398}
399
400sp<DataStruct> IccHelper::writeIccProfile(jpegr_transfer_function tf, jpegr_color_gamut gamut) {
401 ICCHeader header;
402
403 std::vector<std::pair<uint32_t, sp<DataStruct>>> tags;
404
405 // Compute profile description tag
406 std::string desc = get_desc_string(tf, gamut);
407
408 tags.emplace_back(kTAG_desc, write_text_tag(desc.c_str()));
409
410 Matrix3x3 toXYZD50;
411 switch (gamut) {
412 case JPEGR_COLORGAMUT_BT709:
413 toXYZD50 = kSRGB;
414 break;
415 case JPEGR_COLORGAMUT_P3:
416 toXYZD50 = kDisplayP3;
417 break;
418 case JPEGR_COLORGAMUT_BT2100:
419 toXYZD50 = kRec2020;
420 break;
421 default:
422 // Should not fall here.
423 return new DataStruct(0);
424 }
425
426 // Compute primaries.
427 {
428 tags.emplace_back(kTAG_rXYZ,
429 write_xyz_tag(toXYZD50.vals[0][0], toXYZD50.vals[1][0], toXYZD50.vals[2][0]));
430 tags.emplace_back(kTAG_gXYZ,
431 write_xyz_tag(toXYZD50.vals[0][1], toXYZD50.vals[1][1], toXYZD50.vals[2][1]));
432 tags.emplace_back(kTAG_bXYZ,
433 write_xyz_tag(toXYZD50.vals[0][2], toXYZD50.vals[1][2], toXYZD50.vals[2][2]));
434 }
435
436 // Compute white point tag (must be D50)
437 tags.emplace_back(kTAG_wtpt, write_xyz_tag(kD50_x, kD50_y, kD50_z));
438
439 // Compute transfer curves.
440 if (tf != JPEGR_TF_PQ) {
441 if (tf == JPEGR_TF_HLG) {
442 std::vector<uint8_t> trc_table;
443 trc_table.resize(kTrcTableSize * 2);
444 for (uint32_t i = 0; i < kTrcTableSize; ++i) {
445 float x = i / (kTrcTableSize - 1.f);
446 float y = hlgOetf(x);
447 y *= compute_tone_map_gain(tf, y);
448 float_to_table16(y, &trc_table[2 * i]);
449 }
450
451 tags.emplace_back(kTAG_rTRC,
452 write_trc_tag(kTrcTableSize, reinterpret_cast<uint8_t*>(trc_table.data())));
453 tags.emplace_back(kTAG_gTRC,
454 write_trc_tag(kTrcTableSize, reinterpret_cast<uint8_t*>(trc_table.data())));
455 tags.emplace_back(kTAG_bTRC,
456 write_trc_tag(kTrcTableSize, reinterpret_cast<uint8_t*>(trc_table.data())));
457 } else {
458 tags.emplace_back(kTAG_rTRC, write_trc_tag_for_linear());
459 tags.emplace_back(kTAG_gTRC, write_trc_tag_for_linear());
460 tags.emplace_back(kTAG_bTRC, write_trc_tag_for_linear());
461 }
462 }
463
464 // Compute CICP.
465 if (tf == JPEGR_TF_HLG || tf == JPEGR_TF_PQ) {
466 // The CICP tag is present in ICC 4.4, so update the header's version.
467 header.version = Endian_SwapBE32(0x04400000);
468
469 uint32_t color_primaries = 0;
470 if (gamut == JPEGR_COLORGAMUT_BT709) {
471 color_primaries = kCICPPrimariesSRGB;
472 } else if (gamut == JPEGR_COLORGAMUT_P3) {
473 color_primaries = kCICPPrimariesP3;
474 }
475
476 uint32_t transfer_characteristics = 0;
477 if (tf == JPEGR_TF_SRGB) {
478 transfer_characteristics = kCICPTrfnSRGB;
479 } else if (tf == JPEGR_TF_LINEAR) {
480 transfer_characteristics = kCICPTrfnLinear;
481 } else if (tf == JPEGR_TF_PQ) {
482 transfer_characteristics = kCICPTrfnPQ;
483 } else if (tf == JPEGR_TF_HLG) {
484 transfer_characteristics = kCICPTrfnHLG;
485 }
486 tags.emplace_back(kTAG_cicp, write_cicp_tag(color_primaries, transfer_characteristics));
487 }
488
489 // Compute A2B0.
490 if (tf == JPEGR_TF_PQ) {
491 std::vector<uint8_t> a2b_grid;
492 a2b_grid.resize(kGridSize * kGridSize * kGridSize * kNumChannels * 2);
493 size_t a2b_grid_index = 0;
494 for (uint32_t r_index = 0; r_index < kGridSize; ++r_index) {
495 for (uint32_t g_index = 0; g_index < kGridSize; ++g_index) {
496 for (uint32_t b_index = 0; b_index < kGridSize; ++b_index) {
497 float rgb[3] = {
498 r_index / (kGridSize - 1.f),
499 g_index / (kGridSize - 1.f),
500 b_index / (kGridSize - 1.f),
501 };
502 compute_lut_entry(toXYZD50, rgb);
503 float_XYZD50_to_grid16_lab(rgb, &a2b_grid[a2b_grid_index]);
504 a2b_grid_index += 6;
505 }
506 }
507 }
508 const uint8_t* grid_16 = reinterpret_cast<const uint8_t*>(a2b_grid.data());
509
510 uint8_t grid_points[kNumChannels];
511 for (size_t i = 0; i < kNumChannels; ++i) {
512 grid_points[i] = kGridSize;
513 }
514
515 auto a2b_data = write_mAB_or_mBA_tag(kTAG_mABType,
516 /* has_a_curves */ true,
517 grid_points,
518 grid_16);
519 tags.emplace_back(kTAG_A2B0, std::move(a2b_data));
520 }
521
522 // Compute B2A0.
523 if (tf == JPEGR_TF_PQ) {
524 auto b2a_data = write_mAB_or_mBA_tag(kTAG_mBAType,
525 /* has_a_curves */ false,
526 /* grid_points */ nullptr,
527 /* grid_16 */ nullptr);
528 tags.emplace_back(kTAG_B2A0, std::move(b2a_data));
529 }
530
531 // Compute copyright tag
532 tags.emplace_back(kTAG_cprt, write_text_tag("Google Inc. 2022"));
533
534 // Compute the size of the profile.
535 size_t tag_data_size = 0;
536 for (const auto& tag : tags) {
537 tag_data_size += tag.second->getLength();
538 }
539 size_t tag_table_size = kICCTagTableEntrySize * tags.size();
540 size_t profile_size = kICCHeaderSize + tag_table_size + tag_data_size;
541
542 // Write the header.
543 header.data_color_space = Endian_SwapBE32(Signature_RGB);
544 header.pcs = Endian_SwapBE32(tf == JPEGR_TF_PQ ? Signature_Lab : Signature_XYZ);
545 header.size = Endian_SwapBE32(profile_size);
546 header.tag_count = Endian_SwapBE32(tags.size());
547
548 sp<DataStruct> dataStruct = new DataStruct(profile_size);
549 if (!dataStruct->write(&header, sizeof(header))) {
550 ALOGE("writeIccProfile(): error in header");
551 return dataStruct;
552 }
553
554 // Write the tag table. Track the offset and size of the previous tag to
555 // compute each tag's offset. An empty SkData indicates that the previous
556 // tag is to be reused.
557 uint32_t last_tag_offset = sizeof(header) + tag_table_size;
558 uint32_t last_tag_size = 0;
559 for (const auto& tag : tags) {
560 last_tag_offset = last_tag_offset + last_tag_size;
561 last_tag_size = tag.second->getLength();
562 uint32_t tag_table_entry[3] = {
563 Endian_SwapBE32(tag.first),
564 Endian_SwapBE32(last_tag_offset),
565 Endian_SwapBE32(last_tag_size),
566 };
567 if (!dataStruct->write(tag_table_entry, sizeof(tag_table_entry))) {
568 ALOGE("writeIccProfile(): error in writing tag table");
569 return dataStruct;
570 }
571 }
572
573 // Write the tags.
574 for (const auto& tag : tags) {
575 if (!dataStruct->write(tag.second->getData(), tag.second->getLength())) {
576 ALOGE("writeIccProfile(): error in writing tags");
577 return dataStruct;
578 }
579 }
580
581 return dataStruct;
582}
583
584} // namespace android::jpegrecoverymap