Bitmaps?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Bitmaps?

Post by 01000101 »

I recently toyed around with 640x480 256-bit color vga mode, and PLEASE tell me there is a better way to create fonts and such besides bitmaps. actually drawing letters in a *x* matrix array is horrible. also, the size of the code goes skyrocketing, I had only finished maybe half the alphabet in 7x7 matrixes and my kernel had overall multiplied in size by 3.

I have no intention on implementing a GUI or using the higher-res vga in my OS, but I still like messing around with things and seeing how things are properly done.
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

Have you thought about using an SVG type font system? (Describe how the graphic is made vs. the finished graphic.)
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

You could simply hack the font out of the VGA card when it's still in text mode. Otherwise, a bitwise font wouldn't add that much to your kernel at all:

7x7 = 49 bits, lets round it to 56 bits (7x8 matrix) now you need only 256*7 = 1.7k to store the entire font uncompressed. That's hardly what you call large. If you want, you can reduce the set to 128 characters (~1K) and even compress it (~500 bytes). Space isn't an argument, if done properly.

Or in C:

Code: Select all

const unsigned char font[] = {
  ....
  /* A */ 0x7C, 0xC6, 0x82, 0xFE, 0x82, 0x82, 0x00,
  /* B */ 0xFC, 0x86, 0x82, 0xFC, 0x82, 0xFC, 0x00,
  ....
  };

void putchar(unsigned char c, int x, int y)
{
  int lx; int ly;
  for (lx = 0; lx < 7; lx++)
    for (ly = 0; ly < 7; ly++)
      putpixel (x+lx,y+ly, ((font[7*c + ly] << lx) & 0x80) ? WHITE : BLACK );
}
which is basically an application of binary math :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Post by Jef »

Combuster wrote:You could simply hack the font out of the VGA card when it's still in text mode. Otherwise, a bitwise font wouldn't add that much to your kernel at all:

7x7 = 49 bits, lets round it to 56 bits (7x8 matrix) now you need only 256*7 = 1.7k to store the entire font uncompressed. That's hardly what you call large. If you want, you can reduce the set to 128 characters (~1K) and even compress it (~500 bytes). Space isn't an argument, if done properly.

Or in C:

Code: Select all

const unsigned char font[] = {
  ....
  /* A */ 0x7C, 0xC6, 0x82, 0xFE, 0x82, 0x82, 0x00,
  /* B */ 0xFC, 0x86, 0x82, 0xFC, 0x82, 0xFC, 0x00,
  ....
  };

void putchar(unsigned char c, int x, int y)
{
  int lx; int ly;
  for (lx = 0; lx < 7; lx++)
    for (ly = 0; ly < 7; ly++)
      putpixel (x+lx,y+ly, ((font[7*c + ly] << lx) & 0x80) ? WHITE : BLACK );
}
which is basically an application of binary math :wink:
seems good.
I don't know in asm how many lines will be ....
anyway,
an other way, that i used at the start of creation the GUI was to put all characters in a text editor (using oem dos like format) and i capture the screen.
The result was a bmp file ( 2048 X 13 pixels) that represents 255 characters 8 x 13. I convert it to asm data and then the maths was too easy.

maybe sounds stupid, but it was a good start (especially if you want to display Greek characters) and the code that displays a character its small and fast.
I really don't care for the size taken in memory as I care for the fast display.
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Bitmaps are stupid. They are not nicely scalable. They take too much space, if you make them look nice. They are a pain to code. If you *really* insist on using bitmaps, then Jef's method sounds good.

But outline fonts were invented because they are better than bitmap fonts. The patent is expired, which means that the entire concept of "outline fonts" is public domain now. (And, in fact, the entire POINT of the patent system is to encourage the wide public adoption of great ideas after the patent is expired.) Draw your fonts using vectors of specific widths, and I'm intending to use splines to fit the curvy parts. Your fonts will look perfect at any scale, and if you code them nicely, they will take up far less space than a "nice" bitmap.

Adobe has also made a number of their fonts available as freeware. (TrueType itself is still copyrighted, with patent protection.)
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

bewing wrote:(TrueType itself is still copyrighted, with patent protection.)
IIRC, don't the patents only apply to certain guessing algorithms which aren't needed to read and use TTF fonts?
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Well, yes, sort-of. There are two types of patents. I was mostly referring to the second kind. You can't "disassemble" a TrueType font, and rename it a bewingFont, and sell it. The precise font itself is patented. Of the remaining patents of the first type, you are correct -- you don't need to use any of them to display an outline or TrueType font. The patents are just for making the fonts a tiny bit prettier at this point.
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

bewing: You can't patent a font. You CAN copyright it, though.
The cake is a lie | rackbits.com
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post by Alboin »

ucosty wrote:bewing: You can't patent a font. You CAN copyright it, though.
Quite the opposite. Under US copyright law (Is that part of the Berne Convention?) typefaces cannot be copyrighted, but distinguished typefaces may be patented. The only copyrighted part of the font is the actual implementation, so anyone can create their own clone implementation, as long as there are no patents.

See here.
C8H10N4O2 | #446691 | Trust the nodes.
User avatar
ucosty
Member
Member
Posts: 271
Joined: Tue Aug 08, 2006 7:43 am
Location: Sydney, Australia

Post by ucosty »

That's just weird.

edit: Wait a minute I'm not entirely wrong here. We both mentioned fonts which are the implemenation and not the original typeface design.
The cake is a lie | rackbits.com
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

bewing wrote:But outline fonts were invented because they are better than bitmap fonts. (...) Draw your fonts using vectors of specific widths, and I'm intending to use splines to fit the curvy parts. Your fonts will look perfect at any scale, and if you code them nicely, they will take up far less space than a "nice" bitmap.
Of course this is utter nonsence, as the whole reason for having these bytecode stuff in the TTF files is because outline fonts do not look nice on small (i.e. normal) resolutions. The whole hinting, whether through bytecode (Windows/OSX) or autohinting (default Linux) is a big pain. For smaller resolutions, bitmaps are far better to start with. Then, implement TTF rendering using FreeType (current version 2.3.5).


JAL
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

"Hinting" is bogus, yes. With some intelligence you can implement an outline font without it, and it looks just like a bitmap font at low res.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Post by jal »

bewing wrote:"Hinting" is bogus, yes. With some intelligence you can implement an outline font without it, and it looks just like a bitmap font at low res.
Sure. It seems you know what you're talking about. *cough*


JAL
User avatar
zaleschiemilgabriel
Member
Member
Posts: 232
Joined: Mon Feb 04, 2008 3:58 am

Post by zaleschiemilgabriel »

Actually, if you have the time, patience and resources to implement it, you could use OpenType/TrueType/PostScript fonts:

OpenType specification

IIRC all you need to draw OpenType glyph outlines are Bezier curves and straight lines. If you also want to draw filled glyphs, you need a scan-line fill algorithm based on Bezier curves and lines.

It's what I plan on using when I get there...
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Bitmaps?

Post by Brendan »

Hi,
01000101 wrote:I recently toyed around with 640x480 256-bit color vga mode, and PLEASE tell me there is a better way to create fonts and such besides bitmaps.
You could draw them by hand (and use a scanner)! ;)

From a more practical perspective it might be worth pointing out that for font data (IMHO) your video code should blit bitmaps in a special format (no colour data except alpha) and *nothing* else. Later on you'd add a (seperate) font engine to this that converts strings of text into bitmap data, and implement it in a way that the bitmap data from the font engine can be cached by your video code to avoid rebuilding the font data each time it's used.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply