📄 spihtdecode3d.c
字号:
/* * * QccPack: Quantization, compression, and coding utilities * Copyright (C) 1997-2008 James E. Fowler * *//* * ---------------------------------------------------------------------------- * * Public License for the 3D-SPIHT Algorithm * Version 1.1, March 8, 2004 * * ---------------------------------------------------------------------------- * * The 3D Set Partitioning In Hierarchical Trees (3D-SPIHT) algorithm is * protected by US patents 5,764,807 and 6,674,911, and other patents pending. * An implementation of the 3D-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 3D-SPIHT algorithm implementation * contained herein (hereafter referred to as "the 3D-SPIHT source code"). * * 0. Use of the 3D-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 3D-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 3D-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 * 3D-SPIHT source code. * * * END OF TERMS AND CONDITIONS * * * Persons desiring to license the 3D-SPIHT algorithm for commercial purposes * or for uses otherwise prohibited by this license may wish to contact * Dr. Pearlman regarding the possibility of negotiating such licenses: * * Dr. William A. Pearlman, President * PrimaComp, Inc. * 851 Maxwell Drive * Niskayuna, NY 12309 * U.S.A. * * e-mail: wpearlman@spiht.com * tel.: +1 (518) 522-7781 * fax: +1 (518) 393-7412 * * ---------------------------------------------------------------------------- */#include "spihtdecode3d.h"#define USG_STRING "[-w %s:wavelet] [-b %s:boundary] [-m %: %s:mask] [-r %: %f:rate] %s:bitstream %s:icbfile"QccWAVWavelet Wavelet;QccString WaveletFilename = QCCWAVWAVELET_DEFAULT_WAVELET;QccString Boundary = "symmetric";int TransformType;int ZerotreeType;int TemporalNumLevels;int SpatialNumLevels;QccBitBuffer InputBuffer;int NumFrames, NumRows, NumCols;QccIMGImageCube OutputImage;double ImageMean;int MaxCoefficientBits;QccIMGImageCube Mask;int MaskSpecified = 0;int MaskNumFrames, MaskNumRows, MaskNumCols;int ArithmeticCoded;float Rate;int RateSpecified;int NumPixels;int TargetBitCnt;int main(int argc, char *argv[]){ int frame, row, col; QccInit(argc, argv); QccSPIHT3DHeader(); QccWAVWaveletInitialize(&Wavelet); QccIMGImageCubeInitialize(&OutputImage); QccIMGImageCubeInitialize(&Mask); QccBitBufferInitialize(&InputBuffer); if (QccParseParameters(argc, argv, USG_STRING, WaveletFilename, Boundary, &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 (QccSPIHT3DDecodeHeader(&InputBuffer, &TransformType, &ZerotreeType, &TemporalNumLevels, &SpatialNumLevels, &NumFrames, &NumRows, &NumCols, &ImageMean, &MaxCoefficientBits, &ArithmeticCoded)) { QccErrorAddMessage("%s: Error calling QccSPIHT3DDecodeHeader()", argv[0]); QccErrorExit(); } if (MaskSpecified) { if (QccIMGImageCubeRead(&Mask)) { QccErrorAddMessage("%s: Error calling QccIMGImageCubeRead()", argv[0]); QccErrorExit(); } MaskNumFrames = Mask.num_frames; MaskNumRows = Mask.num_rows; MaskNumCols = Mask.num_cols; if ((MaskNumFrames != NumFrames) || (MaskNumRows != NumRows) || (MaskNumCols != NumCols)) { QccErrorAddMessage("%s: Mask must be same size as image cube", argv[0]); QccErrorExit(); } NumPixels = 0; for (frame = 0; frame < MaskNumFrames; frame++) for (row = 0; row < MaskNumRows; row++) for (col = 0; col < MaskNumCols; col++) if (!QccAlphaTransparent(Mask.volume[frame][row][col])) NumPixels++; } else NumPixels = NumFrames * NumRows * NumCols; OutputImage.num_frames = NumFrames; OutputImage.num_rows = NumRows; OutputImage.num_cols = NumCols; if (QccIMGImageCubeAlloc(&OutputImage)) { QccErrorAddMessage("%s: Error calling QccIMGImageCubeAlloc()", argv[0]); QccErrorExit(); } if (!RateSpecified) TargetBitCnt = QCCENT_ANYNUMBITS; else TargetBitCnt = (int)(ceil((NumPixels * Rate)/8.0))*8; if (QccSPIHT3DDecode(&InputBuffer, &OutputImage, (MaskSpecified ? &Mask : NULL), TransformType, ZerotreeType, TemporalNumLevels, SpatialNumLevels, &Wavelet, ImageMean, MaxCoefficientBits, TargetBitCnt, ArithmeticCoded)) { QccErrorAddMessage("%s: Error calling QccSPIHT3DDecode()", argv[0]); QccErrorExit(); } if (QccIMGImageCubeWrite(&OutputImage)) { QccErrorAddMessage("%s: Error calling QccIMGImageCubeWrite()", argv[0]); QccErrorExit(); } if (QccBitBufferEnd(&InputBuffer)) { QccErrorAddMessage("%s: Error calling QccBitBufferEnd()", argv[0]); QccErrorExit(); } QccIMGImageCubeFree(&OutputImage); QccIMGImageCubeFree(&Mask); QccWAVWaveletFree(&Wavelet); QccExit;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -