Advertisement
kknndd_

Untitled

Apr 25th, 2021
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. struct bmp_image* rotate_right(const struct bmp_image* image){
  2.  
  3.     if(image == NULL || image->header == NULL || image->data == NULL){
  4.         return NULL;
  5.     }
  6.  
  7.     struct bmp_image* new_image = malloc(sizeof (struct bmp_image*));
  8.  
  9.     new_image->header = image->header;
  10.    
  11.     uint32_t old_w = image->header->width;
  12.     uint32_t old_h = image->header->height;
  13.  
  14.     new_image->header->width = old_h;
  15.     new_image->header->height = old_w;
  16.  
  17.     new_image->data = malloc(sizeof (struct pixel*)*old_w*old_h);
  18.  
  19.     uint32_t idx = 0;
  20.  
  21.     for(uint32_t i = 0; i < old_w; i++){
  22.         for(uint32_t j = 0; j < old_h; j++){
  23.             new_image->data[idx].green = image->data[ ((j+1)*old_w)-i-1 ].green;
  24.             new_image->data[idx].red = image->data[ ((j+1)*old_w)-i-1 ].red;
  25.             new_image->data[idx].blue = image->data[ ((j+1)*old_w)-i-1 ].blue;
  26.             idx++;
  27.         }
  28.     }
  29.  
  30.     return new_image;
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement