/* Copyright (c) 2022 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __Grid_H__ #define __Grid_H__ #ifdef __cplusplus extern "C" { #endif // Performs an intersection test between the two specified rectangles, and writes values to ioWidth, ioHeight, // outStartX, and outStartY that enclose a safe region of the source grid that can be read for copying to the // target grid at the specified location, without overrunning either source or target's bounds. void clampGridCopyRegion(int sourceX, int sourceY, int targetX, int targetY, unsigned int sourceWidth, unsigned int sourceHeight, unsigned int targetWidth, unsigned int targetHeight, unsigned int * ioWidth, unsigned int * ioHeight, unsigned int * outStartX, unsigned int * outStartY); // Results are undefined if target overlaps source void copyGridCells(void * target, void * source, unsigned int sourceWidth, unsigned int sourceHeight, unsigned int targetWidth, unsigned int targetHeight, unsigned int bytesPerCell, int sourceX, int sourceY, int targetX, int targetY, unsigned int copyWidth, unsigned int copyHeight); // Transforms cells in place. For 90 degree rotations, transpose width and height after calling the rotate function. void flipGridHorizontal(void * cells, unsigned int width, unsigned int height, unsigned int bytesPerCell); void flipGridVertical(void * cells, unsigned int width, unsigned int height, unsigned int bytesPerCell); void rotateGrid90CW(void * cells, unsigned int width, unsigned int height, unsigned int bytesPerCell); void rotateGrid90CCW(void * cells, unsigned int width, unsigned int height, unsigned int bytesPerCell); void rotateGrid180(void * cells, unsigned int width, unsigned int height, unsigned int bytesPerCell); #ifdef __cplusplus } #endif #endif