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

📄 vector.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 2 页
字号:
    return(0);  printf("< ");  for (component = 0; component < vector_dimension; component++)    printf("%g ", vector[component]);  printf(">\n");  return(0);}/*  Based on QS2I1D, part of the SLATEC library  */#define QccQuickSortSwap(a,b) {double temp;temp=(a);(a)=(b);(b)=temp;}static int QccVectorQuickSortAscending(QccVector A, int low, int high){  int low_pnt, high_pnt, pivot_position;  double pivot;  pivot_position = low + (high - low)/2;  pivot = A[pivot_position];  /*  If first element of array is greater than it, interchange with it.  */  if (A[low] > pivot)    QccQuickSortSwap(A[pivot_position], A[low]);  /*  If last element of array is less than it, swap with it.  */  if (A[high] < pivot)    {      QccQuickSortSwap(A[pivot_position], A[high]);      /*  If first element of array is greater than it, swap with it.  */      if (A[low] > A[pivot_position])        QccQuickSortSwap(A[pivot_position], A[low]);    }    low_pnt = low;  high_pnt = high;  while (low_pnt < high_pnt)    {      /*  Find an element in the second half of the array which is          smaller than it.  */      do        high_pnt--;      while (A[high_pnt] > pivot);            /*  Find an element in the first half of the array which is          greater than it.  */      do        low_pnt++;      while (A[low_pnt] < pivot);            /*  Interchange these elements.  */      if (low_pnt <= high_pnt)        QccQuickSortSwap(A[high_pnt], A[low_pnt]);    }  if (high_pnt + 1 < high)    QccVectorQuickSortAscending(A, high_pnt + 1, high);  if (low < high_pnt)    QccVectorQuickSortAscending(A, low, high_pnt);  return(0);}static int QccVectorQuickSortAscendingWithAux(QccVector A, int low,                                               int high, int *auxiliary_list){  int low_pnt, high_pnt, pivot_position;  double pivot;  pivot_position = low + (high - low)/2;  pivot = A[pivot_position];  /*  If first element of array is greater than it, interchange with it.  */  if (A[low] > pivot)    {      QccQuickSortSwap(A[pivot_position], A[low]);      QccQuickSortSwap(auxiliary_list[pivot_position], auxiliary_list[low]);    }  /*  If last element of array is less than it, swap with it.  */  if (A[high] < pivot)    {      QccQuickSortSwap(A[pivot_position], A[high]);      QccQuickSortSwap(auxiliary_list[pivot_position], auxiliary_list[high]);      /*  If first element of array is greater than it, swap with it.  */      if (A[low] > A[pivot_position])        {          QccQuickSortSwap(A[pivot_position], A[low]);          QccQuickSortSwap(auxiliary_list[pivot_position], auxiliary_list[low]);        }    }    low_pnt = low;  high_pnt = high;  while (low_pnt < high_pnt)    {      /*  Find an element in the second half of the array which is          smaller than it.  */      do        high_pnt--;      while (A[high_pnt] > pivot);            /*  Find an element in the first half of the array which is          greater than it.  */      do        low_pnt++;      while (A[low_pnt] < pivot);            /*  Interchange these elements.  */      if (low_pnt <= high_pnt)        {          QccQuickSortSwap(A[high_pnt], A[low_pnt]);          QccQuickSortSwap(auxiliary_list[high_pnt], auxiliary_list[low_pnt]);        }    }  if (high_pnt + 1 < high)    QccVectorQuickSortAscendingWithAux(A, high_pnt + 1, high, auxiliary_list);  if (low < high_pnt)    QccVectorQuickSortAscendingWithAux(A, low, high_pnt, auxiliary_list);  return(0);}int QccVectorSortComponents(const QccVector vector, QccVector sorted_vector,                            int vector_dimension, int sort_direction,                            int *auxiliary_list){  int component;  if ((vector == NULL) || (sorted_vector == NULL) ||      (vector_dimension <= 0))    return(0);  if (sort_direction == QCCVECTOR_SORTDESCENDING)    for (component = 0; component < vector_dimension; component++)      sorted_vector[component] = -vector[component];  else    for (component = 0; component < vector_dimension; component++)      sorted_vector[component] = vector[component];  if (auxiliary_list == NULL)    {      if (QccVectorQuickSortAscending(sorted_vector, 0, vector_dimension - 1))        {          QccErrorAddMessage("(QccVectorSortComponents): Error calling QccVectorQuickSortAscending()");          return(1);        }    }  else    if (QccVectorQuickSortAscendingWithAux(sorted_vector, 0,                                            vector_dimension - 1,                                           auxiliary_list))      {        QccErrorAddMessage("(QccVectorSortComponents): Error calling QccVectorQuickSortAscendingWithIndex()");        return(1);      }  if (sort_direction == QCCVECTOR_SORTDESCENDING)    for (component = 0; component < vector_dimension; component++)      sorted_vector[component] = -sorted_vector[component];  return(0);}int QccVectorGetSymbolProbs(const int *symbol_list, int symbol_list_length,                            QccVector probs,                             int num_symbols){  int symbol;  for (symbol = 0; symbol < num_symbols; symbol++)    probs[symbol] = (double)0.0;  for (symbol = 0; symbol < symbol_list_length; symbol++)    if (symbol_list[symbol] >= num_symbols)      {        QccErrorAddMessage("(QccVectorGetSymbolProbs): Symbol value out of range");        return(1);      }    else      probs[symbol_list[symbol]] += 1.0;  for (symbol = 0; symbol < num_symbols; symbol++)    probs[symbol] /= (double)symbol_list_length;  return(0);}int QccVectorMoveComponentToFront(QccVector vector, int vector_dimension,                                  int index){  int component;  double tmp;  if (!index)    return(0);  if (index >= vector_dimension)    return(1);  tmp = vector[index];  for (component = index; component; component--)    vector[component] = vector[component - 1];  vector[0] = tmp;  return(0);}int QccVectorSubsample(const QccVector input_signal,                       int input_length,                       QccVector output_signal,                       int output_length,                       int sampling_flag){  int index;  if (input_signal == NULL)    return(0);  if (output_signal == NULL)    return(0);  switch (sampling_flag)    {    case QCCVECTOR_EVEN:      for (index = 0;           (index < output_length) && ((index * 2) < input_length);           index++)        output_signal[index] = input_signal[index * 2];      break;    case QCCVECTOR_ODD:      for (index = 0;           (index < output_length) && ((index * 2 + 1) < input_length);           index++)        output_signal[index] = input_signal[index * 2 + 1];      break;    default:      QccErrorAddMessage("(QccVectorSubsample): Undefined sampling (%d)",                         sampling_flag);      return(1);    }  return(0);}int QccVectorUpsample(const QccVector input_signal,                      int input_length,                      QccVector output_signal,                      int output_length,                      int sampling_flag){  int index;  if (input_signal == NULL)    return(0);  if (output_signal == NULL)    return(0);  QccVectorZero(output_signal, output_length);  switch (sampling_flag)    {    case QCCVECTOR_EVEN:      for (index = 0;           (index < input_length) && ((index * 2) < output_length);           index++)        output_signal[index * 2] = input_signal[index];      break;    case QCCVECTOR_ODD:      for (index = 0;           (index < input_length) && ((index * 2 + 1) < output_length);           index++)        output_signal[index * 2 + 1] = input_signal[index];      break;    default:      QccErrorAddMessage("(QccVectorUpsample): Undefined sampling (%d)",                         sampling_flag);      return(1);    }  return(0);}int QccVectorDCT(const QccVector input_signal,                 QccVector output_signal,                 int signal_length){  double C1, C2, C3;  int n, k;  if ((input_signal == NULL) ||      (output_signal == NULL))    return(0);  if (signal_length <= 0)    return(0);  C1 = 1.0/sqrt((double)signal_length);  C2 = sqrt(2.0/signal_length);  C3 = (double)M_PI/2/signal_length;  output_signal[0] = 0.0;  for (n = 0; n < signal_length; n++)    output_signal[0] += input_signal[n];  output_signal[0] *= C1;  for (k = 1; k < signal_length; k++)    {      output_signal[k] = 0.0;      for (n = 0; n < signal_length; n++)        output_signal[k] +=          input_signal[n] * cos(C3 * (2*n + 1) * k);      output_signal[k] *= C2;    }  return(0);}int QccVectorInverseDCT(const QccVector input_signal,                        QccVector output_signal,                        int signal_length){  double C1, C2, C3;  int n, k;  if ((input_signal == NULL) ||      (output_signal == NULL))    return(0);  if (signal_length <= 0)    return(0);  C1 = 1.0/sqrt((double)signal_length);  C2 = sqrt(2.0/signal_length);  C3 = (double)M_PI/2/signal_length;  for (n = 0; n < signal_length; n++)    {      output_signal[n] = C1 * input_signal[0];      for (k = 1; k < signal_length; k++)        output_signal[n] +=          C2 * input_signal[k] * cos(C3 * (2*n + 1) * k);    }  return(0);}

⌨️ 快捷键说明

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