neochrome32
Joined: 09 Jun 2013 Posts: 153
|
Graphics AntiAliasing |
Posted: Tue Oct 01, 2013 5:46 pm |
|
|
Hi guys, i've come up with some sort of attempt at AntiAliasing, doesn't have to be fantastically awesome, but sometime to put pixels int he right place...
the code i have ..
Code: |
void draw_text(unsigned int16 x, unsigned int16 y, char* textptr, unsigned int16 color, int16 fontwidth=5, int8 size=1, int8 thick=1, int1 blockdraw=0, int1 smoothed=0){
int i, j, k; // Loop counters
BYTE pixelData[5]; // Stores character data
//byte pixelDataH[5]; // for data a head to it to look nicer?
int16 l,m;
int1 gap=0;
int16 tx, ty;
int16 sx, sy;
int8 antt;
if(thick!=1) gap=1;
sx=x;
sy=y;
// Loop through the passed string
for(i=0; textptr[i] != '\0'; ++i, ++x){
memcpy(pixelData, text[textptr[i]-32], fontwidth);
//if(x+fontwidth*thick >= GLCD_WIDTH){ // Performs character wrapping
// x = 0; // Set x at far left position
// y += 7 + 1; // Set y at next position down
//}
if(blockdraw==0){
if(smoothed==0){
for(j=0; j<fontwidth+gap; ++j, x+=thick){ // Loop through character byte data
if(j<fontwidth){
for(k=0; k<8; ++k){ // Loop through the vertical pixels
if(bit_test(pixelData[j], k)){ // Check if the pixel should be set
for(l=0; l<size; ++l){
for(m=0; m<thick; ++m){
draw_pixel(x+m, y+k*size+l, color); // Draws the pixel
}
}
}
}
}
}
} else { // we wanna smooth this [censored] out...
for(j=0; j<fontwidth+gap; ++j, x+=thick){ // Loop through character byte data
if(j<fontwidth){
for(k=0; k<8; ++k){ // Loop through the vertical pixels
antt=0;
//round check;/
if(k>0) if(bit_test(pixelData[j], k-1)) antt++; // check above location;
if(j<5) if(bit_test(pixelData[j+1], k)) antt++; // check to the right of location;
if(k<6) if(bit_test(pixelData[j], k+1)) antt++; // check to the bottom of location;
if(j>0) if(bit_test(pixelData[j-1], k)) antt++; // check to the left of location;
if(j<5 && j>0){
if(bit_test(pixelData[j-1], k) && bit_test(pixelData[j+1], k)) antt=0; // check to the right of location;
}
if(antt>1){
// there is a mix of pixels around here,
draw_pixel(x, y+k, clut[6]);
}
if(bit_test(pixelData[j], k)){ // Check if the pixel should be set
// renders top to down, then next column
draw_pixel(x, y+k, color); // Draws the pixel
}
}
}
}
}
//antialias/
} else { // IS BLOCK MODE
//thick=3;
if(thick!=1)
TX = i+(sx+(i*6) * thick) ;
else
TX = (sx+(i*6) * thick) ;
TY = (sy);// * size;
setviewport(tx, ty, tx+((5*thick)-1), ty+((8*size)-1));
for(j=0; j<8; ++j){ // // 8 bits, top to bottom
for(m=0; m<size; m++){
for(k=0; k<5; ++k){ // 5 offsets in RAM :)
for(l=0; l<thick; ++l){ // Repeat wide pits
if(bit_test(pixeldata[k], j)==1){
LCD_WR_DATA(color);
} else {
LCD_WR_DATA(_background_colour);
}
}
}
}
}
}
}
}
|
Sorry for the way my code is written, but im struggling with getting the Antiasing to look right.. as some of the areas are filled in so it looks like the font is a bit bold...
Thanks guys |
|