#include <yuvCaptureLayout.h>
#include <stdexcept>

namespace smo {
namespace stim_buff {
namespace lcamera_buff {

YuvCaptureLayoutPath classifyYuvCaptureLayoutPath(
	const lcamera_dev::LcameraDevConfiguredCameraMode& configuredMode)
{
	if (configuredMode.isFullyPlanar && configuredMode.planeCount == 3u) {
		return YuvCaptureLayoutPath::FullPlanarDirect;
	}

	if (configuredMode.planeCount == 2u) {
		return YuvCaptureLayoutPath::SemiPlanarDeinterleave;
	}

	if (configuredMode.planeCount == 1u) {
		return YuvCaptureLayoutPath::PackedDeinterleave;
	}

	throw std::runtime_error(
		"lcameraBuff: unsupported configured YUV layout: pixelFormat="
		+ configuredMode.pixelFormatName
		+ " planeCount=" + std::to_string(configuredMode.planeCount));
}

YuvChannelBackingPlan getChannelBackingPlanForLayoutPath(
	YuvCaptureLayoutPath layoutPath)
{
	switch (layoutPath)
	{
	case YuvCaptureLayoutPath::FullPlanarDirect:
		return YuvChannelBackingPlan::LCameraDirect;

	case YuvCaptureLayoutPath::SemiPlanarDeinterleave:
	case YuvCaptureLayoutPath::PackedDeinterleave:
		return YuvChannelBackingPlan::MmapDeinterleaved;
	}

	throw std::logic_error(
		"lcameraBuff: unhandled YuvCaptureLayoutPath in "
		"getChannelBackingPlanForLayoutPath");
}

} // namespace lcamera_buff
} // namespace stim_buff
} // namespace smo
