[go: up one dir, main page]

Menu

Tree [7d60eb] master /
 History

HTTPS access


File Date Author Commit
 Examples 2023-07-31 Malcolm McLean Malcolm McLean [7d60eb] UTF-16 surroggate pairs support in
 src 2023-07-31 Malcolm McLean Malcolm McLean [7d60eb] UTF-16 surroggate pairs support in
 .gitignore 2016-08-27 Malcolm McLean Malcolm McLean [e628ac] Added Visual Studio project and rearranged, min...
 CMakeLists.txt 2023-07-22 Malcolm McLean Malcolm McLean [302a21] Audio rate resampling added
 README.md 2023-07-29 Malcolm McLean Malcolm McLean [3b2afc] Update README.md

Read Me

babyxrc

This is the Baby X resource compiler. It's intended for use with Baby X, but can be used with any programs, it's a standalone system.

The purpose of the program is to convert resources - images, text, fonts and so on - to compilable ANSI C. It's not meant to be a fully-fledged image processing program, but it allows for resizing and expansion of images. It also rasterises fonts, so you can take font processing out of programs - the font is dumped in a simple raster graphic format. You are of course then restricted to one size of font.

Input file format

Example script file:

<BabyXRC>
<image src = "smiley.png", name = "fred", width = "10", height = "10"> </image>
<image src = "lena.jpg"> </image>
<font src = "arial.ttf", name = "arial12", points="12"> </font>
<string src = "external.txt"> </string>
<string name = "internal"> "A C string\n"> </string>
<string name = "embedded"> Embedded string </string>
<audio src = "Beep.wav", name = "beep", samplerate = "44100"> </audio> 
<binary src = "dump.bin", name = "dump_bin"> </binary>
</BabyXRC>

Scope and use

The idea is to act as a portable resource compiler of the type that
comes attached to monolithic IDEs. The only way of importing binary
data portably into C is to dump as C source files. Fortunately these
zip through modern compilers pretty quickly, there's no complexity
or optimisation. However you can't edit dumped source directly, at
least easily. So you need to keep a list of original binary resources
handy. A simple xml file lists the resources to compile.

Because resizing images is such a frequent requirement, it is built
in. Current just two algorithms, both of which operate in rgba
space, an averaging "shrink" and bilinear interpolation for expansion.
The resource compiler isn't going to support a full image processing
transform chain, however, at least yet.

The other major functionality is font rasterisation. The freetype
library is included and used to rasterise the font. However freetype
is slow and complicated for runtime, and many programs just use a
restricted set of fonts at preset sizes. So they are dumped in a
simple raster format, and it is then trivial to write a "draw text"
routine.

Audio support has been added. Three formats are supported, wav,
aiff, and mp3. Only 16 bit uncompressed aiff files are currently
supported. Mp3 files are decompressed and written out as pcm samples.
(If you can play mp3 data, use the \<binary> tag). There is an optional
"samplerate" attribute which will resample the audio at the rate required
by your program.

There's now much better string support. You can add a string as a C
string literal with the \<string> tag, or you can add as UTF-8 with
the \<utf8> tag. UTF-16 source is difficult, but the Baby X resource
compiler will attempt to intelligently recognise UTF-16. There's also
brand new support for internationalization. Whilst there is a very strong
case for allowing UTF-16 input, allowing UTF-16 output was a more difficult
decision. UTF-16 encoding should be discouraged. However sometimes people
might find it easier to work with UTF-16, so there is now a \<utf16> tag.
Note that it won't handle surrogate pairs correctly. If you need raw
UTF-16 in your code, it's unlikely that you will want to handle surrogate
pairs either.

Currently I use the resource compiler myself, and the intention is
to gradually roll it out as a standalone tool for general users.
Those users will be C programmers, so the tool can be modified to
produce slightly different output. If you need ABGR rather than
RGBA, for example. A savejpeg function that is not actually linked
has been included, you can use it save images in compressed
format if that's what you want.

Other uses

The codebase is also by its nature a treasury of useful routines,
some of them written by me, some by other people. There's a
loadimage function which will load practically anything - TIFFs
in virtually any format, JPEGs, PNGs, SVGs, GIF, BMP. You're welcome
to raid the components for your own purposes. There's also a vanilla
xml parser, a commandline options parser, and the image resizing
routines. Do respect the licence terms of the components not
authored by me.

The code is meant to be portable ANSI C with no dependencies except
the standard library.