equal
deleted
inserted
replaced
|
1 #include "Bitmap.h" |
|
2 #include "Errors.h" |
|
3 #include "Histogram.h" |
|
4 |
|
5 Bitmap::Bitmap(int w, int h) |
|
6 { |
|
7 int i; |
|
8 |
|
9 height = h; |
|
10 width = w; |
|
11 |
|
12 // Assignem memòria |
|
13 pixels = new (char*)[height]; |
|
14 for (i=0; i<height; i++) |
|
15 pixels[i] = new char[width]; |
|
16 // Memòria assignada |
|
17 |
|
18 //PointsPerLine = new vector<int> |
|
19 } |
|
20 |
|
21 Bitmap::~Bitmap() |
|
22 { |
|
23 int i; |
|
24 for (i=0; i<height; i++) |
|
25 delete[] pixels[i]; |
|
26 |
|
27 delete[] pixels; |
|
28 } |
|
29 |
|
30 void Bitmap::setToZero() |
|
31 { |
|
32 int i,j; |
|
33 |
|
34 for (i=0; i<height; i++) |
|
35 for (j=0; j<width; j++) |
|
36 pixels[i][j] = 0; |
|
37 } |
|
38 |
|
39 int Bitmap::points_per_row(int line) |
|
40 { |
|
41 int weight=0; |
|
42 |
|
43 for(int j=0; j<width; j++) |
|
44 if (pixels[line][j]) |
|
45 ++weight; |
|
46 return weight; |
|
47 } |
|
48 |
|
49 void Bitmap::calcHistogram(Histogram* &myhist) |
|
50 { |
|
51 int i,j; |
|
52 |
|
53 myhist = new Histogram(height); |
|
54 |
|
55 for(i=0; i<height; i++) |
|
56 myhist->weights[i] = points_per_row(i); |
|
57 |
|
58 myhist->calcStatistics(); |
|
59 } |