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,1,
0,1,1,0
},
{ 0,1,1,1,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0
},
{ 1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,0,0,1,
1,1,1,1
},
{ 1,0,0,1,
1,0,0,1,
1,0,0,1,
0,1,1,0,
0,1,1,0,
0,1,1,0
},
{ 1,0,0,1,
1,0,0,1,
1,0,0,1,
1,1,1,1,
1,1,1,1,
1,0,0,1
},
{ 1,0,0,1,
1,0,0,1,
0,1,1,0,
1,0,0,1,
1,0,0,1,
1,0,0,1
},
{ 1,0,0,1,
1,0,0,1,
0,1,0,0,
0,0,1,0,
0,1,0,0,
1,0,0,0
},
{ 1,1,1,1,
0,0,0,1,
0,0,1,0,
0,1,0,0,
1,0,0,0,
1,1,1,1
},
};
static const char ascii91[6][FONT_WIDTH*FONT_HEIGHT] = {
{ 0,1,1,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,0,0,
0,1,1,0
},
{ 1,0,0,0,
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1,
0,0,0,1
},
{ 0,1,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,0,1,0,
0,1,1,0
},
{ 0,1,0,1,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0
},
{ 0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
1,1,1,1
},
{ 0,1,0,0,
0,0,1,0,
0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0
}
};
#define FONT_ZOOM 2
void IMAGE::draw_num(const int stride, const int height, const char * font, const int x, const int y) {
for(int j = 0; j < FONT_ZOOM * FONT_HEIGHT && y+j < height; j++) {
for(int i = 0; i < FONT_ZOOM * FONT_WIDTH && x+i < stride; i++) {
if(font[(j/FONT_ZOOM)*FONT_WIDTH + (i/FONT_ZOOM)]) {
int offset = (y+j)*stride + (x+i);
int offset2 =((y+j)/2)*(stride/2) + ((x+i)/2);
IMAGE::y[offset] = 255;
IMAGE::u[offset2] = 127;
IMAGE::v[offset2] = 127;
}
}
}
}
void IMAGE::Print(int edged_width, int height, int x, int y, const char *buf) {
int i;
for(i = 0; buf[i]; i++) {
const char * font;
if (buf[i] >= '!' && buf[i] <= '@')
font = ascii33[buf[i]-'!'];
else if (buf[i] >= 'A' && buf[i] <= 'Z')
font = ascii65[buf[i]-'A'];
else if (buf[i] >= '[' && buf[i] <= '`')
font = ascii91[buf[i]-'['];
else if (buf[i] >= 'a' && buf[i] <= 'z')
font = ascii65[buf[i]-'a'];
else
continue;
draw_num(edged_width, height, font, x + i*FONT_ZOOM*(FONT_WIDTH+1), y);
}
}