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

📄 idwt_aux.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* $Id: idwt_aux.cpp,v 1.1 2003/05/05 21:24:01 wmaycisco Exp $ *//****************************************************************************//*   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 *//************************************************************/#ifndef _DWT_DBL_#define _DWT_INT_#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <memory.h>#include "basic.hpp"#include "dwt.h"#endif#undef DWTDATA1#undef DWTDATA#ifdef _DWT_INT_#define DWTDATA1 Int#define DWTDATA Int#else#define DWTDATA1 double#define DWTDATA double#endif/* Function:    iDWTInt() or iDWTDbl()   Description: Integer or Double Inverse DWT for MPEG-4 Still Texture Coding    Input:   InCoeff -- Input Wavelet Coefficients at CurLevel decomposition   InMask -- Input  Mask for InCoeff, if ==1, data inside object,               otherwise outside.   Width  -- Width of Original Image (must be multiples of 2^nLevels);   Height -- Height of Original Image (must be multiples of 2^nLevels);   CurLevel -- Currect Decomposition Level of the input wavelet coefficients;   DstLevel -- Destined decomposition level that the wavelet coefficient is                synthesized to. DstLevel always less than or equal to CurLevel;   OutDataType -- OutData Type: 0 - BYTE; 1 -- SHORT   Filter     -- Filter Used.   UpdateInput -- Update the level of decomposition to DstLevel                    for InCoeff and/or InMask or Not.                  0 = No  Update; 1 = Update InCoeff; 2: Update InCoeff and InMask;   FullSizeOut -- 0 = Output image size equals to Width/2^DstLevel x Height/2^DstLevel;                  1 = Output Image size equals to Width x Height; 		  ( Highpass band filled with zero after DstLevel)   Output:    OutData -- Output Image data of Width x Height or Width/2^DstLevel x Height/2^DstLevel              size depending on FullSizeOut, data type decided by OutDataType;   OutMask    -- Output mask corresponding to OutData   Return: DWT_OK if successful.  */#ifdef _DWT_INT_  // hjlee 0901Int VTCIDWT:: iDWTInt(DATA *InCoeff, UChar *InMask, Int Width, Int Height, Int CurLevel,	 Int DstLevel, Int OutDataType, FILTER **Filter,  Void *OutData, 	 UChar *OutMask, Int UpdateInput, Int FullSizeOut)#elseInt VTCIDWT:: iDWTDbl(DATA *InCoeff, UChar *InMask, Int Width, Int Height, Int CurLevel,	 Int DstLevel, Int OutDataType, FILTER **Filter,  Void *OutData, 	 UChar *OutMask, Int UpdateInput, Int FullSizeOut)#endif{  Int nBits, MaxCoeff, MinCoeff;  Int i,level, k;  DWTDATA1 *tempCoeff; /* Int for Int, double for Dbl */  Int ret;  DWTDATA1 *a;  Int *b;  UChar *c;  UShort *s;  UChar *d,*e, *tempMask;  /* Check filter class first */  for(level=CurLevel;level>DstLevel; level--) {    if(Filter[level-1]->DWT_Class != DWT_ODD_SYMMETRIC && Filter[level-1]->DWT_Class != DWT_EVEN_SYMMETRIC ) {      return(DWT_FILTER_UNSUPPORTED);    }  /* check filter Type */#ifdef _DWT_INT_  if(Filter[level-1]->DWT_Type!=DWT_INT_TYPE) return(DWT_INTERNAL_ERROR);#else  if(Filter[level-1]->DWT_Type!=DWT_DBL_TYPE) return(DWT_INTERNAL_ERROR);#endif  }  /* Check output coefficient buffer capacity */  nBits = sizeof(Int)*8;  MaxCoeff = (1<<(nBits-1))-1;  MinCoeff = -(1<<(nBits-1));  /* Limit nLevels as: 0 - 15*/  if(DstLevel < 0 || CurLevel >=16 || DstLevel >=16 || DstLevel > CurLevel)     return(DWT_INVALID_LEVELS);  /* Check Width and Height, must be multiples of 2^CurLevel */  if((Width &( (1<<CurLevel)-1))!=0) return(DWT_INVALID_WIDTH);  if((Height &( (1<<CurLevel)-1))!=0) return(DWT_INVALID_HEIGHT);  /* copy mask */  tempMask = (UChar *)malloc(sizeof(UChar)*Width*Height);  if(tempMask==NULL) return(DWT_MEMORY_FAILED);  memcpy(tempMask, InMask, sizeof(UChar)*Width*Height);    /* allocate temp  buffer */  tempCoeff = (DWTDATA1 *) malloc(sizeof(DWTDATA1)*Width*Height);  if(tempCoeff == NULL) {    free(tempMask);    return(DWT_MEMORY_FAILED);  }  memset(tempCoeff, (UChar)0, Width*Height*sizeof(DWTDATA1));  /* copy CurLevel decomposition results to temp buffer */  for(k=0;k<Width*(Height>>(DstLevel));k+=Width) {    for(a=tempCoeff+k, b=InCoeff+k;a<tempCoeff+k+(Width>>(DstLevel));a++, b++) {      *a = (DWTDATA1) *b;    }  }  /* Perform the  iDWT */  for(level=CurLevel;level>DstLevel;level--) {    /* Synthesize one level */#ifdef _DWT_INT_    ret=SynthesizeOneLevelInt(tempCoeff, tempMask, Width, Height, 			      level, Filter[level-1], MaxCoeff, MinCoeff, DWT_NONZERO_HIGH);#else    ret=SynthesizeOneLevelDbl(tempCoeff, tempMask, Width, Height, 			      level, Filter[level-1], DWT_NONZERO_HIGH);#endif          if(ret!=DWT_OK) {      free(tempCoeff);      free(tempMask);      return(ret);    }  }  /* check to see if required to update InCoeff and/or InMask */  if(UpdateInput>0) {    /* update InCoeff */    for(k=0;k<Width*(Height>>DstLevel); k+=Width) {      for(b=InCoeff+k,a=tempCoeff+k;b<InCoeff+k+(Width>>DstLevel);b++,a++) {#ifdef _DWT_INT_	*b = (Int) *a;#else	Int iTmp;	iTmp = (Int)floor(*a+0.5); /* rounding */	if(iTmp> MaxCoeff || iTmp< MinCoeff) {	  free(tempCoeff);	  free(tempMask);	  return(DWT_COEFF_OVERFLOW);	}	else	  *b = (Int) iTmp;#endif      }    }  }  if(UpdateInput>1) {    /* Update InMask */    for(k=0;k<Width*(Height>>DstLevel); k+=Width) {      for(d=InMask+k,e=tempMask+k;d<InMask+k+(Width>>DstLevel);d++,e++) {	*d = *e;      }    }  }    if(FullSizeOut) {    /* Perform the rest of iDWT till fullsize */    for(level=DstLevel;level>0;level--) {      /* Synthesize one level */#ifdef _DWT_INT_      ret=SynthesizeOneLevelInt(tempCoeff, tempMask, Width, Height, 				level, Filter[level-1], MaxCoeff, MinCoeff, DWT_ZERO_HIGH);#else      ret=SynthesizeOneLevelDbl(tempCoeff, tempMask, Width, Height, 				level, Filter[level-1], DWT_ZERO_HIGH);#endif      if(ret!=DWT_OK) {	free(tempCoeff);	free(tempMask);	return(ret);      }    }   }    /* copy the output to OutData and OutMask */  if(FullSizeOut) level=0;  else level=DstLevel;    for(i=0,k=0;k<Width*(Height >> level);k+=Width,i+=(Width>>level)) {        if(OutDataType==0) { /* Unsigned CHAR */      c = (UChar *)OutData; c+=i;      for(a=tempCoeff+k;a<tempCoeff+k+(Width>>level);c++,a++) {	Int iTmp;#ifdef _DWT_INT_	iTmp = (Int) *a;	iTmp = level>0?((iTmp+(1<<(level-1))) >> level):iTmp; /* scale and round */#else	iTmp = (Int)floor(*a/(1<<level)+0.5); /*scale down by 2^level and  rounding */#endif	iTmp = (iTmp >0) ? ((iTmp > 255)?255:iTmp): 0; /* clipping */	*c = (UChar) iTmp;      }    }    else { /* UShort */      s = (UShort *)OutData; s+=i;      for(a=tempCoeff+k;a<tempCoeff+k+(Width>>level);s++,a++) {	Int iTmp;#ifdef _DWT_INT_	iTmp = (Int)*a;	iTmp = level>0?((iTmp+(1<<(level-1))) >> level):iTmp; /* scale and round */#else	iTmp = (Int)floor(*a/(1<<level)+0.5); /*scale down by 2^level and  rounding */#endif	iTmp = (iTmp >0) ? ((iTmp > 65535)?65535:iTmp): 0; /* clipping */	*s = (UShort) iTmp;      }    }    d = OutMask + i;    for(e=tempMask+k;e<tempMask+k+(Width>>level);e++,d++)  *d=*e;  }  free(tempCoeff);  free(tempMask);  return(DWT_OK);}#ifdef _DWT_INT_/* Function:   SynthesizeOneLevelInt()    Description: Integer Synthesize one level of wavelet coefficients   Input:   Width  -- Width of Image;    Height -- Height of Image;   level -- current  level   Filter     -- Filter Used.   MaxCoeff, MinCoeff -- bounds of the output data;   ZeroHigh -- 1 Highpass bands are all zeros;   Input/Output:   OutCoeff   -- Ouput wavelet coefficients   OutMask    -- Output mask corresponding to wavelet coefficients   Return: DWT_OK if successful.*/Int VTCIDWT::SynthesizeOneLevelInt(Int *OutCoeff, UChar *OutMask, Int Width,				Int Height, Int level, FILTER *Filter,				Int MaxCoeff, Int MinCoeff, Int ZeroHigh){  Int *InBuf, *OutBuf ;  UChar *InMaskBuf, *OutMaskBuf;  Int width = Width>>(level-1);  Int height = Height>>(level-1);  Int MaxLength = (width > height)?width:height;  Int i,k,ret;  Int *a;  UChar *c,*d;  Int *e;  /* double check filter type */  if(Filter->DWT_Type != DWT_INT_TYPE) return(DWT_INTERNAL_ERROR);  /* allocate line buffers */  InBuf = (Int *) malloc(sizeof(Int)*MaxLength);  InMaskBuf = (UChar *) malloc(sizeof(UChar)*MaxLength);  OutBuf = (Int *) malloc(sizeof(Int)*MaxLength);  OutMaskBuf = (UChar *) malloc(sizeof(UChar)*MaxLength);  if(InBuf==NULL || InMaskBuf ==NULL || OutBuf == NULL || OutMaskBuf==NULL)     return(DWT_MEMORY_FAILED);  /* vertical synthesis first */  for(i=0;i<width;i++) {    /* get a column of coefficients and mask*/    for(a=InBuf, e=OutCoeff+i, c= InMaskBuf, d= OutMask+i;	a<InBuf+height; a++, c++, e+=Width, d+=Width) {      *a=(Int) *e;      *c = *d;

⌨️ 快捷键说明

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