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     status_t convert(
39             const void *srcBits,
40             size_t srcWidth, size_t srcHeight,
41             size_t srcCropLeft, size_t srcCropTop,
42             size_t srcCropRight, size_t srcCropBottom,
43             void *dstBits,
44             size_t dstWidth, size_t dstHeight,
45             size_t dstCropLeft, size_t dstCropTop,
46             size_t dstCropRight, size_t dstCropBottom);
47 
48 private:
49     struct BitmapParams {
50         BitmapParams(
51                 void *bits,
52                 size_t width, size_t height,
53                 size_t cropLeft, size_t cropTop,
54                 size_t cropRight, size_t cropBottom,
55                 OMX_COLOR_FORMATTYPE colorFromat);
56 
57         size_t cropWidth() const;
58         size_t cropHeight() const;
59 
60         void *mBits;
61         OMX_COLOR_FORMATTYPE mColorFormat;
62         size_t mWidth, mHeight;
63         size_t mCropLeft, mCropTop, mCropRight, mCropBottom;
64         size_t mBpp, mStride;
65     };
66 
67     OMX_COLOR_FORMATTYPE mSrcFormat, mDstFormat;
68     uint8_t *mClip;
69 
70     uint8_t *initClip();
71 
72     status_t convertCbYCrY(
73             const BitmapParams &src, const BitmapParams &dst);
74 
75     status_t convertYUV420Planar(
76             const BitmapParams &src, const BitmapParams &dst);
77 
78     status_t convertYUV420PlanarUseLibYUV(
79             const BitmapParams &src, const BitmapParams &dst);
80 
81     status_t convertYUV420Planar16(
82             const BitmapParams &src, const BitmapParams &dst);
83 
84     status_t convertYUV420Planar16ToY410(
85             const BitmapParams &src, const BitmapParams &dst);
86 
87     status_t convertYUV420Planar16ToRGB(
88             const BitmapParams &src, const BitmapParams &dst);
89 
90     status_t convertQCOMYUV420SemiPlanar(
91             const BitmapParams &src, const BitmapParams &dst);
92 
93     status_t convertYUV420SemiPlanar(
94             const BitmapParams &src, const BitmapParams &dst);
95 
96     status_t convertTIYUV420PackedSemiPlanar(
97             const BitmapParams &src, const BitmapParams &dst);
98 
99     ColorConverter(const ColorConverter &);
100     ColorConverter &operator=(const ColorConverter &);
101 };
102 
103 }  // namespace android
104 
105 #endif  // COLOR_CONVERTER_H_
106