diff options
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/filter.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 1be5cf99e19..2835a587136 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -206,29 +206,46 @@ void imb_filterx(struct ImBuf *ibuf) void IMB_filterN(ImBuf *out, ImBuf *in) { register char *row1, *row2, *row3; - register char *cp; + register char *cp, *r11, *r13, *r21, *r23, *r31, *r33; int rowlen, x, y; rowlen= in->x; - for(y=2; y<in->y; y++) { + for(y=0; y<in->y; y++) { /* setup rows */ - row1= (char *)(in->rect + (y-2)*rowlen); - row2= row1 + 4*rowlen; - row3= row2 + 4*rowlen; + row2= (char*)(in->rect + y*rowlen); + row1= (y == 0)? row2: row2 - 4*rowlen; + row3= (y == in->y-1)? row2: row2 + 4*rowlen; - cp= (char *)(out->rect + (y-1)*rowlen); - cp[0]= row2[0]; - cp[1]= row2[1]; - cp[2]= row2[2]; - cp[3]= row2[3]; - cp+= 4; + cp= (char *)(out->rect + y*rowlen); - for(x=2; x<rowlen; x++) { - cp[0]= (row1[0] + 2*row1[4] + row1[8] + 2*row2[0] + 4*row2[4] + 2*row2[8] + row3[0] + 2*row3[4] + row3[8])>>4; - cp[1]= (row1[1] + 2*row1[5] + row1[9] + 2*row2[1] + 4*row2[5] + 2*row2[9] + row3[1] + 2*row3[5] + row3[9])>>4; - cp[2]= (row1[2] + 2*row1[6] + row1[10] + 2*row2[2] + 4*row2[6] + 2*row2[10] + row3[2] + 2*row3[6] + row3[10])>>4; - cp[3]= (row1[3] + 2*row1[7] + row1[11] + 2*row2[3] + 4*row2[7] + 2*row2[11] + row3[3] + 2*row3[7] + row3[11])>>4; + for(x=0; x<rowlen; x++) { + if(x == 0) { + r11 = row1; + r21 = row1; + r31 = row1; + } + else { + r11 = row1-4; + r21 = row1-4; + r31 = row1-4; + } + + if(x == rowlen-1) { + r13 = row1; + r23 = row1; + r33 = row1; + } + else { + r13 = row1+4; + r23 = row1+4; + r33 = row1+4; + } + + cp[0]= (r11[0] + 2*row1[0] + r13[0] + 2*r21[0] + 4*row2[0] + 2*r23[0] + r31[0] + 2*row3[0] + r33[0])>>4; + cp[1]= (r11[1] + 2*row1[1] + r13[1] + 2*r21[1] + 4*row2[1] + 2*r23[1] + r31[1] + 2*row3[1] + r33[1])>>4; + cp[2]= (r11[2] + 2*row1[2] + r13[2] + 2*r21[2] + 4*row2[2] + 2*r23[2] + r31[2] + 2*row3[2] + r33[2])>>4; + cp[3]= (r11[3] + 2*row1[3] + r13[3] + 2*r21[3] + 4*row2[3] + 2*r23[3] + r31[3] + 2*row3[3] + r33[3])>>4; cp+=4; row1+=4; row2+=4; row3+=4; } } |