/src/libultrahdr/lib/include/ultrahdr/jpegrutils.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2022 The Android Open Source Project |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
5 | | * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
6 | | * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your |
7 | | * option. This file may not be copied, modified, or distributed |
8 | | * except according to those terms. |
9 | | */ |
10 | | |
11 | | #ifndef ULTRAHDR_JPEGRUTILS_H |
12 | | #define ULTRAHDR_JPEGRUTILS_H |
13 | | |
14 | | #include "ultrahdr/jpegr.h" |
15 | | |
16 | | // TODO (dichenzhang): This is old version metadata, new version can be found in |
17 | | // https://drive.google.com/file/d/1yUGmjGytRuBa2vpr9eM5Uu8CVhyyddjp/view?resourcekey=0-HGzFrzPQzu5FNYLRAJXQBA |
18 | | // and in gainmapmetadata.h/.cpp |
19 | | // This file is kept in order to keep the backward compatibility. |
20 | | namespace ultrahdr { |
21 | | |
22 | 200k | static constexpr uint32_t EndianSwap32(uint32_t value) { |
23 | 200k | return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | |
24 | 200k | (value >> 24); |
25 | 200k | } Unexecuted instantiation: ultrahdr_api.cpp:ultrahdr::EndianSwap32(unsigned int) Unexecuted instantiation: jpegr.cpp:ultrahdr::EndianSwap32(unsigned int) Unexecuted instantiation: jpegrutils.cpp:ultrahdr::EndianSwap32(unsigned int) Unexecuted instantiation: multipictureformat.cpp:ultrahdr::EndianSwap32(unsigned int) icc.cpp:ultrahdr::EndianSwap32(unsigned int) Line | Count | Source | 22 | 200k | static constexpr uint32_t EndianSwap32(uint32_t value) { | 23 | 200k | return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) | ((value & 0xFF0000) >> 8) | | 24 | 200k | (value >> 24); | 25 | 200k | } |
|
26 | 0 | static inline uint16_t EndianSwap16(uint16_t value) { |
27 | 0 | return static_cast<uint16_t>((value >> 8) | ((value & 0xFF) << 8)); |
28 | 0 | } Unexecuted instantiation: ultrahdr_api.cpp:ultrahdr::EndianSwap16(unsigned short) Unexecuted instantiation: jpegr.cpp:ultrahdr::EndianSwap16(unsigned short) Unexecuted instantiation: jpegrutils.cpp:ultrahdr::EndianSwap16(unsigned short) Unexecuted instantiation: multipictureformat.cpp:ultrahdr::EndianSwap16(unsigned short) Unexecuted instantiation: icc.cpp:ultrahdr::EndianSwap16(unsigned short) |
29 | | |
30 | | /* |
31 | | * Mutable data structure. Holds information for metadata. |
32 | | */ |
33 | | class DataStruct { |
34 | | private: |
35 | | void* data; |
36 | | size_t writePos; |
37 | | size_t length; |
38 | | |
39 | | public: |
40 | | DataStruct(size_t s); |
41 | | ~DataStruct(); |
42 | | |
43 | | void* getData(); |
44 | | size_t getLength(); |
45 | | size_t getBytesWritten(); |
46 | | bool write8(uint8_t value); |
47 | | bool write16(uint16_t value); |
48 | | bool write32(uint32_t value); |
49 | | bool write(const void* src, size_t size); |
50 | | }; |
51 | | |
52 | | /* |
53 | | * Helper function used for writing data to destination. |
54 | | * |
55 | | * @param destination destination of the data to be written. |
56 | | * @param source source of data being written. |
57 | | * @param length length of the data to be written. |
58 | | * @param position cursor in desitination where the data is to be written. |
59 | | * @return success or error code. |
60 | | */ |
61 | | uhdr_error_info_t Write(uhdr_compressed_image_t* destination, const void* source, size_t length, |
62 | | size_t& position); |
63 | | |
64 | | /* |
65 | | * Parses XMP packet and fills metadata with data from XMP |
66 | | * |
67 | | * @param xmp_data pointer to XMP packet |
68 | | * @param xmp_size size of XMP packet |
69 | | * @param metadata place to store HDR metadata values |
70 | | * @return success or error code. |
71 | | */ |
72 | | uhdr_error_info_t getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, |
73 | | uhdr_gainmap_metadata_ext_t* metadata); |
74 | | |
75 | | /* |
76 | | * This method generates XMP metadata for the primary image. |
77 | | * |
78 | | * below is an example of the XMP metadata that this function generates where |
79 | | * secondary_image_length = 1000 |
80 | | * |
81 | | * <x:xmpmeta |
82 | | * xmlns:x="adobe:ns:meta/" |
83 | | * x:xmptk="Adobe XMP Core 5.1.2"> |
84 | | * <rdf:RDF |
85 | | * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
86 | | * <rdf:Description |
87 | | * xmlns:Container="http://ns.google.com/photos/1.0/container/" |
88 | | * xmlns:Item="http://ns.google.com/photos/1.0/container/item/" |
89 | | * xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/" |
90 | | * hdrgm:Version="1"> |
91 | | * <Container:Directory> |
92 | | * <rdf:Seq> |
93 | | * <rdf:li |
94 | | * rdf:parseType="Resource"> |
95 | | * <Container:Item |
96 | | * Item:Semantic="Primary" |
97 | | * Item:Mime="image/jpeg"/> |
98 | | * </rdf:li> |
99 | | * <rdf:li |
100 | | * rdf:parseType="Resource"> |
101 | | * <Container:Item |
102 | | * Item:Semantic="GainMap" |
103 | | * Item:Mime="image/jpeg" |
104 | | * Item:Length="1000"/> |
105 | | * </rdf:li> |
106 | | * </rdf:Seq> |
107 | | * </Container:Directory> |
108 | | * </rdf:Description> |
109 | | * </rdf:RDF> |
110 | | * </x:xmpmeta> |
111 | | * |
112 | | * @param secondary_image_length length of secondary image |
113 | | * @return XMP metadata in type of string |
114 | | */ |
115 | | std::string generateXmpForPrimaryImage(size_t secondary_image_length, |
116 | | uhdr_gainmap_metadata_ext_t& metadata); |
117 | | |
118 | | /* |
119 | | * This method generates XMP metadata for the recovery map image. |
120 | | * Link: https://developer.android.com/media/platform/hdr-image-format#XMP-attributes |
121 | | * |
122 | | * below is an example of the XMP metadata that this function generates where |
123 | | * max_content_boost = 8.0 |
124 | | * min_content_boost = 0.5 |
125 | | * |
126 | | * <x:xmpmeta |
127 | | * xmlns:x="adobe:ns:meta/" |
128 | | * x:xmptk="Adobe XMP Core 5.1.2"> |
129 | | * <rdf:RDF |
130 | | * xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
131 | | * <rdf:Description |
132 | | * xmlns:hdrgm="http://ns.adobe.com/hdr-gain-map/1.0/" |
133 | | * hdrgm:Version="1" |
134 | | * hdrgm:GainMapMin="-1" |
135 | | * hdrgm:GainMapMax="3" |
136 | | * hdrgm:Gamma="1" |
137 | | * hdrgm:OffsetSDR="0" |
138 | | * hdrgm:OffsetHDR="0" |
139 | | * hdrgm:HDRCapacityMin="0" |
140 | | * hdrgm:HDRCapacityMax="3" |
141 | | * hdrgm:BaseRenditionIsHDR="False"/> |
142 | | * </rdf:RDF> |
143 | | * </x:xmpmeta> |
144 | | * |
145 | | * @param metadata JPEG/R metadata to encode as XMP |
146 | | * @return XMP metadata in type of string |
147 | | */ |
148 | | std::string generateXmpForSecondaryImage(uhdr_gainmap_metadata_ext_t& metadata); |
149 | | |
150 | | } // namespace ultrahdr |
151 | | |
152 | | #endif // ULTRAHDR_JPEGRUTILS_H |