美文网首页
Raw interpolation RGB 算法代码

Raw interpolation RGB 算法代码

作者: 码嘟嘟 | 来源:发表于2021-02-22 10:13 被阅读0次

链接地址:https://zhuanlan.zhihu.com/p/37354802

#define RAW_HORIZION 2592

#define RAW_VERTICAL 1944

//the layout can not be modified, RGB color mode

#define RED 0

#define GREEN 1

#define BLUE 2

char g_raw_array[RAW_VERTICAL][RAW_HORIZION] = {0};

char g_rgb_array[RAW_VERTICAL][RAW_HORIZION][3] = {0};

bool raw_interpolation(char *raw_array, char *rgb_array, unsigned int piexl_horizion, unsigned int pixel_vertical){

unsigned int x, y;

//row loop

for(y=0; y<pixel_vertical; y++){

//column loop

for(x=0; x<piexl_horizion; x++){

//RGB channel

if(y%2){//this odd row, first piexl is green

if(x%2){//this piexl is red

//rgb_array[y][x][RED] = raw_array[y][x];

*(rgb_array+y*piexl_horizion*3+x*3+RED) = *(raw_array+y*piexl_horizion+x);

//rgb_array[y][x][GREEN] = (raw_array[y-1][x] + raw_array[y+1][x] + raw_array[y][x-1] + raw_array[y][x+1])/4;

*(rgb_array+y*piexl_horizion*3+x*3+GREEN) = (*(raw_array+(y-1)*piexl_horizion+x)+*(raw_array+(y+1)*piexl_horizion+x)+*(raw_array+y*piexl_horizion+(x-1))+*(raw_array+y*piexl_horizion+(x+1)))/4;

//rgb_array[y][x][BLUE] = (raw_array[y-1][x-1] + raw_array[y-1][x+1] + raw_array[y+1][x-1] + raw_array[y+1][x+1])/4;

*(rgb_array+y*piexl_horizion*3+x*3+BLUE) = (*(raw_array+(y-1)*piexl_horizion+(x-1))+*(raw_array+(y-1)*piexl_horizion+(x+1))+*(raw_array+(y+1)*piexl_horizion+(x-1))+*(raw_array+(y+1)*piexl_horizion+(x+1)))/4;

}else{//this piexl is green_odd

//rgb_array[y][x][RED] = (raw_array[y][x-1] + raw_array[y][x+1])/2;

*(rgb_array+y*piexl_horizion*3+x*3+RED) = (*(raw_array+y*piexl_horizion+(x-1))+*(raw_array+y*piexl_horizion+(x+1)))/2;

//rgb_array[y][x][GREEN] = raw_array[y][x];

*(rgb_array+y*piexl_horizion*3+x*3+GREEN) = *(raw_array+y*piexl_horizion+x);

//rgb_array[y][x][BLUE] = (raw_array[y-1][x] + raw_array[y+1][x])/2;

*(rgb_array+y*piexl_horizion*3+x*3+BLUE) = (*(raw_array+(y-1)*piexl_horizion+x) + *(raw_array+(y+1)*piexl_horizion+x))/2;

}

}else{//this even row, first piexl is blue

if(x%2){//this piexl is green_even

//rgb_array[y][x][RED] = (raw_array[y-1][x] + raw_array[y+1][x])/2;

*(rgb_array+y*piexl_horizion*3+x*3+RED) = (*(raw_array+(y-1)*piexl_horizion+x) + *(raw_array+(y+1)*piexl_horizion+x))/2;

//rgb_array[y][x][GREEN] = raw_array[y][x];

*(rgb_array+y*piexl_horizion*3+x*3+GREEN) = *(raw_array+y*piexl_horizion+x);

//rgb_array[y][x][BLUE] = (raw_array[y][x-1] + raw_array[y][x+1])/2;

*(rgb_array+y*piexl_horizion*3+x*3+BLUE) = (*(raw_array+y*piexl_horizion+(x-1))+*(raw_array+y*piexl_horizion+(x+1)))/2;

}else{//this piexl is blue

//rgb_array[y][x][RED] = (raw_array[y-1][x-1] + raw_array[y-1][x+1] + raw_array[y+1][x-1] + raw_array[y+1][x+1])/4;

*(rgb_array+y*piexl_horizion*3+x*3+RED) = (*(raw_array+(y-1)*piexl_horizion+(x-1))+*(raw_array+(y-1)*piexl_horizion+(x+1))+*(raw_array+(y+1)*piexl_horizion+(x-1))+*(raw_array+(y+1)*piexl_horizion+(x+1)))/4;

//rgb_array[y][x][GREEN] = (raw_array[y-1][x] + raw_array[y+1][x] + raw_array[y][x-1] + raw_array[y][x+1])/4;

*(rgb_array+y*piexl_horizion*3+x*3+GREEN) = (*(raw_array+(y-1)*piexl_horizion+x)+*(raw_array+(y+1)*piexl_horizion+x)+*(raw_array+y*piexl_horizion+(x-1))+*(raw_array+y*piexl_horizion+(x+1)))/4;

//rgb_array[y][x][BLUE] = raw_array[y][x];

*(rgb_array+y*piexl_horizion*3+x*3+BLUE) = *(raw_array+y*piexl_horizion+x);

}

}

}

}

return true;

}

相关文章

网友评论

      本文标题:Raw interpolation RGB 算法代码

      本文链接:https://www.haomeiwen.com/subject/isywaktx.html