21 int pos(
int x,
int y) {
23 if (x>=width) x=width-1;
25 if (y>=height) y=height-1;
26 return ((height-y-1)*width +x);
35 return data[
pos(x, y)];
43 for (
int i=0; i<size; ++i) {
60 void init(
int pwidth,
int pheight) {
63 data =
new Color[width*height];
66 void read(
const char * filename) {
67 FILE* f = fopen(filename,
"rb");
72 fread(info,
sizeof(
BMP_byte), 54, f);
74 width = *( (
int*) &info[18]);
75 height = *( (
int*) &info[22]);
76 int psize = *( (
int*) &info[34]);
78 data =
new Color[width*height];
80 row_padded = (psize/height);
86 for(
int y = height-1; y >= 0; --y) {
87 fread(row,
sizeof(
BMP_byte), row_padded, f);
88 for(
int x = 0; x < width; ++x) {
90 G(x, y) = row[(3*x)+1];
91 R(x, y) = row[(3*x)+2];
97 void write(
const char * filename) {
98 FILE* f = fopen(filename,
"wb");
100 'B',
'M', 0,0,0,0, 0,0, 0,0, 54,0,0,0,
101 40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0,
104 int xbytes = 4 - ((width * 3) % 4);
105 if (xbytes == 4) xbytes = 0;
106 int psize = ((width * 3) + xbytes) * height;
108 *( (
int*) &info[2]) = 54 + psize;
109 *( (
int*) &info[18]) = width;
110 *( (
int*) &info[22]) = height;
111 *( (
int*) &info[34]) = psize;
113 fwrite(info,
sizeof(
BMP_byte),
sizeof(info), f);
116 for (y=height-1; y>=0; --y) {
117 for (x=0; x<width; ++x) {
118 fprintf(f,
"%c", B(x, y));
119 fprintf(f,
"%c", G(x, y));
120 fprintf(f,
"%c", R(x, y));
124 for (n = 0; n < xbytes; ++n) fprintf(f,
"%c", 0);
unsigned char BMP_byte
Definition: Bmp.hpp:9
double pos
Definition: osm2graph_bitmap.cpp:125
void read(const char *filename)
Definition: Bmp.hpp:66
void init(int pwidth, int pheight)
Definition: Bmp.hpp:60
Color & get(int x, int y)
Definition: Bmp.hpp:34
BMP_byte & B(int x, int y)
Definition: Bmp.hpp:48
void copy(const Bmp &src)
Definition: Bmp.hpp:38
Color * data
Definition: Bmp.hpp:30
void write(const char *filename)
Definition: Bmp.hpp:97
BMP_byte & R(int x, int y)
Definition: Bmp.hpp:56
int height
Definition: Bmp.hpp:32
BMP_byte & G(int x, int y)
Definition: Bmp.hpp:51
int width
Definition: Bmp.hpp:31
int pos(int x, int y)
Definition: Bmp.hpp:21
BMP_byte blue
Definition: Bmp.hpp:12
BMP_byte red
Definition: Bmp.hpp:14
BMP_byte green
Definition: Bmp.hpp:13