Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define W 800
- #define H 1200
- #define SIZE_IN_BYTES W*H*3
- #define BLUR_VAL 5 // distance in pixels to neighbours taken for blurring process
- #define KERNEL_LENGTH (BLUR_VAL * 2 + 1)
- #define KERNEL_SIZE (KERNEL_LENGTH * KERNEL_LENGTH)
- typedef unsigned unsigned3 __attribute__((ext_vector_type(3)));
- typedef unsigned char uchar3 __attribute__((ext_vector_type(3)));
- typedef struct __yuv {
- unsigned char y, u, v;
- }_yuv;
- void foo(){
- FILE *input =
- fopen("david.rgb", "rb");
- if (input == NULL){
- printf("Error opening reading file\n");
- return;
- }
- FILE *output = fopen("rgbee.rgb", "wb");
- if(output == NULL){
- printf("Error opening/creating output file\n");
- return;
- }
- uchar3 *bufArray = (uchar3 *)malloc(H * W * sizeof(uchar3));
- fread(bufArray, sizeof(uchar3), W*H, input);
- fwrite(bufArray, sizeof(uchar3), W*H, output);
- return;
- int i, j;
- for (i = 0; i < H; ++i){
- for (j = 0; j < W; ++j){
- //unsigned sumYUV[3] = { 0 };
- unsigned3 sumYUV = { 0 };
- //sumYUV[0] = 0; sumYUV[1] = 0; sumYUV[2] = 0;
- for (int k = i - BLUR_VAL; (k <= i + BLUR_VAL) && k < H; ++k){
- for (int l = j - BLUR_VAL; (l <= j + BLUR_VAL) && l < W; ++l){
- if (k < 0){
- k = -1;
- break;
- }
- if (l < 0){
- l = -1;
- continue;
- }
- // sumYUV += (__builtin_convertvector(bufArray[k * W + l], unsigned3));
- /*sumYUV[0] += bufArray[k * W + l].y;
- sumYUV[1] += bufArray[k * W + l].u;
- sumYUV[2] += bufArray[k * W + l].v;*/
- sumYUV[0] += bufArray[k * W + l][0];
- sumYUV[1] += bufArray[k * W + l][1];
- sumYUV[2] += bufArray[k * W + l][2];
- }
- }
- uchar3 Pixel = {
- //unsigned char Pixel[3] = {
- sumYUV[0] / KERNEL_SIZE, sumYUV[1] / KERNEL_SIZE, sumYUV[2] / KERNEL_SIZE
- };
- fwrite(&Pixel, 1, 3, output);
- }
- }
- free(bufArray);
- fclose(input);
- fclose(output);
- }
- int main(){
- //printf("kernel length is %d\n",KERNEL_LENGTH);
- foo();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement