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

📄 seg.cpp

📁 《Visual C++小波变换技术与工程实践》靳济芳编著的光盘程序。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************/
/*   MPEG4 Visual Texture Coding (VTC) Mode Software                        */
/*                                                                          */
/*   This software was jointly developed by the following participants:     */
/*                                                                          */
/*   Single-quant,  multi-quant and flow control                            */
/*   are provided by  Sarnoff Corporation                                   */
/*     Iraj Sodagar   (iraj@sarnoff.com)                                    */
/*     Hung-Ju Lee    (hjlee@sarnoff.com)                                   */
/*     Paul Hatrack   (hatrack@sarnoff.com)                                 */
/*     Shipeng Li     (shipeng@sarnoff.com)                                 */
/*     Bing-Bing Chai (bchai@sarnoff.com)                                   */
/*     B.S. Srinivas  (bsrinivas@sarnoff.com)                               */
/*                                                                          */
/*   Bi-level is provided by Texas Instruments                              */
/*     Jie Liang      (liang@ti.com)                                        */
/*                                                                          */
/*   Shape Coding is provided by  OKI Electric Industry Co., Ltd.           */
/*     Zhixiong Wu    (sgo@hlabs.oki.co.jp)                                 */
/*     Yoshihiro Ueda (yueda@hlabs.oki.co.jp)                               */
/*     Toshifumi Kanamaru (kanamaru@hlabs.oki.co.jp)                        */
/*                                                                          */
/*   OKI, Sharp, Sarnoff, TI and Microsoft contributed to bitstream         */
/*   exchange and bug fixing.                                               */
/*                                                                          */
/*                                                                          */
/* In the course of development of the MPEG-4 standard, this software       */
/* module is an implementation of a part of one or more MPEG-4 tools as     */
/* specified by the MPEG-4 standard.                                        */
/*                                                                          */
/* The copyright of this software belongs to ISO/IEC. ISO/IEC gives use     */
/* of the MPEG-4 standard free license to use this  software module or      */
/* modifications thereof for hardware or software products claiming         */
/* conformance to the MPEG-4 standard.                                      */
/*                                                                          */
/* Those intending to use this software module in hardware or software      */
/* products are advised that use may infringe existing  patents. The        */
/* original developers of this software module and their companies, the     */
/* subsequent editors and their companies, and ISO/IEC have no liability    */
/* and ISO/IEC have no liability for use of this software module or         */
/* modification thereof in an implementation.                               */
/*                                                                          */
/* Permission is granted to MPEG members to use, copy, modify,              */
/* and distribute the software modules ( or portions thereof )              */
/* for standardization activity within ISO/IEC JTC1/SC29/WG11.              */
/*                                                                          */
/* Copyright 1995, 1996, 1997, 1998 ISO/IEC                                 */
/****************************************************************************/

/************************************************************/
/*     Sarnoff Very Low Bit Rate Still Image Coder          */
/*     Copyright 1995, 1996, 1997, 1998 Sarnoff Corporation */
/************************************************************/


#include <stdio.h>
#include <math.h>
#include <string.h>
#include "dataStruct.hpp"

// #include "errorHandler.h"
//#include "globals.h"
//#include "dwt.h"
//#include "ShapeCodec.h"



/*--------------------------------------------------------------------
  read_segimage()
  
  Return Values
  -------------
  0: full-frame  1: shape-adaptive
  
  Comments
  --------
  Exits program if error occurs.
  --------------------------------------------------------------------*/
Int CVTCEncoder::read_segimage(Char *seg_path, Int seg_width, Int seg_height, 
		  Int img_colors,
		  PICTURE *MyImage)
{
  FILE *infptr = NULL;
  Int  seg_size;
  Int  status,col;
  UChar *inmask;

  if ((infptr = fopen(seg_path,"rb")) == NULL) { /* full-frame */
    MyImage[0].mask = MyImage[1].mask = MyImage[2].mask = NULL;
    return (0);
  }
  

  seg_size = seg_width*seg_height; 
  inmask = (UChar *)malloc(sizeof(UChar)*seg_size);

  if(inmask==NULL)
    errorHandler("Couldn't allocate memory to image mask\n");
  
  /* Read image */
  if ((status=fread(inmask, sizeof(UChar), seg_size,
		    infptr))
      != seg_size)
    errorHandler("Error in reading image file: %s\n",seg_path);
  fclose(infptr);
  
  MyImage[0].mask = inmask;
  for (col=1; col<img_colors; col++) 
    MyImage[col].mask = NULL;

  return 1;
}



#if 0 //deleted by SL 030399
Void CVTCEncoder::get_virtual_image(PICTURE *MyImage, Int wvtDecompLev, 
		       Int usemask, Int colors, Int alphaTH, 
		       //Int change_CR_disable,  //modified by SL 030399
			   FILTER *Filter) 
{
  Int Nx[3], Ny[3];
  Int Width[3], Height[3];
  Int nLevels[3];
  Int col,i;

  /* for 4:2:0 YUV image only */
  Nx[0] = Ny[0]=2;
  for(col=1; col<colors; col++) Nx[col]=Ny[col]=1;


  Width[0] = MyImage[0].width;
  Width[1] = Width[2] = (Width[0]+1)>>1;

  Height[0] = MyImage[0].height;
  Height[1] = Height[2] = (Height[0]+1)>>1;

  nLevels[0] = wvtDecompLev ;
  nLevels[1] = nLevels[2] = nLevels[0]-1;
  

  for (col=0; col<colors; col++) {
	  MyImage[col].mask = (UChar *)malloc(sizeof(UChar)*Width[col]*Height[col]);
	  for(i=0;i<Width[col]*Height[col];i++) {
		 MyImage[col].mask[i] = DWT_IN;
	  }
  }
  mzte_codec.m_iWidth = Width[0];
  mzte_codec.m_iHeight = Height[0];
  mzte_codec.m_iOriginX = Width[0];
  mzte_codec.m_iOriginY = Height[0];
  mzte_codec.m_iRealWidth = Width[0];
  mzte_codec.m_iRealHeight = Height[0];

}





Void CVTCDecoder::get_virtual_mask(PICTURE *MyImage,  Int wvtDecompLev,
		      Int w, Int h, Int usemask, Int colors, 
			  Int *target_shape_layer, Int StartCodeEnable,
			  FILTER **filters) 
{
//  Int width[3], height[3];
  Int Width[3], Height[3];
  Int nLevels[3];
  Int col,i;
  Int Nx[3], Ny[3];

  /* for 4:2:0 YUV image only */
  Nx[0] = Ny[0]=2;
  for(col=1; col<3; col++) Nx[col]=Ny[col]=1;

  nLevels[0] = wvtDecompLev;
  nLevels[1] = nLevels[2] = nLevels[0]-1;
  Width[0]= w;
  Width[1]=Width[2]= (w+1)>>1;
  
  Height[0]= h;
  Height[1]=Height[2] = (h+1)>>1;




	if (!usemask) {

		for (col=0; col<mzte_codec.m_iColors; col++) {
			MyImage[col].mask 
				=(UChar *)malloc(sizeof(UChar)*Width[col]*Height[col]);
			if (MyImage[col].mask==NULL)
				errorHandler("Couldn't allocate memory to image\n");
			for (i=0; i<Width[col]*Height[col]; i++)
				MyImage[col].mask[i] = DWT_IN;
		}
		mzte_codec.m_iWidth = Width[0];
		mzte_codec.m_iHeight = Height[0];
		mzte_codec.m_iOriginX = 0;
		mzte_codec.m_iOriginY = 0;
		mzte_codec.m_iRealWidth = Width[0];
		mzte_codec.m_iRealHeight = Height[0]; 
  }
//  else {
//    mzte_codec.m_iWidth = width[0];
//   mzte_codec.m_iHeight = height[0];
//  }

}
#endif //deleted by SL 030399

// FPDAM begin : added by Sharp (99/8/19)
Void CVTCEncoder::get_real_image(PICTURE *MyImage, Int wvtDecompLev, 
		       Int usemask, Int colors, Int alphaTH, 
		       /* Int change_CR_disable,*/ FILTER *Filter) 
{
  Int Nx[3], Ny[3];
  Int Width[3], Height[3], width[3], height[3];
  Int nLevels[3];
  UChar *inimage[3], *outimage[3];
  UChar *inmask[3], *outmask[3];
  Int ret,col;
  Int origin_x[3], origin_y[3];
  Int Shape;
  /* for 4:2:0 YUV image only */
  Nx[0] = Ny[0]=2;
  for(col=1; col<colors; col++) Nx[col]=Ny[col]=1;


  Width[0] = MyImage[0].width;
  Width[1] = Width[2] = (Width[0]+1)>>1;

  Height[0] = MyImage[0].height;
  Height[1] = Height[2] = (Height[0]+1)>>1;

  nLevels[0] = wvtDecompLev ;
  nLevels[1] = nLevels[2] = nLevels[0]-1;
  

  for (col=0; col<colors; col++) {
    
    inimage[col] = (UChar *)MyImage[col].data; 
    inmask[col] = (UChar *)MyImage[col].mask; 
    if(col==0) {
      Shape = usemask? ((STO_const_alpha) ? STO_const_alpha_value : MASK_VAL):RECTANGULAR;
      ret = GetRealMaskBox(inmask[col], &outmask[col],
		       Width[col], Height[col], Nx[col],Ny[col],
		       &width[col], &height[col], &origin_x[col], &origin_y[col],
		       Shape,
		       nLevels[col]);
			
      if (ret!=DWT_OK) 
	errorHandler("DWT Error code = %d\n", ret);
      if (usemask) free(inmask[col]);
    }
    else {
      width[col] = width[0]/Nx[0];
      height[col] = height[0]/Ny[0]; 
      origin_x[col] = origin_x[0]/Nx[0]; 
      origin_y[col] = origin_y[0]/Ny[0];
    }
    ret=GetBox(inimage[col], 
	       (Void **)&outimage[col], 
	       Width[col], Height[col], 
	       width[col], height[col], origin_x[col], origin_y[col], 0);
    
    if (ret!=DWT_OK) 
      errorHandler("DWT Error code = %d\n", ret);
    if(col==0) {
      if(usemask) {  /* do shape quantization */
	QuantizeShape(outmask[0], width[0], height[0], alphaTH);
      }
    }
    
    free(inimage[col]);
    MyImage[col].data = outimage[col];
    MyImage[col].mask = outmask[col];
  }

/*	{*/
/*    FILE *fp;*/
/*    if ((fp = fopen("ttt.yuv","w")) == NULL ){*/
/*      puts("Error");*/
/*      exit(1);*/
/*    }*/
/*    printf("%d %d\n", width[0], height[0]);*/
/*    printf("%d %d\n", Width[0], Height[0]);*/
/*    printf("%d\n",fwrite(MyImage[0].mask, sizeof(UChar), width[0]*height[0], fp));*/
/*    fclose(fp);*/
/*  }*/

  mzte_codec.m_iObjectWidth = mzte_codec.m_iWidth = width[0];
  mzte_codec.m_iObjectHeight = mzte_codec.m_iHeight = height[0];
  mzte_codec.m_iObjectOriginX = mzte_codec.m_iOriginX = origin_x[0];
  mzte_codec.m_iObjectOriginY = mzte_codec.m_iOriginY = origin_y[0];
  mzte_codec.m_iRealWidth = Width[0];
  mzte_codec.m_iRealHeight = Height[0];

}
// FPDAM end : added by Sharp (99/8/19)

//begin added by SL

Void CVTCEncoder::get_virtual_image(PICTURE *MyImage, Int wvtDecompLev, 
		       Int usemask, Int colors, Int alphaTH, 
		       /* Int change_CR_disable,*/ FILTER *Filter) 
{
  Int Nx[3], Ny[3];
  Int Width[3], Height[3], width[3], height[3];
  Int nLevels[3];
  UChar *inimage[3], *outimage[3];
  UChar *inmask[3], *outmask[3];
  Int ret,col,i;
  Int origin_x[3], origin_y[3];
  Int Shape;
  /* for 4:2:0 YUV image only */
  Nx[0] = Ny[0]=2;
  for(col=1; col<colors; col++) Nx[col]=Ny[col]=1;


  Width[0] = MyImage[0].width;
  Width[1] = Width[2] = (Width[0]+1)>>1;

  Height[0] = MyImage[0].height;

⌨️ 快捷键说明

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