#include "util.h"

namespace UTIL
{
	void flip_surface(SDL_Surface* surface)
	{
		SDL_LockSurface(surface);

		int pitch = surface->pitch;
		char* temp = new char[pitch];
		char* pixels = (char*)surface->pixels;

		for (int i = 0; i < surface->h / 2; i++)
		{
			char* row1 = pixels + i * pitch;
			char* row2 = pixels + (surface->h - i - 1) * pitch;

			SDL_memcpy(temp, row1, pitch);
			SDL_memcpy(row1, row2, pitch);
			SDL_memcpy(row2, temp, pitch);
		}
		delete[] temp;
		SDL_UnlockSurface(surface);
	}

	std::string parsePrefix(const std::string& id)
	{
		std::string prefix;
		size_t left = 0;
		size_t right = 0;
		UTIL::split(id, &left, &right, &prefix);
		prefix += "/";
		UTIL::split(id, &left, &right, &prefix);

		return prefix;
	}
}
