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

📄 decoder.cpp

📁 《Visual C++小波变换技术与工程实践》靳济芳编著的光盘程序。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*************************************************************************

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)

and edited by

	Hiroyuki Katata (katata@imgsl.mkhar.sharp.co.jp), Sharp Corporation
	Norio Ito (norio@imgsl.mkhar.sharp.co.jp), Sharp Corporation
	Shuichi Watanabe (watanabe@imgsl.mkhar.sharp.co.jp), Sharp Corporation
	(date: October, 1997)

and also edited by
	Dick van Smirren (D.vanSmirren@research.kpn.com), KPN Research
	Cor Quist (C.P.Quist@research.kpn.com), KPN Research
	(date: July, 1998)

and also edited by 
	Takefumi Nagumo (nagumo@av.crl.sony.co.jp), SONY corporation
     Sehoon Son (shson@unitel.co.kr) Samsung AIT

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. 
Sharp 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) 1997.

Module Name:

	tps_decoder.cpp

Abstract:

	caller for decoder for temporal scalability

Revision History:
	Feb. 12. 2000: Bug fix of OBSS by Takefumi Nagumo(SONY)


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

#include <stdio.h>
#include <stdlib.h>
#include <fstream.h>

#ifdef __PC_COMPILER_
#include <windows.h>
#include <mmsystem.h>
#endif // __PC_COMPILER_

#include "typeapi.h"
#include "mode.hpp"
#include "vopses.hpp"
#include "entropy/bitstrm.hpp"
#include "tps_enhcbuf.hpp"
#include "decoder/enhcbufdec.hpp"
#include "decoder/vopsedec.hpp"

#include "dataStruct.hpp"

#ifndef __GLOBAL_VAR_
#define __GLOBAL_VAR_
#endif

#include "global.hpp"

#ifdef __MFC_
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define new DEBUG_NEW
#endif // __MFC_

Void dumpFrame (const CVOPU8YUVBA* pvopcQuant, const CVOPU8YUVBA** ppvopcPrevDisp, FILE* pfYUV, FILE* pfSeg, FILE** ppfAux, Int iAuxCompCount,
                AlphaUsage, CRct& rct, UInt nBits, Int iAlphaScale,
                Int DumpSkip, Bool bInterlace);
Void dumpFrameNonCoded(FILE* pfYUV, FILE* pfSeg, FILE **ppfAux, Int iAuxCompCount, 
				const CVOPU8YUVBA* pvopcPrevDisp, AlphaUsage, CRct& rctDisplay, UInt nBits);

#define MAX_TIME	99999			// for bitstreams stopped at BVOP
#define USAGE "Usage: \tDECODER bitstream_file [enhn_layer_bitstream_file] output_file width height\n\
or:    \tDECODER -vtc bitstream_file output_file display_width display_height \
target_spatial_layer target_snr_layer \
[target_shape_layer fullsize_out [target_tile_id(from) target_tile_id(to)]]\n" 
// modified by Sharp (99/2/16) further modified by SL@Sarnoff (03/02/99)

// Main Routine
void main(int argc, char* argv[])
{
	Bool bScalability = 0;
	Bool bWavelet = 0;

	Bool main_short_video_header; // Added by KPN for short headers [FDS]
	
	main_short_video_header = FALSE; 

	if(argc>1 && strcmp(argv[1],"-vtc")==0)
	{
		bWavelet = 1;
 		if(argc!=12 && argc != 10 && argc != 8) //modified by SL@Sarnoff (03/02/99)
		{
			fprintf(stderr,USAGE);
			exit(1);
		}
	}
	else	
	{
		if (argc < 5 || argc > 8) {		//OBSS_SAIT_991015
			fprintf (stderr,USAGE);
			exit(1);
		}
		else if (argc == 6 || argc == 8)		//OBSS_SAIT_991015
			bScalability = 1;
	}		

	FILE *pfBits;
	if ((pfBits = fopen (argv [bWavelet + 1], "rb")) == NULL )
		fatal_error("Bitstream File Not Found");
	fclose (pfBits);
	if (bScalability) {
		if ((pfBits = fopen (argv [2], "rb")) == NULL )
			fatal_error("Bitstream File for Enhancement Layer Not Found\n");
		fclose (pfBits);
	}


	if(bWavelet)
	{
	/////  WAVELET VTC: begin   /////////////////////////
		CVTCDecoder vtcdec;

		// start VTC decoding 
		// argv[1]: "-vtc"
		// argv[2]: bitstream file
		// argv[3]: decoded image file
		// argv[4]: display width
		// argv[5]: display height
		// argv[6]: target spatial layer
		// argv[7]: target SNR layer
		// argv[8]: target Shape layer
		// argv[9]: fullsize_out
		// argv[10]: start tile id
		// argv[11]: end tile id
// begin : added by Sharp (99/2/16) modified by SL@Sarnoff (03/02/99)
		if ( argc == 8 )
			vtcdec.decode(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]) , atoi(argv[6]), atoi(argv[7]), -1, 0, 0, 0 );
		else if(argc==10)
			vtcdec.decode(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]) , atoi(argv[6]), atoi(argv[7]), atoi(argv[8]), atoi(argv[9]), 0, 0 );
		else 
			vtcdec.decode(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]) , atoi(argv[6]), atoi(argv[7]), atoi(argv[8]), atoi(argv[9]), atoi(argv[10]), atoi(argv[11]));
// end : added by Sharp (99/2/16)
//			vtcdec.decode(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]) ); // deleted by Sharp (99/2/16)

		return;
	/////// WAVELET VTC: end   /////////////////////////
	}

	CRct rctDisplay       (0, 0, atoi (argv [3 + bScalability]), atoi (argv [4 + bScalability]));
/*Added */
	CRct rctDisplay_SSenh (0, 0, atoi (argv [3 + bScalability]), atoi (argv [4 + bScalability]));

	//OBSS_SAIT_991015
	Int iFrmWidth_SS=0;
	Int iFrmHeight_SS=0;
	if (bScalability && argc == 8){
		iFrmWidth_SS = atoi (argv [6]) ;
		iFrmHeight_SS = atoi (argv [7]) ;
		rctDisplay_SSenh.right = iFrmWidth_SS;
		rctDisplay_SSenh.bottom = iFrmHeight_SS;
		rctDisplay_SSenh.width = rctDisplay_SSenh.right - rctDisplay_SSenh.left;
	}
	//~OBSS_SAIT_991015

	Bool bTemporalScalability = 0;
	const CVOPU8YUVBA* rgpvopcPrevDisp[2];
	rgpvopcPrevDisp[BASE_LAYER] = NULL;
	rgpvopcPrevDisp[ENHN_LAYER] = NULL;
	FILE** ppfReconAux[2];
	ppfReconAux[0] = NULL;
	ppfReconAux[1] = NULL;

	if (bScalability){
		CVideoObjectDecoder* pvodec_tps[2];
		cout << "Checking scalability type...\n";
		pvodec_tps[BASE_LAYER] = new CVideoObjectDecoder (argv[1], rctDisplay.width, rctDisplay.height (), NULL, &main_short_video_header);
//OBSS_SAIT_991015
		if (argc == 8)
			pvodec_tps[ENHN_LAYER] = new CVideoObjectDecoder (argv[2], iFrmWidth_SS, iFrmHeight_SS, NULL, &main_short_video_header);					
		else
			pvodec_tps[ENHN_LAYER] = new CVideoObjectDecoder (argv[2], rctDisplay.width, rctDisplay.height (), NULL, &main_short_video_header);
//~OBSS_SAIT_991015
		pvodec_tps[BASE_LAYER]->setClockRateScale( pvodec_tps[ENHN_LAYER] ); // added by Sharp (98/6/26)
		Time FirstBase = pvodec_tps[BASE_LAYER] -> senseTime ();
		Time FirstEnhn = pvodec_tps[ENHN_LAYER] -> senseTime ();

		if ( FirstBase != FirstEnhn ){
			bTemporalScalability = 1;
			cout << "Starting temporal scalability decoding...\n\n";
		}
		else{
			bTemporalScalability = 0;
			cout << "Starting spatial scalability decoding...\n\n";
		}
		
		delete pvodec_tps[BASE_LAYER];
		delete pvodec_tps[ENHN_LAYER];
	}

	if ( !bScalability || !bTemporalScalability ){
		CVideoObjectDecoder* pvodec [2];
		Bool bSpatialScalable = FALSE;
		CRct rctDisplayBackup = rctDisplay; // for recovery from sprite decoding

		pvodec [BASE_LAYER] = new CVideoObjectDecoder (argv [1], rctDisplay.width, rctDisplay.height(), &bSpatialScalable, &main_short_video_header);
	
		// NBIT: get nBits information
		UInt nBits = pvodec [BASE_LAYER]->volmd ().nBits;

		/* Added*/
		if (bScalability){
			//OBSS_SAIT_991015
			if (argc == 8) {
				pvodec [ENHN_LAYER] = new CVideoObjectDecoder (argv [2], iFrmWidth_SS, iFrmHeight_SS, &bSpatialScalable, &main_short_video_header);		
				bSpatialScalable = TRUE;											//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).bSpatialScalability = TRUE;		//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).iFrmWidth_SS = iFrmWidth_SS;		//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).iFrmHeight_SS = iFrmHeight_SS;	//OBSSFIX_1:1
			}
			else {
				pvodec [ENHN_LAYER] = new CVideoObjectDecoder (argv [2], rctDisplay.width, rctDisplay.height(), &bSpatialScalable, &main_short_video_header);
				//OBSSFIX_Usage
				if ((pvodec [ENHN_LAYER]->volmd ()).fAUsage == ONE_BIT) {	
					cout << "\nDecode aborted!\n8 arguments are required for decoding enh-layer of OBSS.\nUsage : decoder base.cmp enh.cmp out_file base_W base_H enh_W enh_H\n";
					exit(1);
				}
				bSpatialScalable = TRUE;																	//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).bSpatialScalability = TRUE;								//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).iFrmWidth_SS = pvodec [ENHN_LAYER]->getvolWidth();		//OBSSFIX_1:1
				(pvodec [ENHN_LAYER]->getvolmd ()).iFrmHeight_SS = pvodec [ENHN_LAYER]->getvolHeight();		//OBSSFIX_1:1
				/*Added*/
				if(bSpatialScalable)
					pvodec[ENHN_LAYER]->set_enh_display_size(rctDisplay, &rctDisplay_SSenh);
			}
			//~OBSS_SAIT_991015
		}
		if (pvodec [BASE_LAYER] -> fSptUsage () == 1) {
				// decode the initial sprite: //wchen: instead of calling decode ()
			pvodec [BASE_LAYER] -> decodeInitSprite ();
		}

		FILE* pfReconYUV [2];
		Char pchTmp [100];
		sprintf (pchTmp, "%s.yuv", argv [2 + bScalability]);
		pfReconYUV [BASE_LAYER] = fopen (pchTmp, "wb");
		fatal_error("cant open output yuv file",pfReconYUV [BASE_LAYER] != NULL);
		if (bScalability)	{
			sprintf (pchTmp, "%s_e.yuv", argv [2 + bScalability]);

⌨️ 快捷键说明

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