CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Graphics AntiAliasing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

Graphics AntiAliasing
PostPosted: Tue Oct 01, 2013 5:46 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group