summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-07-17 18:34:39 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-07-17 18:34:39 (EDT)
commit7fc0d5367622770593312c4244dff9ccf46e6b03 (patch)
tree378e9d6078de1f9e894be2b1ec5b950eed535e8c
parentac148296c2b39816122924dda32afec4ed08735d (diff)
font_render(): New function
-rw-r--r--src/font.c28
-rw-r--r--src/font.h10
2 files changed, 35 insertions, 3 deletions
diff --git a/src/font.c b/src/font.c
index c198943..c2300b5 100644
--- a/src/font.c
+++ b/src/font.c
@@ -27,6 +27,10 @@
#include <linux/font.h>
+#define FONT_H(f) ((size_t) (f)->desc.height)
+#define FONT_W(f) ((size_t) (f)->desc.width)
+#define CHAR_PIXEL(f, c, x, y) (((((c) * FONT_H(f)) + (y)) * FONT_W(f)) + (x))
+
struct font {
const struct font_desc desc;
};
@@ -66,3 +70,27 @@ font_get_height(struct font *font)
{
return font->desc.height;
}
+
+void
+font_render(struct font *font, png_const_colorp fg, png_const_colorp bg,
+ char ch, png_bytepp rows, int row, int col)
+{
+ size_t y;
+ size_t r;
+ size_t x;
+ size_t c;
+
+ for (y = 0, r = row * FONT_H(font); y < FONT_H(font); ++y, ++r) {
+ for (x = 0, c = col * FONT_W(font); x < FONT_W(font); ++x, ++c){
+ if (CHAR_PIXEL(font, ch, x, y)) {
+ *(&rows[r][c] + 0) = fg->red;
+ *(&rows[r][c] + 1) = fg->green;
+ *(&rows[r][c] + 2) = fg->blue;
+ } else {
+ *(&rows[r][c] + 0) = bg->red;
+ *(&rows[r][c] + 1) = bg->green;
+ *(&rows[r][c] + 2) = bg->blue;
+ }
+ }
+ }
+}
diff --git a/src/font.h b/src/font.h
index 0e22c55..ee3942e 100644
--- a/src/font.h
+++ b/src/font.h
@@ -19,8 +19,8 @@
* along with fbcon2png. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef FONT_H
-#define FONT_H
+#ifndef FONT_H_
+#define FONT_H_
#include <png.h>
@@ -35,4 +35,8 @@ font_get_width(struct font *font) __attribute__((pure));
int
font_get_height(struct font *font) __attribute__((pure));
-#endif /* FONT_H */
+void
+font_render(struct font *font, png_const_colorp fg, png_const_colorp bg,
+ char ch, png_bytepp rows, int row, int col);
+
+#endif /* FONT_H_ */