среда, 30 июня 2010 г.

Translator

Description of png file

Binary PNG;

ByteOrder=MSB;
BitOrder=MSB;

StartMetadataKey IHDR(offset=12, size=4);

checkKey(IHDR)="IHDR";

MetadataKey width(IHDR, offset=0, size=4);
SetTag Width(getNumber(width));

MetadataKey height(width, offset=0, size=4);
SetTag Height(getNumber(height));

MetadataKey ColorType(height, offset=0, size=1);
SetTag Color_type(getNumber(ColorType));

MetadataKey Compression(ColorType, offset=0, size=1);
SetTag Compression_method(getNumber(Compression));

MetadataKey Filter(Compression, offset=0, size=1);
SetTag Filter_method(getNumber(Filter));

MetadataKey Interlace(Filter, offset=0, size=1);
SetTag Interlace_method(getNumber(Interlace));


Is generated parser

#include "MetadataKey.h"
#include "Tag.h"
#include "MetadataFunc.h"
#include
#include


int main(){

std::ifstream is;
int DefaultByteOrder=ByteOrderMSB;
int DefaultBitOrder=BitOrderMSB;
MetadataKey ColorType;
MetadataKey Compression;
MetadataKey Filter;
MetadataKey Interlace;
MetadataKey height;
MetadataKey width;


std::vector TagArray;
is.open ("test.png", std::ifstream::in | std::ifstream::binary);
if (is.good()) {
MetadataKey IHDR(is);
IHDR.setOffset(12);
IHDR.setSize(4);
if(!checkKey(IHDR,"IHDR")) return -1;
width.setStream(is);
width.setBaseKey(IHDR);
width.setOffset(0);
width.setSize(4);
Tag t0;
t0.setName("Width" );
t0.setValue(width.getNumber(DefaultByteOrder));
TagArray.push_back(t0);
height.setStream(is);
height.setBaseKey(width);
height.setOffset(0);
height.setSize(4);
Tag t1;
t1.setName("Height" );
t1.setValue(height.getNumber(DefaultByteOrder));
TagArray.push_back(t1);
ColorType.setStream(is);
ColorType.setBaseKey(height);
ColorType.setOffset(0);
ColorType.setSize(1);
Tag t2;
t2.setName("Color_type" );
t2.setValue(ColorType.getNumber(DefaultByteOrder));
TagArray.push_back(t2);
Compression.setStream(is);
Compression.setBaseKey(ColorType);
Compression.setOffset(0);
Compression.setSize(1);
Tag t3;
t3.setName("Compression_method" );
t3.setValue(Compression.getNumber(DefaultByteOrder));
TagArray.push_back(t3);
Filter.setStream(is);
Filter.setBaseKey(Compression);
Filter.setOffset(0);
Filter.setSize(1);
Tag t4;
t4.setName("Filter_method" );
t4.setValue(Filter.getNumber(DefaultByteOrder));
TagArray.push_back(t4);
Interlace.setStream(is);
Interlace.setBaseKey(Filter);
Interlace.setOffset(0);
Interlace.setSize(1);
Tag t5;
t5.setName("Interlace_method" );
t5.setValue(Interlace.getNumber(DefaultByteOrder));
TagArray.push_back(t5);

}
return 0;
}

понедельник, 28 июня 2010 г.

Translator

Description of mp3 file

Binary ID3;

ByteOrder=MSB;
BitOrder=MSB;

StartMetadataKey ID3(offset=0, size=3);


checkKey(ID3)="ID3";

MetadataKey HeaderFlag(start, offset=5, size=1);

MetadataKey ID3_size(start, offset=6, size=4);

MetadataSize=getNumber(ID3_size);

if (getBit(HeaderFlag, 6)==1)
{
MetadataKey ExHeaderSize(start, offset=10, size=4);
MetadataKey FirstFrameID(start, offset=getNumber(ExHeaderSize)+10, size=4);
MetadataSize-=(10+getNumber(ExHeaderSize));
}
else
MetadataKey FirstFrameID(start, offset=10, size=4);

key=FirstFrameID;
while(MetadataSize>0)
{
MetadataKey sizeOfTag(key, offset=0, size=4);
if(getByte(key, 0)==0x00)
{
break;
}
else {
TagSize=getNumber(sizeOfTag);
if(getValue(key)=="TALB" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
SetTag Album(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TCOM" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Composer(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TDAT" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Date(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TRCK" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Track_number(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TIT2" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Title(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}
if(getValue(key)=="TENC" && (TagSize>1))
{
MetadataKey encoding(key, offset=6, size=1);
setTag Encoded_by(getStringByLink(encoding, offset=0, size=getNumber(sizeOfTag)-1));
}

MetadataSize-=(10+getNumber(sizeOfTag));
shift(key, 10+getNumber(sizeOfTag));
}

}

Is generated parser

#include "MetadataKey.h"
#include "Tag.h"
#include "MetadataFunc.h"
#include
#include


int main(){

std::ifstream is;
int DefaultByteOrder=ByteOrderMSB;
int DefaultBitOrder=BitOrderMSB;
MetadataKey ExHeaderSize;
MetadataKey FirstFrameID;
MetadataKey HeaderFlag;
MetadataKey ID3_size;
int MetadataSize;
int TagSize;
MetadataKey encoding;
MetadataKey key;
MetadataKey sizeOfTag;


std::vector TagArray;
is.open ("test.mp3", std::ifstream::in | std::ifstream::binary);
if (is.good()) {
MetadataKey ID3(is);
ID3.setOffset(0);
ID3.setSize(3);
if(!checkKey(ID3,"ID3")) return -1;
HeaderFlag.setStream(is);
HeaderFlag.setOffset(5);
HeaderFlag.setSize(1);
ID3_size.setStream(is);
ID3_size.setOffset(6);
ID3_size.setSize(4);
MetadataSize=ID3_size.getNumber(DefaultByteOrder);

if(HeaderFlag.getBit(6, DefaultBitOrder)==1){
ExHeaderSize.setStream(is);
ExHeaderSize.setOffset(10);
ExHeaderSize.setSize(4);
FirstFrameID.setStream(is);
FirstFrameID.setOffset(ExHeaderSize.getNumber(DefaultByteOrder)+10);
FirstFrameID.setSize(4);
MetadataSize-=(10+ExHeaderSize.getNumber(DefaultByteOrder));
}

else{
FirstFrameID.setStream(is);
FirstFrameID.setOffset(10);
FirstFrameID.setSize(4);
}
key=FirstFrameID;
while(MetadataSize>0){
sizeOfTag.setStream(is);
sizeOfTag.setBaseKey(key);
sizeOfTag.setOffset(0);
sizeOfTag.setSize(4);

if(key.getByte(0)==0x00){
break;}

else{
{
TagSize=sizeOfTag.getNumber(DefaultByteOrder);

if(key.getValue()=="TALB"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t0;
t0.setName("Album" );
t0.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t0);
}

if(key.getValue()=="TCOM"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t1;
t1.setName("Composer" );
t1.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t1);
}

if(key.getValue()=="TDAT"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t2;
t2.setName("Date" );
t2.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t2);
}

if(key.getValue()=="TRCK"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t3;
t3.setName("Track_number" );
t3.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t3);
}

if(key.getValue()=="TIT2"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t4;
t4.setName("Title" );
t4.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t4);
}

if(key.getValue()=="TENC"&&(TagSize>1)){
encoding.setStream(is);
encoding.setBaseKey(key);
encoding.setOffset(6);
encoding.setSize(1);
Tag t5;
t5.setName("Encoded_by" );
t5.setValue(getStringByLink(encoding,0,sizeOfTag.getNumber(DefaultByteOrder)-1));
TagArray.push_back(t5);
}
MetadataSize-=(10+sizeOfTag.getNumber(DefaultByteOrder));
key.setOffset(10+sizeOfTag.getNumber(DefaultByteOrder)+key.getSize());
}
}
}

}
return 0;
}

 

пятница, 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);
}
}

четверг, 10 июня 2010 г.

ID3

Binary ID3;

StartMetadataKey ID3(offset=0, size=3);

If(getValue(ID3)!=”ID3”) exit;

MetadataKye HeaderFlag(start, offset=3, size=1);

MeatdataKey ID3_size(start, offset=6, size=4);

MetadataSize=getValue(ID3_size);

 

If(getValue(HeaderFlag)[6])

{

                MetadataKey ExHeaderSize(start, offset=10, size=4);

                MetadataKey FirstFrameID(ExHeaderSize, offset=getValue(ExHeaderSize)+10, size=4);

                MetadataSize -=(10+getValue(ExHeaderSize));

}

Else

                MetadataKey FirstFrameID(start, offset=10, size=4);

Key=FirstFrameID;

While(MetadataSize>0)

{

                MetadataKey size(key, offset=4, size=4);

                If(getValue(key)==”TALB”)

                {

                               MetadataKey encoding(key, offset=10, size=1);

                               SetTag Album(getVakue(encoding) , getValueByLink(encoding, offset=1, size=getValue(size)-1));

                }

If(getValue(key)==”TCOM”)

                {

                               MetadataKey encoding(key, offset=10, size=1);

                               SetTag Composer(getVakue(encoding) , getValueByLink(encoding, offset=1, size=getValue(size)-1));

                }

                If(getValue(key)==”TDAT”)

                {

                               MetadataKey encoding(key, offset=10, size=1);

                               SetTag Date(getVakue(encoding) , getValueByLink(encoding, offset=1, size=getValue(size)-1));

                }

 

                MetadataSize -=(10+getValue(size));

                MetadataKey newKey(key, offset=10+geValue(size), size=4);

                Key=newKey;

}

Exif

Binary Exif;

StartMetadataKey APP1_Marker(offset=2, size=2);

If(getValue(APP1_Marker)!=0xFFE1) exit;

MetadataKey Length(APP1_Marker, offset=2, size=2);

MetadataKey APP1(APP1_Marker, offset=10, size=getValue(Length));

MetadataKey IFD_Offset(APP1, offset=4, size=4);

MetadataKey CountOfTag(APP1, offset-getValue(IDF_Offset), size=2);

MetadataKey FirstTagID(CountOfTag, offset=2, size=2);

MetadataKey TagID=FirstTagID;

count=getValue(CountOgTag));

While(coun>0)

{

                MetadataKey Type(TagID, offset=2, size=2);

MetadataKey ValueOffset(TagID, offset=8, size=4);

If(getValue(TagID)==0x0E01)

                {

                               If(getValue(Type)==0x200)  SetTag ImageDescription(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag ImageDescription(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag ImageDescription(0x01, getValue(ValueOffset));

                }

If(getValue(TagID)==0x0F01)

                {

                               If(getValue(Type)==0x200)  SetTag Make (0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag Make(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag Make (0x01, getValue(ValueOffset));

                }

If(getValue(TagID)==0x1001)

                {

                               If(getValue(Type)==0x200)  SetTag Model(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag Model(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag Model(0x01, getValue(ValueOffset));

}

If(getValue(TagID)==0x1201)

                {

                               If(getValue(Type)==0x200)  SetTag Orientation(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag Orientation0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag Orientation(0x01, getValue(ValueOffset));

                }

If(getValue(TagID)==0x1A01)

                {

                               If(getValue(Type)==0x200)  SetTag XResolution(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag XResolution (0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag XResolution (0x01, getValue(ValueOffset));

                }

If(getValue(TagID)==0x1B01)

                {

                               If(getValue(Type)==0x200)  SetTag YResolution(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag YResolution (0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag YResolution (0x01, getValue(ValueOffset));

                }

If(getValue(TagID)==0x3201)

                {

                               If(getValue(Type)==0x200)  SetTag DateTime(0x01, getValueByLink(TagID,offset=getValue(ValueOffset), key=00));

                               If(getValue(Type)==0x500) SetTag DateTime (0x01, getValueByLink(TagID,offset=getValue(ValueOffset), size=8));

if(tag.Type==0x0100 || tag.Type==0x0300 || tag.Type==0x0400)SetTag DateTime(0x01, getValue(ValueOffset));

                }

                count-=1;

                Metadatakey newTagID(TagID, offset=12, size=2);

                TagID=newTadIG;

}