Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void resizeBilinearGray(uint8_t *pixels, uint8_t *temp, int w, int h, int w2, int h2) {
- int A, B, C, D, x, y, index, gray ;
- float x_ratio = ((float)(w-1))/w2 ;
- float y_ratio = ((float)(h-1))/h2 ;
- float x_diff, y_diff;
- int offset = 0 ;
- for (int i=0;i<h2;i++) {
- for (int j=0;j<w2;j++) {
- x = (int)(x_ratio * j) ;
- y = (int)(y_ratio * i) ;
- x_diff = (x_ratio * j) - x ;
- y_diff = (y_ratio * i) - y ;
- index = y*w+x ;
- // range is 0 to 255 thus bitwise AND with 0xff
- A = pixels[index] & 0xff ;
- B = pixels[index+1] & 0xff ;
- C = pixels[index+w] & 0xff ;
- D = pixels[index+w+1] & 0xff ;
- // Y = A(1-w)(1-h) + B(w)(1-h) + C(h)(1-w) + Dwh
- gray = (int)(
- A*(1-x_diff)*(1-y_diff) + B*(x_diff)*(1-y_diff) +
- C*(y_diff)*(1-x_diff) + D*(x_diff*y_diff)
- ) ;
- temp[offset++] = gray ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement