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");
- FILE *f2 = fopen("pigvin256q.bmp", "wb");
- fread(&file_header, sizeof(file_header), 1, f1);
- fwrite(&file_header, sizeof(file_header), 1, f2);
- 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;
- int width = map_info.Width;
- int height = map_info.Height;
- map_info.Height = map_info.Width;
- map_info.Width = height;
- fwrite(&map_info, sizeof(map_info), 1, f2);
- int border, padding = 0;
- if(map_info.BitCount == 8 || map_info.BitCount == 4) {
- int N = map_info.ClrUsed;
- RGBquad BmiColors[N];
- fread(BmiColors, sizeof(RGBquad), N, f1);
- fwrite(BmiColors, sizeof(RGBquad), N, f2);
- border = 1;
- }else if(map_info.BitCount == 16)
- border = 2;
- else if(map_info.BitCount == 24)
- border = 3;
- else
- cout << "Unsupported image color type" << endl;
- width *= border;
- if(width % 4)
- padding = 4 - (width % 4);
- byte **buffer = new byte*[height];
- for(int i = 0; i < height; i++) {
- buffer[i] = new byte[width];
- fread(buffer[i], 1, width, f1);
- if(padding != 0)
- fseek(f1, padding, SEEK_CUR);
- }
- padding = 0;
- if((height * 3) % 4)
- padding = 4 - (height * 3) % 4;
- int b = 0;
- for(int j = width - 1; j >= 0; j--) {
- for(int i = 0; i < height; i++)
- fwrite(&buffer[i][j], 1, 1, f2);
- //if(j < height)
- if(padding != 0) {
- fwrite(&b, padding, 1, f2);
- }
- }
- for(int i = 0; i < height; i++)
- delete [] buffer[i];
- delete [] buffer;
- fclose(f1);
- fclose(f2);
- return 0;
- }
Add Comment
Please, Sign In to add comment