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

📄 rawfile.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 2 页
字号:
{  FILE *infile1;  FILE *infile2;  int row, col;  double mean;  int sample1;  int sample2;  double signal_power = 0;  double ae;  double mse1 = 0;  double mae1 = 0;  double snr1 = 0;      if (QccHYPRawMean2D(filename1,                      &mean,                      num_rows,                      num_cols,                      bpp,                      signed_data,                      endian))    {      QccErrorAddMessage("(QccHYPRawDist2D): Error calling QccHYPRawMean2D()");      return(1);    }    if ((infile1 = QccFileOpen(filename1, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawDist2D): Error calling QccFileOpen()");      return(1);    }  if ((infile2 = QccFileOpen(filename2, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawDist2D): Error calling QccFileOpen()");      return(1);    }    for (row = 0; row < num_rows; row++)    for (col = 0; col < num_cols; col++)      {        if (QccHYPRawReadSample(infile1,                                &sample1,                                bpp,                                signed_data,                                endian))          {            QccErrorAddMessage("(QccHYPRawDist2D): Error calling QccHYPRawReadSample()");            return(1);          }        if (QccHYPRawReadSample(infile2,                                &sample2,                                bpp,                                signed_data,                                endian))          {            QccErrorAddMessage("(QccHYPRawDist2D): Error calling QccHYPRawReadSample()");            return(1);          }        mse1 += (double)(sample1 - sample2)*(sample1 - sample2) /          num_rows / num_cols;        ae = fabs((double)(sample1 - sample2));        if (ae > mae1)          mae1 = ae;        signal_power += (sample1 - mean)*(sample1 - mean) /          num_rows / num_cols;      }    if (mse1 != 0.0)    snr1 = 10.0*log10(signal_power/(mse1));    QccFileClose(infile1);  QccFileClose(infile2);    if (mse != NULL)    *mse = mse1;  if (mae != NULL)    *mae = mae1;  if (snr != NULL)    *snr = snr1;  return(0);}int QccHYPRawRead3D(QccString filename,                    QccIMGImageCube *image_cube,                    int bpv,                    int signed_data,                    int format,                    int endian){  FILE *infile;  int frame, row, col;  int sample;    if (image_cube == NULL)    return(1);    if ((infile = QccFileOpen(filename, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawRead3D): Error calling QccFileOpen()");      return(1);    }    switch (format)    {    case QCCHYP_RAWFORMAT_BSQ:      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 (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawRead3D): Error calling QccHYPRawReadSample()");                  return(1);                }              image_cube->volume[frame][row][col] = (double)sample;            }      break;          case QCCHYP_RAWFORMAT_BIL:      for (row = 0; row < image_cube->num_rows; row++)        for (frame = 0; frame < image_cube->num_frames; frame++)          for (col = 0; col < image_cube->num_cols; col++)            {              if (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawRead3D): Error calling QccHYPRawReadSample()");                  return(1);                }              image_cube->volume[frame][row][col] = (double)sample;            }      break;          case QCCHYP_RAWFORMAT_BIP:      for (row = 0; row < image_cube->num_rows; row++)        for (col = 0; col < image_cube->num_cols; col++)          for (frame = 0; frame < image_cube->num_frames; frame++)            {              if (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawRead3D): Error calling QccHYPRawReadSample()");                  return(1);                }              image_cube->volume[frame][row][col] = (double)sample;            }      break;          default:      {        QccErrorAddMessage("(QccHYPRawRead3D): Unrecognized format");        return(1);      }    }    QccFileClose(infile);    return(0);}int QccHYPRawWrite3D(QccString filename,                     const QccIMGImageCube *image_cube,                     int bpv,                     int format,                     int endian){  FILE *outfile;  int frame, row, col;  int sample;  if (image_cube == NULL)    return(1);  if ((outfile = QccFileOpen(filename, "w")) == NULL)    {      QccErrorAddMessage("(QccHYPRawWrite3D): Error calling QccFileOpen()");      return(1);    }    switch (format)    {    case QCCHYP_RAWFORMAT_BSQ:      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++)            {              sample =                (int)rint(image_cube->volume[frame][row][col]);              if (QccHYPRawWriteSample(outfile,                                       sample,                                       bpv,                                       endian))                {                  QccErrorAddMessage("(QccHYPRawWrite3D): Error calling QccHYPRawWriteSample()");                  return(1);                }            }      break;          case QCCHYP_RAWFORMAT_BIL:      for (row = 0; row < image_cube->num_rows; row++)        for (frame = 0; frame < image_cube->num_frames; frame++)          for (col = 0; col < image_cube->num_cols; col++)            {              sample =                (int)rint(image_cube->volume[frame][row][col]);              if (QccHYPRawWriteSample(outfile,                                       sample,                                       bpv,                                       endian))                {                  QccErrorAddMessage("(QccHYPRawWrite3D): Error calling QccHYPRawWriteSample()");                  return(1);                }            }      break;          case QCCHYP_RAWFORMAT_BIP:      for (row = 0; row < image_cube->num_rows; row++)        for (col = 0; col < image_cube->num_cols; col++)          for (frame = 0; frame < image_cube->num_frames; frame++)            {              sample =                (int)rint(image_cube->volume[frame][row][col]);              if (QccHYPRawWriteSample(outfile,                                       sample,                                       bpv,                                       endian))                {                  QccErrorAddMessage("(QccHYPRawWrite3D): Error calling QccHYPRawWriteSample()");                  return(1);                }            }      break;          default:      {        QccErrorAddMessage("(QccHYPRawWrite3D): Unrecognized format");        return(1);      }    }    QccFileClose(outfile);    return(0);}static int QccHYPRawMean3D(QccString filename,                           double *mean,                           int num_frames,                           int num_rows,                           int num_cols,                           int bpv,                           int signed_data,                           int format,                           int endian){  FILE *infile;  int frame, row, col;  int sample;    *mean = 0;    if ((infile = QccFileOpen(filename, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawMean3D): Error calling QccFileOpen()");      return(1);    }    switch (format)    {    case QCCHYP_RAWFORMAT_BSQ:      for (frame = 0; frame < num_frames; frame++)        for (row = 0; row < num_rows; row++)          for (col = 0; col < num_cols; col++)            {              if (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawMean3D): Error calling QccHYPRawReadSample()");                  return(1);                }              *mean += (double)sample / num_rows / num_cols / num_frames;            }      break;          case QCCHYP_RAWFORMAT_BIL:      for (row = 0; row < num_rows; row++)        for (frame = 0; frame < num_frames; frame++)          for (col = 0; col < num_cols; col++)            {              if (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawMean3D): Error calling QccHYPRawReadSample()");                  return(1);                }              *mean += (double)sample / num_rows / num_cols / num_frames;            }      break;          case QCCHYP_RAWFORMAT_BIP:      for (row = 0; row < num_rows; row++)        for (col = 0; col < num_cols; col++)          for (frame = 0; frame < num_frames; frame++)            {              if (QccHYPRawReadSample(infile,                                      &sample,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawMean3D): Error calling QccHYPRawReadSample()");                  return(1);                }              *mean += (double)sample / num_rows / num_cols / num_frames;            }      break;          default:      {        QccErrorAddMessage("(QccHYPRawMean3D): Unrecognized format");        return(1);      }    }    QccFileClose(infile);    return(0);}int QccHYPRawDist3D(QccString filename1,                    QccString filename2,                    double *mse,                    double *mae,                    double *snr,                    int num_frames,                    int num_rows,                    int num_cols,                    int bpv,                    int signed_data,                    int format,                    int endian){  FILE *infile1;  FILE *infile2;  int frame, row, col;  double mean;  int sample1;  int sample2;  double signal_power = 0;  double ae;  double mse1 = 0;  double mae1 = 0;  double snr1 = 0;    if (QccHYPRawMean3D(filename1,                      &mean,                      num_frames,                      num_rows,                      num_cols,                      bpv,                      signed_data,                      format,                      endian))    {      QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawMean3D()");      return(1);    }    if ((infile1 = QccFileOpen(filename1, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccFileOpen()");      return(1);    }  if ((infile2 = QccFileOpen(filename2, "r")) == NULL)    {      QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccFileOpen()");      return(1);    }    switch (format)    {    case QCCHYP_RAWFORMAT_BSQ:      for (frame = 0; frame < num_frames; frame++)        for (row = 0; row < num_rows; row++)          for (col = 0; col < num_cols; col++)            {              if (QccHYPRawReadSample(infile1,                                      &sample1,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              if (QccHYPRawReadSample(infile2,                                      &sample2,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              mse1 += (double)(sample1 - sample2)*(sample1 - sample2) /                num_frames / num_rows / num_cols;              ae = fabs((double)(sample1 - sample2));              if (ae > mae1)                mae1 = ae;              signal_power += (sample1 - mean)*(sample1 - mean) /                num_frames / num_rows / num_cols;            }      break;          case QCCHYP_RAWFORMAT_BIL:      for (row = 0; row < num_rows; row++)        for (frame = 0; frame < num_frames; frame++)          for (col = 0; col < num_cols; col++)            {              if (QccHYPRawReadSample(infile1,                                      &sample1,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              if (QccHYPRawReadSample(infile2,                                      &sample2,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              mse1 += (double)(sample1 - sample2)*(sample1 - sample2) /                num_frames / num_rows / num_cols;              ae = fabs((double)(sample1 - sample2));              if (ae > mae1)                mae1 = ae;              signal_power += (sample1 - mean)*(sample1 - mean) /                num_frames / num_rows / num_cols;            }      break;          case QCCHYP_RAWFORMAT_BIP:      for (row = 0; row < num_rows; row++)        for (col = 0; col < num_cols; col++)          for (frame = 0; frame < num_frames; frame++)            {              if (QccHYPRawReadSample(infile1,                                      &sample1,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              if (QccHYPRawReadSample(infile2,                                      &sample2,                                      bpv,                                      signed_data,                                      endian))                {                  QccErrorAddMessage("(QccHYPRawDist3D): Error calling QccHYPRawReadSample()");                  return(1);                }              mse1 += (double)(sample1 - sample2)*(sample1 - sample2) /                num_frames / num_rows / num_cols;              ae = fabs((double)(sample1 - sample2));              if (ae > mae1)                mae1 = ae;              signal_power += (sample1 - mean)*(sample1 - mean) /                num_frames / num_rows / num_cols;            }      break;          default:      {        QccErrorAddMessage("(QccHYPRawDist3D): Unrecognized format");        return(1);      }    }    if (mse1 != 0.0)    snr1 = 10.0*log10(signal_power/(mse1));    QccFileClose(infile1);  QccFileClose(infile2);    if (mse != NULL)    *mse = mse1;  if (mae != NULL)    *mae = mae1;  if (snr != NULL)    *snr = snr1;  return(0);}

⌨️ 快捷键说明

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