1 /* 2 RawSpeed - RAW file decoder. 3 4 Copyright (C) 2009-2014 Klaus Post 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 #pragma once 22 23 #include "rawspeedconfig.h" // for HAVE_PUGIXML 24 #include "common/Point.h" // for iPoint2D 25 #include "metadata/BlackArea.h" // for BlackArea 26 #include "metadata/CameraSensorInfo.h" // for CameraSensorInfo 27 #include "metadata/ColorFilterArray.h" // for ColorFilterArray, CFAColor 28 #include <cstdint> // for uint32_t 29 #include <map> // for map, operator!=, _Rb_tree_con... 30 #include <sstream> // for istringstream 31 #include <string> // for string, basic_string, operator== 32 #include <utility> // for pair 33 #include <vector> // for vector 34 35 #ifdef HAVE_PUGIXML 36 37 namespace pugi { 38 class xml_node; 39 } // namespace pugi 40 41 #endif 42 43 namespace rawspeed { 44 45 class Hints 46 { 47 std::map<std::string, std::string> data; 48 public: add(const std::string & key,const std::string & value)49 void add(const std::string& key, const std::string& value) 50 { 51 data.insert({key, value}); 52 } 53 has(const std::string & key)54 [[nodiscard]] bool has(const std::string& key) const { 55 return data.find(key) != data.end(); 56 } 57 58 template <typename T> get(const std::string & key,T defaultValue)59 [[nodiscard]] T get(const std::string& key, T defaultValue) const { 60 auto hint = data.find(key); 61 if (hint != data.end() && !hint->second.empty()) { 62 std::istringstream iss(hint->second); 63 iss >> defaultValue; 64 } 65 return defaultValue; 66 } 67 get(const std::string & key,bool defaultValue)68 [[nodiscard]] bool get(const std::string& key, bool defaultValue) const { 69 auto hint = data.find(key); 70 if (hint == data.end()) 71 return defaultValue; 72 return "true" == hint->second; 73 } 74 }; 75 76 class Camera 77 { 78 public: 79 #ifdef HAVE_PUGIXML 80 explicit Camera(const pugi::xml_node& camera); 81 #endif 82 83 Camera(const Camera* camera, uint32_t alias_num); 84 [[nodiscard]] const CameraSensorInfo* getSensorInfo(int iso) const; 85 std::string make; 86 std::string model; 87 std::string mode; 88 std::string canonical_make; 89 std::string canonical_model; 90 std::string canonical_alias; 91 std::string canonical_id; 92 std::vector<std::string> aliases; 93 std::vector<std::string> canonical_aliases; 94 ColorFilterArray cfa; 95 bool supported; 96 iPoint2D cropSize; 97 iPoint2D cropPos; 98 std::vector<BlackArea> blackAreas; 99 std::vector<CameraSensorInfo> sensorInfo; 100 int decoderVersion; 101 Hints hints; 102 protected: 103 static const std::map<char, CFAColor> char2enum; 104 static const std::map<std::string, CFAColor> str2enum; 105 106 #ifdef HAVE_PUGIXML 107 void parseCFA(const pugi::xml_node &node); 108 void parseCrop(const pugi::xml_node &node); 109 void parseBlackAreas(const pugi::xml_node &node); 110 void parseAliases(const pugi::xml_node &node); 111 void parseHints(const pugi::xml_node &node); 112 void parseID(const pugi::xml_node &node); 113 void parseSensor(const pugi::xml_node &node); 114 115 void parseCameraChild(const pugi::xml_node &node); 116 #endif 117 }; 118 119 } // namespace rawspeed 120