Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "tbb/tick_count.h"
  3. #include "tbb/blocked_range2d.h"
  4. #include "tbb/parallel_for.h"
  5.  
  6. #define IMAGE_FILEPATH "C:\\Users\\Ap0\\Desktop\\image\\image.bmp"
  7.  
  8. /*
  9. Go to "Project -> Properties -> Configuration Properties -> Intel Performance Libraries -> Use Intel TBB" set to "Yes"
  10. Go to "Tools -> Options -> Debugging -> Symbols" select checkbox "Microsoft Symbol Servers"
  11. Go to "Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions" add "_CRT_SECURE_NO_WARNINGS"
  12. */
  13.  
  14. /*
  15. matrix R [M][N] = matrix A [M][P] * matrix B [P][N]
  16. */
  17.  
  18. unsigned char* readBMP()
  19. {
  20. int i;
  21. FILE* f = fopen(IMAGE_FILEPATH, "rb");
  22. unsigned char info[54];
  23. fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
  24.  
  25. // extract image height and width from header
  26. int width = *(int*)&info[18];
  27. int height = *(int*)&info[22];
  28.  
  29. int size = 3 * width * height;
  30. unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel
  31. fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
  32. fclose(f);
  33. unsigned char* dataGrayScale = new unsigned char[width*height];
  34. int counter = 0;
  35.  
  36. for (i = 0; i < size; i += 3)
  37. {
  38. dataGrayScale[i] = (data[i] + data[i + 1] + data[i + 2]) / 3; //the avg of the rgb is the grayscale value
  39. counter++;
  40. }
  41.  
  42. delete[] data;
  43. return dataGrayScale;
  44. }
  45.  
  46. void rgb_to_grayscale_serial()
  47. {
  48. readBMP();
  49. }
  50.  
  51. void rgb_to_grayscale_parallel()
  52. {
  53.  
  54. }
  55.  
  56. int main()
  57. {
  58. /* serial converting of RGB image to grayscale */
  59. printf("Serial converting of RGB image to grayscale...\n");
  60. getchar();
  61. tbb::tick_count startTime = tbb::tick_count::now();
  62. rgb_to_grayscale_serial();
  63. tbb::tick_count endTime = tbb::tick_count::now();
  64. printf("Time: %lf seconds\n", (endTime - startTime).seconds());
  65.  
  66. /* parallel converting of RGB image to grayscale */
  67. printf("Parallel converting of RGB image to grayscale...\n");
  68. getchar();
  69. startTime = tbb::tick_count::now();
  70. rgb_to_grayscale_parallel();
  71. endTime = tbb::tick_count::now();
  72. printf("Time: %lf seconds\n", (endTime - startTime).seconds());
  73.  
  74. getchar();
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement