YUVCanvas.cpp revision db205a1d75c1e9a7d0dbd8fa011335249ad6f4ac
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#define LOG_NDEBUG 0 18#define LOG_TAG "YUVCanvas" 19 20#include <media/stagefright/YUVCanvas.h> 21#include <media/stagefright/YUVImage.h> 22#include <ui/Rect.h> 23 24namespace android { 25 26YUVCanvas::YUVCanvas(YUVImage &yuvImage) 27 : mYUVImage(yuvImage) { 28} 29 30YUVCanvas::~YUVCanvas() { 31} 32 33void YUVCanvas::FillYUV(uint8_t yValue, uint8_t uValue, uint8_t vValue) { 34 for (int32_t y = 0; y < mYUVImage.height(); ++y) { 35 for (int32_t x = 0; x < mYUVImage.width(); ++x) { 36 mYUVImage.setPixelValue(x, y, yValue, uValue, vValue); 37 } 38 } 39} 40 41void YUVCanvas::FillYUVRectangle(const Rect& rect, 42 uint8_t yValue, uint8_t uValue, uint8_t vValue) { 43 for (int32_t y = rect.top; y < rect.bottom; ++y) { 44 for (int32_t x = rect.left; x < rect.right; ++x) { 45 mYUVImage.setPixelValue(x, y, yValue, uValue, vValue); 46 } 47 } 48} 49 50void YUVCanvas::CopyImageRect( 51 const Rect& srcRect, 52 int32_t destStartX, int32_t destStartY, 53 const YUVImage &srcImage) { 54 55 // Try fast copy first 56 if (YUVImage::fastCopyRectangle( 57 srcRect, 58 destStartX, destStartY, 59 srcImage, mYUVImage)) { 60 return; 61 } 62 63 int32_t srcStartX = srcRect.left; 64 int32_t srcStartY = srcRect.top; 65 for (int32_t offsetY = 0; offsetY < srcRect.height(); ++offsetY) { 66 for (int32_t offsetX = 0; offsetX < srcRect.width(); ++offsetX) { 67 int32_t srcX = srcStartX + offsetX; 68 int32_t srcY = srcStartY + offsetY; 69 70 int32_t destX = destStartX + offsetX; 71 int32_t destY = destStartY + offsetY; 72 73 uint8_t yValue; 74 uint8_t uValue; 75 uint8_t vValue; 76 77 srcImage.getPixelValue(srcX, srcY, &yValue, &uValue, & vValue); 78 mYUVImage.setPixelValue(destX, destY, yValue, uValue, vValue); 79 } 80 } 81} 82 83} // namespace android 84