Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ReadBMP(string filename)
- {
- FILE* fileOpen = fopen(filename.c_str(), "rb");
- if (fileOpen == NULL)
- throw "Argument Exception";
- fread(info, sizeof(unsigned char), 54, fileOpen); // read the 54-byte header
- width = *(int*)&info[18];
- height = *(int*)&info[22];
- int max_value, temp_value;
- for (int i = 1; i < width; i++)
- {
- temp_value = GCD(i, width);
- if (temp_value > max_value)
- max_value = temp_value;
- }
- int row_padded = (width * 3 + 3) & (~3);
- unsigned char* data = new unsigned char[row_padded];
- unsigned char tempPixel;
- img.width = width;
- img.height = height;
- img.pixels = new int[height * width * 3];
- cpuImage.width = width;
- cpuImage.height = height;
- cpuImage.pixels = new int[height * width * 3];
- gpuImage.width = width;
- gpuImage.height = height;
- gpuImage.pixels = new int[height * width * 3];
- N = width * height * 3;
- for (int i = 0; i < height; i++)
- {
- fread(data, sizeof(unsigned char), row_padded, fileOpen);
- for (int j = 0; j < width * 3; j += 3)
- {
- tempPixel = data[j];
- data[j] = data[j + 2];
- data[j + 2] = tempPixel;
- img.pixels[i * width * 3 + (j / 3) * 3 + 0] = (int)data[j];
- img.pixels[i * width * 3 + (j / 3) * 3 + 1] = (int)data[j + 1];
- img.pixels[i * width * 3 + (j / 3) * 3 + 2] = (int)data[j + 2];
- }
- }
- fclose(fileOpen);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement