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 private: 51 struct ColorSpace { 52 uint32_t mStandard; 53 uint32_t mRange; 54 uint32_t mTransfer; 55 56 bool isBt709(); 57 bool isJpeg(); 58 }; 59 60 struct BitmapParams { 61 BitmapParams( 62 void *bits, 63 size_t width, size_t height, size_t stride, 64 size_t cropLeft, size_t cropTop, 65 size_t cropRight, size_t cropBottom, 66 OMX_COLOR_FORMATTYPE colorFromat); 67 68 size_t cropWidth() const; 69 size_t cropHeight() const; 70 71 void *mBits; 72 OMX_COLOR_FORMATTYPE mColorFormat; 73 size_t mWidth, mHeight; 74 size_t mCropLeft, mCropTop, mCropRight, mCropBottom; 75 size_t mBpp, mStride; 76 }; 77 78 OMX_COLOR_FORMATTYPE mSrcFormat, mDstFormat; 79 ColorSpace mSrcColorSpace; 80 uint8_t *mClip; 81 82 uint8_t *initClip(); 83 84 status_t convertCbYCrY( 85 const BitmapParams &src, const BitmapParams &dst); 86 87 status_t convertYUV420Planar( 88 const BitmapParams &src, const BitmapParams &dst); 89 90 status_t convertYUV420PlanarUseLibYUV( 91 const BitmapParams &src, const BitmapParams &dst); 92 93 status_t convertYUV420SemiPlanarUseLibYUV( 94 const BitmapParams &src, const BitmapParams &dst); 95 96 status_t convertYUV420Planar16( 97 const BitmapParams &src, const BitmapParams &dst); 98 99 status_t convertYUV420Planar16ToY410( 100 const BitmapParams &src, const BitmapParams &dst); 101 102 status_t convertYUV420Planar16ToRGB( 103 const BitmapParams &src, const BitmapParams &dst); 104 105 status_t convertQCOMYUV420SemiPlanar( 106 const BitmapParams &src, const BitmapParams &dst); 107 108 status_t convertYUV420SemiPlanar( 109 const BitmapParams &src, const BitmapParams &dst); 110 111 status_t convertTIYUV420PackedSemiPlanar( 112 const BitmapParams &src, const BitmapParams &dst); 113 114 ColorConverter(const ColorConverter &); 115 ColorConverter &operator=(const ColorConverter &); 116 }; 117 118 } // namespace android 119 120 #endif // COLOR_CONVERTER_H_ 121