• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #ifndef ULTRAHDR_MULTIPICTUREFORMAT_H
18 #define ULTRAHDR_MULTIPICTUREFORMAT_H
19 
20 #include <memory>
21 
22 #ifndef USE_BIG_ENDIAN_IN_MPF
23 #define USE_BIG_ENDIAN_IN_MPF true
24 #endif
25 
26 #undef Endian_SwapBE32
27 #undef Endian_SwapBE16
28 #if USE_BIG_ENDIAN_IN_MPF
29 #define Endian_SwapBE32(n) EndianSwap32(n)
30 #define Endian_SwapBE16(n) EndianSwap16(n)
31 #else
32 #define Endian_SwapBE32(n) (n)
33 #define Endian_SwapBE16(n) (n)
34 #endif
35 
36 #include "ultrahdr/ultrahdr.h"
37 #include "ultrahdr/jpegr.h"
38 #include "ultrahdr/gainmapmath.h"
39 #include "ultrahdr/jpegrutils.h"
40 
41 namespace ultrahdr {
42 
43 constexpr size_t kNumPictures = 2;
44 constexpr size_t kMpEndianSize = 4;
45 constexpr uint16_t kTagSerializedCount = 3;
46 constexpr uint32_t kTagSize = 12;
47 
48 constexpr uint16_t kTypeLong = 0x4;
49 constexpr uint16_t kTypeUndefined = 0x7;
50 
51 static constexpr uint8_t kMpfSig[] = {'M', 'P', 'F', '\0'};
52 constexpr uint8_t kMpLittleEndian[kMpEndianSize] = {0x49, 0x49, 0x2A, 0x00};
53 constexpr uint8_t kMpBigEndian[kMpEndianSize] = {0x4D, 0x4D, 0x00, 0x2A};
54 
55 constexpr uint16_t kVersionTag = 0xB000;
56 constexpr uint16_t kVersionType = kTypeUndefined;
57 constexpr uint32_t kVersionCount = 4;
58 constexpr size_t kVersionSize = 4;
59 constexpr uint8_t kVersionExpected[kVersionSize] = {'0', '1', '0', '0'};
60 
61 constexpr uint16_t kNumberOfImagesTag = 0xB001;
62 constexpr uint16_t kNumberOfImagesType = kTypeLong;
63 constexpr uint32_t kNumberOfImagesCount = 1;
64 
65 constexpr uint16_t kMPEntryTag = 0xB002;
66 constexpr uint16_t kMPEntryType = kTypeUndefined;
67 constexpr uint32_t kMPEntrySize = 16;
68 
69 constexpr uint32_t kMPEntryAttributeFormatJpeg = 0x0000000;
70 constexpr uint32_t kMPEntryAttributeTypePrimary = 0x030000;
71 
72 size_t calculateMpfSize();
73 std::shared_ptr<DataStruct> generateMpf(int primary_image_size, int primary_image_offset,
74                                         int secondary_image_size, int secondary_image_offset);
75 
76 }  // namespace ultrahdr
77 
78 #endif  // ULTRAHDR_MULTIPICTUREFORMAT_H
79