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

📄 zerotree.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * * QccPack: Quantization, compression, and coding libraries * Copyright (C) 1997-2009  James E. Fowler *  * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. *  * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, * MA 02139, USA. *  */#include "libQccPack.h"int QccWAVZerotreeInitialize(QccWAVZerotree *zerotree){  if (zerotree == NULL)    return(0);  QccStringMakeNull(zerotree->filename);  QccStringCopy(zerotree->magic_num, QCCWAVZEROTREE_MAGICNUM);  QccGetQccPackVersion(&zerotree->major_version,                       &zerotree->minor_version,                       NULL);  zerotree->image_num_cols = 0;  zerotree->image_num_rows = 0;  zerotree->image_mean = 0.0;  zerotree->num_levels = 0;  zerotree->num_subbands = 0;  zerotree->alphabet_size = QCCWAVZEROTREE_NUMSYMBOLS;  zerotree->num_cols = NULL;  zerotree->num_rows = NULL;  zerotree->zerotree = NULL;  return(0);}int QccWAVZerotreeCalcSizes(const QccWAVZerotree *zerotree){  int subband;  QccWAVSubbandPyramid subband_pyramid;    if (zerotree == NULL)    return(0);  if ((zerotree->num_cols == NULL) ||      (zerotree->num_rows == NULL))    return(0);    subband_pyramid.num_levels = zerotree->num_levels;  subband_pyramid.num_rows = zerotree->image_num_rows;  subband_pyramid.num_cols = zerotree->image_num_cols;  for (subband = 0; subband < zerotree->num_subbands; subband++)    if (QccWAVSubbandPyramidSubbandSize(&subband_pyramid,                                        subband,                                        &zerotree->num_rows[subband],                                        &zerotree->num_cols[subband]))      {        QccErrorAddMessage("(QccWAVZerotreeCalcSizes): Error calling QccWAVSubbandPyramidSubbandSize()");        return(1);      }    return(0);}int QccWAVZerotreeAlloc(QccWAVZerotree *zerotree){  int return_value;  int subband, row;  if (zerotree == NULL)    return(0);  if ((zerotree->num_cols == NULL) || (zerotree->num_rows == NULL))    {      if (zerotree->num_cols == NULL)        if ((zerotree->num_cols =             (int *)malloc(sizeof(int)*zerotree->num_subbands)) == NULL)          {            QccErrorAddMessage("(QccWAVZerotreeAlloc): Error allocating memory");            goto Error;          }      if (zerotree->num_rows == NULL)        if ((zerotree->num_rows =             (int *)malloc(sizeof(int)*zerotree->num_subbands)) == NULL)          {            QccErrorAddMessage("(QccWAVZerotreeAlloc): Error allocating memory");            goto Error;          }            if (QccWAVZerotreeCalcSizes(zerotree))        {          QccErrorAddMessage("(QccWAVZerotreeAlloc): Error calling QccVZTZerotreeCalcSizes()");          goto Error;        }    }    if (zerotree->zerotree == NULL)    {      if ((zerotree->zerotree =            (char ***)malloc(sizeof(char **) *                             zerotree->num_subbands)) == NULL)        {          QccErrorAddMessage("(QccWAVZerotreeAlloc): Error allocating memory");          goto Error;        }            for (subband = 0; subband < zerotree->num_subbands; subband++)        {          if ((zerotree->zerotree[subband] =                (char **)malloc(sizeof(char *) *                                zerotree->num_rows[subband])) == NULL)            {              QccErrorAddMessage("(QccWAVZerotreeAlloc): Error allocating memory");              goto Error;            }                for (row = 0; row < zerotree->num_rows[subband]; row++)            if ((zerotree->zerotree[subband][row] =                  (char *)calloc(zerotree->num_cols[subband],                                 sizeof(char))) == NULL)              {                QccErrorAddMessage("(QccWAVZerotreeAlloc): Error allocating memory");                goto Error;              }        }    }    return_value = 0;  goto Return; Error:  QccWAVZerotreeFree(zerotree);  return_value = 1; Return:  return(return_value);}void QccWAVZerotreeFree(QccWAVZerotree *zerotree){  int subband, row;  if (zerotree == NULL)    return;  if ((zerotree->zerotree != NULL) && (zerotree->num_rows != NULL))    {      for (subband = 0; subband < zerotree->num_subbands; subband++)        if (zerotree->zerotree[subband] != NULL)          {            for (row = 0; row < zerotree->num_rows[subband]; row++)              if (zerotree->zerotree[subband][row] != NULL)                QccFree(zerotree->zerotree[subband][row]);            QccFree(zerotree->zerotree[subband]);          }      QccFree(zerotree->zerotree);      zerotree->zerotree = NULL;    }  if (zerotree->num_rows != NULL)    {      QccFree(zerotree->num_rows);      zerotree->num_rows = NULL;    }  if (zerotree->num_cols != NULL)    {      QccFree(zerotree->num_cols);      zerotree->num_cols = NULL;    }}int QccWAVZerotreePrint(const QccWAVZerotree *zerotree){  int subband;  int row, col;  QccString subband_string;  int level;  int space;    if (QccFilePrintFileInfo(zerotree->filename,                           zerotree->magic_num,                           zerotree->major_version,                           zerotree->minor_version))    return(1);  printf("Image size: %dx%d\n",         zerotree->image_num_cols,         zerotree->image_num_rows);  printf("Image mean: %10.2f\n", zerotree->image_mean);  printf("Num. of octave-band decomposition levels: %d\n",         zerotree->num_levels);  printf("Num. of subbands: %d\n",         zerotree->num_subbands);  printf("Alphabet size: %d\n\n\n", zerotree->alphabet_size);    for (subband = 0; subband < zerotree->num_subbands; subband++)    {      level =         QccWAVSubbandPyramidCalcLevelFromSubband(subband,                                                 zerotree->num_levels);      space = 1 << (zerotree->num_levels - level);      QccWAVSubbandPyramidSubbandToQccString(subband, zerotree->num_levels,                                              subband_string);      printf("---Subband #%d (%s)---------\n", subband, subband_string);      printf("  Subband size: %dx%d\n",              zerotree->num_cols[subband],             zerotree->num_rows[subband]);      printf("  Symbol array:\n");            for (row = 0; row < zerotree->num_rows[subband]; row++)        {          if (!(row % space))            {              for (col = 0; col < zerotree->num_cols[subband]; col++)                {                  printf("-");                  if (!(col % space))                    printf("-");                }                            printf("\n");            }          for (col = 0; col < zerotree->num_cols[subband]; col++)            {              if (!(col % space))                printf("|");              if (QccWAVZerotreeNullSymbol(zerotree->zerotree                                           [subband][row][col]))                printf("%c", '.');              else                switch (zerotree->zerotree[subband][row][col])                  {                  case QCCWAVZEROTREE_SYMBOLSIGNIFICANT:                    printf("%c", 'S');                    break;                  case QCCWAVZEROTREE_SYMBOLINSIGNIFICANT:                    printf("%c", 'I');                    break;                  case QCCWAVZEROTREE_SYMBOLZTROOT:                    printf("%c", 'Z');                    break;                  }            }                    printf("\n");        }            printf("\n");    }    return(0);}int QccWAVZerotreeNullSymbol(const char symbol){  return((int)symbol < 0);}int QccWAVZerotreeMakeSymbolNull(char *symbol){  if (symbol == NULL)    return(0);    *symbol = (char)(-abs((int)*symbol));  return(0);}int QccWAVZerotreeMakeSymbolNonnull(char *symbol){  if (symbol == NULL)    return(0);    *symbol = (char)abs((int)*symbol);  return(0);}int QccWAVZerotreeMakeFullTree(QccWAVZerotree *zerotree){  int subband, row, col;  if (zerotree == NULL)    return(0);    if (QccWAVZerotreeAlloc(zerotree))    {      QccErrorAddMessage("(QccWAVZerotreeMakeFullTree): Error calling QccWAVZerotreeAlloc()");      return(1);    }  for (subband = 0; subband < zerotree->num_subbands; subband++)    for (row = 0; row < zerotree->num_rows[subband]; row++)      for (col = 0; col < zerotree->num_cols[subband]; col++)        zerotree->zerotree[subband][row][col] =          QCCWAVZEROTREE_SYMBOLSIGNIFICANT;    return(0);}int QccWAVZerotreeMakeEmptyTree(QccWAVZerotree *zerotree){  int subband, row, col;  if (zerotree == NULL)    return(0);    if (zerotree->zerotree == NULL)    {      if (QccWAVZerotreeAlloc(zerotree))        {          QccErrorAddMessage("(QccWAVZerotreeMakeFullTree): Error calling QccWAVZerotreeAlloc()");          return(1);        }      if (QccWAVZerotreeMakeFullTree(zerotree))        {          QccErrorAddMessage("(QccWAVZerotreeMakeFullTree): Error calling QccWAVZerotreeMakeFullTree()");          return(1);        }    }  for (subband = 0; subband < zerotree->num_subbands; subband++)    for (row = 0; row < zerotree->num_rows[subband]; row++)      for (col = 0; col < zerotree->num_cols[subband]; col++)        zerotree->zerotree[subband][row][col] =          QccWAVZerotreeMakeSymbolNull(&(zerotree->zerotree                                         [subband][row][col]));

⌨️ 快捷键说明

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