📄 umc_color_space_converter_cbycr.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 PIXEL_CBYCR{public: vm_var32 Y; vm_var32 U; vm_var32 V; PIXEL_CBYCR &operator = (vm_var32 lValue) { Y = U = V = lValue; return *this; }; PIXEL_CBYCR &operator += (PIXEL_CBYCR &Value) { Y += Value.Y; U += Value.U; V += Value.V; return *this; }; PIXEL_CBYCR &operator -= (PIXEL_CBYCR &Value) { Y -= Value.Y; U -= Value.U; V -= Value.V; return *this; }; PIXEL_CBYCR &operator *= (vm_var32 lValue) { Y *= lValue; U *= lValue; V *= lValue; return *this; }; PIXEL_CBYCR &operator /= (vm_var32 lValue) { Y /= lValue; U /= lValue; V /= lValue; return *this; };};class POINTER_CBYCR{public: POINTER_CBYCR(void) { m_lpbData = NULL; m_bOdd = true; }; POINTER_CBYCR &operator = (void *lpv) { m_lpbData = reinterpret_cast<vm_byte *> (lpv); m_bOdd = true; return *this; }; POINTER_CBYCR &operator += (size_t lValue) { if (0 < (signed) lValue) { // we set pointer only to UYVY quad potion if (m_bOdd) { m_lpbData += (lValue & ~(1)) * 2; m_bOdd = (lValue & 1) ? (false) : (true); } else { m_lpbData += ((lValue + 1) & ~(1)) * 2; m_bOdd = (lValue & 1) ? (true) : (false); }; } else if (0 > (signed) lValue) { if (m_bOdd) { m_lpbData += ((lValue - 1) & ~(1)) * 2; m_bOdd = (lValue & 1) ? (false) : (true); } else { m_lpbData += (lValue & ~(1)) * 2; m_bOdd = (lValue & 1) ? (true) : (false); }; }; return *this; }; POINTER_CBYCR &operator -= (size_t lValue) { return operator += (((unsigned) -((signed)lValue))); }; POINTER_CBYCR &operator ++ (void) { return operator += (1); }; POINTER_CBYCR &operator -- (void) { return operator += ((unsigned) -1); }; operator PIXEL_CBYCR(void) { PIXEL_CBYCR yuv = {(m_bOdd) ? (m_lpbData[1]) : (m_lpbData[3]), m_lpbData[0], m_lpbData[2]}; return yuv; }; void operator = (PIXEL_CBYCR yuv) { if (m_bOdd) { m_lpbData[0] = static_cast<vm_byte> (yuv.U); m_lpbData[1] = static_cast<vm_byte> (yuv.Y); m_lpbData[2] = static_cast<vm_byte> (yuv.V); } else { m_lpbData[0] = static_cast<vm_byte> ((yuv.U + m_lpbData[0]) / 2); m_lpbData[2] = static_cast<vm_byte> ((yuv.V + m_lpbData[2]) / 2); m_lpbData[3] = static_cast<vm_byte> (yuv.Y); }; }; POINTER_CBYCR operator *(void) { POINTER_CBYCR ptr = *this; return ptr; }; POINTER_CBYCR operator [](size_t lValue) { POINTER_CBYCR ptr = *this; ptr.operator += (lValue); return ptr; };protected: vm_byte *m_lpbData; bool m_bOdd;};// Intel compiler makes a remark// "value copied to temporary, reference to temporary used"#ifdef __ICL#pragma warning(disable : 383)#endif // __ICLstaticvoid resize_hor_CbYCr(void *lpvSrc, IppiSize SizeSrc, size_t lPitchSrc, void *lpvDst, IppiSize SizeDst, size_t lPitchDst){ // if images are equal if (SizeDst.width == SizeSrc.width) { IppiSize SizeDest = {SizeDst.width * 2, SizeDst.height}; ippiCopy_8u_C1R(reinterpret_cast<vm_byte *> (lpvSrc), (vm_var32) lPitchSrc, reinterpret_cast<vm_byte *> (lpvDst), (vm_var32) lPitchDst, SizeDest); } // stretching image in else if (SizeDst.width < SizeSrc.width) { vm_var32 nWeight = SizeSrc.width, nPixelWeight = SizeDst.width; PIXEL_CBYCR Pixel, Value; vm_var32 x, y; vm_var32 nCurWeight; POINTER_CBYCR lpSrc, lpDst; for (y = 0;y < (unsigned) SizeSrc.height;y++) { lpSrc = reinterpret_cast<vm_byte *> (lpvSrc) + lPitchSrc * y; lpDst = reinterpret_cast<vm_byte *> (lpvDst) + lPitchDst * y; Pixel = 0; nCurWeight = nWeight; for (x = 0;x < (unsigned) SizeDst.width;x++) { // get whole pixels while (nCurWeight >= nPixelWeight) {// Pixel += static_cast<PIXEL_CBYCR> (lpSrc[0]); PIXEL_CBYCR Tmp = lpSrc[0]; Pixel += Tmp; nCurWeight -= nPixelWeight; ++lpSrc; }; // get pixel part if (nCurWeight) { PIXEL_CBYCR Tail; Tail = static_cast<PIXEL_CBYCR> (*lpSrc); Tail *= nCurWeight; Tail /= nPixelWeight; Value = Pixel; Value += Tail; Pixel = static_cast<PIXEL_CBYCR> (*lpSrc); Pixel -= Tail; ++lpSrc; nCurWeight = nWeight - (nPixelWeight - nCurWeight); } // only whole pixels used else { Value = Pixel; Pixel = 0; nCurWeight = nWeight; }; // write new pixel Value *= nPixelWeight; Value /= nWeight; lpDst = Value; ++lpDst; }; }; } // stretching image out else { vm_var32 nWeight = SizeSrc.width, nPixelWeight = SizeDst.width; PIXEL_CBYCR Pixel; vm_var32 x, y; vm_var32 nCurWeight; POINTER_CBYCR lpSrc, lpDst; for (y = 0;y < (unsigned) SizeDst.height;y++) { lpSrc = reinterpret_cast<vm_byte *> (lpvSrc) + lPitchSrc * y; lpDst = reinterpret_cast<vm_byte *> (lpvDst) + lPitchDst * y; nCurWeight = nPixelWeight; for (x = 0;x < (unsigned) SizeDst.width;x++) { Pixel = *lpSrc; if (nCurWeight < nWeight) { PIXEL_CBYCR Tail; ++lpSrc; Pixel *= nCurWeight; Tail = *lpSrc; Tail *= (nWeight - nCurWeight); Pixel += Tail; Pixel /= nWeight; nCurWeight += nPixelWeight; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -