libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

drawchar.c (1020B)


      1 /*
      2  * drawchar.c
      3  * libansilove 1.2.4
      4  * https://www.ansilove.org
      5  *
      6  * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus
      7  * All rights reserved.
      8  *
      9  * libansilove is licensed under the BSD 2-Clause License.
     10  * See LICENSE file for details.
     11  */
     12 
     13 #include <gd.h>
     14 
     15 #include "drawchar.h"
     16 
     17 void
     18 drawchar(gdImagePtr im, const uint8_t *font_data, uint32_t bits,
     19     uint32_t height, uint32_t column, uint32_t row,
     20     uint32_t background, uint32_t foreground, uint8_t character)
     21 {
     22 	uint32_t x, y;
     23 
     24 	gdImageFilledRectangle(im, column * bits, row*height, column * bits +
     25 	    bits - 1, row * height + height - 1, background);
     26 
     27 	for (y = 0; y < height; y++) {
     28 		for (x = 0; x < bits; x++) {
     29 
     30 			if ((font_data[y+character*height] & (0x80 >> x)) != 0) {
     31 				gdImageSetPixel(im, column * bits + x,
     32 				    row*height + y, foreground);
     33 
     34 				if (bits == 9 && x == 7 &&
     35 				    character > 191 && character < 224)
     36 					gdImageSetPixel(im, column * bits + 8,
     37 					    row * height + y, foreground);
     38 			}
     39 		}
     40 	}
     41 }