Browse Source

render: add one-parameter dvline() and dhline()

Behave like Basic's Horizontal and Vertical commands. Internal dline()
optimizations are renamed gint_dhline() and gint_dvline().

Also supports ghline() and gvline() in the gray engine.

Optimization cases here are amost negligible due to limiting RAM access
frequencies and the very limited amount of work accomplished in the
functions. Code maintainability is prioritized by using dline().
compat
Lephe 1 month ago
parent
commit
ef0e5e32f8
Signed by: Lephe <sebastien.michelland@protonmail.com> GPG Key ID: 1BBA026E13FC0495

+ 4
- 4
include/display/common.h View File

@@ -7,15 +7,15 @@

#include <gint/display.h>

/* dhline() - optimized drawing of a horizontal line
/* gint_dhline(): Optimized horizontal line
@x1 @x2 @y Coordinates of endpoints of line (both included)
@color Any color suitable for dline() */
void dhline(int x1, int x2, int y, color_t color);
void gint_dhline(int x1, int x2, int y, color_t color);

/* dvline() - optimized drawing of a vertical line
/* gint_dvline(): Optimized vertical line
@y1 @y2 @x Coordinates of endpoints of line (both included)
@color Any color suitable for dline() */
void dvline(int y1, int y2, int x, color_t color);
void gint_dvline(int y1, int y2, int x, color_t color);

//---
// Font rendering (topti)

+ 18
- 0
include/gint/display.h View File

@@ -95,6 +95,24 @@ void dpixel(int x, int y, color_t color);
fxcg50: Any R5G6B5 color */
void dline(int x1, int y1, int x2, int y2, color_t color);

/* dhline(): Full-width horizontal line
This function draws a horizontal line from the left end of the screen to the
right end, much like the Basic command "Horizontal".

@y Line number
@color fx9860g: white, black, none, invert
fxcg50: Any R5G6B5 color */
void dhline(int y, color_t color);

/* dvline(): Full-height vertical line
This function draws a vertical line from the top end of the screen to the
bottom end, much like the Basic command "Vertical".

@x Column number
@color fx9860g: white, black, none, invert
fxcg50: Any R5G6B5 color */
void dvline(int x, color_t color);

//---
// Text rendering (topti)
//---

+ 10
- 0
include/gint/gray.h View File

@@ -130,6 +130,16 @@ void gpixel(int x, int y, color_t color);
@color white, light, dark, black, none, invert, lighten, darken */
void gline(int x1, int y1, int x2, int y2, color_t color);

/* ghline(): Full-width horizontal line
@y Line number
@color white, light, dark, black, none, invert, lighten, darken */
void ghline(int y, color_t color);

/* gvline(): Full-height vertical line
@x Column number
@color white, light, dark, black, none, invert, lighten, darken */
void gvline(int x, color_t color);

//---
// Text rendering
//---

+ 7
- 0
src/gray/ghline.c View File

@@ -0,0 +1,7 @@
#include <gint/gray.h>

/* ghline(): Full-width horizontal line */
void ghline(int y, color_t color)
{
gline(0, y, 127, y, color);
}

+ 7
- 0
src/gray/gvline.c View File

@@ -0,0 +1,7 @@
#include <gint/gray.h>

/* gvline(): Full-height vertical line */
void gvline(int x, color_t color)
{
gline(x, 0, x, 63, color);
}

+ 7
- 0
src/render-cg/dhline.c View File

@@ -0,0 +1,7 @@
#include <gint/display.h>

/* dhline(): Full-width horizontal line */
void dhline(int y, color_t color)
{
dline(0, y, 395, y, color);
}

+ 4
- 4
src/render-cg/dline.c View File

@@ -2,8 +2,8 @@
#include <gint/display.h>
#include <gint/defs/util.h>

/* dhline() - optimized drawing of a horizontal line */
void dhline(int x1, int x2, int y, uint16_t color)
/* gint_dhline(): Optimized horizontal line */
void gint_dhline(int x1, int x2, int y, uint16_t color)
{
/* Order and bounds */
if((uint)y >= 224) return;
@@ -30,8 +30,8 @@ void dhline(int x1, int x2, int y, uint16_t color)
while(end > start) *--end = op;
}

/* dvline() - optimized drawing of a vertical line */
void dvline(int y1, int y2, int x, uint16_t color)
/* gint_dvline(): Optimized vertical line */
void gint_dvline(int y1, int y2, int x, uint16_t color)
{
/* Order and bounds */
if((uint)x >= 395) return;

+ 7
- 0
src/render-cg/dvline.c View File

@@ -0,0 +1,7 @@
#include <gint/display.h>

/* dvline(): Full-height vertical line */
void dvline(int x, color_t color)
{
dline(x, 0, x, 223, color);
}

+ 7
- 0
src/render-fx/dhline.c View File

@@ -0,0 +1,7 @@
#include <gint/display.h>

/* dhline(): Full-width horizontal line */
void dhline(int y, color_t color)
{
dline(0, y, 127, y, color);
}

+ 4
- 4
src/render-fx/dline.c View File

@@ -3,8 +3,8 @@
#include <gint/defs/util.h>
#include <display/fx.h>

/* dhline() - optimized drawing of a horizontal line using a rectangle mask */
void dhline(int x1, int x2, int y, color_t color)
/* gint_dhline(): Optimized horizontal line using a rectangle mask */
void gint_dhline(int x1, int x2, int y, color_t color)
{
if((uint)y >= 64) return;
if(x1 > x2) swap(x1, x2);
@@ -38,8 +38,8 @@ void dhline(int x1, int x2, int y, color_t color)
}
}

/* dvline() - optimized drawing of a vertical line */
void dvline(int y1, int y2, int x, color_t color)
/* gint_dvline(): Optimized vertical line */
void gint_dvline(int y1, int y2, int x, color_t color)
{
if((uint)x >= 128) return;
if(y1 > y2) swap(y1, y2);

+ 7
- 0
src/render-fx/dvline.c View File

@@ -0,0 +1,7 @@
#include <gint/display.h>

/* dvline(): Full-height vertical line */
void dvline(int x, color_t color)
{
dline(x, 0, x, 63, color);
}

+ 3
- 3
src/render/dline.c View File

@@ -2,7 +2,7 @@
#include <gint/defs/util.h>
#include <display/common.h>

/* dline() - Bresenham line drawing algorithm
/* dline(): Bresenham line drawing algorithm
Remotely adapted from MonochromeLib code by Pierre "PerriotLL" Le Gall.
Relies on platform-dependent dhline() and dvline() for optimized situations.
@x1 @y1 @x2 @y2 Coordinates of endpoints of line (included)
@@ -12,12 +12,12 @@ void dline(int x1, int y1, int x2, int y2, color_t color)
/* Possible optimizations */
if(y1 == y2)
{
dhline(x1, x2, y1, color);
gint_dhline(x1, x2, y1, color);
return;
}
if(x1 == x2)
{
dvline(y1, y2, x1, color);
gint_dvline(y1, y2, x1, color);
return;
}


Loading…
Cancel
Save