Home | History | Annotate | Download | only in stagefright
      1 /*
      2  * Copyright (C) 2010 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 // YUVCanvas holds a reference to a YUVImage on which it can do various
     18 // drawing operations. It provides various utility functions for filling,
     19 // cropping, etc.
     20 
     21 
     22 #ifndef YUV_CANVAS_H_
     23 
     24 #define YUV_CANVAS_H_
     25 
     26 #include <stdint.h>
     27 
     28 namespace android {
     29 
     30 class YUVImage;
     31 class Rect;
     32 
     33 class YUVCanvas {
     34 public:
     35 
     36     // Constructor takes in reference to a yuvImage on which it can do
     37     // various drawing opreations.
     38     YUVCanvas(YUVImage &yuvImage);
     39     ~YUVCanvas();
     40 
     41     // Fills the entire image with the given YUV values.
     42     void FillYUV(uint8_t yValue, uint8_t uValue, uint8_t vValue);
     43 
     44     // Fills the rectangular region [startX,endX]x[startY,endY] with the given YUV values.
     45     void FillYUVRectangle(const Rect& rect,
     46             uint8_t yValue, uint8_t uValue, uint8_t vValue);
     47 
     48     // Copies the region [startX,endX]x[startY,endY] from srcImage into the
     49     // canvas' target image (mYUVImage) starting at
     50     // (destinationStartX,destinationStartY).
     51     // Note that undefined behavior may occur if srcImage is same as the canvas'
     52     // target image.
     53     void CopyImageRect(
     54             const Rect& srcRect,
     55             int32_t destStartX, int32_t destStartY,
     56             const YUVImage &srcImage);
     57 
     58     // Downsamples the srcImage into the canvas' target image (mYUVImage)
     59     // The downsampling copies pixels from the source image starting at
     60     // (srcOffsetX, srcOffsetY) to the target image, starting at (0, 0).
     61     // For each X increment in the target image, skipX pixels are skipped
     62     // in the source image.
     63     // Similarly for each Y increment in the target image, skipY pixels
     64     // are skipped in the source image.
     65     void downsample(
     66             int32_t srcOffsetX, int32_t srcOffsetY,
     67             int32_t skipX, int32_t skipY,
     68             const YUVImage &srcImage);
     69 
     70 private:
     71     YUVImage& mYUVImage;
     72 
     73     YUVCanvas(const YUVCanvas &);
     74     YUVCanvas &operator=(const YUVCanvas &);
     75 };
     76 
     77 }  // namespace android
     78 
     79 #endif  // YUV_CANVAS_H_
     80