Skip to content

Commit ab375fb

Browse files
clanmillsD4N
authored andcommitted
Add support for FocusPosition in Sony RAW files (#906)
* Fix 582 Add support for FocusPosition in Sony RAW files * Thanks to @boardhead sonyFpCrypt() works correctly. Removed debug code. Fixed typos. * Update doc/templates/Makefile to process Sony2Fp * Following review by @boardhead. Renamed sonyFpCrypt() as sonyTagDecipher(). * Fixed writing the tag thanks to @boardhead explaining encipher/decipher. Sadly, ArrayCfg/crpyt does not know if he's encrypting/decrypting. I've added a sniff in TiffEncoder::visitBinaryArrayEnd to avoid changing the API. * Added URL to discussion concerning sonyTagCipher() * make sonyTagCipher() a static function with no external visibility.
1 parent 0a47d93 commit ab375fb

File tree

9 files changed

+110
-4
lines changed

9 files changed

+110
-4
lines changed

doc/templates/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ TABLES = Exif \
9898
OlympusFi \
9999
OlympusFe1 \
100100
OlympusRi \
101-
Panasonic \
101+
Panasonic \
102102
PanasonicRaw \
103103
Pentax \
104104
Samsung2 \
@@ -110,7 +110,8 @@ TABLES = Exif \
110110
Sony1Cs2 \
111111
Sony1MltCs7D \
112112
Sony1MltCsOld \
113-
Sony1MltCsA100
113+
Sony1MltCsA100 \
114+
Sony2Fp
114115

115116
SCHEMA = xmp_dc \
116117
xmp_dwc \

src/sonymn_int.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "minoltamn_int.hpp"
2929
#include "sonymn_int.hpp"
3030
#include "tags_int.hpp"
31+
#include "tiffcomposite_int.hpp"
3132
#include "value.hpp"
3233
#include "i18n.h" // NLS support.
3334

@@ -795,4 +796,54 @@ namespace Exiv2 {
795796
return tagInfoCs2_;
796797
}
797798

799+
//! Sony Tag 9402 Sony2Fp (FocusPosition)
800+
const TagInfo SonyMakerNote::tagInfoFp_[] = {
801+
TagInfo( 0x04, "AmbientTemperature", N_("Ambient Temperature"), N_("Ambient Temperature"), sony2FpId, makerTags, signedByte, 1, printValue),
802+
TagInfo( 0x16, "FocusMode" , N_("Focus Mode") , N_("Focus Mode") , sony2FpId, makerTags, unsignedByte, 1, printValue),
803+
TagInfo( 0x17, "AFAreaMode" , N_("AF Area Mode") , N_("AF Area Mode") , sony2FpId, makerTags, unsignedByte, 1, printValue),
804+
TagInfo( 0x2d, "FocusPosition2" , N_("Focus Position 2") , N_("Focus Position 2") , sony2FpId, makerTags, unsignedByte, 1, printValue),
805+
// End of list marker
806+
TagInfo(0xffff, "(Unknownsony2FpTag)", "(Unknownsony2FpTag)" , "(Unknownsony2FpTag)" , sony2FpId, makerTags, unsignedByte, 1, printValue)
807+
};
808+
809+
const TagInfo* SonyMakerNote::tagListFp()
810+
{
811+
return tagInfoFp_;
812+
}
813+
814+
// https://github.com/Exiv2/exiv2/pull/906#issuecomment-504338797
815+
static DataBuf sonyTagCipher(uint16_t /* tag */, const byte* bytes, uint32_t size, TiffComponent* const /*object*/, bool bDecipher)
816+
{
817+
DataBuf b(bytes,size); // copy the data
818+
819+
// initialize the code table
820+
byte code[256];
821+
for ( uint32_t i = 0 ; i < 249 ; i++ ) {
822+
if ( bDecipher ) {
823+
code[(i * i * i) % 249] = i ;
824+
} else {
825+
code[i] = (i * i * i) % 249 ;
826+
}
827+
}
828+
for ( uint32_t i = 249 ; i < 256 ; i++ ) {
829+
code[i] = i;
830+
}
831+
832+
// code byte-by-byte
833+
for ( uint32_t i = 0 ; i < size ; i++ ) {
834+
b.pData_[i] = code[bytes[i]];
835+
}
836+
837+
return b;
838+
}
839+
840+
DataBuf sonyTagDecipher(uint16_t tag, const byte* bytes, uint32_t size, TiffComponent* const object)
841+
{
842+
return sonyTagCipher(tag,bytes,size,object,true);
843+
}
844+
DataBuf sonyTagEncipher(uint16_t tag, const byte* bytes, uint32_t size, TiffComponent* const object)
845+
{
846+
return sonyTagCipher(tag,bytes,size,object,false);
847+
}
848+
798849
}} // namespace Internal, Exiv2

src/sonymn_int.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Email communication with <a href="mailto:caulier dot gilles at gmail dot com">ca
3636
// included header files
3737
#include "tags.hpp"
3838
#include "types.hpp"
39+
#include "tiffcomposite_int.hpp"
3940

4041
// + standard includes
4142
#include <string>
@@ -58,6 +59,8 @@ namespace Exiv2 {
5859
static const TagInfo* tagListCs();
5960
//! Return read-only list of built-in Sony Standard Camera Settings version 2 tags
6061
static const TagInfo* tagListCs2();
62+
//! Return read-only list of built-in Sony FocusPosition tags
63+
static const TagInfo* tagListFp();
6164

6265
//! @name Print functions for Sony %MakerNote tags
6366
//@{
@@ -71,9 +74,13 @@ namespace Exiv2 {
7174
static const TagInfo tagInfo_[];
7275
static const TagInfo tagInfoCs_[];
7376
static const TagInfo tagInfoCs2_[];
77+
static const TagInfo tagInfoFp_[];
7478

7579
}; // class SonyMakerNote
7680

81+
DataBuf sonyTagDecipher(uint16_t, const byte*, uint32_t, TiffComponent* const);
82+
DataBuf sonyTagEncipher(uint16_t, const byte*, uint32_t, TiffComponent* const);
83+
7784
}} // namespace Internal, Exiv2
7885

7986
#endif // #ifndef SONYMN_INT_HPP_

src/tags_int.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ namespace Exiv2 {
162162
{ sony1MltCs7DId, "Makernote", "Sony1MltCs7D", MinoltaMakerNote::tagListCs7D },
163163
{ sony1MltCsOldId, "Makernote", "Sony1MltCsOld",MinoltaMakerNote::tagListCsStd },
164164
{ sony1MltCsNewId, "Makernote", "Sony1MltCsNew",MinoltaMakerNote::tagListCsStd },
165-
{ sony1MltCsA100Id,"Makernote","Sony1MltCsA100",MinoltaMakerNote::tagListCsA100},
165+
{ sony1MltCsA100Id,"Makernote", "Sony1MltCsA100",MinoltaMakerNote::tagListCsA100},
166166
{ sony2CsId, "Makernote", "Sony2Cs", SonyMakerNote::tagListCs },
167167
{ sony2Cs2Id, "Makernote", "Sony2Cs2", SonyMakerNote::tagListCs2 },
168+
{ sony2FpId, "Makernote", "Sony2Fp", SonyMakerNote::tagListFp },
168169
{ lastId, "(Last IFD info)", "(Last IFD item)", 0 }
169170
};
170171

src/tags_int.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ namespace Exiv2 {
154154
sony1Cs2Id,
155155
sony2CsId,
156156
sony2Cs2Id,
157+
sony2FpId,
157158
sony1MltCs7DId,
158159
sony1MltCsOldId,
159160
sony1MltCsNewId,

src/tiffimage_int.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "error.hpp"
44
#include "makernote_int.hpp"
5+
#include "sonymn_int.hpp"
56
#include "tiffvisitor_int.hpp"
67
#include "i18n.h" // NLS support.
78

@@ -767,6 +768,24 @@ namespace Exiv2 {
767768
false, // Don't concatenate gaps
768769
{ 0, ttUnsignedShort, 1 }
769770
};
771+
772+
extern const ArrayCfg sony2FpCfg = {
773+
sony2FpId, // Group for the elements
774+
bigEndian, // Big endian
775+
ttUnsignedByte, // Type for array entry and size element
776+
sonyTagDecipher, // (uint16_t, const byte*, uint32_t, TiffComponent* const);
777+
false, // No size element
778+
false, // No fillers
779+
false, // Don't concatenate gaps
780+
{ 0, ttUnsignedByte, 1 }
781+
};
782+
extern const ArrayDef sony2FpDef[] = {
783+
{ 0x4, ttSignedByte , 1 }, // Exif.Sony2Fp.AmbientTemperature
784+
{ 0x16, ttUnsignedByte, 1 }, // Exif.Sony2Fp.FocusMode
785+
{ 0x17, ttUnsignedByte, 1 }, // Exif.Sony2Fp.AFAreaMode
786+
{ 0x2d, ttUnsignedByte, 1 } // Exif.Sony2Fp.FocusPosition2
787+
};
788+
770789
//! Sony[12] Camera Settings binary array - definition
771790
extern const ArrayDef sonyCsDef[] = {
772791
{ 12, ttSignedShort, 1 } // Exif.Sony[12]Cs.WhiteBalanceFineTune
@@ -988,6 +1007,7 @@ namespace Exiv2 {
9881007
{ Tag::root, sony1MltCs7DId, sonyMltId, 0x0004 },
9891008
{ Tag::root, sony1MltCsA100Id, sonyMltId, 0x0114 },
9901009
{ Tag::root, sony2Id, exifId, 0x927c },
1010+
{ Tag::root, sony2FpId, sony2Id, 0x9402 },
9911011
{ Tag::root, sony2CsId, sony2Id, 0x0114 },
9921012
{ Tag::root, sony2Cs2Id, sony2Id, 0x0114 },
9931013
{ Tag::root, minoltaId, exifId, 0x927c },
@@ -1418,6 +1438,10 @@ namespace Exiv2 {
14181438
{ Tag::all, sony1CsId, newTiffBinaryElement },
14191439
{ Tag::all, sony1Cs2Id, newTiffBinaryElement },
14201440

1441+
// Tag 0x9402 Sony2Fp Focus Position
1442+
{ Tag::all, sony2FpId, newTiffBinaryElement },
1443+
{ 0x9402, sony2Id, EXV_BINARY_ARRAY(sony2FpCfg, sony2FpDef) },
1444+
14211445
// Sony2 makernote
14221446
{ 0x0114, sony2Id, EXV_COMPLEX_BINARY_ARRAY(sony2CsSet, sonyCsSelector) },
14231447
{ Tag::next, sony2Id, ignoreTiffComponent },

src/tiffvisitor_int.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "value.hpp"
3737
#include "image.hpp"
3838
#include "jpgimage.hpp"
39+
#include "sonymn_int.hpp"
3940
#include "i18n.h" // NLS support.
4041

4142
// + standard includes
@@ -780,7 +781,10 @@ namespace Exiv2 {
780781
if (!object->initialize(pRoot_)) return;
781782

782783
// Re-encrypt buffer if necessary
783-
const CryptFct cryptFct = object->cfg()->cryptFct_;
784+
CryptFct cryptFct = object->cfg()->cryptFct_;
785+
if ( cryptFct == sonyTagDecipher ) {
786+
cryptFct = sonyTagEncipher;
787+
}
784788
if (cryptFct != 0) {
785789
const byte* pData = object->pData();
786790
DataBuf buf = cryptFct(object->tag(), pData, size, pRoot_);

test/data/exiv2-pr906.exv

48.3 KB
Binary file not shown.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from system_tests import CaseMeta, path
4+
5+
class Sony2FpTest(metaclass=CaseMeta):
6+
7+
filename = path("$data_path/exiv2-pr906.exv")
8+
commands = ["$exiv2 -pa --grep Sony2Fp $filename"]
9+
10+
stdout = ["""Exif.Sony2Fp.AmbientTemperature SByte 1 19
11+
Exif.Sony2Fp.FocusMode Byte 1 6
12+
Exif.Sony2Fp.AFAreaMode Byte 1 12
13+
Exif.Sony2Fp.FocusPosition2 Byte 1 140
14+
"""
15+
]
16+
stderr = [""]
17+
retval = [0]

0 commit comments

Comments
 (0)