1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| typedef struct { int red; int green; int blue; } my_pixel_sum;
char smooth_my_descr[] = "smooth: 我的实现版本"; void smooth_my(int dim, pixel *src, pixel *dst){ int i, j;
int q1, q2, q3, q4, idx; q1 = 0; q2 = 1; q3 = dim; q4 = dim + 1; idx = 0; dst[idx].blue = (src[q1].blue + src[q2].blue + src[q3].blue + src[q4].blue) / 4; dst[idx].green = (src[q1].green + src[q2].green + src[q3].green + src[q4].green) / 4; dst[idx].red = (src[q1].red + src[q2].red + src[q3].red + src[q4].red) / 4;
q1 = dim - 2; q2 = dim - 1; q3 = dim + dim - 2; q4 = dim + dim - 1; idx = dim - 1; dst[idx].blue = (src[q1].blue + src[q2].blue + src[q3].blue + src[q4].blue) / 4; dst[idx].green = (src[q1].green + src[q2].green + src[q3].green + src[q4].green) / 4; dst[idx].red = (src[q1].red + src[q2].red + src[q3].red + src[q4].red) / 4;
q1 = (dim - 2) * dim; q2 = (dim - 2) * dim + 1; q3 = (dim - 1) * dim; q4 = (dim - 1) * dim + 1; idx = (dim - 1) * dim; dst[idx].blue = (src[q1].blue + src[q2].blue + src[q3].blue + src[q4].blue) / 4; dst[idx].green = (src[q1].green + src[q2].green + src[q3].green + src[q4].green) / 4; dst[idx].red = (src[q1].red + src[q2].red + src[q3].red + src[q4].red) / 4;
q1 = dim * dim - 2 - dim; q2 = dim * dim - 1 - dim; q3 = dim * dim - 2; q4 = dim * dim - 1; idx = dim * dim - 1; dst[idx].blue = (src[q1].blue + src[q2].blue + src[q3].blue + src[q4].blue) / 4; dst[idx].green = (src[q1].green + src[q2].green + src[q3].green + src[q4].green) / 4; dst[idx].red = (src[q1].red + src[q2].red + src[q3].red + src[q4].red) / 4;
my_pixel_sum *temp_pixel_group = (my_pixel_sum *)malloc(sizeof(my_pixel_sum) * 3);
for (i = 0; i <= 1; i++) { temp_pixel_group[i].blue = src[RIDX(0, i, dim)].blue + src[RIDX(1, i, dim)].blue; temp_pixel_group[i].green = src[RIDX(0, i, dim)].green + src[RIDX(1, i, dim)].green; temp_pixel_group[i].red = src[RIDX(0, i, dim)].red + src[RIDX(1, i, dim)].red; } for (j = 1; j <= dim - 2; j++) { q1 = j + 1; temp_pixel_group[q1 % 3].blue = src[RIDX(0, q1, dim)].blue + src[RIDX(1, q1, dim)].blue; temp_pixel_group[q1 % 3].green = src[RIDX(0, q1, dim)].green + src[RIDX(1, q1, dim)].green; temp_pixel_group[q1 % 3].red = src[RIDX(0, q1, dim)].red + src[RIDX(1, q1, dim)].red; dst[RIDX(0, j, dim)].blue = (temp_pixel_group[0].blue + temp_pixel_group[1].blue + temp_pixel_group[2].blue) / 6; dst[RIDX(0, j, dim)].red = (temp_pixel_group[0].red + temp_pixel_group[1].red + temp_pixel_group[2].red) / 6; dst[RIDX(0, j, dim)].green = (temp_pixel_group[0].green + temp_pixel_group[1].green + temp_pixel_group[2].green) / 6; }
for (i = 0; i <= 1; i++) { temp_pixel_group[i].blue = src[RIDX(dim - 1, i, dim)].blue + src[RIDX(dim - 2, i, dim)].blue; temp_pixel_group[i].green = src[RIDX(dim - 1, i, dim)].green + src[RIDX(dim - 2, i, dim)].green; temp_pixel_group[i].red = src[RIDX(dim - 1, i, dim)].red + src[RIDX(dim - 2, i, dim)].red; } for (j = 1; j <= dim - 2; j++) { q1 = j + 1; temp_pixel_group[q1 % 3].blue = src[RIDX(dim - 1, q1, dim)].blue + src[RIDX(dim - 2, q1, dim)].blue; temp_pixel_group[q1 % 3].green = src[RIDX(dim - 1, q1, dim)].green + src[RIDX(dim - 2, q1, dim)].green; temp_pixel_group[q1 % 3].red = src[RIDX(dim - 1, q1, dim)].red + src[RIDX(dim - 2, q1, dim)].red; dst[RIDX(dim - 1, j, dim)].blue = (temp_pixel_group[0].blue + temp_pixel_group[1].blue + temp_pixel_group[2].blue) / 6; dst[RIDX(dim - 1, j, dim)].red = (temp_pixel_group[0].red + temp_pixel_group[1].red + temp_pixel_group[2].red) / 6; dst[RIDX(dim - 1, j, dim)].green = (temp_pixel_group[0].green + temp_pixel_group[1].green + temp_pixel_group[2].green) / 6; }
for (i = 0; i <= 1; i++) { temp_pixel_group[i].blue = src[RIDX(i, 0, dim)].blue + src[RIDX(i, 1, dim)].blue; temp_pixel_group[i].green = src[RIDX(i, 0, dim)].green + src[RIDX(i, 1, dim)].green; temp_pixel_group[i].red = src[RIDX(i, 0, dim)].red + src[RIDX(i, 1, dim)].red; } for (i = 1; i <= dim - 2; i++) { q1 = i + 1; temp_pixel_group[q1 % 3].blue = src[RIDX(q1, 0, dim)].blue + src[RIDX(q1, 1, dim)].blue; temp_pixel_group[q1 % 3].green = src[RIDX(q1, 0, dim)].green + src[RIDX(q1, 1, dim)].green; temp_pixel_group[q1 % 3].red = src[RIDX(q1, 0, dim)].red + src[RIDX(q1, 1, dim)].red; dst[RIDX(i, 0, dim)].blue = (temp_pixel_group[0].blue + temp_pixel_group[1].blue + temp_pixel_group[2].blue) / 6; dst[RIDX(i, 0, dim)].red = (temp_pixel_group[0].red + temp_pixel_group[1].red + temp_pixel_group[2].red) / 6; dst[RIDX(i, 0, dim)].green = (temp_pixel_group[0].green + temp_pixel_group[1].green + temp_pixel_group[2].green) / 6; }
for (i = 0; i <= 1; i++) { temp_pixel_group[i].blue = src[RIDX(i, dim - 1, dim)].blue + src[RIDX(i, dim - 2, dim)].blue; temp_pixel_group[i].green = src[RIDX(i, dim - 1, dim)].green + src[RIDX(i, dim - 2, dim)].green; temp_pixel_group[i].red = src[RIDX(i, dim - 1, dim)].red + src[RIDX(i, dim - 2, dim)].red; } for (i = 1; i <= dim - 2; i++) { q1 = i + 1; temp_pixel_group[q1 % 3].blue = src[RIDX(q1, dim - 1, dim)].blue + src[RIDX(q1, dim - 2, dim)].blue; temp_pixel_group[q1 % 3].green = src[RIDX(q1, dim - 1, dim)].green + src[RIDX(q1, dim - 2, dim)].green; temp_pixel_group[q1 % 3].red = src[RIDX(q1, dim - 1, dim)].red + src[RIDX(q1, dim - 2, dim)].red; dst[RIDX(i, dim - 1, dim)].blue = (temp_pixel_group[0].blue + temp_pixel_group[1].blue + temp_pixel_group[2].blue) / 6; dst[RIDX(i, dim - 1, dim)].red = (temp_pixel_group[0].red + temp_pixel_group[1].red + temp_pixel_group[2].red) / 6; dst[RIDX(i, dim - 1, dim)].green = (temp_pixel_group[0].green + temp_pixel_group[1].green + temp_pixel_group[2].green) / 6; }
int k; for (i = 1; i <= dim - 2; i++) { for (k = 0; k <= 2; k++) { temp_pixel_group[k].blue = src[RIDX(i-1, k, dim)].blue + src[RIDX(i, k, dim)].blue + src[RIDX(i+1, k, dim)].blue; temp_pixel_group[k].green = src[RIDX(i-1, k, dim)].green + src[RIDX(i, k, dim)].green + src[RIDX(i+1, k, dim)].green; temp_pixel_group[k].red = src[RIDX(i-1, k, dim)].red + src[RIDX(i, k, dim)].red + src[RIDX(i+1, k, dim)].red; } for (j = 1; j <= dim - 2; j++) { q1 = j+1; temp_pixel_group[q1 % 3].blue = src[RIDX(i-1, j+1, dim)].blue + src[RIDX(i, j+1, dim)].blue+ src[RIDX(i+1, j+1, dim)].blue; temp_pixel_group[q1 % 3].green = src[RIDX(i-1, j+1, dim)].green + src[RIDX(i, j+1, dim)].green+ src[RIDX(i+1, j+1, dim)].green; temp_pixel_group[q1 % 3].red = src[RIDX(i-1, j+1, dim)].red + src[RIDX(i, j+1, dim)].red+ src[RIDX(i+1, j+1, dim)].red; dst[RIDX(i, j, dim)].blue = (temp_pixel_group[0].blue + temp_pixel_group[1].blue + temp_pixel_group[2].blue) / 9; dst[RIDX(i, j, dim)].red = (temp_pixel_group[0].red + temp_pixel_group[1].red + temp_pixel_group[2].red) / 9; dst[RIDX(i, j, dim)].green = (temp_pixel_group[0].green + temp_pixel_group[1].green + temp_pixel_group[2].green) / 9; } } }
|