GithubHelp home page GithubHelp logo

malcolmmclean / babyxrc Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 9.0 5.37 MB

Resource compiler, packages images, fonts, cursors, etc as compilable C source. Portable ANSI C.

Home Page: http://malcolmmclean.github.io/babyxrc/

C 99.13% C++ 0.64% Makefile 0.20% Shell 0.01% CMake 0.01%
audio-processing c gif jpeg-decoder jpeg-encoder tiff-format xml-parser

babyxrc's Introduction

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.

Check out our webpages.

Usage

babyxrc [options] <script.xml>

Options:
      -header - output a .h header file instead of a .c source file.
 

Building

There is a CMake script. So if you have CMake, make a directory called "build" under the BabyXRC root directory containing CMakeLists.txt, navigate to it, then type

cmake ..
make

or

cmake -G <your generator> ..

If you don't have CMake, the code is all clean portable C 99 with no dependencies or problems. So it's easy to compile on the commandline. Navigate to the "src" directory and type

gcc *.c freetype/*.c samplerate/*.c -lm

should do it. Replace "gcc" with your C compiler of choice.

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 unless you set the allowsurrogatepairs attribute. The main reason for using UTF-16 is to guarantee one symbol per character, so surrogate pairs are disallowed by default.

There's an experimental <dataframe> tag which allows you to import CSV data. It is then written out as an array of C structs, with the fields determined by the header. This might or might not work out in actual use.

Sometimes the small things make all the difference. There is now a <comment> tag whcih inserts a comment into the output. It's vital for attaching licence data to open source resources that might be GPLed.

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.

babyxrc's People

Contributors

malcolmmclean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

babyxrc's Issues

Compilation error in babyxrcmain.c

When I compile babyxrcmain.c, I get:

$ gcc -c -std=c17 -pedantic-errors babyxrcmain.c 
babyxrcmain.c:131:2: error: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]
  131 | };
      |  ^
babyxrcmain.c:317:2: error: ISO C does not allow extra ‘;’ outside of a function [-Wpedantic]
  317 | };
      |  ^

I suggest updating compileme.txt so it doesn't suggest compiling with no options (gcc is quite lax by default).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.