Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include "bmp.h"
  2. void bmp_gray(bmp_image image)
  3. {
  4. unsigned int i, j, a , b;
  5.  
  6. /* Получаем линейные размеры изображения */
  7. unsigned int w = image.header.width;
  8. unsigned int h = image.header.height;
  9. bmp_image image2;
  10. image2.pixel_array = (double*)malloc(3 * (w + 4) * (h + 4) * sizeof(double));
  11.  
  12.  
  13.  
  14. for (i = 0; i < h; i++) {
  15. for(j = 0; j < w; j++) {
  16. image2.pixel_array[0 * h * w + i * w + j] = image.pixel_array[0 * h * w + i * w + j];
  17. image2.pixel_array[1 * h * w + i * w + j] = image.pixel_array[1 * h * w + i * w + j];
  18. image2.pixel_array[2 * h * w + i * w + j] = image.pixel_array[2 * h * w + i * w + j];
  19. }
  20. }
  21.  
  22. for (i = 0; i < w; i++) {
  23. for(j = 0; j < h; j++) {
  24. image.pixel_array[0 * h * w + i * w + j] = image2.pixel_array[0 * h * w + i * h + (w * i - j)];
  25. image.pixel_array[1 * h * w + i * w + j] = image2.pixel_array[1 * h * w + i * h + (w * i - j)];
  26. image.pixel_array[2 * h * w + i * w + j] = image2.pixel_array[2 * h * w + i * h + (w * i - j)];
  27. }
  28. }
  29.  
  30. /* for (i = h-w; i < h; i++) {
  31. for(j = 0; j < h; j++) {
  32. image.pixel_array[0 * h * w + i * w + j] = image2.pixel_array[0 * h* w + j * w + (w + 1 + i)];
  33. image.pixel_array[1 * h * w + i * w + j] = image2.pixel_array[1 * h* w + j * w + (w + 1 + i)];
  34. image.pixel_array[2 * h * w + i * w + j] = image2.pixel_array[2 * h* w + j * w + (w + 1 + i)];
  35. }
  36. } */
  37.  
  38. free(image2.pixel_array);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement