[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/strigi/src/streamanalyzer/endanalyzers
From: Vincent Ricard <magic () magicninja ! org>
Date: 2007-03-31 20:52:33
Message-ID: 1175374353.380193.15364.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 648617 by ricard:
extract all metadata described in the PNG specfication.
Remaining issues:
- parse the "Creation Time" format
- convert the iso-latin-1 to utf-8 for the tEXt chuncks
- there is a problem with some compressed fields (e.g. Description value in \
/usr/share/apps/kdm/pics/users/Apple.png)
M +68 -4 pngendanalyzer.cpp
M +22 -0 pngendanalyzer.h
--- trunk/kdesupport/strigi/src/streamanalyzer/endanalyzers/pngendanalyzer.cpp \
#648616:648617 @@ -39,6 +39,16 @@
const string PngEndAnalyzerFactory::compressionFieldName("compression");
const string PngEndAnalyzerFactory::interlaceModeFieldName("interlaceMode");
const string PngEndAnalyzerFactory::lastModificationTimeFieldName("lastModificationTime");
+const string PngEndAnalyzerFactory::titleFieldName("title");
+const string PngEndAnalyzerFactory::authorFieldName("author");
+const string PngEndAnalyzerFactory::descriptionFieldName("description");
+const string PngEndAnalyzerFactory::copyrightFieldName("copyright");
+const string PngEndAnalyzerFactory::creationTimeFieldName("creationTime");
+const string PngEndAnalyzerFactory::softwareFieldName("software");
+const string PngEndAnalyzerFactory::disclaimerFieldName("disclaimer");
+const string PngEndAnalyzerFactory::warningFieldName("warning");
+const string PngEndAnalyzerFactory::sourceFieldName("source");
+const string PngEndAnalyzerFactory::commentFieldName("comment");
// and for the colors
static const char* colors[] = {
@@ -58,8 +68,8 @@
void
PngEndAnalyzerFactory::registerFields(FieldRegister& reg) {
- widthField
- = reg.registerField(widthFieldName, FieldRegister::integerType, 1, 0);
+ widthField = reg.registerField(widthFieldName,
+ FieldRegister::integerType, 1, 0);
heightField = reg.registerField(heightFieldName,
FieldRegister::integerType, 1, 0);
colorDepthField = reg.registerField(colorDepthFieldName,
@@ -72,6 +82,26 @@
FieldRegister::integerType, 1, 0);
lastModificationTimeField = reg.registerField(lastModificationTimeFieldName,
FieldRegister::integerType, 1, 0);
+ titleField = reg.registerField(titleFieldName,
+ FieldRegister::stringType, 1, 0);
+ authorField = reg.registerField(authorFieldName,
+ FieldRegister::stringType, 1, 0);
+ descriptionField = reg.registerField(descriptionFieldName,
+ FieldRegister::stringType, 1, 0);
+ copyrightField = reg.registerField(copyrightFieldName,
+ FieldRegister::stringType, 1, 0);
+ creationTimeField = reg.registerField(creationTimeFieldName,
+ FieldRegister::integerType, 1, 0);
+ softwareField = reg.registerField(softwareFieldName,
+ FieldRegister::stringType, 1, 0);
+ disclaimerField = reg.registerField(disclaimerFieldName,
+ FieldRegister::stringType, 1, 0);
+ warningField = reg.registerField(warningFieldName,
+ FieldRegister::stringType, 1, 0);
+ sourceField = reg.registerField(sourceFieldName,
+ FieldRegister::stringType, 1, 0);
+ commentField = reg.registerField(commentFieldName,
+ FieldRegister::stringType, 1, 0);
}
PngEndAnalyzer::PngEndAnalyzer(const PngEndAnalyzerFactory* f) :factory(f) {
@@ -216,8 +246,9 @@
int32_t nlen = 0;
while (nlen < nread && c[nlen]) nlen++;
if (nlen == nread) return -1;
- string name(c, nlen); // do something with the name!
+ const string name(c, nlen); // do something with the name!
in->reset(nlen+1);
+ addMetaData(name, as, in);
TextEndAnalyzer tea;
return tea.analyze(as, in);
}
@@ -233,9 +264,10 @@
int32_t nlen = 0;
while (nlen < nread && c[nlen]) nlen++;
if (nlen == nread) return -1;
- string name(c, nlen); // do something with the name!
+ const string name(c, nlen); // do something with the name!
in->reset(nlen+2);
GZipInputStream z(in, GZipInputStream::ZLIBFORMAT);
+ addMetaData(name, as, &z);
TextEndAnalyzer tea;
return tea.analyze(as, &z);
}
@@ -277,3 +309,35 @@
// If someone has a better solution...
return sinceEpoch + timeZoneOffset;
}
+void
+PngEndAnalyzer::addMetaData(const string& key,
+ Strigi::AnalysisResult& as, InputStream* in) {
+ const char* b;
+ // try to store the whole buffer
+ int32_t nread = in->read(b, 0, 80);
+ if (0 < nread) {
+ const string value(b, nread);
+ if ("Title" == key) {
+ as.addValue(factory->titleField, value);
+ } else if ("Author" == key) {
+ as.addValue(factory->authorField, value);
+ } else if ("Description" == key) {
+ as.addValue(factory->descriptionField, value);
+ } else if ("Copyright" == key) {
+ as.addValue(factory->copyrightField, value);
+ } else if ("Creation Time" == key) {
+ // TODO we need to parse the date time
+ // "[...]the date format defined in section 5.2.14 of RFC 1123[...]"
+ } else if ("Software" == key) {
+ as.addValue(factory->softwareField, value);
+ } else if ("Disclaimer" == key) {
+ as.addValue(factory->disclaimerField, value);
+ } else if ("Warning" == key) {
+ as.addValue(factory->warningField, value);
+ } else if ("Source" == key) {
+ as.addValue(factory->sourceField, value);
+ } else if ("Comment" == key) {
+ as.addValue(factory->commentField, value);
+ }
+ }
+}
--- trunk/kdesupport/strigi/src/streamanalyzer/endanalyzers/pngendanalyzer.h \
#648616:648617 @@ -31,6 +31,8 @@
char analyze(Strigi::AnalysisResult& idx, Strigi::InputStream* in);
const char* name() const { return "PngEndAnalyzer"; }
int32_t extractTime(const char* chunck);
+ void addMetaData(const std::string& key, Strigi::AnalysisResult& as,
+ Strigi::InputStream* in);
/*
Internal function called to analyze text embedded in the png.
Such text has a special format: 79 bytes of header, a \0 and content
@@ -52,6 +54,16 @@
static const std::string compressionFieldName;
static const std::string interlaceModeFieldName;
static const std::string lastModificationTimeFieldName;
+ static const std::string titleFieldName;
+ static const std::string authorFieldName;
+ static const std::string descriptionFieldName;
+ static const std::string copyrightFieldName;
+ static const std::string creationTimeFieldName;
+ static const std::string softwareFieldName;
+ static const std::string disclaimerFieldName;
+ static const std::string warningFieldName;
+ static const std::string sourceFieldName;
+ static const std::string commentFieldName;
const Strigi::RegisteredField* widthField;
const Strigi::RegisteredField* heightField;
const Strigi::RegisteredField* colorDepthField;
@@ -59,6 +71,16 @@
const Strigi::RegisteredField* compressionField;
const Strigi::RegisteredField* interlaceModeField;
const Strigi::RegisteredField* lastModificationTimeField;
+ const Strigi::RegisteredField* titleField;
+ const Strigi::RegisteredField* authorField;
+ const Strigi::RegisteredField* descriptionField;
+ const Strigi::RegisteredField* copyrightField;
+ const Strigi::RegisteredField* creationTimeField;
+ const Strigi::RegisteredField* softwareField;
+ const Strigi::RegisteredField* disclaimerField;
+ const Strigi::RegisteredField* warningField;
+ const Strigi::RegisteredField* sourceField;
+ const Strigi::RegisteredField* commentField;
const char* name() const {
return "PngEndAnalyzer";
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic