draw.c File Reference

Buffered graphics routines. More...

Include dependency graph for draw.c:

Defines

#define FONT_FIRST_CHAR   32
#define FONT_HEIGHT   7
#define FONT_LAST_CHAR   127

Functions

void draw_bitmap (uns8 x, uns8 y, uns8 colour, char *bitmap)
void draw_circle (int x_centre, int y_centre, int r, uns8 colour)
void draw_circle2 (int x_centre, int y_centre, int r, uns8 colour)
void draw_circle_lines (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour)
void draw_circle_points (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour)
void draw_circle_points2 (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour)
void draw_clear_screen ()
void draw_filled_circle (int x_centre, int y_centre, int r, uns8 colour)
uns8 draw_get_pixel (uns8 x, uns8 y)
void draw_init ()
uns16 draw_length_str (char *str)
void draw_line (uns8 x0, uns8 y0, uns8 x1, uns8 y1, uns8 colour)
void draw_print_buffer ()
void draw_print_str (uns8 x, uns8 y, uns8 width, uns8 start_pixel, uns8 colour, char *str)
void draw_rect (uns8 x, uns8 y, uns16 width, uns8 height, uns8 colour)
void draw_set_pixel (uns8 x, uns8 y, uns8 colour)
void draw_setup_io ()

Variables

rom char PicPack5x7_bitmap_0 [1]
rom char PicPack5x7_bitmap_1 [1]
uns16 PicPack5x7_index [1]

Detailed Description


Define Documentation

#define FONT_FIRST_CHAR   32
#define FONT_HEIGHT   7
#define FONT_LAST_CHAR   127

Function Documentation

void draw_bitmap ( uns8  x,
uns8  y,
uns8  colour,
char *  bitmap 
)

00593                                                             {
00594 
00595 
00596 uns8 bitpos = 0;
00597 uns8 bytepos = 0;
00598 uns8 value;
00599 uns8 bitmap_width = bitmap[0];
00600 uns8 bitmap_height = bitmap[1];
00601 uns8 bitmap_bpp = bitmap[2];
00602 uns8 xbitmap, ybitmap;
00603 
00604 
00605     bytepos = 3;    // first byte of data - 1
00606     bitpos = 0b10000000;    // left most bit
00607     
00608     for (xbitmap = 0; xbitmap < bitmap_width; xbitmap++) {
00609         for (ybitmap = 0; ybitmap < bitmap_height; ybitmap++) {
00610             if (bitpos == 0b10000000) {
00611                 bitpos = 0b00000001;
00612                 bytepos++;
00613                 value = bitmap[bytepos];
00614             } else {
00615                 bitpos = bitpos << 1;
00616             }
00617             if (value & bitpos) {
00618                 #if DRAW_HW_Y_ORIGIN == TOP_LEFT
00619                     draw_set_pixel(x + xbitmap, y + ybitmap, colour);
00620                 #else
00621                     draw_set_pixel(x + xbitmap, y - ybitmap, colour);
00622                 #endif
00623             }
00624         }   
00625     }   
00626 }    

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_circle ( int  x_centre,
int  y_centre,
int  r,
uns8  colour 
)

00392                                                                  {
00393     int x,y;
00394     int p = 1 - r;         // Initial value of decision parameter.
00395 
00396     x = 0;
00397     y = r;
00398     
00399     draw_circle_points(x_centre, y_centre, x, y, 2);
00400 
00401     while (x < y) {
00402         x++;
00403         if (p < 0)
00404             p += 2 * x + 1;
00405         else {
00406             y--;
00407             p += 2 * (x - y + 1);
00408         }
00409         draw_circle_points (x_centre, y_centre, x, y, colour);
00410     }
00411 
00412 }

Here is the call graph for this function:

void draw_circle2 ( int  x_centre,
int  y_centre,
int  r,
uns8  colour 
)

00428                                                                   {
00429     int x, y;
00430     //int p = 1 - r; // orig
00431     //int p = 3 - 2*r;         // (a) Initial value of decision parameter.
00432     //int p = 1-r; // (b)
00433     int p = 1 -r; // (c) 5//4 - r  
00434     x = 0;
00435     y = r;
00436     
00437     draw_circle_points2(x_centre, y_centre, x, y, colour);
00438 
00439     while (x < y) {
00440         x++;
00441         if (p < 0)
00442             //p += 2 * x + 2; // (orig)
00443             //p = p + (4 * x) + 6; // (a)
00444             //p = p + 2* x + 3; // (b)
00445             p = p + 2* x + 1; // (c)
00446         else {
00447             y--;
00448             //p += 2 * (x - y + 1); // (orig)
00449             // p = p + 4 * (x - y) + 10; // (a)
00450             //p = p + 2 * (x - y) + 5;
00451             p = p + 2*(x-y) + 1;
00452         }
00453         draw_circle_points2 (x_centre, y_centre, x, y, colour);
00454     }
00455 
00456 }

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_circle_lines ( int  ctr_x,
int  ctr_y,
int  pt_x,
int  pt_y,
uns8  colour 
)

00347                                                                                {
00348     draw_line(ctr_x - pt_x, ctr_y + pt_y, ctr_x + pt_x, ctr_y + pt_y, colour);
00349     draw_line(ctr_x - pt_x, ctr_y - pt_y, ctr_x + pt_x, ctr_y - pt_y, colour);
00350     draw_line(ctr_x + pt_y, ctr_y + pt_x, ctr_x - pt_y, ctr_y + pt_x, colour);
00351     draw_line(ctr_x + pt_y, ctr_y - pt_x, ctr_x - pt_y, ctr_y - pt_x, colour);
00352 }

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_circle_points ( int  ctr_x,
int  ctr_y,
int  pt_x,
int  pt_y,
uns8  colour 
)

00377                                                                                 {
00378     // the eight symmetric points
00379     draw_set_pixel (ctr_x + pt_x, ctr_y + pt_y, colour);
00380     draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y, colour);
00381 
00382     draw_set_pixel (ctr_x + pt_x, ctr_y - pt_y, colour);
00383     draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00384     
00385     draw_set_pixel (ctr_x + pt_y, ctr_y + pt_x, colour);
00386     draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x, colour);
00387     
00388     draw_set_pixel (ctr_x + pt_y, ctr_y - pt_x, colour);
00389     draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00390 }

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_circle_points2 ( int  ctr_x,
int  ctr_y,
int  pt_x,
int  pt_y,
uns8  colour 
)

00413                                                                                  {
00414     // the eight symmetric points
00415     draw_set_pixel (ctr_x + pt_x + 1, ctr_y + pt_y +1, colour);
00416     draw_set_pixel (ctr_x + pt_y + 1, ctr_y + pt_x +1, colour);
00417 
00418     draw_set_pixel (ctr_x + pt_x + 1, ctr_y - pt_y, colour);
00419     draw_set_pixel (ctr_x + pt_y + 1, ctr_y - pt_x, colour);
00420 
00421     draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00422     draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00423 
00424     draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y +1, colour);
00425     draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x +1, colour);
00426     
00427 }

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_clear_screen (  ) 

00049                          {
00050 
00051 uns8 count;
00052     #if DRAW_TOTAL_BUFFER_SIZE == 1024 | DRAW_TOTAL_BUFFER_SIZE == 768 | DRAW_TOTAL_BUFFER_SIZE == 512 | DRAW_TOTAL_BUFFER_SIZE == 256
00053         count = 0;
00054         do {
00055             draw_buffer0[count] = 0;
00056             #if DRAW_TOTAL_BUFFER_SIZE > 256
00057                 draw_buffer1[count] = 0;
00058                 #if DRAW_TOTAL_BUFFER_SIZE > 512
00059                     draw_buffer2[count] = 0;
00060                     #if DRAW_TOTAL_BUFFER_SIZE > 768
00061                         draw_buffer3[count] = 0;
00062                     #endif
00063                 #endif
00064             #endif
00065             count++;
00066         } while (count != 0);
00067     #else
00068         #if DRAW_TOTAL_BUFFER_SIZE < 256
00069             count = 0;
00070             do {
00071                 draw_buffer0[count] = 0;
00072                 count++;
00073             } while (count < DRAW_TOTAL_BUFFER_SIZE);
00074         #else
00075             count = 0;
00076             do {
00077                 draw_buffer0[count] = 0;
00078                 count++;
00079             } while (count != 0);
00080             #if DRAW_TOTAL_BUFFER_SIZE < 512
00081                 do {
00082                     draw_buffer1[count] = 0;
00083                     count++;
00084                 } while (count < DRAW_TOTAL_BUFFER_SIZE - 256);
00085             #else
00086                 do {
00087                     draw_buffer1[count] = 0;
00088                     count++;
00089                 } while (count != 0);
00090                 #if DRAW_TOTAL_BUFFER_SIZE > 512
00091                     #if DRAW_TOTAL_BUFFER_SIZE < 768
00092                         do {
00093                             draw_buffer2[count] = 0;
00094                             count++;
00095                         } while (count < DRAW_TOTAL_BUFFER_SIZE - 512);
00096                     #else
00097                         // > 768
00098                         do {
00099                             draw_buffer2[count] = 0;
00100                             count++;
00101                         } while (count != 0);
00102                         
00103                         #if DRAW_TOTAL_BUFFER_SIZE < 1024
00104                             do {
00105                                 draw_buffer3[count] = 0;
00106                                 count++;
00107                             } while (count < DRAW_TOTAL_BUFFER_SIZE - 768);
00108                         #else
00109                             do {
00110                                 draw_buffer3[count] = 0;
00111                                 count++;
00112                             } while (count != 0);
00113                         #endif
00114                     #endif  
00115                 #endif
00116                 
00117             #endif      
00118             
00119         #endif
00120     #endif
00121 
00122 }

Here is the caller graph for this function:

void draw_filled_circle ( int  x_centre,
int  y_centre,
int  r,
uns8  colour 
)

00354                                                                         {
00355     int x,y;
00356     int p = 1 - r;         // Initial value of decision parameter.
00357 
00358     x = 0;
00359     y = r;
00360     
00361     draw_circle_lines(x_centre, y_centre, x, y, colour);
00362     
00363     while (x < y) {
00364         x++;
00365         if (p < 0)
00366             p += 2 * x + 1;
00367         else {
00368             y--;
00369             p += 2 * (x - y) + 1;
00370         }
00371         draw_circle_lines (x_centre, y_centre, x, y, colour);
00372     }
00373 
00374 }

Here is the call graph for this function:

uns8 draw_get_pixel ( uns8  x,
uns8  y 
)

00248                                     {
00249     return 0;
00250 }   

void draw_init (  ) 

00128                  {
00129     drv_init();
00130     draw_clear_screen();
00131 }   

Here is the call graph for this function:

uns16 draw_length_str ( char *  str  ) 

00516                                  {
00517 uns8 my_char;
00518 uns16 length;
00519 
00520     length = 0;
00521     while (*str != 0) {
00522         my_char = *str;
00523         my_char = my_char - 32;
00524         length = length + (PicPack5x7_index[my_char + 1] - PicPack5x7_index[my_char]) + 1;
00525         str++;
00526     }
00527     length = length - 1;    // no space at the end
00528     return length;
00529 }   

void draw_line ( uns8  x0,
uns8  y0,
uns8  x1,
uns8  y1,
uns8  colour 
)

00309                                                                 {
00310 
00311     int dy = y1 - y0;
00312     int dx = x1 - x0;
00313     int stepx, stepy;
00314 
00315     if (dy < 0) { dy = -dy;  stepy = -1; } else { stepy = 1; }
00316     if (dx < 0) { dx = -dx;  stepx = -1; } else { stepx = 1; }
00317     dy <<= 1;                                                  // dy is now 2*dy
00318     dx <<= 1;                                                  // dx is now 2*dx
00319 
00320     draw_set_pixel(x0, y0, colour);
00321     if (dx > dy) {
00322         int fraction = dy - (dx >> 1);                         // same as 2*dy - dx
00323         while (x0 != x1) {
00324             if (fraction >= 0) {
00325                 y0 += stepy;
00326                 fraction -= dx;                                // same as fraction -= 2*dx
00327             }
00328             x0 += stepx;
00329             fraction += dy;                                    // same as fraction -= 2*dy
00330             draw_set_pixel(x0, y0, colour);
00331         }
00332     } else {
00333         int fraction = dx - (dy >> 1);
00334         while (y0 != y1) {
00335             if (fraction >= 0) {
00336                 x0 += stepx;
00337                 fraction -= dy;
00338             }
00339             y0 += stepy;
00340             fraction += dx;
00341             draw_set_pixel(x0, y0, colour);
00342         }
00343     }
00344 }

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_print_buffer (  ) 

00268                          {
00269 #ifdef DRAW_DEBUG
00270 uns8    inv_y, x , y,
00271          byte_loc, bit_loc;
00272 uns16    buffer_loc;
00273 
00274     for(y = 0 ; y < DRAW_PIXELS_HIGH ; y++) {
00275         inv_y = DRAW_PIXELS_HIGH - 1 - y; // need to print out from the top
00276         if (inv_y < 10) {
00277             serial_putc('0');
00278         }
00279         serial_print_int(inv_y);
00280         serial_putc(' ');
00281         serial_print_int_hex(inv_y * DRAW_PIXELS_WIDE / DRAW_PIXELS_PER_BYTE);
00282         serial_putc('|');
00283         for(x = 0 ; x < DRAW_PIXELS_WIDE  ; x++) {
00284             buffer_loc = inv_y * DRAW_PIXELS_WIDE + x;
00285             byte_loc = buffer_loc / DRAW_PIXELS_PER_BYTE;
00286             bit_loc = buffer_loc & (DRAW_PIXELS_PER_BYTE -1);
00287 
00288             //if (bit_loc == 0) {
00289             //  serial_putc(' ');
00290             //  serial_print_int_hex(byte_loc);
00291             //  serial_putc(' ');
00292             //} 
00293             
00294             if (test_bit(draw_buffer0[byte_loc], bit_loc)) {
00295                 
00296                     serial_putc('1');
00297                     
00298             } else {
00299                 serial_putc('0');
00300             }
00301         }
00302         
00303         serial_print_str("|\n");
00304         
00305     }
00306 #endif  
00307 }           

Here is the call graph for this function:

void draw_print_str ( uns8  x,
uns8  y,
uns8  width,
uns8  start_pixel,
uns8  colour,
char *  str 
)

00531                                                                                           {
00532 
00533 uns8 my_char;
00534 uns16 index_pos;
00535 uns16 index_pos_next;
00536 uns16 count, s_count;
00537 uns8 sliver, x_origin, y_origin, pixel;
00538     y_origin = y;
00539     x_origin = x;
00540     pixel = 0;
00541     while (*str != 0) {
00542         // first look up character in index
00543         my_char = *str;
00544         my_char = my_char - 32;
00545 
00546 
00547         index_pos = PicPack5x7_index[my_char];
00548         index_pos_next = PicPack5x7_index[my_char + 1];
00549             for(count = index_pos ; count < index_pos_next ; count++) {
00550                 if (count < 256) {
00551                     sliver = PicPack5x7_bitmap_0[count];
00552                 } else {
00553                     sliver = PicPack5x7_bitmap_1[count-256];
00554                 }
00555                 // Now iterate over sliver
00556                 if (pixel >= start_pixel) {
00557                     s_count = 0;
00558                     while (s_count < 7) {
00559                         if (test_bit(sliver, 6)) {
00560                             #if DRAW_HW_Y_ORIGIN == BOTTOM_LEFT
00561                                 draw_set_pixel(x, y + s_count, colour);
00562                             #else
00563                             // DRAW_HW_Y_ORIGIN == TOP_LEFT
00564                                 draw_set_pixel(x, y - s_count, colour);
00565                             #endif
00566                         }   
00567                         sliver <<= 1;
00568                         s_count++;
00569                     }
00570                     x++;
00571                 }
00572                 if (x - x_origin == width) {
00573                     return;
00574                 }   
00575                 pixel++;    
00576                 // Need to add a bit here to only
00577                 // increment to new line when we have got to height chars
00578                 
00579             }       
00580         str++;
00581         if (pixel >= start_pixel) {
00582             x++;
00583         }
00584         pixel++;
00585             
00586         if (x - x_origin == width) {
00587             return;
00588         }   
00589     }
00590 }    

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_rect ( uns8  x,
uns8  y,
uns16  width,
uns8  height,
uns8  colour 
)

00253                                                                       {
00254 uns16 dx, dy;
00255 
00256     for(dy = y ; dy < y + height ; dy++) {
00257         for(dx = x ; dx < x + width ; dx++) {
00258             draw_set_pixel(dx, dy, colour);
00259 /*          serial_print_str("P:");
00260             serial_print_int(dx);
00261             serial_print_str(",");
00262             serial_print_int(dy);
00263             serial_print_nl();
00264 */      }
00265     }   
00266 }   

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_set_pixel ( uns8  x,
uns8  y,
uns8  colour 
)

00135                                                  {
00136 
00137 uns8 *buffer;
00138 uns16 buffer_loc, loc_byte;
00139 uns8  loc_bit, loc_in_buffer, buffer_num;
00140 uns8  bit_count;
00141     // inverse here
00142     // y = DRAW_PIXELS_HIGH - 1 - y;
00143     
00144     #if DRAW_HW_Y_ORIGIN == TOP_LEFT
00145         #if DRAW_HW_BUFFER_ORIENTATION == HORIZONTAL
00146             buffer_loc = y * DRAW_PIXELS_WIDE + x;
00147         #else
00148         // DRAW_HW_BUFFER_ORIENTATION == VERTICAL
00149             buffer_loc = x * DRAW_PIXELS_HIGH + y;
00150         #endif
00151     #else
00152     // DRAW_HW_Y_ORIENTATION == BOTTOM_LEFT
00153         #if DRAW_HW_BUFFER_ORIENTATION == HORIZONTAL
00154             buffer_loc = y * DRAW_PIXELS_WIDE + x;
00155         #else
00156         // DRAW_HW_BUFFER_ORIENTATION == VERTICAL
00157             buffer_loc = x * DRAW_PIXELS_HIGH + y;
00158         #endif
00159     #endif
00160 /*    serial_print_int(x);
00161     serial_putc(' ');
00162     serial_print_int(y);
00163     serial_print_nl();
00164     
00165     serial_print_str("->");
00166     serial_print_int(buffer_loc);
00167 */
00168     
00169     buffer_loc = buffer_loc * DRAW_BITS_PER_PIXEL;           
00170 //  loc_byte = buffer_loc / DRAW_PIXELS_PER_BYTE;
00171     loc_byte = buffer_loc / 8;
00172     loc_bit = (buffer_loc & (0x07));
00173     
00174 /*byte  0        1        2   
00175 bit     0 2 4 6  0 2 4 6  0 2 4 6
00176 pix     0 1 2 3  4 5 6 7  8 9 a b 
00177 bit pos 0 2 4 6  8 a c e
00178 */
00179     loc_in_buffer = loc_byte & 0xff;
00180     buffer_num = loc_byte >> 8;
00181     
00182     /* 
00183     // For debugging
00184     serial_print_str(" x=");
00185     serial_print_int(x);
00186     serial_print_str(" y=");
00187     serial_print_int(y);
00188     serial_print_str(" buffer_loc=");
00189     serial_print_int(buffer_loc);
00190     serial_print_str(" loc_byte=");
00191     serial_print_int(loc_byte);
00192     serial_print_str(" loc_bit=");
00193     serial_print_int(loc_bit); 
00194     serial_print_str(" LIB=");
00195     serial_print_int(loc_in_buffer);
00196     serial_print_nl();
00197     serial_print_str(" bnum=");
00198     serial_print_int(buffer_num);
00199     serial_print_str("\n");
00200     */
00201     if (buffer_num == 0) {
00202         buffer = &draw_buffer0;
00203     }
00204     #if DRAW_TOTAL_BUFFER_SIZE > 256
00205     
00206     else if (buffer_num == 1) {
00207         buffer = &draw_buffer1;
00208 
00209     }
00210         #if DRAW_TOTAL_BUFFER_SIZE > 512
00211         else if (buffer_num == 2) {
00212             buffer = &draw_buffer2;
00213 
00214         }
00215             #if DRAW_TOTAL_BUFFER_SIZE > 768
00216             else if (buffer_num == 3) {
00217             buffer = &draw_buffer3;
00218 
00219             }
00220             #endif
00221         #endif
00222     #endif
00223     #if DRAW_BITS_PER_PIXEL > 1
00224     
00225         bit_count = 0;
00226     
00227         while (bit_count < DRAW_BITS_PER_PIXEL) {
00228             if (test_bit(colour, bit_count)) {
00229                 set_bit(buffer[loc_in_buffer], loc_bit);
00230             } else {
00231                 clear_bit(buffer[loc_in_buffer], loc_bit);
00232             }
00233             bit_count++;
00234             loc_bit++;
00235         }
00236     #else
00237     
00238         if (colour) {
00239             set_bit(buffer[loc_in_buffer], loc_bit);
00240         } else {
00241             clear_bit(buffer[loc_in_buffer], loc_bit);
00242         }   
00243     #endif  
00244 
00245 }

Here is the caller graph for this function:

void draw_setup_io (  ) 

00124                      {
00125     drv_setup_io();
00126 }

Here is the call graph for this function:


Variable Documentation

rom char PicPack5x7_bitmap_0[1]
rom char PicPack5x7_bitmap_1[1]
uns16 PicPack5x7_index[1]

Generated on Fri Aug 19 09:04:47 2011 for Pic Pack Library by  doxygen 1.6.1