Cube  tools.m at [5b7b7d2fc5]

File src/tools.m artifact 8e8dbaa306 part of check-in 5b7b7d2fc5


// implementation of generic tools

#include "tools.h"

///////////////////////// misc tools ///////////////////////

void
endianswap(
    void *memory, int stride, int length) // little indians as storage format
{
	if (*((char *)&stride))
		return;

	for (int w = 0; w < length; w++) {
		for (int i = 0; i < stride / 2; i++) {
			unsigned char *p = (unsigned char *)memory + w * stride;
			unsigned char t = p[i];
			p[i] = p[stride - i - 1];
			p[stride - i - 1] = t;
		}
	}
}