Skip to content

Commit 35f48ae

Browse files
Replace weird sign-conversion code with a simple static_cast.
1 parent 5444fce commit 35f48ae

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/panasonicmn_int.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -691,17 +691,15 @@ namespace Exiv2 {
691691

692692
std::ostream& PanasonicMakerNote::printAccelerometer(std::ostream& os, const Value& value, const ExifData*)
693693
{
694-
// value is stored as unsigned int, but should be readed as signed int, so manually convert it
695-
int i = value.toLong();
696-
i = i - ((i & 0x8000) >> 15) * 0xffff;
694+
// value is stored as unsigned int, but should be read as int16_t.
695+
const int16_t i = static_cast<int16_t>(value.toLong());
697696
return os << i;
698697
} // PanasonicMakerNote::printAccelerometer
699698

700699
std::ostream& PanasonicMakerNote::printRollAngle(std::ostream& os, const Value& value, const ExifData*)
701700
{
702-
// roll angle is stored as signed int, but tag states to be unsigned int
703-
int i = value.toLong();
704-
i = i - ((i & 0x8000) >> 15) * 0xffff;
701+
// value is stored as unsigned int, but should be read as int16_t.
702+
const int16_t i = static_cast<int16_t>(value.toLong());
705703
std::ostringstream oss;
706704
oss.copyfmt(os);
707705
os << std::fixed << std::setprecision(1) << i / 10.0;
@@ -712,10 +710,8 @@ namespace Exiv2 {
712710

713711
std::ostream& PanasonicMakerNote::printPitchAngle(std::ostream& os, const Value& value, const ExifData*)
714712
{
715-
// pitch angle is stored as signed int, but tag states to be unsigned int
716-
// change sign to be compatible with ExifTool: positive is upwards
717-
int i = value.toLong();
718-
i = i - ((i & 0x8000) >> 15) * 0xffff;
713+
// value is stored as unsigned int, but should be read as int16_t.
714+
const int16_t i = static_cast<int16_t>(value.toLong());
719715
std::ostringstream oss;
720716
oss.copyfmt(os);
721717
os << std::fixed << std::setprecision(1) << -i / 10.0;

tests/bugfixes/github/test_issue_2006.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class PanasonicMakerPrintAccelerometerIntOverflow(metaclass=CaseMeta):
1616
Exif.Image.DNGPrivateData 0x2020 32 80 97 110 97 115 111 110 105 99 32 32 32 0 32 32 255 32 32 32 32 32 255 255 255 32 255 255 198 52 32 32 0
1717
Exif.MakerNote.Offset Long 1 48
1818
Exif.MakerNote.ByteOrder Ascii 3 MM
19-
Exif.Panasonic.AccelerometerY SLong 4 2147483425
19+
Exif.Panasonic.AccelerometerY SLong 4 -224
2020
"""]
2121
retval = [0]

0 commit comments

Comments
 (0)