• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 COLOR_CONVERTER_H_
18 
19 #define COLOR_CONVERTER_H_
20 
21 #include <sys/types.h>
22 
23 #include <stdint.h>
24 #include <utils/Errors.h>
25 
26 #include <OMX_Video.h>
27 
28 namespace android {
29 
30 struct ColorConverter {
31     ColorConverter(OMX_COLOR_FORMATTYPE from, OMX_COLOR_FORMATTYPE to);
32     ~ColorConverter();
33 
34     bool isValid() const;
35 
36     bool isDstRGB() const;
37 
38     void setSrcColorSpace(uint32_t standard, uint32_t range, uint32_t transfer);
39 
40     status_t convert(
41             const void *srcBits,
42             size_t srcWidth, size_t srcHeight, size_t srcStride,
43             size_t srcCropLeft, size_t srcCropTop,
44             size_t srcCropRight, size_t srcCropBottom,
45             void *dstBits,
46             size_t dstWidth, size_t dstHeight, size_t dstStride,
47             size_t dstCropLeft, size_t dstCropTop,
48             size_t dstCropRight, size_t dstCropBottom);
49 
50     struct Coeffs; // matrix coefficients
51 
52 private:
53     struct ColorSpace {
54         uint32_t mStandard;
55         uint32_t mRange;
56         uint32_t mTransfer;
57 
58         bool isBt2020() const;
59 
60         // libyuv helper methods
61         bool isH420() const;
62         bool isI420() const;
63         bool isJ420() const;
64     };
65 
66     struct BitmapParams {
67         BitmapParams(
68                 void *bits,
69                 size_t width, size_t height, size_t stride,
70                 size_t cropLeft, size_t cropTop,
71                 size_t cropRight, size_t cropBottom,
72                 OMX_COLOR_FORMATTYPE colorFromat);
73 
74         size_t cropWidth() const;
75         size_t cropHeight() const;
76 
77         bool isValid() const;
78 
79         void *mBits;
80         OMX_COLOR_FORMATTYPE mColorFormat;
81         size_t mWidth, mHeight;
82         size_t mCropLeft, mCropTop, mCropRight, mCropBottom;
83         size_t mBpp, mStride;
84     };
85 
86     OMX_COLOR_FORMATTYPE mSrcFormat, mDstFormat;
87     ColorSpace mSrcColorSpace;
88     uint8_t *mClip;
89     uint16_t *mClip10Bit;
90 
91     uint8_t *initClip();
92     uint16_t *initClip10Bit();
93 
94     // returns the YUV2RGB matrix coefficients according to the color aspects and bit depth
95     const struct Coeffs *getMatrix() const;
96 
97     status_t convertCbYCrY(
98             const BitmapParams &src, const BitmapParams &dst);
99 
100     status_t convertYUV420Planar(
101             const BitmapParams &src, const BitmapParams &dst);
102 
103     status_t convertYUV420PlanarUseLibYUV(
104             const BitmapParams &src, const BitmapParams &dst);
105 
106     status_t convertYUV420SemiPlanarUseLibYUV(
107             const BitmapParams &src, const BitmapParams &dst);
108 
109     status_t convertYUV420Planar16(
110             const BitmapParams &src, const BitmapParams &dst);
111 
112     status_t convertYUV420Planar16ToY410(
113             const BitmapParams &src, const BitmapParams &dst);
114 
115     status_t convertYUV420Planar16ToRGB(
116             const BitmapParams &src, const BitmapParams &dst);
117 
118     status_t convertQCOMYUV420SemiPlanar(
119             const BitmapParams &src, const BitmapParams &dst);
120 
121     status_t convertYUV420SemiPlanar(
122             const BitmapParams &src, const BitmapParams &dst);
123 
124     status_t convertYUV420SemiPlanarBase(
125             const BitmapParams &src, const BitmapParams &dst,
126             size_t row_inc, bool isNV21 = false);
127 
128     status_t convertTIYUV420PackedSemiPlanar(
129             const BitmapParams &src, const BitmapParams &dst);
130 
131     status_t convertYUVP010(
132                 const BitmapParams &src, const BitmapParams &dst);
133 
134     status_t convertYUVP010ToRGBA1010102(
135                 const BitmapParams &src, const BitmapParams &dst);
136 
137     ColorConverter(const ColorConverter &);
138     ColorConverter &operator=(const ColorConverter &);
139 };
140 
141 }  // namespace android
142 
143 #endif  // COLOR_CONVERTER_H_
144