Update Sony2Fp makernote functions

Minor changes using suggestions in #1777:
+ Simplify loop conditions
+ Add startsWith() in SonyMakerNote class
+ Change `if`/`else` to `switch`
main
postscript-dev 4 years ago
parent e821404d69
commit 0827a76b6a
No known key found for this signature in database
GPG Key ID: F3EC02A099292862

@ -1201,10 +1201,8 @@ namespace Exiv2 {
int sony2FpSelector(uint16_t /*tag*/, const byte* /*pData*/, uint32_t /*size*/, TiffComponent* const pRoot)
{
// Not valid for models beginning
const char* models[] = { "SLT-", "HV", "ILCA-" };
std::string model = getExifModel(pRoot);
for (auto&& m : models) {
for (auto& m : { "SLT-", "HV", "ILCA-" }) {
if (startsWith(model, m))
return -1;
}

@ -814,7 +814,7 @@ namespace Exiv2 {
{ 0x17, "AFAreaMode" , N_("AF area mode") , N_("Auto focus area mode"), sony2FpId, makerTags, unsignedByte, 1, EXV_PRINT_TAG(sony2FpAFAreaMode)},
{ 0x2d, "FocusPosition2" , N_("Focus position 2") , N_("Focus position 2") , sony2FpId, makerTags, unsignedByte, 1, printSony2FpFocusPosition2},
// End of list marker
{0xffff, "(UnknownSony2FpTag)", "(UnknownSony2FpTag)" , "(UnknownSony2FpTag)" , sony2FpId, makerTags, unsignedByte, 1, printValue},
{0xffff, "(UnknownSony2FpTag)", "(Unknown Sony2Fp tag)" , "(Unknown Sony2Fp tag)" , sony2FpId, makerTags, unsignedByte, 1, printValue},
};
const TagInfo* SonyMakerNote::tagListFp()
@ -828,18 +828,25 @@ namespace Exiv2 {
os << value;
else {
long val = (value.toLong() & 0x7F);
if (val == 0)
switch (val) {
case 0:
os << N_("Manual");
else if (val == 2)
break;
case 2:
os << N_("AF-S");
else if (val == 3)
break;
case 3:
os << N_("AF-C");
else if (val == 4)
break;
case 4:
os << N_("AF-A");
else if (val == 6)
break;
case 6:
os << N_("DMF");
else
break;
default:
os << "(" << val << ")";
}
}
return os;
@ -855,20 +862,21 @@ namespace Exiv2 {
return os << "(" << value << ")";
// Ranges of models that do not support this tag
const char* models[] = { "DSC-", "Stellar" };
std::string model = pos->toString();
for (auto&& m : models) {
if (model.find(m) == 0) {
for (auto& m : { "DSC-", "Stellar" }) {
if (startsWith(model, m)) {
os << N_("n/a");
return os;
}
}
long val = value.toLong();
if (val == 255)
switch (val) {
case 255:
os << N_("Infinity");
else
break;
default:
os << val;
}
}
return os;
}
@ -947,6 +955,11 @@ namespace Exiv2 {
return tagInfo2010e_;
}
bool SonyMakerNote::startsWith(const std::string& s, const std::string& start)
{
return s.size() >= start.size() && std::memcmp(s.data(), start.data(), start.size()) == 0;
}
// https://github.com/Exiv2/exiv2/pull/906#issuecomment-504338797
static DataBuf sonyTagCipher(uint16_t /* tag */, const byte* bytes, uint32_t size, TiffComponent* const /*object*/, bool bDecipher)
{

@ -75,6 +75,11 @@ namespace Exiv2 {
static const TagInfo tagInfoFp_[];
static const TagInfo tagInfoSonyMisc1_[];
static const TagInfo tagInfo2010e_[];
// TODO: When moving to C++20, this can be replace with
// std::basic_string<CharT,Traits,Allocator>::starts_with() .
// Suggested in https://github.com/Exiv2/exiv2/pull/1777 .
static bool startsWith(const std::string& s, const std::string& start);
}; // class SonyMakerNote
DataBuf sonyTagDecipher(uint16_t, const byte*, uint32_t, TiffComponent* const);

Loading…
Cancel
Save