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

📄 image_cube.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *  * 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. *  *//* *  This code was written by Justin T. Rucker <jtr9@msstate.edu> */#include "libQccPack.h"static QccIMGImageVolume QccIMGImageVolumeAlloc(int num_frames,                                                int num_rows,                                                int num_cols){  QccIMGImageVolume new_volume;    if ((num_frames <=0) || (num_rows <= 0) || (num_cols <= 0))    return(NULL);    if ((new_volume =       (QccIMGImageVolume)QccVolumeAlloc(num_frames,                                         num_rows,                                         num_cols)) == NULL)    {      QccErrorAddMessage("(QccIMGImageVolumeAlloc): Error allocating memory");      return(NULL);    }    return(new_volume);}static void QccIMGImageVolumeFree(QccIMGImageVolume image_volume,                                  int num_frames,                                  int num_rows){  QccVolumeFree((QccVolume)image_volume, num_frames, num_rows);}int QccIMGImageCubeInitialize(QccIMGImageCube *image_cube){  if (image_cube == NULL)    return(0);    QccStringMakeNull(image_cube->filename);  QccStringCopy(image_cube->magic_num, QCCIMGIMAGECUBE_MAGICNUM);  QccGetQccPackVersion(&image_cube->major_version,                       &image_cube->minor_version,                       NULL);  image_cube->num_frames = 0;  image_cube->num_rows = 0;  image_cube->num_cols = 0;  image_cube->min_val = 0.0;  image_cube->max_val = 0.0;  image_cube->volume = NULL;    return(0);}int QccIMGImageCubeAlloc(QccIMGImageCube *image_cube){  if (image_cube == NULL)    return(0);    if (image_cube->volume == NULL)    {      if ((image_cube->num_frames > 0) ||          (image_cube->num_rows > 0) ||          (image_cube->num_cols > 0))        {          if ((image_cube->volume =               QccIMGImageVolumeAlloc(image_cube->num_frames,                                      image_cube->num_rows,                                      image_cube->num_cols)) == NULL)            {              QccErrorAddMessage("(QccIMGImageCubeAlloc): Error calling QccIMGImageVolumeAlloc()");              return(1);            }        }      else        image_cube->volume = NULL;    }    return(0);}void QccIMGImageCubeFree(QccIMGImageCube *image_cube){  if (image_cube == NULL)    return;    if (image_cube->volume != NULL)    {      QccIMGImageVolumeFree(image_cube->volume,                            image_cube->num_frames,                            image_cube->num_rows);      image_cube->volume = NULL;    }}int QccIMGImageCubePrint(const QccIMGImageCube *image_cube){  int frame, row, col;    if (QccFilePrintFileInfo(image_cube->filename,                           image_cube->magic_num,                           image_cube->major_version,                           image_cube->minor_version))    return(1);    printf("Size: %dx%dx%d\n",         image_cube->num_cols,         image_cube->num_rows,         image_cube->num_frames);    printf("Min. value: % 10.4f\n", image_cube->min_val);  printf("Max. value: % 10.4f\n", image_cube->max_val);  printf("\nImage volume:\n\n");    for (frame = 0; frame < image_cube->num_frames; frame++)    {      for (row = 0; row < image_cube->num_rows; row++)        {          for (col = 0; col < image_cube->num_cols; col++)            {              printf("% 10.4f ", image_cube->volume[frame][row][col]);            }          printf("\n");        }      printf("============================================================\n");    }  return(0);}int QccIMGImageCubeSetMin(QccIMGImageCube *image_cube){    int frame, row, col;  double min = MAXDOUBLE;    if (image_cube == NULL)    return(0);  if (image_cube->volume == NULL)    return(0);    for (frame = 0; frame < image_cube->num_frames; frame++)    for (row = 0; row < image_cube->num_rows; row++)      for (col = 0; col < image_cube->num_cols; col++)        if (image_cube->volume[frame][row][col] < min)          min = image_cube->volume[frame][row][col];    image_cube->min_val = min;    return(0);}int QccIMGImageCubeSetMax(QccIMGImageCube *image_cube){  double max = -MAXDOUBLE;  int frame, row, col;    if (image_cube == NULL)    return(0);  if (image_cube->volume == NULL)    return(0);    for (frame = 0; frame < image_cube->num_frames; frame++)    for (row = 0; row < image_cube->num_rows; row++)      for (col = 0; col < image_cube->num_cols; col++)        if (image_cube->volume[frame][row][col] > max)          max = image_cube->volume[frame][row][col];    image_cube->max_val = max;    return(0);}int QccIMGImageCubeSetMaxMin(QccIMGImageCube *image_cube){  if (QccIMGImageCubeSetMax(image_cube))    {      QccErrorAddMessage("(QccIMGImageCubeSetMaxMin): Error calling QccIMGImageCubeSetMax()");      return(1);    }    if (QccIMGImageCubeSetMin(image_cube))    {      QccErrorAddMessage("(QccIMGImageCubeSetMaxMin): Error calling QccIMGImageCubeSetMin()");      return(1);    }    return(0);}int QccIMGImageCubeResize(QccIMGImageCube *image_cube,                          int num_frames,                          int num_rows,                          int num_cols){  if (image_cube == NULL)    return(0);  if ((image_cube->volume =       (QccIMGImageVolume)QccVolumeResize((QccVolume)image_cube->volume,                                          image_cube->num_frames,                                          image_cube->num_rows,                                          image_cube->num_cols,                                          num_frames,                                          num_rows,                                          num_cols)) == NULL)    {      QccErrorAddMessage("(QccIMGImageCubeResize): Error calling QccVolumeResize()");      return(1);    }  image_cube->num_frames = num_frames;  image_cube->num_rows = num_rows;  image_cube->num_cols = num_cols;    QccIMGImageCubeSetMaxMin(image_cube);  return(0);}static int QccIMGImageCubeReadHeader(FILE *infile,                                     QccIMGImageCube *image_cube){  if ((infile == NULL) || (image_cube == NULL))    return(0);    if (QccFileReadMagicNumber(infile,                             image_cube->magic_num,                             &image_cube->major_version,                             &image_cube->minor_version))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading magic number in %s",                         image_cube->filename);      return(1);    }    if (strcmp(image_cube->magic_num, QCCIMGIMAGECUBE_MAGICNUM))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): %s is not of image_cube (%s) type",                         image_cube->filename, QCCIMGIMAGECUBE_MAGICNUM);      return(1);    }    fscanf(infile, "%d", &(image_cube->num_cols));  if (ferror(infile) || feof(infile))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of columns in %s",                         image_cube->filename);      return(1);    }    if (QccFileSkipWhiteSpace(infile, 0))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of columns in %s",                         image_cube->filename);      return(1);    }    fscanf(infile, "%d", &(image_cube->num_rows));  if (ferror(infile) || feof(infile))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of rows in %s",                         image_cube->filename);      return(1);    }    if (QccFileSkipWhiteSpace(infile, 0))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of rows in %s",                         image_cube->filename);      return(1);    }  fscanf(infile, "%d", &(image_cube->num_frames));  if (ferror(infile) || feof(infile))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of frames in %s",                         image_cube->filename);      return(1);    }    if (QccFileSkipWhiteSpace(infile, 0))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of frames in %s",                         image_cube->filename);      return(1);    }    fscanf(infile, "%lf", &(image_cube->min_val));  if (ferror(infile) || feof(infile))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of rows in %s",                         image_cube->filename);      return(1);    }    if (QccFileSkipWhiteSpace(infile, 0))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of rows in %s",                         image_cube->filename);      return(1);    }    fscanf(infile, "%lf%*1[\n]", &(image_cube->max_val));  if (ferror(infile) || feof(infile))    {      QccErrorAddMessage("(QccIMGImageCubeReadHeader): Error reading number of rows in %s",                         image_cube->filename);      return(1);    }    return(0);}static int QccIMGImageCubeReadData(FILE *infile,                                   QccIMGImageCube *image_cube){  int frame, row, col;    if ((infile == NULL) ||      (image_cube == NULL))    return(0);    for (frame = 0; frame < image_cube->num_frames; frame++)    for (row = 0; row < image_cube->num_rows; row++)      for (col = 0; col < image_cube->num_cols; col++)        if (QccFileReadDouble(infile,                              &(image_cube->volume[frame][row][col])))          {            QccErrorAddMessage("(QccIMGImageCubeReadData): Error calling QccFileReadDouble()",                               image_cube->filename);            return(1);          }    return(0);}int QccIMGImageCubeRead(QccIMGImageCube *image_cube){  FILE *infile = NULL;    if (image_cube == NULL)    return(0);

⌨️ 快捷键说明

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