📄 umc_color_space_converter_nv12.cpp
字号:
/*//// INTEL CORPORATION PROPRIETARY INFORMATION// This software is supplied under the terms of a license agreement or// nondisclosure agreement with Intel Corporation and may not be copied// or disclosed except in accordance with the terms of that agreement.// Copyright (c) 2003-2005 Intel Corporation. All Rights Reserved.//*/#include <stdlib.h>#include <ippi.h>#include <ippcc.h>#include "umc_color_space_converter.h"#include "vm_debug.h"namespace UMC{class UV_MERGED{public: vm_var32 nU; vm_var32 nV; UV_MERGED &operator = (vm_var32 iValue) { nU = nV = iValue; return *this; }; UV_MERGED &operator += (UV_MERGED Value) { nU += Value.nU; nV += Value.nV; return *this; }; UV_MERGED &operator -= (UV_MERGED Value) { nU -= Value.nU; nV -= Value.nV; return *this; }; UV_MERGED &operator *= (vm_var32 iValue) { nU *= iValue; nV *= iValue; return *this; }; UV_MERGED &operator /= (vm_var32 iValue) { nU /= iValue; nV /= iValue; return *this; };};class UV_POINTER{public: UV_MERGED operator * (void) { UV_MERGED Pixel; Pixel.nU = m_lpbSource[0]; Pixel.nV = m_lpbSource[1]; return Pixel; }; UV_POINTER &operator = (void *lpvSource) { m_lpbSource = reinterpret_cast<vm_byte *> (lpvSource); return *this; } UV_POINTER &operator += (vm_var32 lValue) { m_lpbSource += lValue * 2; return *this; }; UV_POINTER &operator -= (vm_var32 lValue) { return operator += ((unsigned) -((signed) lValue)); }; UV_POINTER &operator ++ (void) { return operator += (1); }; UV_POINTER &operator -- (void) { return operator += ((unsigned) -1); }; UV_MERGED operator = (UV_MERGED Pixel) { m_lpbSource[0] = static_cast<vm_byte> (Pixel.nU); m_lpbSource[1] = static_cast<vm_byte> (Pixel.nV); return Pixel; };protected: vm_byte *m_lpbSource;};staticvoid resize_hor_UV_merged(void *lpvSrc, IppiSize SizeSrc, size_t lPitchSrc, void *lpvDst, IppiSize SizeDst, size_t lPitchDst){ // if images are equal if (SizeDst.width == SizeSrc.width) { ippiCopy_8u_C1R(reinterpret_cast<vm_byte *> (lpvSrc), (vm_var32) lPitchSrc, reinterpret_cast<vm_byte *> (lpvDst), (vm_var32) lPitchDst, SizeDst); } // stretching image in else if (SizeDst.width <= SizeSrc.width) { vm_var32 nWeight = SizeSrc.width, nPixelWeight = SizeDst.width; UV_MERGED Pixel, Value; vm_var32 x, y; vm_var32 nCurWeight; vm_byte *lpbSrc = reinterpret_cast<vm_byte *> (lpvSrc); vm_byte *lpbDst = reinterpret_cast<vm_byte *> (lpvDst); UV_POINTER lpSrc, lpDst; for (y = 0;y < (unsigned) SizeSrc.height;y++) { lpSrc = (lpbSrc + lPitchSrc * y); lpDst = (lpbDst + lPitchDst * y); Pixel = 0; nCurWeight = nWeight; for (x = 0;x < (unsigned) SizeDst.width;x++) { // calc whole old pixel(s) into new pixel while (nCurWeight >= nPixelWeight) { Pixel += *lpSrc; nCurWeight -= nPixelWeight; ++lpSrc; }; // add remain value if (nCurWeight) { UV_MERGED Tail; Tail = (*lpSrc); Tail *= nCurWeight; Tail /= nPixelWeight; Value = Pixel; Value += Tail; Pixel = *lpSrc; Pixel -= Tail; ++lpSrc; nCurWeight = nWeight - (nPixelWeight - nCurWeight); } else { Value = Pixel; Pixel = 0; nCurWeight = nWeight; }; // save new pixel Value *= nPixelWeight; Value /= nWeight; lpDst = Value; ++lpDst; }; }; } // stretching image out else { vm_var32 nWeight = SizeSrc.width, nPixelWeight = SizeDst.width; UV_MERGED Pixel; vm_var32 x, y; vm_var32 nCurWeight; vm_byte *lpbSrc = reinterpret_cast<vm_byte *> (lpvSrc); vm_byte *lpbDst = reinterpret_cast<vm_byte *> (lpvDst); UV_MERGED *lpSrc, *lpDst; for (y = 0;y < (unsigned) SizeSrc.height;y++) { lpSrc = reinterpret_cast<UV_MERGED *> (lpbSrc + lPitchSrc * y); lpDst = reinterpret_cast<UV_MERGED *> (lpbDst + lPitchDst * y); nCurWeight = nPixelWeight; for (x = 0;x < (unsigned) SizeDst.width;x++) { // take pixel value Pixel = *lpSrc; if (nCurWeight < nWeight) { UV_MERGED Tail; lpSrc++; Pixel *= nCurWeight; Tail = *lpSrc; Tail *= (nWeight - nCurWeight); Pixel += Tail; Pixel /= nWeight; nCurWeight += nPixelWeight; } nCurWeight -= nWeight; // save new pixel *lpDst = Pixel; lpDst++; }; }; };} // void resize_UV_merged( void *lpvSrc, IppiSize SizeSrc, size_t lPitchSrc,void ColorSpaceConverter::ResizeNV12(ColorConversionParams &ConvertParam){ vm_byte *lpY, *lpUV; IppiSize SizeSrc = {ConvertParam.ConversionInit.SizeSource.width, ConvertParam.ConversionInit.SizeSource.height}; IppiSize SizeDst = {ConvertParam.ConversionInit.SizeDest.width, ConvertParam.ConversionInit.SizeDest.height}; IppiRect RectSrc = {0, 0, SizeSrc.width, SizeSrc.height}; IppiRect RectDst = {0, 0, SizeDst.width, SizeDst.height}; size_t lPitchY, lPitchUV; if (ConvertParam.ConversionInit.FormatDest != ConvertParam.ConversionInit.FormatSource) { size_t lNeededSize; // correct dest size(s) SizeDst.width = (SizeDst.width + 1) & ~(1); SizeDst.height = (SizeDst.height + 1) & ~(1); // calc needed internal buffer size lNeededSize = (SizeDst.width * SizeDst.height * 3) / 2; if (lNeededSize > m_lBufferSize) { if (false == AllocateInternalBuffer(lNeededSize)) return; }; lpY = reinterpret_cast<vm_byte *> (m_lpvBuffer); lpUV = lpY + SizeDst.width * SizeDst.height; lPitchY = SizeDst.width; lPitchUV = SizeDst.width; } else { lpY = ConvertParam.lpDest0; lpUV = ConvertParam.lpDest1; lPitchY = ConvertParam.PitchDest0; lPitchUV = ConvertParam.PitchDest1; };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -