Thread: Avisynth+
View Single Post
Old 6th January 2019, 00:19   #4383  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by davidhorman View Post
What are hints, and how are they implemented?
Dont know much about this (I'm sure someone will correct if wrong), but think that the hints are 64 bits encoded in LSB (Least Significant Bit) of the top LHS row of 64 pixels. [what they represent, I dont know, I guess is implementation defined (maybe in luma channel only, dont know)].

EDIT: Methinks that DGIndex embeds some hint stuff, maybe see source. (also TFM I think).

EDIT: Here from DGindex source (looks like only storing 32 bits of colorimetry data there [with additional 32 bits of magic number to signify valid hint]).

Utilities.h
Code:
bool PutHintingData(unsigned char *video, unsigned int hint);
bool GetHintingData(unsigned char *video, unsigned int *hint);

#define HINT_INVALID 0x80000000
#define PROGRESSIVE  0x00000001
#define IN_PATTERN   0x00000002
#define COLORIMETRY  0x0000001C
#define COLORIMETRY_SHIFT  2
Utilities.cpp

Code:
#include <windows.h>

#define MAGIC_NUMBER (0xdeadbeef)

bool PutHintingData(unsigned char *video, unsigned int hint)
{
	unsigned char *p;
	unsigned int i, magic_number = MAGIC_NUMBER;
	bool error = false;

	p = video;
	for (i = 0; i < 32; i++)
	{
		*p &= ~1; 
		*p++ |= ((magic_number & (1 << i)) >> i);    // 1st 32 bits of Magic number validity flag
	}
	for (i = 0; i < 32; i++)
	{
		*p &= ~1;
		*p++ |= ((hint & (1 << i)) >> i);            // 2nd 32 bits of colorimetry data
	}
	return error;
}

bool GetHintingData(unsigned char *video, unsigned int *hint)
{
	unsigned char *p;
	unsigned int i, magic_number = 0;
	bool error = false;

	p = video;
	for (i = 0; i < 32; i++)
	{
		magic_number |= ((*p++ & 1) << i);
	}
	if (magic_number != MAGIC_NUMBER)
	{
		error = true;
	}
	else
	{
		*hint = 0;
		for (i = 0; i < 32; i++)
		{
			*hint |= ((*p++ & 1) << i);
		}
	}
	return error;
}
AvisynthAPI.cpp
Code:
PVideoFrame __stdcall MPEG2Source::GetFrame(int n, IScriptEnvironment* env)
{
	int gop, pct;
	char Matrix_s[40];
	unsigned int raw;
	unsigned int hint;

...

	else if (m_decoder.info == 3)
	{
		hint = 0;
		if (m_decoder.FrameList[raw].pf == 1) hint |= PROGRESSIVE;
		hint |= ((m_decoder.GOPList[gop]->matrix & 7) << COLORIMETRY_SHIFT);
		PutHintingData(frame->GetWritePtr(PLANAR_Y), hint);
	}
}
EDIT: The hint encoder/decoder would be in the duplicated DGDecode.dll source.
EDIT: GetHintingData() seems not to be used in DGIndex source code, (probably some duplication in DGDecode::Mpeg2Source).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 6th January 2019 at 04:19.
StainlessS is offline