Add neg y check for screen bit/pixmap and add black on white or white on black options for AA font conversions

This commit is contained in:
David Schmenk committed 2025-01-16 09:53:38 -08:00
1 parent 95a30fb13a
commit 794802c2b1
6 files changed
+114 -129

No files matched your search

+1 -2
View File
@@ -4,8 +4,7 @@ import dhgrutils
//
const FONT_MONO = $00
const FONT_PROP = $80
const FONT_BITMAP = $00
const FONT_PIXMAP = $40
const FONT_AA = $40
byte fontDefWide
byte fontDefThin
predef dhgrAllocBl7Mem(w, h)#2
+47 -57
View File
@@ -572,7 +572,21 @@ asm dcgrBitMapScr(x, y, bitw, bith, bitptr)#0
INX
INX
STX ESP
LDA ESTKL-5,X ; BITPTR
- LDY ESTKH-2,X ; MSB YCOORD
BPL ++
LDA ESTKL-3,X ; WIDTH
LSR ; WIDTH/2
ADC ESTKL-5,X ; PIXPTR += SPAN
STA ESTKL-5,X
BCC +
INC ESTKH-5,X
+ DEC ESTKL-4,X ; HEIGHT
BEQ RETBITS
INC ESTKL-2,X
BNE -
INC ESTKH-2,X
BMI -
++ LDA ESTKL-5,X ; BITPTR
STA SRCL
LDA ESTKH-5,X
STA SRCH
@@ -582,18 +596,7 @@ asm dcgrBitMapScr(x, y, bitw, bith, bitptr)#0
YBITS LDY ESTKL-2,X ; Y COORD
INC ESTKL-2,X ; Y COORD++
CPY #192 ; OFF SCREEN?
BCC +
LDA ESTKL-3,X ; WIDTH
ADC #6 ; ROUND UP (WITH CARRY)
LSR
LSR
LSR
ADC SRCL ; NEXT BITMAP ROW
STA SRCL
LDA #$00
ADC SRCH
STA SRCH
BNE NXTBITS ; BRA
BCS RETBITS
end
asm _dcgrBitmapScrA
+ LDA $1000,Y ; HGRSCANL
@@ -637,7 +640,21 @@ asm dcgrPixMapScr(x, y, pixw, pixh, pixptr)#0
INX
INX
STX ESP
LDA ESTKL-5,X ; PIXPTR
- LDA ESTKH-2,X ; MSB YCOORD
BPL ++
LDA ESTKL-3,X ; WIDTH
LSR ; WIDTH/2
ADC ESTKL-5,X ; PIXPTR += SPAN
STA ESTKL-5,X
BCC +
INC ESTKH-5,X
+ DEC ESTKL-4,X ; HEIGHT
BEQ RETBITS
INC ESTKL-2,X
BNE -
INC ESTKH-2,X
BMI -
++ LDA ESTKL-5,X ; PIXPTR
STA SRCL
LDA ESTKH-5,X
STA SRCH
@@ -648,15 +665,7 @@ asm dcgrPixMapScr(x, y, pixw, pixh, pixptr)#0
YPIXS LDY ESTKL-2,X ; Y COORD
INC ESTKL-2,X ; Y COORD++
CPY #192 ; OFF SCREEN?
BCC +
LDA ESTKL-3,X ; WIDTH
LSR
ADC SRCL ; NEXT PIXMAP ROW
STA SRCL
LDA #$00
ADC SRCH
STA SRCH
BNE NXTPIXS ; BRA
BCS RETPIXS
end
asm _dcgrPixmapScrA
+ LDA $1000,Y ; HGRSCANL
@@ -1057,10 +1066,6 @@ asm dcgrBitMapMem(x, y, bitw, bith, bitptr, memw, memh, memptr, memspan)#0
ADC #9
TAX
STX ESP
LDA ESTKL-8,X ; DST PTR
STA DSTL
LDA ESTKH-8,X
STA DSTH
- LDY ESTKH-2,X ; MSB YCOORD
BPL ++
LDA ESTKL-3,X ; WIDTH
@@ -1080,7 +1085,11 @@ asm dcgrBitMapMem(x, y, bitw, bith, bitptr, memw, memh, memptr, memspan)#0
BNE -
INC ESTKH-2,X
BMI -
++ LDY ESTKL-2,X ; Y COORD
++ LDA ESTKL-8,X ; DST PTR
STA DSTL
LDA ESTKH-8,X
STA DSTH
LDY ESTKL-2,X ; Y COORD
BEQ +
;CLC ; ADVANCE TO Y SCANLINE
- LDA ESTKL-9,X ; SPAN
@@ -1101,19 +1110,8 @@ asm dcgrBitMapMem(x, y, bitw, bith, bitptr, memw, memh, memptr, memspan)#0
YBITM LDA ESTKL-2,X ; Y COORD
INC ESTKL-2,X ; Y COORD++
CMP ESTKL-7,X ; OUT OF DST BOUNDS?
BCC +
LDA ESTKL-3,X ; WIDTH
ADC #6 ; ROUND UP (WITH CARRY)
LSR
LSR
LSR
ADC SRCL ; NEXT BITMAP ROW
STA SRCL
LDA #$00
ADC SRCH
STA SRCH
BNE NXTBITM ; BRA
+ LDA ESTKL-1,X ; X COORD
BCS RETBITM
LDA ESTKL-1,X ; X COORD
STA ESTKH-1,X ; CURRENT X COORD
BITM8 LDA #8
STA ESTKH-2,X ; BIT COUNT
@@ -1157,10 +1155,6 @@ asm dcgrPixMapMem(x, y, pixw, pixh, pixptr, memw, memh, memptr, memspan)#0
ADC #9
TAX
STX ESP
LDA ESTKL-8,X ; DST PTR
STA DSTL
LDA ESTKH-8,X
STA DSTH
- LDY ESTKH-2,X ; MSB YCOORD
BPL ++
LDA ESTKL-3,X ; WIDTH
@@ -1175,7 +1169,11 @@ asm dcgrPixMapMem(x, y, pixw, pixh, pixptr, memw, memh, memptr, memspan)#0
BNE -
INC ESTKH-2,X
BMI -
++ LDY ESTKL-2,X ; Y COORD
++ LDA ESTKL-8,X ; DST PTR
STA DSTL
LDA ESTKH-8,X
STA DSTH
LDY ESTKL-2,X ; Y COORD
BEQ +
- CLC ; ADVANCE TO Y SCANLINE
LDA ESTKL-9,X ; SPAN
@@ -1197,18 +1195,10 @@ asm dcgrPixMapMem(x, y, pixw, pixh, pixptr, memw, memh, memptr, memspan)#0
YPIXM LDA ESTKL-2,X ; Y COORD
INC ESTKL-2,X ; Y COORD++
CMP ESTKL-7,X ; OUT OF DST BOUNDS?
BCC +
LDA ESTKL-3,X ; WIDTH
LSR
ADC SRCL ; NEXT PIXMAP ROW
STA SRCL
LDA #$00
ADC SRCH
STA SRCH
BNE NXTPIXM ; BRA
BCS RETPIXM
end
asm _dcgrPixmapMemA
+ LDA ESTKL-1,X ; X COORD
LDA ESTKL-1,X ; X COORD
STA TMPL
LDY #$00
PIXMEML CMP ESTKL-6,X ; OUT OF DST BOUNDS?
@@ -1266,7 +1256,7 @@ NXTPIXM CLC
STA DSTH
DEC ESTKL-4,X ; HEIGHT
BNE YPIXM ; NEXT ROW
RTS
RETPIXM RTS
end
asm dcgrRleMapMem(x, y, pixw, pixh, pixptr, memw, memh, memptr, memspan)#0
TXA
+7 -19
View File
@@ -116,26 +116,14 @@ export def dhgrAllocBl7Mem(w, h)#2
memblk = heapalloc(span * h)
return memblk, span
end
def bitCtrlGlyph(x, y, c)#2
def ctrlGlyph(x, y, c)#2
when c
is '\n'
x = 0
y = y + fontPtr->fnt_height
break
is '\t'
x = x + (fontPtr->fnt_width * 8)
break
wend
return x, y
end
def pixCtrlGlyph(x, y, c)#2
when c
is '\n'
x = 0
y = y + fontPtr->fnt_height
break
is '\t'
x = x + (fontPtr->fnt_width * 4)
x = x + (fontPtr->fnt_width * fontPtr & FONT_AA ?? 8 :: 4)
break
wend
return x, y
@@ -157,7 +145,7 @@ def bitMonoGlyphStr(x, y, strptr)#2
strikes + (^(strptr + i) - first) * size)
x = x + width
else
x, y = bitCtrlGlyph(x, y, ch)
x, y = ctrlGlyph(x, y, ch)
fin
next
return x, y
@@ -181,7 +169,7 @@ def pixPropGlyphStr(x, y, strptr)#2
glyph + gly_strike)
x = x + glyph->gly_adv
else
x, y = pixCtrlGlyph(x, y, ch)
x, y = ctrlGlyph(x, y, ch)
fin
next
return x / 4, y
@@ -204,7 +192,7 @@ def bitPropGlyphStr(x, y, strptr)#2
glyph + gly_strike)
x = x + glyph->gly_adv
else
x, y = bitCtrlGlyph(x, y, ch)
x, y = ctrlGlyph(x, y, ch)
fin
next
return x, y
@@ -241,7 +229,7 @@ export def dcgrFont(font)#1
fin
fontPtr = font
if fontPtr->fnt_typelen & FONT_PROP
if fontPtr->fnt_typelen & FONT_PIXMAP
if fontPtr->fnt_typelen & FONT_AA
dcgrStr:1 = @pixPropGlyphStr
else
dcgrStr:1 = @bitPropGlyphStr
@@ -267,7 +255,7 @@ export def fontRead(filename)#1
num = font_header->fnt_last - font_header->fnt_first
if font_header->fnt_typelen & FONT_PROP
gly_ptr = heapalloc(num * 2) // Allocate glyph ptrs right after
if font_header->fnt_typelen & FONT_PIXMAP
if font_header->fnt_typelen & FONT_AA
roundup = 1
pixbyte = 2
else
+3 -23
View File
@@ -8,41 +8,21 @@ include "dhgr.tk/inc/dhgrutils.plh"
sysflags resxtxt1|reshgr1|resxhgr1
var arg
var xPen = 58
var xPen = 60
var yPen = 30
var fontWidth, fontHeight
var surf, span
char msg = "Hello, world"
arg = argNext(argFirst)
dhgrMode(DHGR_COLOR_MODE)
screenRead("scroll.dhgr")
//dcgrColor(CLR_WHITE)
//dhgrClearBl7(0, 0, SCR_WIDTH7, SCR_HEIGHT)
//dcgrColor(CLR_BLACK)
//xPen, yPen = dcgrStr(xPen, yPen, @msg)
//dcgrFont(@fontDefThin)
//xPen, yPen = dcgrStr(xPen, yPen, @msg)
while arg and ^arg
dcgrFont(fontRead(arg))
fontWidth, fontHeight = fontGlyphDim
fontHeight++
dcgrColor(CLR_BLACK)
dcgrStr(xPen, yPen + (fontHeight * 3) / 4, @msg)
yPen = yPen + fontHeight
if fontType & FONT_PIXMAP
surf, span = dhgrAllocBl7Mem(fontWidth * msg, fontHeight)
dhgrSurfMem(OP_SRC, fontHeight, surf, span)
dcgrColor(CLR_WHITE)
dhgrClearBl7(0, 0, span>>2, fontHeight)
dhgrOp(OP_XOR)
dcgrStr(0, (fontHeight * 3) / 4, @msg)
dhgrSurfScr(OP_AND)
dhgrMemBl7(xPen/7, yPen, span >> 2, fontHeight, surf, span)
heaprelease(surf)
else
dhgrOp(OP_SRC)
dcgrColor(CLR_BLACK)
dcgrStr(xPen, yPen, @msg)
fin
arg = argNext(arg)
loop
getc
+28 -14
View File
@@ -9,14 +9,13 @@
#include <stdint.h>
#include <ctype.h>
#define FONT_WIDTH 32
#define FONT_WIDTH 28
#define FONT_HEIGHT 12
#define GLYPH_FIRST 32
#define GLYPH_LAST 127
#define GLYPH_COUNT (GLYPH_LAST-GLYPH_FIRST+1)
#define FONT_BITMAP 0
#define FONT_PIXMAP 1
int fontFormat = FONT_BITMAP;
#define FONT_AA 0x40
int fontFormat = 0;
struct gsfont {
uint16_t offsetMacFont;
uint16_t family;
@@ -52,8 +51,21 @@ uint16_t *owTable;
*/
unsigned char bitReverse[256];
unsigned char clrSwap[256];
unsigned char clrRot[] = {0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
/*
* White on Black and black is xpar
*/
unsigned char clrRotWonB[] = {0x05,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
0x01,0x03,0x05,0x07,0x09,0x0B,0x0D,0x0F};
/*
* Black on white and white is xpar
*/
unsigned char clrRotBonW[] = {0x05,0x0D,0x0B,0x09,0x07,0x0A,0x03,0x01,
0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00};
/*
* Default to black on white
*/
unsigned char *clrRot = clrRotBonW;
void write_glyph(FILE *fp, int c)
{
uint8_t glyphdef[5], *swapbuf, *glyphBits;
@@ -77,7 +89,7 @@ void write_glyph(FILE *fp, int c)
glyphdef[0] = left;
glyphdef[1] = -top;
glyphdef[2] = fontFormat == FONT_PIXMAP ? (width + 3) / 4 : width;
glyphdef[2] = fontFormat == FONT_AA ? (width + 3) / 4 : width;
glyphdef[3] = height;
glyphdef[4] = width + left;
fwrite(&glyphdef, 1, 5, fp);
@@ -107,7 +119,7 @@ void write_glyph(FILE *fp, int c)
rowbits >>= bitShift;
rowbits &= 0xFFFFFFFF >> (32 - pixWidth);
}
if (fontFormat == FONT_PIXMAP)
if (fontFormat == FONT_AA)
{
glyphdef[0] = clrSwap[rowbits & 0xFF];
glyphdef[1] = clrSwap[(rowbits >> 8) & 0xFF];
@@ -152,8 +164,7 @@ void write_font_file(char *filename, char *fontfile)
memset(font_header, 0, 16);
strncpy(&font_header[1], fontname, 15);
ch = strlen(fontname);
font_header[0] = ch < 16 ? ch : 15;
font_header[0] |= fontFormat == FONT_PIXMAP ? 0x80 | 0x40 : 0x80; // FONT_PROP
font_header[0] = (ch < 16 ? ch : 15) | fontFormat | 0x80; // FONT_PROP
fwrite(font_header, 1, 16, fp);
glyph_width = macf->rectWidth;
glyph_height = macf->rectHeight;
@@ -161,7 +172,7 @@ void write_font_file(char *filename, char *fontfile)
fwrite(&ch, 1, 1, fp);
ch = GLYPH_LAST;
fwrite(&ch, 1, 1, fp);
ch = fontFormat == FONT_PIXMAP ? (glyph_width + 3) / 4 : glyph_width;
ch = fontFormat == FONT_AA ? (glyph_width + 3) / 4 : glyph_width;
fwrite(&ch, 1, 1, fp);
ch = glyph_height;
fwrite(&ch, 1, 1, fp);
@@ -264,11 +275,14 @@ int main(int argc, char **argv)
{
switch (toupper(argv[0][1]))
{
case 'B':
fontFormat = FONT_BITMAP;
case 'A':
fontFormat |= FONT_AA;
break;
case 'P':
fontFormat = FONT_PIXMAP;
case 'B':
fontFormat &= ~FONT_AA;
break;
case 'I':
clrRot = clrRotWonB;
break;
}
}
+28 -14
View File
@@ -11,21 +11,33 @@
//#include FT_FREETYPE2_H
#include <freetype2/freetype/freetype.h>
#define FONT_WIDTH 32
#define FONT_WIDTH 28
#define FONT_HEIGHT 12
#define GLYPH_FIRST 32
#define GLYPH_LAST 127
#define GLYPH_COUNT (GLYPH_LAST-GLYPH_FIRST+1)
#define FONT_BITMAP 0
#define FONT_PIXMAP 1
int fontFormat = FONT_PIXMAP;
#define FONT_AA 0x40
int fontFormat = FONT_AA;
/*
* Bit reversals
*/
unsigned char bitReverse[256];
unsigned char clrSwap[256];
unsigned char clrRot[] = {0x00,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
/*
* White on Black and black is xpar
*/
unsigned char clrRotWonB[] = {0x05,0x02,0x04,0x06,0x08,0x0A,0x0C,0x0E,
0x01,0x03,0x05,0x07,0x09,0x0B,0x0D,0x0F};
/*
* Black on white and white is xpar
*/
unsigned char clrRotBonW[] = {0x05,0x0D,0x0B,0x09,0x07,0x0A,0x03,0x01,
0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00};
/*
* Default to black on white
*/
unsigned char *clrRot = clrRotBonW;
void write_glyph(FILE *fp, int left, int top, int width, int height, int advance, unsigned char *buf, int pitch)
{
unsigned char glyphdef[5], *swapbuf;
@@ -33,12 +45,12 @@ void write_glyph(FILE *fp, int left, int top, int width, int height, int advance
glyphdef[0] = left;
glyphdef[1] = -top;
glyphdef[2] = fontFormat == FONT_PIXMAP ? (width + 3) / 4 : width;
glyphdef[2] = fontFormat == FONT_AA ? (width + 3) / 4 : width;
glyphdef[3] = height;
glyphdef[4] = advance;
fwrite(&glyphdef, 1, 5, fp);
swapbuf = malloc(pitch * height);
if (fontFormat == FONT_PIXMAP)
if (fontFormat == FONT_AA)
{
for (i = 0; i < pitch * height; i++)
swapbuf[i] = clrSwap[buf[i]];
@@ -83,14 +95,13 @@ void write_font_file(char *filename, char *fontfile, FT_Face face, int glyph_wid
memset(font_header, 0, 16);
strncpy(&font_header[1], fontname, 15);
ch = strlen(fontname);
font_header[0] = ch < 16 ? ch : 15;
font_header[0] |= fontFormat == FONT_PIXMAP ? 0x80 | 0x40 : 0x80; // FONT_PROP
font_header[0] = (ch < 16 ? ch : 15) | fontFormat | 0x80; // FONT_PROP
fwrite(font_header, 1, 16, fp);
ch = GLYPH_FIRST;
fwrite(&ch, 1, 1, fp);
ch = GLYPH_LAST;
fwrite(&ch, 1, 1, fp);
ch = fontFormat == FONT_PIXMAP ? (glyph_width + 3) / 4 : glyph_width;
ch = fontFormat == FONT_AA ? (glyph_width + 3) / 4 : glyph_width;
fwrite(&ch, 1, 1, fp);
ch = glyph_height;
fwrite(&ch, 1, 1, fp);
@@ -199,11 +210,11 @@ int main(int argc, char **argv)
{
switch (toupper(argv[0][1]))
{
case 'B':
fontFormat = FONT_BITMAP;
case 'A':
fontFormat |= FONT_AA;
break;
case 'P':
fontFormat = FONT_PIXMAP;
case 'B':
fontFormat &= ~FONT_AA;
break;
case 'W':
glyph_width = atoi(&argv[0][2]);
@@ -211,6 +222,9 @@ int main(int argc, char **argv)
case 'H':
glyph_height = atoi(&argv[0][2]);
break;
case 'I':
clrRot = clrRotWonB;
break;
}
}
else