﻿/* bcdec.h - v0.94
   provides functions to decompress blocks of BC compressed images
   written by Sergii "iOrange" Kudlai in 2022
   This library does not allocate memory and is trying to use as less stack as possible
   The library was never optimized specifically for speed but for the overall size
   it has zero external dependencies and is not using any runtime functions
   Supported BC formats:
   BC1 (also known as DXT1) + it's "binary alpha" variant BC1A (DXT1A)
   BC2 (also known as DXT3)
   BC3 (also known as DXT5)
   BC4 (also known as ATI1N)
   BC5 (also known as ATI2N)
   BC6H (HDR format)
   BC7
   BC1/BC2/BC3/BC7 are expected to decompress into 4*4 RGBA blocks 8bit per component (32bit pixel)
   BC4/BC5 are expected to decompress into 4*4 R/RG blocks 8bit per component (8bit and 16bit pixel)
   BC6H is expected to decompress into 4*4 RGB blocks of either 32bit float or 16bit "half" per
   component (96bit or 48bit pixel)
   For more info, issues and suggestions please visit https://github.com/iOrange/bcdec
   CREDITS:
	  Aras Pranckevicius (@aras-p)      - BC1/BC3 decoders optimizations (up to 3x the speed)
										- BC6H/BC7 bits pulling routines optimizations
										- Split BC6H decompression function into 'half' and
										  'float' variants
   LICENSE: See end of file for license information.
*/


/*  Used information sources:
	https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-resources-block-compression
	https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc6h-format
	https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc7-format
	https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc7-format-mode-reference
	! WARNING ! Khronos's BPTC partitions tables contain mistakes, do not use them!
	https://www.khronos.org/registry/DataFormat/specs/1.1/dataformat.1.1.html#BPTC
	! Use tables from here instead !
	https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_compression_bptc.txt
	Leaving it here as it's a nice read
	https://fgiesen.wordpress.com/2021/10/04/gpu-bcn-decoding/
	Fast half to float function from here
	https://gist.github.com/rygorous/2144712
*/