Как я скрестил JPEG, GIF и получил VP9

29d9673fa5c1425e465f954b5cc062b7
//Собирается OpenWatcom 1.9 как Win32 текстовое консольное приложение.
#include 
#include 
#include 

#define max(a,b)  (((a) > (b)) ? (a) : (b))
#define min(a,b)  (((a) < (b)) ? (a) : (b))

//double Stat2D[8][8]={0}, Stat3D[8][8][8]={0};
//int Count2D=0, Count3D=0;

double CosFreq[8][8] = {
	1, 1, 1, 1, 1, 1, 1, 1, 
	0.980785, 0.83147, 0.55557, 0.19509, -0.19509, -0.55557, -0.83147, -0.980785, 
	0.92388, 0.382683, -0.382683, -0.92388, -0.92388, -0.382683, 0.382683, 0.92388, 
	0.83147, -0.19509, -0.980785, -0.55557, 0.55557, 0.980785, 0.19509, -0.83147, 
	0.707107, -0.707107, -0.707107, 0.707107, 0.707107, -0.707107, -0.707107, 0.707107, 
	0.55557, -0.980785, 0.19509, 0.83147, -0.83147, -0.19509, 0.980785, -0.55557, 
	0.382683, -0.92388, 0.92388, -0.382683, -0.382683, 0.92388, -0.92388, 0.382683, 
	0.19509, -0.55557, 0.83147, -0.980785, 0.980785, -0.83147, 0.55557, -0.19509 };

double AlphaNorm[8] = {1.4142135623730950488016887242097, 1, 1, 1, 1, 1, 1, 1};

static double PreCalcCoeffs[512][512];

double round (double FuckinWatcomLibrary)
{
	if (FuckinWatcomLibrary<0) return ceil (FuckinWatcomLibrary - .5);
	return floor (FuckinWatcomLibrary + .5);
}

char* ReadBMP (char *Name, int *XSize, int *YSize, void *Colormap, int Restrictions)
{
	#pragma pack(push)
	#pragma pack(0)
		struct
		{
			short Id;
			long FSize, Ver, DataOffset, Unused, Width, Height;
			short WTF, BPP;
			long Compr; //0 for uncompressed, 1,2 for RLE
			long DataSize,   XRes, YRes, PalSize, Unused2;
		//	char Palette[256][4];
			char Palette[2][4];
		} BmpHeader;
	#pragma pack(pop)
	fstream f;
	char *Raw, *P;
	int line, netto, brutto;

	f.open (Name, ios::in|ios::binary);
	if (f.fail()) return NULL;
	f.read ((char*)&BmpHeader, sizeof (BmpHeader));
	if (f.fail()) {f.close(); return NULL;}
	if (BmpHeader.Id!=0x4D42) {f.close(); return NULL;}	//Wrong BMP id!
	if (BmpHeader.Compr) {f.close(); return NULL;}	//Compressed files are not supported
	*XSize = BmpHeader.Width;
	*YSize = BmpHeader.Height;
	f.seekg(BmpHeader.DataOffset);

	switch (BmpHeader.BPP)
	{
		case 24:
			netto = BmpHeader.Width*3;
			brutto = (netto + 3) & ~3;
			Raw = (char*)malloc(BmpHeader.Height*netto);
			if (!Raw) {f.close(); return NULL;}
			for (line=0,P=Raw; line255) cout<<"Quant. error: "<

© Habrahabr.ru