Skip to content
Steven Arnow edited this page May 14, 2014 · 7 revisions

DARNIT_IMAGE_DATA

A struct that holds information about an image loaded by d_img_load_raw.

typedef struct {
	unsigned int		w;
	unsigned int		h;
	unsigned int		*data;
} DARNIT_IMAGE_DATA;
  • w - The width of the image
  • h - The height of the image
  • data - Pixel data. You need to free this yourself.

Functions

DARNIT_UTIL

Various functions. Isn't much more to say about them.

DARNIT_RANDOM

Functions used to generate random numbers, provided the seed is the same, will be the same ones across different platforms. This is just a Mersenne twister.

d_img_load_raw

DARNIT_IMAGE_DATA d_img_load_raw(const char *fname);

Loads an image file and returns the raw pixel data in 32 bpp RGBA pixel format.

Arguments

  • fname - The image file to load

Return value

Returns a DARNIT_IMAGE_DATA struct. You'll have to free the pixel data yourself.

d_util_htonl

unsigned int d_util_htonl(unsigned int arg);

Converts an int from host endianess to network (big) endianess.

Arguments

  • arg - The integer to convert

Return value

Returns arg converted to network endian

d_util_ntohl

unsigned int d_util_ntohl(unsigned int arg);

Converts an int from network endianess to host endianess.

Arguments

  • arg - The integer to convert

Return value

Returns the integer converted to host endian.

d_util_path_translate

char *d_util_path_translate(const char *path);

Will duplicate the string and replace all / with \ if you are running on a windows system.

Arguments

  • path - The path to convert

Return value

Returns a cloned string with / replaced with \ if you're using a windows system. If not, the forward-slashes are preserved.

d_util_string_to_int_array

int d_util_string_to_int_array(const char *str, const char *delimiter, int *dest, int max_tokens);

Converts a string into an array if integers.

Arguments

  • str - Input string
  • delimiter - What separates the numbers
  • dest - An array to put the converted integers in
  • max_tokens - The maximum number of integers to put in max_tokens

Return value

Returns the number of integers it found in the string

d_util_endian_convert

void d_util_endian_convert(unsigned int *block, int elements);

If you are using a little endian system, this function swaps endianess of an array of integers. If you're running on a big endian system, it does nothing.

Arguments

  • block - The array of integers to convert
  • elements - The number of integers to convert

Return value None.

d_util_sin

int d_util_sin(int angle);

Fast look-up table based integer sinus function.

Arguments

  • angle - Angle in 1/10ths of a degree (range: 0..3599)

Return value

Returns the sine function of angle. Range is 0..65536 (0x0 .. 0x10000.)

d_str_null

const char *d_str_null(const char *str);

Returns NULL if str contains the string "NULL".

Arguments

  • str - The string to check

Return value

Returns NULL if str is NULL or contains the string "NULL". Otherwise, it returns str.

d_util_compress

int d_util_compress(void *data_in, unsigned int data_len, void **data_out);

Compresses a memory buffer with libbz2. NOTE: Not directly compatible with bunzip etc, as libdarnit prepends the memory buffer with the size of the decompressed memory block. Skip the first 4 bytes if you need to use those tools.

Arguments

  • data_in - The memory buffer containing the data to be compressed
  • data_len - The size of the memory buffer to compress
  • data_out - A pointer to a valid memory block containing the compressed data. You need to free this block yourself

Return value

Returns the size of the compressed memory block.

d_util_decompress

int d_util_decompress(void *data_in, unsigned int data_len, void **data_out);

Decompresses a memory buffer using libbz2. NOTE: Expects a non-standard format for bz2-data; it expects the first 4 bytes to be the size of the decompressed memory block, stored in big endian.

Arguments

  • data_in - The memory buffer to decompress
  • data_len - The size of the memory buffer to decompress
  • data_out - A pointer to a memory buffer containing the decompressed data will be placed here. You must free this buffer yourself.

Return value

Returns the size of the decompressed memory buffer

Clone this wiki locally