/strigi-0.7.7/libstreamanalyzer/lib/endanalyzers/bmpendanalyzer.cpp
C++ | 132 lines | 60 code | 7 blank | 65 comment | 13 complexity | f259ad8afd29729ee44b88b8daff26ed MD5 | raw file
Possible License(s): LGPL-2.0
1/* This file is part of Strigi Desktop Search
2 *
3 * Copyright (C) 2006 Jos van den Oever <jos@vandenoever.info>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#include "bmpendanalyzer.h"
21#include <strigi/strigiconfig.h>
22#include <strigi/analysisresult.h>
23#include <strigi/fieldtypes.h>
24#include <strigi/textutils.h>
25#include <sstream>
26#include <cstring>
27using namespace std;
28using namespace Strigi;
29
30void
31BmpEndAnalyzerFactory::registerFields(FieldRegister& reg) {
32 typeField = reg.registerField(
33 "http://freedesktop.org/standards/xesam/1.0/core#formatSubtype");
34 compressionField = reg.registerField(
35 "http://freedesktop.org/standards/xesam/1.0/core#compressionAlgorithm");
36 widthField = reg.registerField(
37 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width");
38 heightField = reg.registerField(
39 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height");
40 colorDepthField = reg.registerField(
41 "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#colorDepth");
42 rdftypeField = reg.typeField;
43
44 addField(typeField);
45 addField(compressionField);
46 addField(widthField);
47 addField(heightField);
48 addField(colorDepthField);
49 addField(rdftypeField);
50}
51
52bool
53BmpEndAnalyzer::checkHeader(const char* header, int32_t headersize) const {
54 bool ok = false;
55 if (headersize > 2) {
56 ok = strncmp(header, "BM", 2) == 0
57 || strncmp(header, "BA", 2) == 0
58 || strncmp(header, "CI", 2) == 0
59 || strncmp(header, "CP", 2) == 0
60 || strncmp(header, "IC", 2) == 0
61 || strncmp(header, "PT", 2) == 0;
62 }
63 return ok;
64}
65signed char
66BmpEndAnalyzer::analyze(AnalysisResult& rs, InputStream* in) {
67 // read BMP file type and ensure it is not damaged
68 /*
69 const char * bmptype_bm = "BM";
70 const char * bmptype_ba = "BA";
71 const char * bmptype_ci = "CI";
72 const char * bmptype_cp = "CP";
73 const char * bmptype_ic = "IC";
74 const char * bmptype_pt = "PT";
75 */
76
77 const char* bmp_id;
78 in->read(bmp_id, 2, 2);
79 in->reset(0);
80/* //FIXME: either get rid of this or replace with NIE equivalent
81 if (memcmp(bmp_id, bmptype_bm, 2) == 0) {
82 rs.addValue(factory->typeField, "Windows Bitmap");
83 } else if (memcmp(bmp_id, bmptype_ba, 2) == 0) {
84 rs.addValue(factory->typeField, "OS/2 Bitmap Array");
85 } else if (memcmp(bmp_id, bmptype_ci, 2) == 0) {
86 rs.addValue(factory->typeField, "OS/2 Color Icon");
87 } else if (memcmp(bmp_id, bmptype_cp, 2) == 0) {
88 rs.addValue(factory->typeField, "OS/2 Color Pointer");
89 } else if (memcmp(bmp_id, bmptype_ic, 2) == 0) {
90 rs.addValue(factory->typeField, "OS/2 Icon");
91 } else if (memcmp(bmp_id, bmptype_pt, 2) == 0) {
92 rs.addValue(factory->typeField, "OS/2 Pointer");
93 } else {
94 return -1;
95 }
96*/
97 // read compression type (bytes #30-33)
98 const char* h;
99 int32_t n = in->read(h, 34, 34);
100 in->reset(0);
101 if (n < 34) return -1;
102
103 uint32_t width = readLittleEndianUInt32(h+18);
104 rs.addValue(factory->widthField, width);
105 uint32_t height = readLittleEndianUInt32(h+22);
106 rs.addValue(factory->heightField, height);
107 uint32_t colorDepth = readLittleEndianUInt16(h+28);
108 rs.addValue(factory->colorDepthField, colorDepth);
109/* //FIXME: either get rid of this or replace with NIE equivalent
110 uint32_t bmpi_compression = readLittleEndianUInt32(h+30);
111 switch (bmpi_compression) {
112 case 0 :
113 rs.addValue(factory->compressionField, "None");
114 break;
115 case 1 :
116 rs.addValue(factory->compressionField, "RLE 8bit/pixel");
117 break;
118 case 2 :
119 rs.addValue(factory->compressionField, "RLE 4bit/pixel");
120 break;
121 case 3 :
122 rs.addValue(factory->compressionField, "Bitfields");
123 break;
124 default :
125 rs.addValue(factory->compressionField, "Unknown");
126 }
127*/
128 rs.addValue(factory->rdftypeField, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#RasterImage");
129
130 return 0;
131}
132