Home | History | Annotate | Download | only in stagefright
      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     status_t convert(
     37             const void *srcBits,
     38             size_t srcWidth, size_t srcHeight,
     39             size_t srcCropLeft, size_t srcCropTop,
     40             size_t srcCropRight, size_t srcCropBottom,
     41             void *dstBits,
     42             size_t dstWidth, size_t dstHeight,
     43             size_t dstCropLeft, size_t dstCropTop,
     44             size_t dstCropRight, size_t dstCropBottom);
     45 
     46 private:
     47     struct BitmapParams {
     48         BitmapParams(
     49                 void *bits,
     50                 size_t width, size_t height,
     51                 size_t cropLeft, size_t cropTop,
     52                 size_t cropRight, size_t cropBottom);
     53 
     54         size_t cropWidth() const;
     55         size_t cropHeight() const;
     56 
     57         void *mBits;
     58         size_t mWidth, mHeight;
     59         size_t mCropLeft, mCropTop, mCropRight, mCropBottom;
     60     };
     61 
     62     OMX_COLOR_FORMATTYPE mSrcFormat, mDstFormat;
     63     uint8_t *mClip;
     64 
     65     uint8_t *initClip();
     66 
     67     status_t convertCbYCrY(
     68             const BitmapParams &src, const BitmapParams &dst);
     69 
     70     status_t convertYUV420Planar(
     71             const BitmapParams &src, const BitmapParams &dst);
     72 
     73     status_t convertQCOMYUV420SemiPlanar(
     74             const BitmapParams &src, const BitmapParams &dst);
     75 
     76     status_t convertYUV420SemiPlanar(
     77             const BitmapParams &src, const BitmapParams &dst);
     78 
     79     status_t convertTIYUV420PackedSemiPlanar(
     80             const BitmapParams &src, const BitmapParams &dst);
     81 
     82     ColorConverter(const ColorConverter &);
     83     ColorConverter &operator=(const ColorConverter &);
     84 };
     85 
     86 }  // namespace android
     87 
     88 #endif  // COLOR_CONVERTER_H_
     89