/* Copyright 1990 by Christopher A. Wichura.
   See file GIFMachine.doc for full description of rights.
*/

#include "GIFMachine.h"

extern struct GIFdescriptor gdesc;
EXTERNBITPLANE;

extern char *AbortMsg;

void DoXFlip(void)
{
	register UWORD x1;
	register UWORD x2;
	register UWORD y;
	struct RGB TempColourStore;

	MyPrintf("...Flipping image %s.\n......%s ", "horizontally", "Line");

        for (y = 0; y < gdesc.gd_Height; y++) {
		MyPrintf("%5ld", y);

		for (x1 = 0, x2 = gdesc.gd_Width - 1; x1 < x2; x1++, x2--) {
			TempColourStore = BitPlane[y][x1];
			BitPlane[y][x1] = BitPlane[y][x2];
			BitPlane[y][x2] = TempColourStore;
		}

		if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
			MyPrintf("\n%s", AbortMsg);
			MyExit(ABORTEXITVAL);
		}

		PutStr("\x9B" "5D");
	}

	MyPrintf("\x9B" "%sDFlipped.    \n", "5");
}

void DoYFlip(void)
{
	register UWORD y1;
	register UWORD y2;
	register UWORD x;
	struct RGB TempColourStore;

	MyPrintf("...Flipping image %s.\n......%s ", "vertically", "Column");

        for (x = 0; x < gdesc.gd_Width; x++) {
		MyPrintf("%5ld", x);

		for (y1 = 0, y2 = gdesc.gd_Height - 1; y1 < y2; y1++, y2--) {
			TempColourStore = BitPlane[y1][x];
			BitPlane[y1][x] = BitPlane[y2][x];
			BitPlane[y2][x] = TempColourStore;
		}

		if (SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
			MyPrintf("\n%s", AbortMsg);
			MyExit(ABORTEXITVAL);
		}

		PutStr("\x9B" "5D");
	}

	MyPrintf("\x9B" "%sDFlipped.    \n", "7");
}
