[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 8c68be6: [graph] Implement much faster vertical
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 8c68be6: [graph] Implement much faster vertical grid lines. |
Date: |
Fri, 15 Jan 2021 23:45:33 -0500 (EST) |
branch: master
commit 8c68be6eec0dd6c6e0aef1dd7e583d39153a1ee1
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[graph] Implement much faster vertical grid lines.
* graph/gbfill.c (gr_fill_hline_*): Accept pitch increment as
additional argument and act accordingly.
(grFillVLine, grFillHLine, grFillRect): Updated all callers.
---
ChangeLog | 14 ++++++--
graph/grfill.c | 110 +++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 91 insertions(+), 33 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a145dd4..b96fb5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,14 @@
+2021-01-15 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [graph] Implement much faster vertical grid lines.
+
+ * graph/gbfill.c (gr_fill_hline_*): Accept pitch increment as
+ additional argument and act accordingly.
+ (grFillVLine, grFillHLine, grFillRect): Updated all callers.
+
2021-01-14 Alexei Podtelezhnikov <apodtele@gmail.com>
- * graph/gblamy.h (*): Blend a bit faster.
+ * graph/gblany.h (*): Blend a bit faster.
2021-01-14 Alexei Podtelezhnikov <apodtele@gmail.com>
@@ -24,8 +32,8 @@
(GDST_PIX, GDST_CHANNEL): New macros to convert color.
(grBlitGlyphToSurface, grSetTargetPenBrush): Pass `grColor' unchanged.
* graph/gblany.h (*): Use new marcos here.
- * graph/gblblit.h (GBlenderBlitFunc): Accept `grColor'.
- * graph/grobjs.h (grSurface): Use `grColor'.
+ * graph/gblblit.h (GBlenderBlitFunc): Accept `grColor'.
+ * graph/grobjs.h (grSurface): Use `grColor'.
2021-01-13 Alexei Podtelezhnikov <apodtele@gmail.com>
diff --git a/graph/grfill.c b/graph/grfill.c
index 2256f5d..7b69b23 100644
--- a/graph/grfill.c
+++ b/graph/grfill.c
@@ -6,17 +6,30 @@ static void
gr_fill_hline_mono( unsigned char* line,
int x,
int width,
+ int incr,
grColor color )
{
- int c1 = (x >> 3);
- int lmask = 0xFF >> (x & 7);
- int c2 = ((x+width-1) >> 3);
- int rmask = 0x7F8 >> ((x+width-1) & 7);
+ int c1, c2, lmask, rmask;
+
+ if ( incr & ~3 ) /* vertical */
+ {
+ c1 = c2 = x >> 3;
+ lmask = rmask = 0x80 >> (x & 7);
+ }
+ else /* horizontal */
+ {
+ c1 = x >> 3;
+ lmask = 0xFF >> (x & 7);
+ c2 = (x+width-1) >> 3;
+ rmask = 0x7F8 >> ((x+width-1) & 7);
+ width = 1;
+ }
if ( color.value != 0 )
{
if ( c1 == c2 )
- line[c1] = (unsigned char)( line[c1] | (lmask & rmask));
+ for ( ; width > 0; width--, line += incr )
+ line[c1] = (unsigned char)( line[c1] | (lmask & rmask));
else
{
line[c1] = (unsigned char)(line[c1] | lmask);
@@ -28,7 +41,8 @@ gr_fill_hline_mono( unsigned char* line,
else
{
if ( c1 == c2 )
- line[c1] = (unsigned char)( line[c1] & ~(lmask & rmask) );
+ for ( ; width > 0; width--, line += incr )
+ line[c1] = (unsigned char)( line[c1] & ~(lmask & rmask) );
else
{
line[c1] = (unsigned char)(line[c1] & ~lmask);
@@ -43,53 +57,80 @@ static void
gr_fill_hline_4( unsigned char* line,
int x,
int width,
+ int incr,
grColor color )
{
int col = color.value | (color.value << 4);
line += (x >> 1);
- if ( x & 1 )
- {
- line[0] = (unsigned char)((line[0] & 0xF0) | (col & 0x0F));
- line++;
- width--;
- }
- for ( ; width >= 2; width -= 2 )
+ if ( incr & ~3 ) /* vertical */
{
- line[0] = (unsigned char)col;
- line++;
+ if ( x & 1 )
+ for ( ; width > 0; width--, line += incr )
+ line[0] = (unsigned char)((line[0] & 0xF0) | (col & 0x0F));
+ else
+ for ( ; width > 0; width--, line += incr )
+ line[0] = (unsigned char)((line[0] & 0x0F) | (col & 0xF0));
}
+ else /* horizontal */
+ {
+ if ( x & 1 )
+ {
+ line[0] = (unsigned char)((line[0] & 0xF0) | (col & 0x0F));
+ line++;
+ width--;
+ }
- if ( width > 0 )
- line[0] = (unsigned char)((line[0] & 0x0F) | (col & 0xF0));
+ for ( ; width >= 2; width -= 2, line ++ )
+ line[0] = (unsigned char)col;
+
+ if ( width > 0 )
+ line[0] = (unsigned char)((line[0] & 0x0F) | (col & 0xF0));
+ }
}
static void
gr_fill_hline_8( unsigned char* line,
int x,
int width,
+ int incr,
grColor color )
{
- memset( line+x, color.value, (size_t)width );
+ line += x;
+
+ if ( incr == 1 )
+ memset( line, color.value, (size_t)width );
+ else
+ {
+ /* there might be some pitch */
+ for ( ; width > 0; width--, line += incr )
+ *line = (unsigned char)color.value;
+ }
}
static void
gr_fill_hline_16( unsigned char* _line,
int x,
int width,
+ int incr,
grColor color )
{
unsigned short* line = (unsigned short*)_line + x;
- for ( ; width > 0; width-- )
- *line++ = (unsigned short)color.value;
+ /* adjust what looks like pitch */
+ if ( incr & ~3 )
+ incr >>= 1;
+
+ for ( ; width > 0; width--, line += incr )
+ *line = (unsigned short)color.value;
}
static void
gr_fill_hline_24( unsigned char* line,
int x,
int width,
+ int incr,
grColor color )
{
int r = color.chroma[0];
@@ -98,11 +139,15 @@ gr_fill_hline_24( unsigned char* line,
line += 3*x;
- if (r == g && g == b)
+ if ( incr == 1 && r == g && g == b )
memset( line, r, (size_t)(width*3) );
else
{
- for ( ; width > 0; width--, line += 3 )
+ /* adjust what does not look like pitch */
+ if ( !( incr & ~3 ) )
+ incr *= 3;
+
+ for ( ; width > 0; width--, line += incr )
{
line[0] = (unsigned char)r;
line[1] = (unsigned char)g;
@@ -115,18 +160,24 @@ static void
gr_fill_hline_32( unsigned char* _line,
int x,
int width,
+ int incr,
grColor color )
{
uint32_t* line = (uint32_t*)_line + x;
- for ( ; width > 0; width-- )
- *line++ = color.value;
-}
+ /* adjust what looks like pitch */
+ if ( incr & ~3 )
+ incr >>= 2;
+ for ( ; width > 0; width--, line += incr )
+ *line = color.value;
+}
+/* these function render vertical lines by passing pitch as increment */
typedef void (*grFillHLineFunc)( unsigned char* line,
int x,
int width,
+ int incr,
grColor color );
static const grFillHLineFunc gr_fill_hline_funcs[gr_pixel_mode_max] =
@@ -173,7 +224,7 @@ grFillHLine( grBitmap* target,
if ( target->pitch < 0 )
line -= target->pitch*(target->rows-1);
- hline_func( line, x, width, color );
+ hline_func( line, x, width, 1, color );
}
extern void
@@ -203,8 +254,7 @@ grFillVLine( grBitmap* target,
if ( target->pitch < 0 )
line -= target->pitch*(target->rows-1);
- for ( ; height > 0; height--, line += target->pitch )
- hline_func( line, x, 1, color );
+ hline_func( line, x, height, target->pitch, color );
}
extern void
@@ -258,7 +308,7 @@ grFillRect( grBitmap* target,
case gr_pixel_mode_rgb565:
case gr_pixel_mode_rgb555:
size += 2;
- hline_func( line, x, width, color );
+ hline_func( line, x, width, 1, color );
for ( line += size * x; --height > 0; line += target->pitch )
memcpy( line + target->pitch, line, (size_t)size * (size_t)width );
break;
@@ -268,7 +318,7 @@ grFillRect( grBitmap* target,
case gr_pixel_mode_pal4:
case gr_pixel_mode_mono:
for ( ; height-- > 0; line += target->pitch )
- hline_func( line, x, width, color );
+ hline_func( line, x, width, 1, color );
break;
default:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 8c68be6: [graph] Implement much faster vertical grid lines.,
Alexei Podtelezhnikov <=