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

📄 spihtdecode.c

📁 该文件是小波信源编码SPIHT算法的C语言代码
💻 C
字号:
/* * * QccPack: Quantization, compression, and coding utilities * Copyright (C) 1997-2008  James E. Fowler *  *//* * ---------------------------------------------------------------------------- *  * Public License for the SPIHT Algorithm * Version 1.2, March 8, 2004 *  * ---------------------------------------------------------------------------- *  * The Set Partitioning In Hierarchical Trees (SPIHT) algorithm is protected * by US Patent #5,764,807 (issued June 9, 1998), US Patent #6,674,911 (issued * January 6, 2004), and other international patents and patents pending. An * implementation of the SPIHT algorithm is included herein with the gracious * permission of Dr. William A. Pearlman, President of PrimaComp, Inc., * exclusive holder of patent rights. PrimaComp, Inc., has 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 Dr. Pearlman. *  * 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, Inc.,  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, Inc., 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. *   851 Maxwell Drive *   Schenectady, NY 12309 *   U.S.A. *   +1 (857) 231-6135 *   email: bmazor@spiht.com *   http://www.cipr.rpi.edu/research/SPIHT *  * ----------------------------------------------------------------------------*/#include "spihtdecode.h"#define USG_STRING "[-w %s:wavelet] [-b %s:boundary] [-pw %: %s:pcpfile] [-m %: %s:mask] [-r %: %f:rate] %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;float Rate;int RateSpecified;int NumPixels;int TargetBitCnt;int main(int argc, char *argv[]){  int row, col;  QccInit(argc, argv);    QccSPIHTHeader();  QccWAVWaveletInitialize(&Wavelet);  QccWAVPerceptualWeightsInitialize(&PerceptualWeights);  QccIMGImageInitialize(&OutputImage);  QccIMGImageInitialize(&Mask);  QccBitBufferInitialize(&InputBuffer);  if (QccParseParameters(argc, argv,                         USG_STRING,                         WaveletFilename,                         Boundary,                         &UsePerceptualWeights,                         PerceptualWeights.filename,                         &MaskSpecified,                         Mask.filename,                         &RateSpecified,                         &Rate,                         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 (QccIMGImageGetSize(&Mask,                             &MaskNumRows, &MaskNumCols))        {          QccErrorAddMessage("%s: Error calling QccIMGImageGetSize()",                             argv[0]);          QccErrorExit();        }      if ((MaskNumRows != NumRows) ||          (MaskNumCols != NumCols))        {          QccErrorAddMessage("%s: Mask must be same size as image",                             argv[0]);          QccErrorExit();        }      NumPixels = 0;      for (row = 0; row < MaskNumRows; row++)        for (col = 0; col < MaskNumCols; col++)          if (!QccAlphaTransparent(Mask.Y.image[row][col]))            NumPixels++;    }  else    NumPixels = NumRows * NumCols;  if (QccIMGImageDetermineType(&OutputImage))    {      QccErrorAddMessage("%s: Error calling QccIMGImageDetermineType()",                         argv[0]);      QccErrorExit();    }  if (QccIMGImageColor(&OutputImage))    {      QccErrorAddMessage("%s: Output image must be grayscale",                         argv[0]);      QccErrorExit();    }  if (QccIMGImageSetSize(&OutputImage,                         NumRows,                         NumCols))    {      QccErrorAddMessage("%s: Error calling QccIMGImageSetSize()",                         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 (!RateSpecified)    TargetBitCnt = QCCENT_ANYNUMBITS;  else    TargetBitCnt = (int)(ceil((NumPixels * Rate)/8.0))*8;  if (QccSPIHTDecode(&InputBuffer,                     &(OutputImage.Y),                     (MaskSpecified ? &(Mask.Y) : NULL),                     NumLevels,                     &Wavelet,                     ((UsePerceptualWeights) ? &PerceptualWeights :                      NULL),                     ImageMean,                     MaxCoefficientBits,                     TargetBitCnt,                     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();    }  QccIMGImageFree(&OutputImage);  QccIMGImageFree(&Mask);  QccWAVWaveletFree(&Wavelet);  QccWAVPerceptualWeightsFree(&PerceptualWeights);  QccExit;}

⌨️ 快捷键说明

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