Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "tbb/tick_count.h"
- #include "tbb/blocked_range2d.h"
- #include "tbb/parallel_for.h"
- #define IMAGE_FILEPATH "C:\\Users\\Ap0\\Desktop\\image\\image.bmp"
- /*
- Go to "Project -> Properties -> Configuration Properties -> Intel Performance Libraries -> Use Intel TBB" set to "Yes"
- Go to "Tools -> Options -> Debugging -> Symbols" select checkbox "Microsoft Symbol Servers"
- Go to "Project -> Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions" add "_CRT_SECURE_NO_WARNINGS"
- */
- /*
- matrix R [M][N] = matrix A [M][P] * matrix B [P][N]
- */
- unsigned char* readBMP()
- {
- int i;
- FILE* f = fopen(IMAGE_FILEPATH, "rb");
- unsigned char info[54];
- fread(info, sizeof(unsigned char), 54, f); // read the 54-byte header
- // extract image height and width from header
- int width = *(int*)&info[18];
- int height = *(int*)&info[22];
- int size = 3 * width * height;
- unsigned char* data = new unsigned char[size]; // allocate 3 bytes per pixel
- fread(data, sizeof(unsigned char), size, f); // read the rest of the data at once
- fclose(f);
- unsigned char* dataGrayScale = new unsigned char[width*height];
- int counter = 0;
- for (i = 0; i < size; i += 3)
- {
- dataGrayScale[i] = (data[i] + data[i + 1] + data[i + 2]) / 3; //the avg of the rgb is the grayscale value
- counter++;
- }
- delete[] data;
- return dataGrayScale;
- }
- void rgb_to_grayscale_serial()
- {
- readBMP();
- }
- void rgb_to_grayscale_parallel()
- {
- }
- int main()
- {
- /* serial converting of RGB image to grayscale */
- printf("Serial converting of RGB image to grayscale...\n");
- getchar();
- tbb::tick_count startTime = tbb::tick_count::now();
- rgb_to_grayscale_serial();
- tbb::tick_count endTime = tbb::tick_count::now();
- printf("Time: %lf seconds\n", (endTime - startTime).seconds());
- /* parallel converting of RGB image to grayscale */
- printf("Parallel converting of RGB image to grayscale...\n");
- getchar();
- startTime = tbb::tick_count::now();
- rgb_to_grayscale_parallel();
- endTime = tbb::tick_count::now();
- printf("Time: %lf seconds\n", (endTime - startTime).seconds());
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement