author | viric <viriketo@gmail.com> |
Sun, 24 Apr 2011 18:47:28 +0200 | |
changeset 2 | 5cdb891abc1e |
parent 0 | 6b8091ca909a |
permissions | -rw-r--r-- |
0 | 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 |
|
2
5cdb891abc1e
Almenys faig que compili amb un g++ -I. -lnetpbm -o rektigi *.cc
viric <viriketo@gmail.com>
parents:
0
diff
changeset
|
13 |
pixels = new char* [height]; |
0 | 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 |
} |