简单的图像裁剪函数

S32 Crop_columns_images(U8 *pbuf,U8 partial_width1,U8 partial_height1)//图像buf,两遍各自裁剪的列数,上下各自裁剪的行数
{
     U32 m = 0;
     U32 hight = 0;
     U32 weight = 0;
     U8  hight_r = g_sensor_config->partial_height;//原有图像的高度
     U8  width_c = g_sensor_config->partial_width;//原有图像的宽度
     U8 (*Crop_buf)[width_c] = malloc(hight_r * sizeof(U8[width_c]));//申请一个二位数组
     if (Crop_buf == NULL){
        printf("Memory allocation failed\n");
        return -1;
     }
      memcpy(Crop_buf,pbuf,g_sensor_config->partial_height*g_sensor_config->partial_width);//将图像copy到crop_buf中
      for(hight = partial_height1; hight < (g_sensor_config->partial_height-partial_height1); hight++){
         for(weight = partial_width1; weight < (g_sensor_config->partial_width-partial_width1); weight++) {
            pbuf[m]= Crop_buf[hight][weight];//将需要的图像copy到pbuf中
            m++;
         }
       }
      free(Crop_buf);
      return  (g_sensor_config->partial_height-(2*partial_height1))*(g_sensor_config->partial_width-(2*partial_width1));//返回裁剪后图像的总长度
}

你可能感兴趣的:(java,linux,算法)