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

📄 spihtdecode.c

📁 该源码是SPIHT即分层树集合划分算法的c代码,希望对搞压缩编码的朋友们有用.
💻 C
字号:
/*
 *
 * QccPack: Quantization, compression, and coding utilities
 * Copyright (C) 1997-2001  James E. Fowler
 * 
 */

/*
 * ----------------------------------------------------------------------------
 * 
 * Public License for the SPIHT Algorithm
 * Version 1.0, September 22, 1999
 * 
 * ----------------------------------------------------------------------------
 * 
 * The Set Partitioning In Hierarchical Trees (SPIHT) algorithm is protected
 * by US Patent #5,764,807 (issued June 9, 1998) and other international
 * patents and patents pending. An implementation of the SPIHT algorithm is
 * included herein with the permission of PrimaComp, Inc., exclusive holder
 * of patent rights. PrimaComp has gracioulsy granted the following license
 * governing the terms and conditions for use, copying, distribution, and
 * modification of the SPIHT algorithm implementation contained herein
 * (hereafter referred to as "the SPIHT source code").
 * 
 * 0. Use of the SPIHT source code, including any executable-program or
 *    linkable-library form resulting from its compilation, is restricted to
 *    solely academic or non-commercial research activities.
 * 
 * 1. Any other use, including, but not limited to, use in the development
 *    of a commercial product, use in a commercial application, or commercial
 *    distribution, is prohibited by this license. Such acts require a separate
 *    license directly from PrimaComp, Inc.
 * 
 * 2. For academic and non-commercial purposes, this license does not restrict
 *    use; copying, distribution, and modification are permitted under the
 *    terms of the GNU General Public License as published by the Free Software
 *    Foundation, with the further restriction that the terms of the present
 *    license shall also apply to all subsequent copies, distributions,
 *    or modifications of the SPIHT source code.
 * 
 * NO WARRANTY
 * 
 * 3. PrimaComp dislaims all warranties, expressed or implied, including
 *    without limitation any warranty whatsoever as to the fitness for a
 *    particular use or the merchantability of the SPIHT source code.
 * 
 * 4. In no event shall PrimaComp be liable for any loss of profits, loss of 
 *    business, loss of use or loss of data, nor for indirect, special,
 *    incidental or consequential damages of any kind related to use of the
 *    SPIHT source code.
 * 
 * 
 * END OF TERMS AND CONDITIONS
 * 
 * 
 * Persons desiring to license the SPIHT algorithm for commercial purposes or
 * for uses otherwise prohibited by this license may wish to contact
 * PrimaComp, Inc., regarding the possibility of negotiating such licenses:
 * 
 *   PrimaComp, Inc.
 *   1223 Peoples Ave.
 *   Troy, New York  12180
 *   USA
 *   +1 (518) 276-8276
 *   inquire@primacomp.com
 *   http://www.primacomp.com
 * 
 * ----------------------------------------------------------------------------
 */


#include "spihtdecode.h"

#define USG_STRING "[-w %s:wavelet] [-b %s:boundary] [-pw %: %s:pcpfile] [-m %: %s:mask] %s:bitstream %s:imgfile"

QccWAVWavelet Wavelet;
QccString WaveletFilename = QCCWAVWAVELET_DEFAULT_WAVELET;
QccString Boundary = "symmetric";

QccWAVPerceptualWeights PerceptualWeights;
int UsePerceptualWeights = 0;

int NumLevels;
int NumSubbands;

QccBitBuffer InputBuffer;

int NumRows, NumCols;

QccIMGImage OutputImage;

double ImageMean;
int MaxCoefficientBits;

QccIMGImage Mask;
int MaskSpecified = 0;
int MaskNumRows, MaskNumCols;

int ArithmeticCoded;

int main(int argc, char *argv[])
{
  
  QccInit(argc, argv);
  
  QccSetUserHeader(QCCSPIHT_LICENSE);

  QccWAVWaveletInitialize(&Wavelet);
  QccWAVPerceptualWeightsInitialize(&PerceptualWeights);
  QccIMGImageInitialize(&OutputImage);
  QccIMGImageInitialize(&Mask);
  QccBitBufferInitialize(&InputBuffer);

  if (QccParseParameters(argc, argv,
			 USG_STRING,
			 WaveletFilename,
			 Boundary,
			 &UsePerceptualWeights,
			 PerceptualWeights.filename,
			 &MaskSpecified,
			 Mask.filename,
			 InputBuffer.filename,
			 OutputImage.filename))
    QccErrorExit();
  
  if (QccWAVWaveletCreate(&Wavelet, WaveletFilename, Boundary))
    {
      QccErrorAddMessage("%s: Error calling QccWAVWaveletCreate()",
			 argv[0]);
      QccErrorExit();
    }
  
  InputBuffer.type = QCCBITBUFFER_INPUT;
  if (QccBitBufferStart(&InputBuffer))
    {
      QccErrorAddMessage("%s: Error calling QccBitBufferStart()",
			 argv[0]);
      QccErrorExit();
    }

  if (QccSPIHTDecodeHeader(&InputBuffer,
			   &NumLevels,
			   &NumRows, &NumCols,
			   &ImageMean,
			   &MaxCoefficientBits,
			   &ArithmeticCoded))
    {
      QccErrorAddMessage("%s: Error calling QccSPIHTDecodeHeader()",
			 argv[0]);
      QccErrorExit();
    }
  NumSubbands = QccWAVSubbandPyramidNumLevelsToNumSubbands(NumLevels);

  if (MaskSpecified)
    {
      if (QccIMGImageRead(&Mask))
	{
	  QccErrorAddMessage("%s: Error calling QccIMGImageRead()",
			     argv[0]);
	  QccErrorExit();
	}
      if (QccIMGImageColor(&Mask))
	{
	  QccErrorAddMessage("%s: Mask must be grayscale",
			     argv[0]);
	  QccErrorExit();
	}
      if (QccIMGImageGetResolution(&Mask,
				   &MaskNumRows, &MaskNumCols))
	{
	  QccErrorAddMessage("%s: Error calling QccIMGImageGetResolution()",
			     argv[0]);
	  QccErrorExit();
	}

      if ((MaskNumRows != NumRows) ||
	  (MaskNumCols != NumCols))
	{
	  QccErrorAddMessage("%s: Mask must be same size as image",
			     argv[0]);
	  QccErrorExit();
	}
    }

  OutputImage.image_type = QCCIMGTYPE_PGM;
  if (QccIMGImageSetResolution(&OutputImage,
			       NumRows,
			       NumCols))
    {
      QccErrorAddMessage("%s: Error calling QccIMGImageSetResolution()",
			 argv[0]);
      QccErrorExit();
    }
  if (QccIMGImageAlloc(&OutputImage))
    {
      QccErrorAddMessage("%s: Error calling QccIMGImageAlloc()",
			 argv[0]);
      QccErrorExit();
    }

  if (UsePerceptualWeights)
    {
      if (QccWAVPerceptualWeightsRead(&PerceptualWeights))
	{
	  QccErrorAddMessage("%s: Error calling QccWAVPerceptualWeightsRead()",
			     argv[0]);
	  QccErrorExit();
	}
      if (PerceptualWeights.num_subbands != NumSubbands)
	{
	  QccErrorAddMessage("%s: Number of subbands in %s does not match that specified in %s",
			     argv[0],
			     PerceptualWeights.filename,
			     InputBuffer.filename);
	}
    }
  
  if (QccSPIHTDecode(&InputBuffer,
		     &(OutputImage.Y),
		     (MaskSpecified ? &(Mask.Y) : NULL),
		     NumLevels,
		     &Wavelet,
		     ((UsePerceptualWeights) ? &PerceptualWeights :
		      NULL),
		     ImageMean,
		     MaxCoefficientBits,
		     ArithmeticCoded))
    {
      QccErrorAddMessage("%s: Error calling QccSPIHTDecode()",
			 argv[0]);
      QccErrorExit();
    }

  if (QccIMGImageWrite(&OutputImage))
    {
      QccErrorAddMessage("%s: Error calling QccIMGImageWrite()",
			 argv[0]);
      QccErrorExit();
    }
  
  if (QccBitBufferEnd(&InputBuffer))
    {
      QccErrorAddMessage("%s: Error calling QccBitBufferEnd()",
			 argv[0]);
      QccErrorExit();
    }

  QccExit;
}

⌨️ 快捷键说明

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