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

📄 image_component.c

📁 spiht for linux this is used to decod and encode vedio i wich all enjoy
💻 C
📖 第 1 页 / 共 3 页
字号:
  for (block_row = 0; block_row < block_num_rows; block_row++)    for (block_col = 0; block_col < block_num_cols; block_col++)      {        current_image_row = image_row + block_row;        current_image_col = image_col + block_col;        block[block_row][block_col] =          ((current_image_row >= 0) &&            (current_image_row < image_component->num_rows) &&           (current_image_col >= 0) &&           (current_image_col < image_component->num_cols)) ?          image_component->image[current_image_row][current_image_col] : 0;      }  return(0);}int QccIMGImageComponentInsertBlock(QccIMGImageComponent *image_component,                                    int image_row, int image_col,                                    const QccMatrix block,                                    int block_num_rows, int block_num_cols){  int block_row, block_col;  int current_image_row, current_image_col;  for (block_row = 0; block_row < block_num_rows; block_row++)    for (block_col = 0; block_col < block_num_cols; block_col++)      {        current_image_row = image_row + block_row;        current_image_col = image_col + block_col;        if ((current_image_row >= 0) &&             (current_image_row < image_component->num_rows) &&            (current_image_col >= 0) &&            (current_image_col < image_component->num_cols))           image_component->image[current_image_row][current_image_col] =            block[block_row][block_col];      }  if (QccIMGImageComponentSetMaxMin(image_component))    {      QccErrorAddMessage("(QccIMGImageComponentInsertBlock): Error calling QccIMGImageComponentSetMaxMin()");      return(1);    }  return(0);}int QccIMGImageComponentCopy(QccIMGImageComponent *image_component1,                             const QccIMGImageComponent *image_component2){  int row, col;    if ((image_component1 == NULL) ||      (image_component2 == NULL))    return(0);    if ((image_component2->image == NULL) ||      (image_component2->num_rows <= 0) ||      (image_component2->num_cols <= 0))    return(0);  if (image_component1->image == NULL)    {      image_component1->num_rows = image_component2->num_rows;      image_component1->num_cols = image_component2->num_cols;      if (QccIMGImageComponentAlloc(image_component1))        {          QccErrorAddMessage("(QccIMGImageComponentCopy): Error calling QccIMGImageComponentAlloc()");          return(1);        }    }  else    {      if ((image_component1->num_rows != image_component2->num_rows) ||          (image_component1->num_cols != image_component2->num_cols))        {          QccErrorAddMessage("(QccIMGImageComponentCopy): Image-component arrays have different sizes");          return(1);        }    }  for (row = 0; row < image_component1->num_rows; row++)    for (col = 0; col < image_component1->num_cols; col++)      image_component1->image[row][col] =         image_component2->image[row][col];    if (QccIMGImageComponentSetMaxMin(image_component1))    {      QccErrorAddMessage("(QccIMGImageComponentCopy): Error calling QccIMGImageComponentSetMaxMin()");      return(1);    }  return(0);  }int QccIMGImageComponentAdd(const QccIMGImageComponent *image_component1,                            const QccIMGImageComponent *image_component2,                            QccIMGImageComponent *image_component3){  int row, col;  if (image_component1 == NULL)    return(0);  if (image_component2 == NULL)    return(0);  if (image_component3 == NULL)    return(0);  if (image_component1->image == NULL)    return(0);  if (image_component2->image == NULL)    return(0);  if (image_component3->image == NULL)    return(0);  if ((image_component1->num_rows != image_component2->num_rows) ||      (image_component1->num_cols != image_component2->num_cols) ||      (image_component1->num_rows != image_component3->num_rows) ||      (image_component1->num_cols != image_component3->num_cols))    {      QccErrorAddMessage("(QccIMGImageComponentSubtract): Image components must have same number of rows and columns");      return(1);    }  for (row = 0; row < image_component1->num_rows; row++)    for (col = 0; col < image_component1->num_cols; col++)      image_component3->image[row][col] =        image_component1->image[row][col] +        image_component2->image[row][col];  if (QccIMGImageComponentSetMaxMin(image_component3))    {      QccErrorAddMessage("(QccIMGImageComponentAdd): Error calling QccIMGImageComponentSetMaxMin()");      return(1);    }  return(0);}int QccIMGImageComponentSubtract(const QccIMGImageComponent *image_component1,                                 const QccIMGImageComponent *image_component2,                                 QccIMGImageComponent *image_component3){  int row, col;  if (image_component1 == NULL)    return(0);  if (image_component2 == NULL)    return(0);  if (image_component3 == NULL)    return(0);  if (image_component1->image == NULL)    return(0);  if (image_component2->image == NULL)    return(0);  if (image_component3->image == NULL)    return(0);  if ((image_component1->num_rows != image_component2->num_rows) ||      (image_component1->num_cols != image_component2->num_cols) ||      (image_component1->num_rows != image_component3->num_rows) ||      (image_component1->num_cols != image_component3->num_cols))    {      QccErrorAddMessage("(QccIMGImageComponentSubtract): Image components must have same number of rows and columns");      return(1);    }  for (row = 0; row < image_component1->num_rows; row++)    for (col = 0; col < image_component1->num_cols; col++)      image_component3->image[row][col] =        image_component1->image[row][col] -        image_component2->image[row][col];  if (QccIMGImageComponentSetMaxMin(image_component3))    {      QccErrorAddMessage("(QccIMGImageComponentSubtract): Error calling QccIMGImageComponentSetMaxMin()");      return(1);    }  return(0);}static int QccIMGImageComponentExtractSubpixelClip(int value,                                                   int min_value,                                                   int max_value){  if (value < min_value)    value = min_value;  if (value > max_value)    value = max_value;  return(value);}int QccIMGImageComponentExtractSubpixel(const QccIMGImageComponent                                        *image_component,                                        double x,                                        double y,                                        double *subpixel){  int top;  int bottom;  int left;  int right;  double alpha, beta;  double gamma;  left =    QccIMGImageComponentExtractSubpixelClip((int)floor(x),                                            0,                                            image_component->num_cols - 1);  top =    QccIMGImageComponentExtractSubpixelClip((int)floor(y),                                            0,                                            image_component->num_rows - 1);  right =    QccIMGImageComponentExtractSubpixelClip((int)ceil(x),                                            0,                                            image_component->num_cols - 1);  bottom =    QccIMGImageComponentExtractSubpixelClip((int)ceil(y),                                            0,                                            image_component->num_rows - 1);  if (left == right)    {      alpha = image_component->image[top][left];      beta = image_component->image[bottom][left];    }  else    {      gamma = (x - left) / (right - left);      alpha =        (1 - gamma) * image_component->image[top][left] +        gamma * image_component->image[top][right];      beta =        (1 - gamma) * image_component->image[bottom][left] +        gamma * image_component->image[bottom][right];    }  if (top == bottom)    *subpixel = alpha;  else    {      gamma = (y - top) / (bottom - top);      *subpixel =        (1 - gamma) * alpha + gamma * beta;    }  return(0);}int QccIMGImageComponentInterpolateBilinear(const QccIMGImageComponent                                            *image_component1,                                            QccIMGImageComponent                                            *image_component2){  int row1, col1;  int row2, col2;  if (image_component1 == NULL)    return(0);  if (image_component2 == NULL)    return(0);  if (image_component1->image == NULL)    return(0);  if (image_component2->image == NULL)    return(0);  if ((image_component2->num_rows != 2 * image_component1->num_rows) ||      (image_component2->num_cols != 2 * image_component1->num_cols))    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateBilinear): Destination image size must be twice that of source image");      return(1);    }        for (row1 = 0, row2 = 0; row1 < image_component1->num_rows;       row1++, row2 += 2)    for (col1 = 0, col2 = 0; col1 < image_component1->num_cols;         col1++, col2 += 2)      image_component2->image[row2][col2] =        image_component1->image[row1][col1];  for (row2 = 1; row2 < image_component2->num_rows - 1; row2 += 2)    for (col2 = 0; col2 < image_component2->num_cols; col2 += 2)      image_component2->image[row2][col2] =        (image_component2->image[row2 - 1][col2] +         image_component2->image[row2 + 1][col2]) / 2;  for (col2 = 1; col2 < image_component2->num_cols - 1; col2 +=2)    for (row2 = 0; row2 < image_component2->num_rows; row2++)      image_component2->image[row2][col2] =        (image_component2->image[row2][col2 - 1] +         image_component2->image[row2][col2 + 1]) / 2;  for (col2 = 0; col2 < image_component2->num_cols; col2++)    image_component2->image[image_component2->num_rows - 1][col2] =      image_component2->image[image_component2->num_rows - 2][col2];  for (row2 = 0; row2 < image_component2->num_rows; row2++)    image_component2->image[row2][image_component2->num_cols - 1] =       image_component2->image[row2][image_component2->num_cols - 2];  if (QccIMGImageComponentSetMaxMin(image_component2))    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateBilinear): Error calling QccIMGImageComponentSetMaxMin()");      return(1);    }  return(0);}int QccIMGImageComponentInterpolateFilter(const QccIMGImageComponent                                          *image_component1,                                          QccIMGImageComponent                                          *image_component2,                                          const QccFilter *filter){  int return_value;  int row1, col1;  int row2, col2;  QccVector input_vector = NULL;  QccVector output_vector = NULL;  if (image_component1 == NULL)    return(0);  if (image_component2 == NULL)    return(0);  if (filter == NULL)    return(0);  if (image_component1->image == NULL)    return(0);  if (image_component2->image == NULL)    return(0);  if (filter->causality != QCCFILTER_SYMMETRICHALF)    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Filter must be half-sample symmetric");      goto Error;    }  if ((image_component2->num_rows != 2 * image_component1->num_rows) ||      (image_component2->num_cols != 2 * image_component1->num_cols))    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Destination image size must be twice that of source image");      goto Error;    }        if ((input_vector =       QccVectorAlloc(QccMathMax(image_component2->num_rows,                                 image_component2->num_cols))) == NULL)    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Error calling QccVectorAlloc()");      goto Error;    }  if ((output_vector =       QccVectorAlloc(QccMathMax(image_component2->num_rows,                                 image_component2->num_cols))) == NULL)    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Error calling QccVectorAlloc()");      goto Error;    }    for (row1 = 0, row2 = 0; row1 < image_component1->num_rows;       row1++, row2 += 2)    for (col1 = 0, col2 = 0; col1 < image_component1->num_cols;         col1++, col2 += 2)      image_component2->image[row2][col2] =        image_component1->image[row1][col1];    for (col1 = 0; col1 < image_component1->num_cols; col1++)    {      for (row1 = 0; row1 < image_component1->num_rows; row1++)        input_vector[row1] = image_component1->image[row1][col1];      QccVectorZero(output_vector, image_component1->num_rows);      if (QccFilterVector(input_vector,                          output_vector,                          image_component1->num_rows,                          filter,                          QCCFILTER_SYMMETRIC_EXTENSION))        {          QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Error calling QccFilterVector()");          goto Error;        }      for (row2 = 1; row2 < image_component2->num_rows - 1; row2 += 2)        image_component2->image[row2][col1 * 2] =          output_vector[row2 / 2];      image_component2->image[image_component2->num_rows - 1][col1 * 2] =        image_component2->image[image_component2->num_rows - 2][col1 * 2];    }    for (row2 = 0; row2 < image_component2->num_rows; row2++)    {      for (col1 = 0; col1 < image_component1->num_cols; col1++)        input_vector[col1] =          image_component2->image[row2][col1 * 2];      QccVectorZero(output_vector, image_component1->num_cols);      if (QccFilterVector(input_vector,                          output_vector,                          image_component1->num_cols,                          filter,                          QCCFILTER_SYMMETRIC_EXTENSION))        {          QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Error calling QccFilterVector()");          goto Error;        }            for (col2 = 1; col2 < image_component2->num_cols - 1; col2 +=2)        image_component2->image[row2][col2] =          output_vector[col2 / 2];      image_component2->image[row2][image_component2->num_cols - 1] =        image_component2->image[row2][image_component2->num_cols - 2];    }    if (QccIMGImageComponentSetMaxMin(image_component2))    {      QccErrorAddMessage("(QccIMGImageComponentInterpolateFilter): Error calling QccIMGImageComponentSetMaxMin()");      goto Error;    }    return_value = 0;  goto Return; Error:  return_value = 1; Return:  QccVectorFree(input_vector);  QccVectorFree(output_vector);  return(return_value);}

⌨️ 快捷键说明

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