Fix bug in hx8357: rasterizing glyphs with width>16.

This commit is contained in:
Serge Vakulenko
2015-10-09 13:21:29 -07:00
parent 08edaaba8c
commit d2fb9b98a6
2 changed files with 42 additions and 32 deletions

View File

@@ -26,6 +26,9 @@ extern const struct gpanel_font_t font_digits20;
#define COLOR_YELLOW COLOR_RGB(31, 63, 0) #define COLOR_YELLOW COLOR_RGB(31, 63, 0)
#define COLOR_MAGENTA COLOR_RGB(31, 0, 31) #define COLOR_MAGENTA COLOR_RGB(31, 0, 31)
#define COLOR_CYAN COLOR_RGB(0, 63, 31) #define COLOR_CYAN COLOR_RGB(0, 63, 31)
#define COLOR_RED COLOR_RGB(31, 0, 0)
#define COLOR_GREEN COLOR_RGB(0, 63, 0)
#define COLOR_BLUE COLOR_RGB(0, 0, 31)
/* /*
* Screen size. * Screen size.
@@ -35,26 +38,27 @@ int xsize, ysize;
void show(const struct gpanel_font_t *font, const char *title, int digits_only) void show(const struct gpanel_font_t *font, const char *title, int digits_only)
{ {
char line[100]; char line[100];
int x = 10; int x = 0, y = 0, i, color;
int y = 10; const char *phrase = digits_only ? "0123456789" :
"The quick brown fox jumps over the lazy dog.";
static const int colortab[] = {
COLOR_YELLOW, COLOR_CYAN, COLOR_MAGENTA,
COLOR_RED, COLOR_GREEN, COLOR_BLUE,
0,
};
gpanel_clear(COLOR_BLACK, 0, 0); gpanel_clear(COLOR_BLACK, 0, 0);
gpanel_text(&font_lucidasans15, COLOR_WHITE, COLOR_BLACK, x, y, title); gpanel_text(&font_lucidasans15, COLOR_WHITE, COLOR_BLACK, x, y, title);
y += font_lucidasans15.height; y += font_lucidasans15.height * 2;
gpanel_text(font, COLOR_YELLOW, COLOR_BLACK, x, y, for (i=0; y<ysize; i++) {
digits_only ? "0123456789" color = colortab[i];
: "The quick brown fox"); if (color == 0)
y += font->height; color = colortab[i = 0];
gpanel_text(font, COLOR_CYAN, COLOR_BLACK, x, y, gpanel_text(font, color, COLOR_BLACK, x, y, phrase);
digits_only ? "3456789012" y += font->height;
: "jumps over"); }
y += font->height;
gpanel_text(font, COLOR_MAGENTA, COLOR_BLACK, x, y,
digits_only ? "6789012345"
: "the lazy dog.");
printf("Font %s: press Enter...", title); printf("Font %s: press Enter...", title);
fflush(stdout); fflush(stdout);

View File

@@ -420,7 +420,8 @@ static void newLine(const struct gpanel_font_t *font)
void drawGlyph(const struct gpanel_font_t *font, void drawGlyph(const struct gpanel_font_t *font,
int color, int background, int width, const unsigned short *bits) int color, int background, int width, const unsigned short *bits)
{ {
int i, j; int h, w;
unsigned bitmask = 0;
if (background >= 0) { if (background >= 0) {
/* /*
@@ -430,33 +431,38 @@ void drawGlyph(const struct gpanel_font_t *font,
while (PMMODE & PIC32_PMMODE_BUSY); while (PMMODE & PIC32_PMMODE_BUSY);
PMADDR = 0x0001; PMADDR = 0x0001;
/* Loop on each glyph row, backwards from bottom to top. */ /* Loop on each glyph row. */
for (i=0; i<font->height; i++) { for (h=0; h<font->height; h++) {
unsigned glyph_row = bits[i]; /* Loop on every pixel in the row (left to right). */
for (w=0; w<width; w++) {
if ((w & 15) == 0)
bitmask = *bits++;
else
bitmask <<= 1;
/* Loop on every two pixels in the row (left to right). */ while (PMMODE & PIC32_PMMODE_BUSY)
for (j=0; j<width; j++) { ;
while (PMMODE & PIC32_PMMODE_BUSY); if (bitmask & 0x8000)
if (glyph_row & 0x8000)
PMDIN = color; PMDIN = color;
else else
PMDIN = background; PMDIN = background;
glyph_row <<= 1;
} }
} }
} else { } else {
/* /*
* Transparent background. * Transparent background.
*/ */
/* Loop on each glyph row, backwards from bottom to top. */ /* Loop on each glyph row. */
for (i=0; i<font->height; i++) { for (h=0; h<font->height; h++) {
unsigned glyph_row = bits[i]; /* Loop on every pixel in the row (left to right). */
for (w=0; w<width; w++) {
if ((w & 15) == 0)
bitmask = *bits++;
else
bitmask <<= 1;
/* Loop on every two pixels in the row (left to right). */ if (bitmask & 0x8000)
for (j=0; j<width; j++) { setPixel(_col + w, _row + h, color);
if (glyph_row & 0x8000)
setPixel(_col + j, _row + i, color);
glyph_row <<= 1;
} }
} }
} }