⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yuvac.cpp

📁 视频音频编码程序 视频音频编码程序 视频音频编码程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************

This software module was originally developed by 

	Ming-Chieh Lee (mingcl@microsoft.com), Microsoft Corporation
	Wei-ge Chen (wchen@microsoft.com), Microsoft Corporation
	Bruce Lin (blin@microsoft.com), Microsoft Corporation
	Chuang Gu (chuanggu@microsoft.com), Microsoft Corporation
	(date: March, 1996)

in the course of development of the MPEG-4 Video (ISO/IEC 14496-2). 
This software module is an implementation of a part of one or more MPEG-4 Video tools 
as specified by the MPEG-4 Video. 
ISO/IEC gives users of the MPEG-4 Video free license to this software module or modifications 
thereof for use in hardware or software products claiming conformance to the MPEG-4 Video. 
Those intending to use this software module in hardware or software products are advised that its use may infringe existing patents. 
The original developer of this software module and his/her company, 
the subsequent editors and their companies, 
and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. 
Copyright is not released for non MPEG-4 Video conforming products. 
Microsoft retains full right to use the code for his/her own purpose, 
assign or donate the code to a third party and to inhibit third parties from using the code for non <MPEG standard> conforming products. 
This copyright notice must be included in all copies or derivative works. 

Copyright (c) 1996, 1997.

Module Name:

	yuva.hpp

Abstract:

	YUVA (4:2:0) VOP 

Revision History:

*************************************************************************/

#include "typeapi.h"

#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

#define new DEBUG_NEW				   
#endif // __MFC_

CVOPU8YUVBA::~CVOPU8YUVBA ()
{
	delete m_puciY;
	delete m_puciU;
	delete m_puciV;
	delete m_puciBY;
	delete m_puciBUV;
	delete m_puciA;
}

Void CVOPU8YUVBA::constructFromVOPU8 (const CVOPU8YUVBA& vopf, const CRct& rc)
{
	if (rc.valid ()) {
		m_rctY = rc;
		m_rctUV = m_rctY.downSampleBy2 ();
		m_puciY = new CU8Image (*vopf.getPlane (Y_PLANE), m_rctY);
		m_puciU = new CU8Image (*vopf.getPlane (U_PLANE), m_rctUV);
		m_puciV = new CU8Image (*vopf.getPlane (V_PLANE), m_rctUV);
		m_ppxlcY = (PixelC*) m_puciY->pixels ();
		m_ppxlcU = (PixelC*) m_puciU->pixels ();
		m_ppxlcV = (PixelC*) m_puciV->pixels ();
		if (m_fAUsage != RECTANGLE) {
			m_puciBY = new CU8Image (*vopf.getPlane (BY_PLANE), m_rctY);
			m_ppxlcBY = (PixelC*) m_puciBY->pixels ();
			m_puciBUV = new CU8Image (*vopf.getPlane (BUV_PLANE), m_rctUV);
			m_ppxlcBUV = (PixelC*) m_puciBUV->pixels ();
			assert (m_puciBY != NULL);
			assert (m_puciBUV != NULL);
			if (m_fAUsage == EIGHT_BIT) {
				m_puciA = new CU8Image (*vopf.getPlane (A_PLANE), m_rctY);
				assert (m_puciA != NULL);
				m_ppxlcA = (PixelC*) m_puciA->pixels ();
			}
		}
	}
	else {
		m_rctY = vopf.whereY ();
		m_rctUV = vopf.whereUV ();
		m_puciY = new CU8Image (*vopf.getPlane (Y_PLANE));
		m_puciU = new CU8Image (*vopf.getPlane (U_PLANE));
		m_puciV = new CU8Image (*vopf.getPlane (V_PLANE));
		m_ppxlcY = (PixelC*) m_puciY->pixels ();
		m_ppxlcU = (PixelC*) m_puciU->pixels ();
		m_ppxlcV = (PixelC*) m_puciV->pixels ();
		if (m_fAUsage != RECTANGLE) {
			m_puciBY = new CU8Image (*vopf.getPlane (BY_PLANE));
			m_ppxlcBY = (PixelC*) m_puciBY->pixels ();
			m_puciBUV = new CU8Image (*vopf.getPlane (BUV_PLANE));
			m_ppxlcBUV = (PixelC*) m_puciBUV->pixels ();
			assert (m_puciBY != NULL);
			assert (m_puciBUV != NULL);
			if (m_fAUsage == EIGHT_BIT) {
				m_puciA = new CU8Image (*vopf.getPlane (A_PLANE));
				assert (m_puciA != NULL);
				m_ppxlcA = (PixelC*) m_puciA->pixels ();
			}
		}
	}
	assert (m_puciY != NULL);
	assert (m_puciU != NULL);
	assert (m_puciV != NULL);
}

CVOPU8YUVBA::CVOPU8YUVBA (const CVOPU8YUVBA& vopf, AlphaUsage fAUsage, const CRct& rc)
{
  m_fAUsage = fAUsage;
  m_puciY = NULL;
  m_puciU = NULL; 
  m_puciV  = NULL; 
  m_puciBY  = NULL; 
  m_puciBUV = NULL; 
  m_puciA = NULL;

  constructFromVOPU8 (vopf, rc);
}

		
CVOPU8YUVBA::CVOPU8YUVBA (const CVOPU8YUVBA& vopf, const CRct& rc) : 
	m_puciY (NULL), m_puciU (NULL), m_puciV (NULL), m_puciBY (NULL), m_puciBUV (NULL), m_puciA (NULL)
{
	m_fAUsage = vopf.fAUsage ();
	constructFromVOPU8 (vopf, rc);
}

CVOPU8YUVBA::CVOPU8YUVBA (const Char* sptFilename) :
	m_puciY (NULL), m_puciU (NULL), m_puciV (NULL), m_puciBY (NULL), m_puciBUV (NULL), m_puciA (NULL)
{
	FILE* pf = fopen (sptFilename, "rb");
	// read overhead
	Int c0 = getc (pf);
	Int c1 = getc (pf);
	Int c2 = getc (pf);
	assert (c0 == 'S' && (c1 == 'P' || c2 == 'T') );
	fread (&m_rctY.left, sizeof (CoordI), 1, pf);
	fread (&m_rctY.top, sizeof (CoordI), 1, pf);
	fread (&m_rctY.right, sizeof (CoordI), 1, pf);
	fread (&m_rctY.bottom, sizeof (CoordI), 1, pf);
	fread (&m_fAUsage, sizeof (Int), 1, pf);
	m_rctY.width = m_rctY.right - m_rctY.left;
	m_rctUV = m_rctY.downSampleBy2 ();
	m_puciY = new CU8Image (m_rctY);
	assert (m_puciY != NULL);
	m_puciU = new CU8Image (m_rctUV);
	assert (m_puciU != NULL);
	m_puciV = new CU8Image (m_rctUV);
	assert (m_puciV != NULL);
	m_ppxlcY = (PixelC*) m_puciY->pixels ();
	m_ppxlcU = (PixelC*) m_puciU->pixels ();
	m_ppxlcV = (PixelC*) m_puciV->pixels ();
	if (m_fAUsage != RECTANGLE) {
		m_puciBY = new CU8Image (m_rctY, MPEG4_TRANSPARENT);		//initialize so that outside VOP is transp
		assert (m_puciBY != NULL);
		m_puciBUV = new CU8Image (m_rctUV, MPEG4_TRANSPARENT);	//initialize so that outside VOP is transp
		assert (m_puciBUV != NULL);
		m_ppxlcBY = (PixelC*) m_puciBY->pixels ();
		m_ppxlcBUV = (PixelC*) m_puciBUV->pixels ();
		if (m_fAUsage == EIGHT_BIT) {
			m_puciA = new CU8Image (m_rctY, MPEG4_TRANSPARENT);	//initialize so that outside VOP is transp
			assert (m_puciA != NULL);
			m_ppxlcA = (PixelC*) m_puciA->pixels ();
		}
	}
	// read the actual data
	fread (m_ppxlcY, sizeof (U8), m_rctY.area (), pf);
	fread (m_ppxlcU, sizeof (U8), m_rctUV.area (), pf);
	fread (m_ppxlcV, sizeof (U8), m_rctUV.area (), pf);
	if (m_fAUsage != RECTANGLE) {
		if (m_fAUsage == EIGHT_BIT)
			fread ((PixelC*) m_ppxlcA, sizeof (U8), m_rctY.area (), pf);
		else
			fread ((PixelC*) m_ppxlcBY, sizeof (U8), m_rctY.area (), pf);
	}
	fclose (pf);
}

CVOPU8YUVBA::CVOPU8YUVBA (AlphaUsage fAUsage, const CRct& rc)
{
	m_puciY = NULL;
	m_puciU = NULL;
	m_puciV = NULL;
	m_puciBY = NULL;
	m_puciBUV = NULL;
	m_puciA = NULL;
	m_fAUsage = fAUsage;

	m_rctY = rc;
	m_rctUV = m_rctY.downSampleBy2 ();
	m_puciY = new CU8Image (m_rctY);
	assert (m_puciY != NULL);
	m_puciU = new CU8Image (m_rctUV);
	assert (m_puciU != NULL);
	m_puciV = new CU8Image (m_rctUV);
	assert (m_puciV != NULL);
	m_ppxlcY = (PixelC*) m_puciY->pixels ();
	m_ppxlcU = (PixelC*) m_puciU->pixels ();
	m_ppxlcV = (PixelC*) m_puciV->pixels ();
	if (m_fAUsage != RECTANGLE) {
		m_puciBY = new CU8Image (m_rctY, MPEG4_TRANSPARENT);		//initialize so that outside VOP is transp
		assert (m_puciBY != NULL);
		m_puciBUV = new CU8Image (m_rctUV, MPEG4_TRANSPARENT);	//initialize so that outside VOP is transp
		assert (m_puciBUV != NULL);
		m_ppxlcBY = (PixelC*) m_puciBY->pixels ();
		m_ppxlcBUV = (PixelC*) m_puciBUV->pixels ();
		if (m_fAUsage == EIGHT_BIT) {
			m_puciA = new CU8Image (m_rctY, MPEG4_TRANSPARENT);	//initialize so that outside VOP is transp
			assert (m_puciA != NULL);
			m_ppxlcA = (PixelC*) m_puciA->pixels ();
		}
	}
}

CVOPU8YUVBA::CVOPU8YUVBA (AlphaUsage fAUsage)
{
	m_puciY = NULL;
	m_puciU = NULL;
	m_puciV = NULL;
	m_puciBY = NULL;
	m_puciBUV = NULL;
	m_puciA = NULL;
	m_fAUsage = fAUsage;
}

Void CVOPU8YUVBA::shift (CoordI left, CoordI top)
{
	m_rctY.shift (left, top);
	m_rctUV.shift (left / 2, top / 2);
	m_puciY -> shift (left, top);
	m_puciU -> shift (left / 2, top / 2);
	m_puciV -> shift (left / 2, top / 2);
	if (m_fAUsage == EIGHT_BIT) 
		m_puciA -> shift (left, top);
	else if (m_fAUsage == ONE_BIT) {
		m_puciBY -> shift (left, top);
		m_puciBUV -> shift (left / 2, top / 2);
	}
}

Void CVOPU8YUVBA::setBoundRct (const CRct& rctBoundY)
{
	assert (rctBoundY <= m_rctY);
	m_rctBoundY = rctBoundY;
	m_rctBoundUV = m_rctBoundY.downSampleBy2 ();
	Int iOffsetY = m_rctY.offset (m_rctBoundY.left, m_rctBoundY.top);
	Int iOffsetUV = m_rctUV.offset (m_rctBoundUV.left, m_rctBoundUV.top);
	m_ppxlcBoundY = (PixelC*) m_puciY->pixels () + iOffsetY;
	m_ppxlcBoundU = (PixelC*) m_puciU->pixels () + iOffsetUV;
	m_ppxlcBoundV = (PixelC*) m_puciV->pixels () + iOffsetUV;
	if (m_fAUsage != RECTANGLE) {
		m_ppxlcBoundBY = (PixelC*) m_puciBY->pixels () + iOffsetY;
		m_ppxlcBoundBUV = (PixelC*) m_puciBUV->pixels () + iOffsetUV;
		if (m_fAUsage == EIGHT_BIT)
			m_ppxlcBoundA = (PixelC*) m_puciA->pixels () + iOffsetY;
	}
}

Void CVOPU8YUVBA::setAndExpandBoundRctOnly (const CRct& rctBoundY, Int iExpand)
{
	assert (rctBoundY <= m_rctY);
	m_rctBoundY = rctBoundY;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -