This is my library of code that is common to my different projects (mostly Photosounder Spiral and Photosounder SplineEQ)
Objective-C C C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
rouziclib Misc Mar 31, 2018
vector_type Misc Mar 31, 2018
LICENSE Changed license to Apache v2 Apr 1, 2018
README.md fixed link Jul 10, 2017
quick_reference.h Misc Mar 31, 2018

README.md

rouziclib

This is my library of code that is common to my different projects (mostly Spiral and SplineEQ)

It includes some of the following:

  • Fast lookup table-based fixed-point arithmetic approximations for sqrt, hypot, log2, exp2, pow, cos, atan2 (both noting angles in turns, not radians), the Gaussian function (e^-x²), the raised error function (0.5+0.5erf(x)) and a windowed sinc function. Some are implemented using linear interpolation, segmented quadratic polynomial approximation or simple lookup, which offers different levels of speed/precision/memory usage tradeoffs.
  • Fast quadratic lookup table-based floating-point approximations for log2, exp2, pow and sqrt (fastsqrt() being slower than sqrt() depending on the machine)
  • Functions to draw lines, points, circles, roundrects and gradients, all antialiased with Gaussian filtering
  • Functions to convert from sRGB to linear RGB for loading images and to convert from linear RGB to sRGB with optional Gaussian dithering for displaying
  • Geometric functions used for computing intersections between lines, shortest the distance of a point to a line or to limit a line to a bounding box
  • Blending modes like additive, subtractive, multiplicative blending and alpha blending
  • Blitting of a buffer onto another, like for displaying a sprite
  • An original Hue-Saturation-Luminance colour space with a Luminance that is about perceptually correct (unlike the 1931 CIE XYZ colour space which gets the weights of each colour blatantly wrong) which is used for HSL to RGB conversion and for bringing out of gamut colours (such as colours that have components brighter than 1.0) to the most appropriate representable colour
  • Vector font generation, vector text rendering and a built-in minimalistic vector font that is always available. A more complete typeface is available in the vector_type directory
  • Vector procedural zoomable interface elements that for instance allow you to have a fully functional button just by calling a function with all the necessary information provided as parameters (without anything stored in memory) and simply getting the return value, with no need for storage for each instance of a control, no unique IDs or anything
  • Various utility functions and macros
  • Code for working with SDL, OpenGL, OpenCL, clFFT, DevIL, OpenCV, FFMPEG, LibRAW and MPFR.

All graphical functions operate on pixels in a linear colour space. Please do not use these functions directly in a gamma-compressed colour space, instead use an intermediary linear framebuffer which you can then convert to an sRGB framebuffer using the function convert_lrgb_to_srgb.

How to use it

Unusually for a library, rouziclib's code relies on macros that are defined inside your project's code. This means that rouziclib isn't entirely independently compiled. So the way to make this work is to create two files in your project, a header file which directly includes the main header, but not before you add the macros you can optionally define, and a code file which includes the aforementioned header file you just created and then includes the library's rouziclib.c. Here's how it looks:

rl.h

#ifndef H_PRL
#define H_PRL
#ifdef __cplusplus
extern "C" {
#endif

// these are examples of optional macros that rouziclib will then use for your project
#define COL_FRGB	// this macro makes the internal format for colour be floating-point instead of fixed-point
#define RL_SDL		// this includes SDL-using code as well as the necessary SDL files
#define RL_OPENCL	// same for OpenCL

// this defines a wrapper for fprintf_rl, so you project can use a custom fprintf-type function that can for instance output to a file
#define fprintf_rl fprintf_wrapper
#include <stdio.h>
#include <stdarg.h>
extern void fprintf_wrapper (FILE *stream, const char* format, ...);

#include <rouziclib/rouziclib.h>

#ifdef __cplusplus
}
#endif
#endif

rl.c

#include "rl.h"

// this creates that custom printing function that all calls to fprintf_rl in rouziclib will use
#include <stdarg.h>
void fprintf_wrapper (FILE *stream, const char* format, ...)
{
	va_list args;

	va_start (args, format);

	vfprintf (stream, format, args);	// printf to original stream
	fflush (stream);

	va_end (args);
}

#include <rouziclib/rouziclib.c>

I realise that this is a bit unusual, but it's pretty simple and very handy. You can for instance include rouziclib in a simple command-line C program without having to worry about dependencies as none will be included, and in another project add dependencies as you need by adding the necessary macros, so without having the recompile anything separately (as you would have to were you to use two versions of a same library compiled with different dependencies) you can have in separate projects a rouziclib with no dependencies or a rouziclib that uses SDL, DevIL, OpenCV, OpenCL, clFFT, FFMPEG and LibRAW.