Skip to content

Commit

Permalink
hvline optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Oct 27, 2015
1 parent a6d9027 commit 6191ca9
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 10 deletions.
2 changes: 1 addition & 1 deletion u8g2/csrc/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/*
The following macro enames the HVLine speed optimization.
It will consume about 300 bytes more in flash memory of the AVR.
It will consume about 30 bytes more in flash memory of the AVR.
*/
#define U8G2_HVLINE_SPEED_OPTIMIZATION

Expand Down
103 changes: 94 additions & 9 deletions u8g2/csrc/u8g2_hvline.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
#include "u8g2.h"
#include <assert.h>

#ifdef U8G2_HVLINE_SPEED_OPTIMIZATION


#ifdef _REALY_FAST_VERSION
static uint8_t *u8g2_get_buffer_ptr(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y) U8G2_NOINLINE;
static uint8_t *u8g2_get_buffer_ptr(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
{
Expand Down Expand Up @@ -202,33 +200,119 @@ static void u8g2_unsafe_draw_hv_line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
}
}

#endif /* really fast version */

#ifdef U8G2_HVLINE_SPEED_OPTIMIZATION

/*
x,y Upper left position of the line within the local buffer (not the display!)
len length of the line in pixel, len must not be 0
dir 0: horizontal line (left to right)
1: vertical line (top to bottom)
asumption:
all clipping done
*/
static void u8g2_unsafe_draw_hv_line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
{
uint16_t offset;
uint8_t *ptr;
uint8_t bit_pos, mask;

//assert(x >= u8g2->buf_x0);
assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
//assert(y >= u8g2->buf_y0);
assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);

/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
bit_pos = y; /* overflow truncate is ok here... */
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
mask = 1;
mask <<= bit_pos;

offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
offset &= ~7;
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
ptr = u8g2->tile_buf_ptr;
ptr += offset;
ptr += x;

if ( dir == 0 )
{
do
{
if ( u8g2->draw_color != 0 )
{
*ptr |= mask;
}
else
{
*ptr &= ~mask;
}
ptr++;
len--;
} while( len != 0 );
}
else
{
do
{
if ( u8g2->draw_color != 0 )
{
*ptr |= mask;
}
else
{
*ptr &= ~mask;
}

bit_pos++;
bit_pos &= 7;
if ( bit_pos == 0 )
{
ptr+=u8g2->width;
mask = 1;
}
else
{
mask <<= 1;
}
len--;
} while( len != 0 );
}
}



#else /* U8G2_HVLINE_SPEED_OPTIMIZATION */

/*
x,y position within the buffer
*/
static void u8g2_draw_pixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
{
uint16_t offset;
uint8_t *ptr;
uint8_t bit_pos, mask;
uint16_t offset;


//assert(x >= u8g2->buf_x0);
assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
//assert(y >= u8g2->buf_y0);
assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);

ptr = u8g2->tile_buf_ptr;
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
bit_pos = y; /* overflow truncate is ok here... */
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
y &= ~7; /* zero the lowest 3 bits, y is tile-row * 8 from now on */
mask = 1;
mask <<= bit_pos;

offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
offset &= ~7;
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
ptr = u8g2->tile_buf_ptr;
ptr += offset;
ptr += x;
mask = 1;
mask <<= bit_pos;


if ( u8g2->draw_color != 0 )
{
*ptr |= mask;
Expand Down Expand Up @@ -271,6 +355,7 @@ static void u8g2_unsafe_draw_hv_line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y,
}



#endif /* U8G2_HVLINE_SPEED_OPTIMIZATION */


Expand Down

0 comments on commit 6191ca9

Please sign in to comment.