optimized some functions, saving ~100 byte

This commit is contained in:
Christian Kroll 2011-02-23 10:34:41 +00:00
parent 3a0d8799bd
commit 85b0922e1d
2 changed files with 23 additions and 79 deletions

69
pixel.c
View File

@ -113,6 +113,7 @@ for (y=p1.y;y<(p1.y+h);y++){
#endif /* ANIMATION_HERWEG */
//shifts pixmap left. It is really shifted right, but because col0 is left in the Display it's left.
void shift_pixmap_l(){
unsigned char plane, row, byte;
@ -137,71 +138,3 @@ unsigned char get_pixel(pixel p){
return 0!= (pixmap[0][p.y][p.x/8] & shl_table[p.x%8]);
}
}
unsigned char get_next_pixel(pixel p, direction dir){
pixel tmp;
switch (dir){
case right:
tmp = (pixel){p.x-1, p.y};
break;
case left:
tmp = (pixel){p.x+1, p.y};
break;
case down:
tmp = (pixel){p.x, p.y+1};
break;
case up:
tmp = (pixel){p.x, p.y-1};
break;
default:
tmp = p;
break;
}
return get_pixel(tmp);
}
direction direction_r(direction dir){
switch (dir){
case right:
return(down);
case down:
return(left);
case left:
return(up);
case up:
return (right);
}
return(0);
}
void set_cursor(cursor* cur, pixel p){
cur->pos = p;
switch (cur->mode){
case clear:
clearpixel(p);
break;
case set:
setpixel(p,3);
break;
}
}
pixel next_pixel(pixel pix, direction dir){
switch (dir){
case right:
return((pixel){pix.x-1, pix.y});
break;
case left:
return((pixel){pix.x+1, pix.y});
break;
case down:
return((pixel){pix.x, pix.y+1});
break;
case up:
return((pixel){pix.x, pix.y-1});
break;
}
return (pixel){0,0};
}

33
pixel.h
View File

@ -12,7 +12,7 @@ typedef struct {
} pixel;
typedef enum {right,left,up,down} direction;
typedef enum {up, right, down, left} direction;
typedef struct {
pixel pos;
direction dir;
@ -22,6 +22,23 @@ typedef struct {
/****************************************************************************
* Pixel routines
*/
unsigned char get_pixel(pixel p);
static inline pixel next_pixel(pixel pix, direction dir){
static char const nDelta[] = {0, -1, 0, 1, 0};
return (pixel){pix.x + nDelta[dir], pix.y + nDelta[dir + 1]};
}
static inline unsigned char get_next_pixel(pixel p, direction dir){
return get_pixel(next_pixel(p, dir));
}
static inline direction direction_r(direction dir){
return (dir + 1) % 4;
}
void clear_screen(unsigned char value);
void setpixel(pixel p, unsigned char value);
#define clearpixel(p) setpixel(p, 0);
@ -35,18 +52,12 @@ void line(pixel p1, pixel p2 ,unsigned char value);
void filled_rectangle(pixel p1, unsigned char w, unsigned char h ,unsigned char value);
unsigned char get_pixel(pixel p);
unsigned char get_next_pixel(pixel p, direction dir);
pixel next_pixel(pixel pix, direction dir);
direction direction_r(direction dir);
void shift_pixmap_l();
void set_cursor(cursor* cur, pixel p);
static inline void set_cursor(cursor* cur, pixel p){
cur->pos = p;
setpixel(p, cur->mode ? 3 : 0);
}
#endif // PIXEL_H