PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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>
  27. using namespace std;
  28. using namespace Strigi;
  29. void
  30. BmpEndAnalyzerFactory::registerFields(FieldRegister& reg) {
  31. typeField = reg.registerField(
  32. "http://freedesktop.org/standards/xesam/1.0/core#formatSubtype");
  33. compressionField = reg.registerField(
  34. "http://freedesktop.org/standards/xesam/1.0/core#compressionAlgorithm");
  35. widthField = reg.registerField(
  36. "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#width");
  37. heightField = reg.registerField(
  38. "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#height");
  39. colorDepthField = reg.registerField(
  40. "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#colorDepth");
  41. rdftypeField = reg.typeField;
  42. addField(typeField);
  43. addField(compressionField);
  44. addField(widthField);
  45. addField(heightField);
  46. addField(colorDepthField);
  47. addField(rdftypeField);
  48. }
  49. bool
  50. BmpEndAnalyzer::checkHeader(const char* header, int32_t headersize) const {
  51. bool ok = false;
  52. if (headersize > 2) {
  53. ok = strncmp(header, "BM", 2) == 0
  54. || strncmp(header, "BA", 2) == 0
  55. || strncmp(header, "CI", 2) == 0
  56. || strncmp(header, "CP", 2) == 0
  57. || strncmp(header, "IC", 2) == 0
  58. || strncmp(header, "PT", 2) == 0;
  59. }
  60. return ok;
  61. }
  62. signed char
  63. BmpEndAnalyzer::analyze(AnalysisResult& rs, InputStream* in) {
  64. // read BMP file type and ensure it is not damaged
  65. /*
  66. const char * bmptype_bm = "BM";
  67. const char * bmptype_ba = "BA";
  68. const char * bmptype_ci = "CI";
  69. const char * bmptype_cp = "CP";
  70. const char * bmptype_ic = "IC";
  71. const char * bmptype_pt = "PT";
  72. */
  73. const char* bmp_id;
  74. in->read(bmp_id, 2, 2);
  75. in->reset(0);
  76. /* //FIXME: either get rid of this or replace with NIE equivalent
  77. if (memcmp(bmp_id, bmptype_bm, 2) == 0) {
  78. rs.addValue(factory->typeField, "Windows Bitmap");
  79. } else if (memcmp(bmp_id, bmptype_ba, 2) == 0) {
  80. rs.addValue(factory->typeField, "OS/2 Bitmap Array");
  81. } else if (memcmp(bmp_id, bmptype_ci, 2) == 0) {
  82. rs.addValue(factory->typeField, "OS/2 Color Icon");
  83. } else if (memcmp(bmp_id, bmptype_cp, 2) == 0) {
  84. rs.addValue(factory->typeField, "OS/2 Color Pointer");
  85. } else if (memcmp(bmp_id, bmptype_ic, 2) == 0) {
  86. rs.addValue(factory->typeField, "OS/2 Icon");
  87. } else if (memcmp(bmp_id, bmptype_pt, 2) == 0) {
  88. rs.addValue(factory->typeField, "OS/2 Pointer");
  89. } else {
  90. return -1;
  91. }
  92. */
  93. // read compression type (bytes #30-33)
  94. const char* h;
  95. int32_t n = in->read(h, 34, 34);
  96. in->reset(0);
  97. if (n < 34) return -1;
  98. uint32_t width = readLittleEndianUInt32(h+18);
  99. rs.addValue(factory->widthField, width);
  100. uint32_t height = readLittleEndianUInt32(h+22);
  101. rs.addValue(factory->heightField, height);
  102. uint32_t colorDepth = readLittleEndianUInt16(h+28);
  103. rs.addValue(factory->colorDepthField, colorDepth);
  104. /* //FIXME: either get rid of this or replace with NIE equivalent
  105. uint32_t bmpi_compression = readLittleEndianUInt32(h+30);
  106. switch (bmpi_compression) {
  107. case 0 :
  108. rs.addValue(factory->compressionField, "None");
  109. break;
  110. case 1 :
  111. rs.addValue(factory->compressionField, "RLE 8bit/pixel");
  112. break;
  113. case 2 :
  114. rs.addValue(factory->compressionField, "RLE 4bit/pixel");
  115. break;
  116. case 3 :
  117. rs.addValue(factory->compressionField, "Bitfields");
  118. break;
  119. default :
  120. rs.addValue(factory->compressionField, "Unknown");
  121. }
  122. */
  123. rs.addValue(factory->rdftypeField, "http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#RasterImage");
  124. return 0;
  125. }