пятница, 18 июня 2010 г.

ID3 and Exif

ID3

/*
Section Name( Length=0, Offset=0,
BeginMarker=0, EndMarker=0 )

Offset= A // Абсолютное смещение
Offset= +A // Смещение вперед
Offset= -A // Смещение назад

-------------------------------------------------

Read ( Length=0, Offset=0,
BeginMarker=0, EndMarker=0 )

*/


Section ID3_Header( Offset=0, BeginMarker="ID3" )
{

Version = Read(1);
Revision = Read(1);
Flags = Read(1);
ID3Size = Read(4);

if (Flags[6])
{
Section ID3_ExtHeader()
{
ExtSize = Read(4);
ExtFlags = Read(2);
SizeOfPadding = Read(4);
}
Skip(ExtSize);
ID3Size -= (10+ExtSize);
}
}

Section Frames(Size=ID3Size)
{
for()
{
Section Frame_Header(Size=10)
{
Frame_ID = Read(4);
Frame_Size = Read(4);
Status = Read(1);
Enc = Read(1);
}

Switch (Frame_ID)
{
case "UFID": Frame_UFID(Frame_Size);
case "TIT2": Frame_TIT2(Frame_Size);

default: Skip(Frame_Size);
}
}
}


function ReadID3String(Enc)
{
if (Enc==0x01) return ReadUnicodeString();
else return ReadString();
}



//Unique file identifier
function Frame_UFID(Frame_Size)
{
Section (Size=Frame_Size)
{
Owner_Identifier = ReadString();
Identifier = Read( Frame_Size-SizeOf(Owner_Identifier) );
}
}


//The 'Title/Songname/Content description' frame is the actual name of the piece (e.g. "Adagio", "Hurricane Donna").
function Frame_TIT2(Frame_Size)
{
Section (Size=Frame_Size)
{
Text_Enc = Read(1);
Title2 = ReadID3String(Text_Enc);
}
}


Exif



/*
Section Name( Length=0, Offset=0,
BeginMarker=0, EndMarker=0 )

Offset= A // Абсолютное смещение
Offset= +A // Смещение вперед
Offset= -A // Смещение назад

-------------------------------------------------

Read ( Length=0, Offset=0,
BeginMarker=0, EndMarker=0 )

*/


Section APP1( Offset=0x02, BeginMarker=0xFFE1 )
{

// APP1Length = Read(Length=2);

APP1Length = Read(2);
Identifier = Read(5);
}

Section APP1_Body(Offset=+1, Size=APP1Length-8)
{
ByteOrder = Read(2);
IFD0_Offset = Read(4, Offset=4);

Section IFD0(Offset=IFD0_Offset)
{
NumberOfInteroperability = Read(2);


for(NumberOfInteroperability)
{
FillParam( Read(Param) );
}

NextIFDOffset = Read(2);
}

Section ExifIFD(Offset=ExifIFDPointer)
{

}
}




--------------------------------------------------------

structure Param
{
Tag(2),
Type(2),
Count(4),
ValueOrOffset(4)
}


function GetValue(Param)
{
Switch(Param.Type)
{
case 0x0200: return ReadString(Offset=Param.ValueOrOffset);
case 0x0500: return Read(8, Offset=Param.ValueOrOffset);
case 0x0300: return Param.ValueOrOffset;
case 0x0400: return Param.ValueOrOffset;
}
}



function FillParam(Param)
{

switch (Param.Tag)
{
case 0x0E01: ImageDescription = GetValue(Param);
case 0x0F01: Make = GetValue(Param);
case 0x1001: Model = GetValue(Param);
case 0x1201: Orientation = GetValue(Param);
case 0x1A01: XResolution = GetValue(Param);
case 0x1B01: YResolution = GetValue(Param);
case 0x2801: ResolutionUnit = GetValue(Param);
case 0x3201: DateTime = GetValue(Param);
case 0x1302: YCbCrPositioning = GetValue(Param);
case 0x9882: CopyRight = GetValue(Param);
case 0x6987: ExifIFDPointer = GetValue(Param);
}
}

Комментариев нет:

Отправить комментарий