55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
|
#include "Bitmap.h"
|
||
|
#include <fstream>
|
||
|
#include <iostream>
|
||
|
|
||
|
Bitmap::Bitmap() {
|
||
|
offset = 0;
|
||
|
width = 0;
|
||
|
height = 0;
|
||
|
bpp = 0;
|
||
|
data = nullptr;
|
||
|
}
|
||
|
|
||
|
Bitmap::~Bitmap() {
|
||
|
if(data){
|
||
|
delete data;
|
||
|
data = nullptr;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Bitmap::load(const std::string &file) {
|
||
|
std::ifstream stream(file);
|
||
|
if(stream.is_open()){
|
||
|
std::string str((std::istreambuf_iterator<char>(stream)),std::istreambuf_iterator<char>());
|
||
|
data = new char[str.size()];
|
||
|
for(int i = 0; i < str.size();i++){
|
||
|
data[i] = str[i];
|
||
|
}
|
||
|
|
||
|
offset = *(unsigned int*)(data + 10);
|
||
|
width = *(unsigned int*)(data + 18);
|
||
|
height = *(unsigned int*)(data + 22);
|
||
|
bpp = *(unsigned short*)(data + 28);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int Bitmap::getWidth() {
|
||
|
return width;
|
||
|
}
|
||
|
|
||
|
int Bitmap::getHeight() {
|
||
|
return height;
|
||
|
}
|
||
|
|
||
|
char *Bitmap::getData() {
|
||
|
return data + offset;
|
||
|
}
|
||
|
|
||
|
int Bitmap::getBitsPerPixel() {
|
||
|
return bpp;
|
||
|
}
|
||
|
|
||
|
char *Bitmap::getPixel(int x, int y) {
|
||
|
return getData() + ((getHeight() - y) * getWidth() + x) * getBitsPerPixel() / 8;
|
||
|
}
|