среда, 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;
}

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

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