1111#include " error.hpp"
1212#include " exif.hpp"
1313#include " i18n.h" // NLS support.
14+ #include " image_int.hpp"
1415#include " makernote_int.hpp"
1516#include " tags_int.hpp"
1617#include " types.hpp"
@@ -2760,11 +2761,8 @@ const TagInfo* CanonMakerNote::tagListTi() {
27602761}
27612762
27622763std::ostream& CanonMakerNote::printFiFileNumber (std::ostream& os, const Value& value, const ExifData* metadata) {
2763- std::ios::fmtflags f (os.flags ());
27642764 if (!metadata || value.typeId () != unsignedLong || value.count () == 0 ) {
2765- os << " (" << value << " )" ;
2766- os.flags (f);
2767- return os;
2765+ return os << " (" << value << " )" ;
27682766 }
27692767
27702768 auto pos = metadata->findKey (ExifKey (" Exif.Image.Model" ));
@@ -2776,32 +2774,22 @@ std::ostream& CanonMakerNote::printFiFileNumber(std::ostream& os, const Value& v
27762774 if (Internal::contains (model, " 20D" ) || Internal::contains (model, " 350D" ) ||
27772775 model.substr (model.size () - 8 , 8 ) == " REBEL XT" || Internal::contains (model, " Kiss Digital N" )) {
27782776 uint32_t val = value.toUint32 ();
2779- uint32_t dn = (val & 0xffc0 ) >> 6 ;
2780- uint32_t fn = ((val >> 16 ) & 0xff ) + ((val & 0x3f ) << 8 );
2781- os << std::dec << dn << " -" << std::setw (4 ) << std::setfill (' 0' ) << fn;
2782- os.flags (f);
2783- return os;
2777+ return os << stringFormat (" {}-{:04}" , (val & 0xffc0 ) >> 6 , ((val >> 16 ) & 0xff ) + ((val & 0x3f ) << 8 ));
27842778 }
27852779 if (Internal::contains (model, " 30D" ) || Internal::contains (model, " 400D" ) || Internal::contains (model, " REBEL XTi" ) ||
27862780 Internal::contains (model, " Kiss Digital X" ) || Internal::contains (model, " K236" )) {
27872781 uint32_t val = value.toUint32 ();
27882782 uint32_t dn = (val & 0xffc00 ) >> 10 ;
27892783 while (dn < 100 )
27902784 dn += 0x40 ;
2791- uint32_t fn = ((val & 0x3ff ) << 4 ) + ((val >> 20 ) & 0x0f );
2792- os << std::dec << dn << " -" << std::setw (4 ) << std::setfill (' 0' ) << fn;
2793- os.flags (f);
2794- return os;
2785+ return os << stringFormat (" {}-{:04}" , dn, ((val & 0x3ff ) << 4 ) + ((val >> 20 ) & 0x0f ));
27952786 }
27962787
2797- os.flags (f);
27982788 return os << " (" << value << " )" ;
27992789}
28002790
28012791std::ostream& CanonMakerNote::printFocalLength (std::ostream& os, const Value& value, const ExifData* metadata) {
2802- std::ios::fmtflags f (os.flags ());
28032792 if (!metadata || value.count () < 4 || value.typeId () != unsignedShort) {
2804- os.flags (f);
28052793 return os << value;
28062794 }
28072795
@@ -2810,18 +2798,10 @@ std::ostream& CanonMakerNote::printFocalLength(std::ostream& os, const Value& va
28102798 if (pos != metadata->end () && pos->value ().count () >= 3 && pos->value ().typeId () == unsignedShort) {
28112799 float fu = pos->value ().toFloat (2 );
28122800 if (fu != 0 .0F ) {
2813- float fl = value.toFloat (1 ) / fu;
2814- std::ostringstream oss;
2815- oss.copyfmt (os);
2816- os << std::fixed << std::setprecision (1 );
2817- os << fl << " mm" ;
2818- os.copyfmt (oss);
2819- os.flags (f);
2820- return os;
2801+ return os << stringFormat (" {:.1f} mm" , value.toFloat (1 ) / fu);
28212802 }
28222803 }
28232804
2824- os.flags (f);
28252805 return os << value;
28262806}
28272807
@@ -2833,16 +2813,11 @@ std::ostream& CanonMakerNote::print0x0008(std::ostream& os, const Value& value,
28332813}
28342814
28352815std::ostream& CanonMakerNote::print0x000a (std::ostream& os, const Value& value, const ExifData*) {
2836- std::istringstream is (value.toString ());
2837- uint32_t l = 0 ;
2838- is >> l;
2839- return os << std::setw (4 ) << std::setfill (' 0' ) << std::hex << ((l & 0xffff0000 ) >> 16 ) << std::setw (5 )
2840- << std::setfill (' 0' ) << std::dec << (l & 0x0000ffff );
2816+ uint32_t l = std::stoul (value.toString ());
2817+ return os << stringFormat (" {:04x}{:05}" , (l >> 16 ) & 0xFFFF , l & 0xFFFF );
28412818}
28422819
28432820std::ostream& CanonMakerNote::print0x000c (std::ostream& os, const Value& value, const ExifData* exifData) {
2844- std::istringstream is (value.toString ());
2845-
28462821 if (!exifData) {
28472822 return os << value;
28482823 }
@@ -2851,10 +2826,8 @@ std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value,
28512826 auto pos = exifData->findKey (key);
28522827 // if model is EOS D30
28532828 if (pos != exifData->end () && pos->value ().count () == 1 && pos->value ().toInt64 () == 0x01140000 ) {
2854- uint32_t l = 0 ;
2855- is >> l;
2856- return os << std::setw (4 ) << std::setfill (' 0' ) << std::hex << ((l & 0xffff0000 ) >> 16 ) << std::setw (5 )
2857- << std::setfill (' 0' ) << std::dec << (l & 0x0000ffff );
2829+ uint32_t l = std::stoul (value.toString ());
2830+ return os << stringFormat (" {:04x}{:05}" , (l >> 16 ) & 0xFFFF , l & 0xFFFF );
28582831 }
28592832 return os << value;
28602833}
@@ -3028,62 +3001,42 @@ std::ostream& CanonMakerNote::printCsLensType(std::ostream& os, const Value& val
30283001}
30293002
30303003std::ostream& CanonMakerNote::printCsLens (std::ostream& os, const Value& value, const ExifData*) {
3031- std::ios::fmtflags f (os.flags ());
3032-
30333004 if (value.count () < 3 || value.typeId () != unsignedShort) {
3034- os << " (" << value << " )" ;
3035- os.flags (f);
3036- return os;
3005+ return os << " (" << value << " )" ;
30373006 }
30383007
30393008 float fu = value.toFloat (2 );
30403009 if (fu == 0 .0F )
30413010 return os << value;
30423011 float len1 = value.toInt64 (0 ) / fu;
30433012 float len2 = value.toInt64 (1 ) / fu;
3044- std::ostringstream oss;
3045- oss.copyfmt (os);
3046- os << std::fixed << std::setprecision (1 );
30473013 if (len1 == len2) {
3048- os << len1 << " mm" ;
3049- } else {
3050- os << len2 << " - " << len1 << " mm" ;
3014+ return os << stringFormat (" {:.1f} mm" , len1);
30513015 }
3052- os.copyfmt (oss);
3053- os.flags (f);
3054- return os;
3016+ return os << stringFormat (" {:.1f} - {:.1f} mm" , len2, len1);
30553017}
30563018
30573019std::ostream& CanonMakerNote::printLe0x0000 (std::ostream& os, const Value& value, const ExifData*) {
30583020 if (value.typeId () != unsignedByte || value.size () != 5 )
30593021 return os << " (" << value << " )" ;
3060- std::ios::fmtflags f (os.flags ());
3061- std::ostringstream oss;
3062- oss.copyfmt (os);
30633022 for (size_t i = 0 ; i < value.size (); ++i) {
3064- os << std::setw ( 2 ) << std::setfill ( ' 0 ' ) << std::hex << value.toInt64 (i);
3023+ os << stringFormat ( " {:02x} " , value.toInt64 (i) );
30653024 }
3066- os.copyfmt (oss);
3067- os.flags (f);
30683025 return os;
30693026}
30703027
30713028std::ostream& CanonMakerNote::printSi0x0001 (std::ostream& os, const Value& value, const ExifData*) {
3072- std::ios::fmtflags f (os.flags ());
30733029 if (value.typeId () == unsignedShort && value.count () > 0 ) {
30743030 os << std::pow (2 .0F , canonEv (value.toInt64 ()) / 32 ) * 100 .0F ;
30753031 }
3076- os.flags (f);
30773032 return os;
30783033}
30793034
30803035std::ostream& CanonMakerNote::printSi0x0002 (std::ostream& os, const Value& value, const ExifData*) {
3081- std::ios::fmtflags f (os.flags ());
30823036 if (value.typeId () == unsignedShort && value.count () > 0 ) {
30833037 // Ported from Exiftool by Will Stokes
30843038 os << std::pow (2 .0F , canonEv (value.toInt64 ())) * 100 .0F / 32 .0F ;
30853039 }
3086- os.flags (f);
30873040 return os;
30883041}
30893042
@@ -3093,11 +3046,8 @@ std::ostream& CanonMakerNote::printSi0x0003(std::ostream& os, const Value& value
30933046 // It might be explained by the fact, that most Canons have a longest
30943047 // exposure of 30s which is 5 EV below 1s
30953048 // see also printSi0x0017
3096- std::ostringstream oss;
3097- oss.copyfmt (os);
30983049 auto res = std::lround (100.0 * (static_cast <short >(value.toInt64 ()) / 32.0 + 5.0 ));
3099- os << std::fixed << std::setprecision (2 ) << res / 100.0 ;
3100- os.copyfmt (oss);
3050+ os << stringFormat (" {:.2f}" , res / 100.0 );
31013051 }
31023052 return os;
31033053}
@@ -3143,35 +3093,26 @@ std::ostream& CanonMakerNote::printSi0x000e(std::ostream& os, const Value& value
31433093}
31443094
31453095std::ostream& CanonMakerNote::printSi0x0013 (std::ostream& os, const Value& value, const ExifData*) {
3146- std::ios::fmtflags f (os.flags ());
31473096 if (value.typeId () != unsignedShort || value.count () == 0 )
31483097 return os << value;
31493098
31503099 if (auto l = value.toInt64 (); l == 0xffff ) {
3151- os << " Infinite" ;
3152- } else {
3153- os << value.toInt64 () / 100.0 << " m" ;
3100+ return os << " Infinite" ;
31543101 }
3155- os.flags (f);
3156- return os;
3102+ return os << value.toInt64 () / 100.0 << " m" ;
31573103}
31583104
31593105std::ostream& CanonMakerNote::printSi0x0015 (std::ostream& os, const Value& value, const ExifData*) {
31603106 if (value.typeId () != unsignedShort || value.count () == 0 )
31613107 return os << value;
31623108
3163- std::ostringstream oss;
3164- oss.copyfmt (os);
31653109 const auto val = static_cast <int16_t >(value.toInt64 ());
31663110 if (val < 0 )
31673111 return os << value;
3168- os << std::setprecision (2 ) << " F" << fnumber (canonEv (val));
3169- os.copyfmt (oss);
3170- return os;
3112+ return os << stringFormat (" F{:.2}" , fnumber (canonEv (val)));
31713113}
31723114
31733115std::ostream& CanonMakerNote::printSi0x0016 (std::ostream& os, const Value& value, const ExifData*) {
3174- std::ios::fmtflags f (os.flags ());
31753116 if (value.typeId () != unsignedShort || value.count () == 0 )
31763117 return os << value;
31773118
@@ -3180,43 +3121,27 @@ std::ostream& CanonMakerNote::printSi0x0016(std::ostream& os, const Value& value
31803121 if (r > 1 ) {
31813122 os << " /" << r;
31823123 }
3183- os.flags (f);
31843124 return os << " s" ;
31853125}
31863126
31873127std::ostream& CanonMakerNote::printSi0x0017 (std::ostream& os, const Value& value, const ExifData*) {
31883128 if (value.typeId () != unsignedShort || value.count () == 0 )
31893129 return os << value;
3190-
3191- std::ostringstream oss;
3192- oss.copyfmt (os);
3193- os << std::fixed << std::setprecision (2 ) << (value.toInt64 () / 8.0 ) - 6.0 ;
3194- os.copyfmt (oss);
3195- return os;
3130+ return os << stringFormat (" {:.2f}" , (value.toInt64 () / 8.0 ) - 6.0 );
31963131}
31973132
31983133std::ostream& CanonMakerNote::printSi0x0018 (std::ostream& os, const Value& value, const ExifData*) {
31993134 return os << value.toInt64 () / 10 ;
32003135}
32013136
32023137std::ostream& CanonMakerNote::printFiFocusDistance (std::ostream& os, const Value& value, const ExifData*) {
3203- std::ios::fmtflags f (os.flags ());
32043138 if (value.typeId () != signedShort || value.count () == 0 )
32053139 return os << value;
32063140
3207- std::ostringstream oss;
3208- oss.copyfmt (os);
3209- os << std::fixed << std::setprecision (2 );
3210-
32113141 if (auto l = value.toInt64 (); l == -1 ) {
3212- os << " Infinite" ;
3213- } else {
3214- os << value.toInt64 () / 100.0 << " m" ;
3142+ return os << " Infinite" ;
32153143 }
3216-
3217- os.copyfmt (oss);
3218- os.flags (f);
3219- return os;
3144+ return os << stringFormat (" {:.2f} m" , value.toInt64 () / 100.0 );
32203145}
32213146
32223147// *****************************************************************************
0 commit comments