1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/ycbcr/YCbCrUtils.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,156 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "gfx2DGlue.h" 1.10 + 1.11 +#include "YCbCrUtils.h" 1.12 +#include "yuv_convert.h" 1.13 +#include "ycbcr_to_rgb565.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace gfx { 1.17 + 1.18 +void 1.19 +GetYCbCrToRGBDestFormatAndSize(const layers::PlanarYCbCrData& aData, 1.20 + SurfaceFormat& aSuggestedFormat, 1.21 + IntSize& aSuggestedSize) 1.22 +{ 1.23 + YUVType yuvtype = 1.24 + TypeFromSize(aData.mYSize.width, 1.25 + aData.mYSize.height, 1.26 + aData.mCbCrSize.width, 1.27 + aData.mCbCrSize.height); 1.28 + 1.29 + // 'prescale' is true if the scaling is to be done as part of the 1.30 + // YCbCr to RGB conversion rather than on the RGB data when rendered. 1.31 + bool prescale = aSuggestedSize.width > 0 && aSuggestedSize.height > 0 && 1.32 + aSuggestedSize != aData.mPicSize; 1.33 + 1.34 + if (aSuggestedFormat == SurfaceFormat::R5G6B5) { 1.35 +#if defined(HAVE_YCBCR_TO_RGB565) 1.36 + if (prescale && 1.37 + !IsScaleYCbCrToRGB565Fast(aData.mPicX, 1.38 + aData.mPicY, 1.39 + aData.mPicSize.width, 1.40 + aData.mPicSize.height, 1.41 + aSuggestedSize.width, 1.42 + aSuggestedSize.height, 1.43 + yuvtype, 1.44 + FILTER_BILINEAR) && 1.45 + IsConvertYCbCrToRGB565Fast(aData.mPicX, 1.46 + aData.mPicY, 1.47 + aData.mPicSize.width, 1.48 + aData.mPicSize.height, 1.49 + yuvtype)) { 1.50 + prescale = false; 1.51 + } 1.52 +#else 1.53 + // yuv2rgb16 function not available 1.54 + aSuggestedFormat = SurfaceFormat::B8G8R8X8; 1.55 +#endif 1.56 + } 1.57 + else if (aSuggestedFormat != SurfaceFormat::B8G8R8X8) { 1.58 + // No other formats are currently supported. 1.59 + aSuggestedFormat = SurfaceFormat::B8G8R8X8; 1.60 + } 1.61 + if (aSuggestedFormat == SurfaceFormat::B8G8R8X8) { 1.62 + /* ScaleYCbCrToRGB32 does not support a picture offset, nor 4:4:4 data. 1.63 + See bugs 639415 and 640073. */ 1.64 + if (aData.mPicX != 0 || aData.mPicY != 0 || yuvtype == YV24) 1.65 + prescale = false; 1.66 + } 1.67 + if (!prescale) { 1.68 + aSuggestedSize = aData.mPicSize; 1.69 + } 1.70 +} 1.71 + 1.72 +void 1.73 +ConvertYCbCrToRGB(const layers::PlanarYCbCrData& aData, 1.74 + const SurfaceFormat& aDestFormat, 1.75 + const IntSize& aDestSize, 1.76 + unsigned char* aDestBuffer, 1.77 + int32_t aStride) 1.78 +{ 1.79 + // ConvertYCbCrToRGB et al. assume the chroma planes are rounded up if the 1.80 + // luma plane is odd sized. 1.81 + MOZ_ASSERT((aData.mCbCrSize.width == aData.mYSize.width || 1.82 + aData.mCbCrSize.width == (aData.mYSize.width + 1) >> 1) && 1.83 + (aData.mCbCrSize.height == aData.mYSize.height || 1.84 + aData.mCbCrSize.height == (aData.mYSize.height + 1) >> 1)); 1.85 + YUVType yuvtype = 1.86 + TypeFromSize(aData.mYSize.width, 1.87 + aData.mYSize.height, 1.88 + aData.mCbCrSize.width, 1.89 + aData.mCbCrSize.height); 1.90 + 1.91 + // Convert from YCbCr to RGB now, scaling the image if needed. 1.92 + if (aDestSize != aData.mPicSize) { 1.93 +#if defined(HAVE_YCBCR_TO_RGB565) 1.94 + if (aDestFormat == SurfaceFormat::R5G6B5) { 1.95 + ScaleYCbCrToRGB565(aData.mYChannel, 1.96 + aData.mCbChannel, 1.97 + aData.mCrChannel, 1.98 + aDestBuffer, 1.99 + aData.mPicX, 1.100 + aData.mPicY, 1.101 + aData.mPicSize.width, 1.102 + aData.mPicSize.height, 1.103 + aDestSize.width, 1.104 + aDestSize.height, 1.105 + aData.mYStride, 1.106 + aData.mCbCrStride, 1.107 + aStride, 1.108 + yuvtype, 1.109 + FILTER_BILINEAR); 1.110 + } else 1.111 +#endif 1.112 + ScaleYCbCrToRGB32(aData.mYChannel, // 1.113 + aData.mCbChannel, 1.114 + aData.mCrChannel, 1.115 + aDestBuffer, 1.116 + aData.mPicSize.width, 1.117 + aData.mPicSize.height, 1.118 + aDestSize.width, 1.119 + aDestSize.height, 1.120 + aData.mYStride, 1.121 + aData.mCbCrStride, 1.122 + aStride, 1.123 + yuvtype, 1.124 + ROTATE_0, 1.125 + FILTER_BILINEAR); 1.126 + } else { // no prescale 1.127 +#if defined(HAVE_YCBCR_TO_RGB565) 1.128 + if (aDestFormat == SurfaceFormat::R5G6B5) { 1.129 + ConvertYCbCrToRGB565(aData.mYChannel, 1.130 + aData.mCbChannel, 1.131 + aData.mCrChannel, 1.132 + aDestBuffer, 1.133 + aData.mPicX, 1.134 + aData.mPicY, 1.135 + aData.mPicSize.width, 1.136 + aData.mPicSize.height, 1.137 + aData.mYStride, 1.138 + aData.mCbCrStride, 1.139 + aStride, 1.140 + yuvtype); 1.141 + } else // aDestFormat != gfxImageFormat::RGB16_565 1.142 +#endif 1.143 + ConvertYCbCrToRGB32(aData.mYChannel, // 1.144 + aData.mCbChannel, 1.145 + aData.mCrChannel, 1.146 + aDestBuffer, 1.147 + aData.mPicX, 1.148 + aData.mPicY, 1.149 + aData.mPicSize.width, 1.150 + aData.mPicSize.height, 1.151 + aData.mYStride, 1.152 + aData.mCbCrStride, 1.153 + aStride, 1.154 + yuvtype); 1.155 + } 1.156 +} 1.157 + 1.158 +} 1.159 +}