-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitMap.cpp
72 lines (60 loc) · 2.32 KB
/
BitMap.cpp
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
//
// Created by Szymek on 06.04.2016.
//
#include "BitMap.h"
static const int bitsOffSet = 54; //Number of bits from beginning of the file to the beginning of the image.
static const int bitsInPixel = 3;
static const char blackColor = '\0';
static const char whiteColor = '\xff';
BitMap::BitMap(){
m_FilePath = NULL;
m_bitmapArray = new double[256];
}
BitMap::BitMap(const char *pathToFile){
m_FilePath = pathToFile;
m_bitmapFile.open(pathToFile, std::ios::in | std::ios::binary);
m_bitmapArray = new double[256];
}
double *BitMap::ProcessingBitmapIntoArrayForNeuralNet(double valueForWhite, double valueForBlack){
m_bitmapFile.seekg(bitsOffSet, std::ios::beg);
int arrayNumberControl = 0;
char onePixel[bitsInPixel];
while(!m_bitmapFile.eof()){
m_bitmapFile.read(onePixel, bitsInPixel);
BlackPixelToNumber(onePixel, valueForBlack, arrayNumberControl);
WhitePixelToNumber(onePixel, valueForWhite, arrayNumberControl);
//m_bitmapFile.seekg(1, std::ios::cur);
arrayNumberControl++;
}
RevertingBitmapArray(arrayNumberControl, 16, 16);
return m_bitmapArray;
}
void BitMap::BlackPixelToNumber(char onePixel[bitsInPixel], double valueForBlack, int arrayNumberControl){
if((onePixel[0] == blackColor) && (onePixel[1] == blackColor) && (onePixel[2] == blackColor))
m_bitmapArray[arrayNumberControl] = valueForBlack;
}
void BitMap::WhitePixelToNumber(char onePixel[bitsInPixel], double valueForWhite, int arrayNumberControl){
if((onePixel[0] == whiteColor) && (onePixel[1] == whiteColor) && (onePixel[2] == whiteColor))
m_bitmapArray[arrayNumberControl] = valueForWhite;
}
void BitMap::RevertingBitmapArray(int arrayNumberControl, int bitmapWidth, int bitmapHeight){
double *temp = new double[256];
int row = bitmapHeight - 1;
int number;
int tempArrayNumberControl = 0;
do{
for(arrayNumberControl = 0; arrayNumberControl < 16; arrayNumberControl++){
number =((row * bitmapWidth) + arrayNumberControl);
temp[tempArrayNumberControl] = m_bitmapArray[number];
tempArrayNumberControl++;
}
row--;
} while(row >= 0);
m_bitmapArray = temp;
for(int i = 0; i < 256; i++)
std::cout << temp[i];
}
BitMap::~BitMap(){
delete[] m_bitmapArray;
m_bitmapFile.close();
}