1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
// ConsoleApplication1.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;
struct BITMAPfileHEADER
{
unsigned short bfType;
unsigned int bfSize;
unsigned short bfReserved1;
unsigned short bfReserved2;
unsigned int bfOffBits;
};
struct BITMAPinfoHEADER
{
unsigned int biSize;
unsigned int biWidth;
unsigned int biHeight;
unsigned short biPlanes;
unsigned short biBitCount;
unsigned int biCompression;
unsigned int biSizeImage;
unsigned int biXpelsPerMeter;
unsigned int biYpelsPerMeter;
unsigned int biClrUses;
unsigned int biClrImportant;
};
int readBFH(ifstream &ifs, BITMAPfileHEADER &bfh)
{
ifs.read(reinterpret_cast<char *>(&bfh.bfType), 2);
ifs.read(reinterpret_cast<char *>(&bfh.bfSize), 4);
ifs.read(reinterpret_cast<char *>(&bfh.bfReserved1), 2);
ifs.read(reinterpret_cast<char *>(&bfh.bfReserved2), 2);
ifs.read(reinterpret_cast<char *>(&bfh.bfOffBits), 4);
return ifs.tellg();
}
int readBIH(ifstream &ifs, BITMAPinfoHEADER &bih)
{
ifs.read(reinterpret_cast<char *>(&bih.biSize), 4);
ifs.read(reinterpret_cast<char *>(&bih.biWidth), 4);
ifs.read(reinterpret_cast<char *>(&bih.biHeight), 4);
ifs.read(reinterpret_cast<char *>(&bih.biPlanes), 2);
ifs.read(reinterpret_cast<char *>(&bih.biBitCount), 2);
ifs.read(reinterpret_cast<char *>(&bih.biCompression), 4);
ifs.read(reinterpret_cast<char *>(&bih.biSizeImage), 4);
ifs.read(reinterpret_cast<char *>(&bih.biXpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(&bih.biYpelsPerMeter), 4);
ifs.read(reinterpret_cast<char *>(&bih.biClrUses), 4);
ifs.read(reinterpret_cast<char *>(&bih.biClrImportant), 4);
return ifs.tellg();
}
unsigned char* readPictureData(ifstream &ifs, unsigned int size, int cursor)
{
ifs.seekg(cursor, ios::beg);
unsigned char *picture = new unsigned char[size];
ifs.read(reinterpret_cast<char *>(picture), size);
return picture;
}
int main()
{
BITMAPfileHEADER bfh_warm;
BITMAPfileHEADER bfh_cold;
BITMAPinfoHEADER bih_warm;
BITMAPinfoHEADER bih_cold;
int cursor_warm;
int cursor_cold;
ifstream ifs_warm("1.bmp", ios::binary);
ifstream ifs_cold("2.bmp", ios::binary);
ofstream ofs_differential("differential.bmp", ofstream::binary);
cursor_warm = readBFH(ifs_warm, bfh_warm);
cursor_warm = readBIH(ifs_warm, bih_warm);
cursor_cold = readBFH(ifs_cold, bfh_cold);
cursor_cold = readBIH(ifs_cold, bih_cold);
unsigned char* picture = readPictureData(ifs_warm, bfh_warm.bfSize - bfh_warm.bfOffBits, cursor_warm);
ofs_differential.write((char*)&bfh_warm, 14); //write header
ofs_differential.write((char*)&bih_warm, 40); //write header
// ofs_differential.write((char*)&picture, (bfh_warm.bfSize - bfh_warm.bfOffBits)/3); //THIS DOESNT WORK
ifs_warm.close();
ifs_warm.close();
ofs_differential.close();
return 0;
}
|