Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <graphics.h>
- #include <iostream>
- using namespace std;
- struct FileHeader {
- WORD bfType;
- DWORD bfSize;
- WORD bfReserved1;
- WORD bfReserved2;
- DWORD bfOffbits;
- } file_header;
- struct MAPINFO {
- DWORD Size;
- DWORD Width;
- DWORD Height;
- WORD Planes;
- WORD BitCount;
- DWORD Compression;
- DWORD SizeImage;
- long XPelsPerMeter;
- long YPelsPerMeter;
- DWORD ClrUsed;
- DWORD ClrImportant;
- } map_info;
- struct RGBquad {
- byte rgbRed;
- byte rgbGreen;
- byte rgbBlue;
- byte rgbReserved;
- };
- int main() {
- FILE *f1 = fopen("pigvin256.bmp", "rb");
- fread(&file_header, sizeof(file_header), 1, f1);
- cout << "-----FILE HEADER" << endl;
- cout << "bfType - " << file_header.bfType << endl;
- cout << "bfSize - " << file_header.bfSize << endl;
- cout << "bfReserved1 - " << file_header.bfReserved1 << endl;
- cout << "bfReserved2 - " << file_header.bfReserved2 << endl;
- cout << "bfOffBits - " << file_header.bfOffbits << endl;
- fread(&map_info, sizeof(map_info), 1, f1);
- cout << "-----MAP INFO" << endl;
- cout << "Size - " << map_info.Size << endl;
- cout << "Width - " << map_info.Width << endl;
- cout << "Height - " << map_info.Height << endl;
- cout << "Planes - " << map_info.Planes << endl;
- cout << "BitCount - " << map_info.BitCount << endl;
- cout << "Compression - " << map_info.Compression << endl;
- cout << "SizeImage - " << map_info.SizeImage << endl;
- cout << "XPelsPerMeter - " << map_info.XPelsPerMeter << endl;
- cout << "YPelsPerMeter - " << map_info.YPelsPerMeter << endl;
- cout << "ClrUsed - " << map_info.ClrUsed << endl;
- cout << "ClrImportant - " << map_info.ClrImportant << endl;
- if(map_info.BitCount == 8) {
- FILE *f2 = fopen("pigvin256q.bmp", "wb");
- fwrite(&file_header, sizeof(file_header), 1, f2);
- fwrite(&map_info, sizeof(map_info), 1, f2);
- int N = map_info.ClrUsed;
- RGBquad BmiColors[N];
- fread(BmiColors, sizeof(RGBquad), N, f1);
- byte r, g, b, v;
- for(int i = 0; i < N; i++) {
- r = BmiColors[i].rgbRed;
- g = BmiColors[i].rgbGreen;
- b = BmiColors[i].rgbBlue;
- v = (r + g + b) / 3;
- BmiColors[i].rgbRed = v;
- BmiColors[i].rgbGreen = v;
- BmiColors[i].rgbBlue = v;
- }
- fwrite(BmiColors, sizeof(RGBquad), N, f2);
- byte *buffer = new byte[map_info.Width];
- int n;
- do {
- n = fread(buffer, sizeof(byte), map_info.Width, f1);
- fwrite(buffer, sizeof(byte), n, f2);
- }while(n == map_info.Width);
- delete [] buffer;
- fclose(f2);
- }else
- cout << "Unsupported image color type" << endl;
- fclose(f1);
- return 0;
- }
Add Comment
Please, Sign In to add comment