Converters.cpp revision 5467be2eefc007ebf09baf109dafe058abc1ffc5
1/* 2 * Copyright (C) 2011 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/* 18 * Contains implemenation of framebuffer conversion routines. 19 */ 20 21#define LOG_NDEBUG 0 22#define LOG_TAG "EmulatedCamera_Converter" 23#include <cutils/log.h> 24#include "Converters.h" 25 26namespace android { 27 28void YV12ToRGB565(const void* yv12, void* rgb, int width, int height) 29{ 30 const int pix_total = width * height; 31 uint16_t* rgb_buf = reinterpret_cast<uint16_t*>(rgb); 32 const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12); 33 const uint8_t* U_pos = Y + pix_total; 34 const uint8_t* V_pos = U_pos + pix_total / 4; 35 const uint8_t* U = U_pos; 36 const uint8_t* V = V_pos; 37 38 for (int y = 0; y < height; y++) { 39 for (int x = 0; x < width; x += 2) { 40 const uint8_t nU = *U; U++; 41 const uint8_t nV = *V; V++; 42 *rgb_buf = YUVToRGB565(*Y, nU, nV); 43 Y++; rgb_buf++; 44 *rgb_buf = YUVToRGB565(*Y, nU, nV); 45 Y++; rgb_buf++; 46 } 47 if (y & 0x1) { 48 U_pos = U; 49 V_pos = V; 50 } else { 51 U = U_pos; 52 V = V_pos; 53 } 54 } 55} 56 57void YV12ToRGB32(const void* yv12, void* rgb, int width, int height) 58{ 59 const int pix_total = width * height; 60 uint32_t* rgb_buf = reinterpret_cast<uint32_t*>(rgb); 61 const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12); 62 const uint8_t* U_pos = Y + pix_total; 63 const uint8_t* V_pos = U_pos + pix_total / 4; 64 const uint8_t* U = U_pos; 65 const uint8_t* V = V_pos; 66 67 for (int y = 0; y < height; y++) { 68 for (int x = 0; x < width; x += 2) { 69 const uint8_t nU = *U; U++; 70 const uint8_t nV = *V; V++; 71 *rgb_buf = YUVToRGB32(*Y, nU, nV); 72 Y++; rgb_buf++; 73 *rgb_buf = YUVToRGB32(*Y, nU, nV); 74 Y++; rgb_buf++; 75 } 76 if (y & 0x1) { 77 U_pos = U; 78 V_pos = V; 79 } else { 80 U = U_pos; 81 V = V_pos; 82 } 83 } 84} 85 86}; /* namespace android */ 87