// PixelSwizzle.cpp
// Copyright 2008 Chris 'Xenon' Hanson (xenon@alphapixel.com) and AlphaPixel, LLC
// All Rights Reserved

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int main (int Count, char *Vector[])
{

if(Count > 2)
	{
	if(FILE *InFile = fopen(Vector[1], "rb"))
		{
		if(FILE *OutFile = fopen(Vector[2], "wb"))
			{
			fseek(InFile, 0, SEEK_END);
			unsigned int FileSizeBytes = ftell(InFile);
			rewind(InFile);
			if(unsigned char *MemBuf = (unsigned char *)malloc(FileSizeBytes))
				{
				fread(MemBuf, 1, FileSizeBytes, InFile);
				for(unsigned int SwizzleSpot = 0; SwizzleSpot < FileSizeBytes; SwizzleSpot++)
					{
					unsigned char SwizzleOut = 0;
					unsigned char SwizzleIn = MemBuf[SwizzleSpot];
					for(unsigned char Bit = 0; Bit < 7; Bit++)
						{
						if(SwizzleIn & 0x01)
							{
							SwizzleOut |= 0x01;
							} // if
						SwizzleOut = SwizzleOut << 1;
						SwizzleIn = SwizzleIn >> 1;
						} // for
					MemBuf[SwizzleSpot] = SwizzleOut;
					} // for
				fwrite(MemBuf, 1, FileSizeBytes, OutFile);
				} // if
			fclose(OutFile);
			} // if
		fclose(InFile);
		} // if
	} // if

return(0);
} // main
