DngUtils.h revision e507721000647a7d8afe44c63ef7fd04ef8971b1
1/*
2 * Copyright 2014 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 IMG_UTILS_DNG_UTILS_H
18#define IMG_UTILS_DNG_UTILS_H
19
20#include <img_utils/ByteArrayOutput.h>
21#include <img_utils/EndianUtils.h>
22
23#include <utils/Errors.h>
24#include <utils/Log.h>
25#include <utils/RefBase.h>
26
27#include <cutils/compiler.h>
28#include <stdint.h>
29
30namespace android {
31namespace img_utils {
32
33#define NELEMS(x) ((int) (sizeof(x) / sizeof((x)[0])))
34
35/**
36 * Utility class for building values for the OpcodeList tags specified
37 * in the Adobe DNG 1.4 spec.
38 */
39class ANDROID_API OpcodeListBuilder : public LightRefBase<OpcodeListBuilder> {
40    public:
41        enum CfaLayout {
42            CFA_RGGB = 0,
43            CFA_GRBG,
44            CFA_GBRG,
45            CFA_BGGR,
46        };
47
48        OpcodeListBuilder();
49        virtual ~OpcodeListBuilder();
50
51        /**
52         * Get the total size of this opcode list in bytes.
53         */
54        virtual size_t getSize() const;
55
56        /**
57         * Get the number of opcodes defined in this list.
58         */
59        virtual uint32_t getCount() const;
60
61        /**
62         * Write the opcode list into the given buffer.  This buffer
63         * must be able to hold at least as many elements as returned
64         * by calling the getSize() method.
65         *
66         * Returns OK on success, or a negative error code.
67         */
68        virtual status_t buildOpList(/*out*/ uint8_t* buf) const;
69
70        /**
71         * Add GainMap opcode(s) for the given metadata parameters.  The given
72         * CFA layout must match the layout of the shading map passed into the
73         * lensShadingMap parameter.
74         *
75         * Returns OK on success, or a negative error code.
76         */
77        virtual status_t addGainMapsForMetadata(uint32_t lsmWidth,
78                                                uint32_t lsmHeight,
79                                                uint32_t activeAreaTop,
80                                                uint32_t activeAreaLeft,
81                                                uint32_t activeAreaBottom,
82                                                uint32_t activeAreaRight,
83                                                CfaLayout cfa,
84                                                const float* lensShadingMap);
85
86
87        /**
88         * Add a GainMap opcode with the given fields.  The mapGains array
89         * must have mapPointsV * mapPointsH * mapPlanes elements.
90         *
91         * Returns OK on success, or a negative error code.
92         */
93        virtual status_t addGainMap(uint32_t top,
94                                    uint32_t left,
95                                    uint32_t bottom,
96                                    uint32_t right,
97                                    uint32_t plane,
98                                    uint32_t planes,
99                                    uint32_t rowPitch,
100                                    uint32_t colPitch,
101                                    uint32_t mapPointsV,
102                                    uint32_t mapPointsH,
103                                    double mapSpacingV,
104                                    double mapSpacingH,
105                                    double mapOriginV,
106                                    double mapOriginH,
107                                    uint32_t mapPlanes,
108                                    const float* mapGains);
109
110        // TODO: Add other Opcode methods
111    protected:
112        static const uint32_t FLAG_OPTIONAL = 0x1u;
113        static const uint32_t FLAG_OPTIONAL_FOR_PREVIEW = 0x2u;
114
115        enum {
116            GAIN_MAP_ID = 9,
117            LSM_R_IND = 0,
118            LSM_GE_IND = 1,
119            LSM_GO_IND = 2,
120            LSM_B_IND = 3,
121        };
122
123        uint32_t mCount;
124        ByteArrayOutput mOpList;
125        EndianOutput mEndianOut;
126
127};
128
129} /*namespace img_utils*/
130} /*namespace android*/
131
132#endif /*IMG_UTILS_DNG_UTILS_H*/
133