Coverage Report

Created: 2026-10-27 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/LibRaw/src/metadata/sony.cpp
Line
Count
Source
1
/* -*- C++ -*-
2
 * Copyright 2019-2025 LibRaw LLC (info@libraw.org)
3
 *
4
 LibRaw is free software; you can redistribute it and/or modify
5
 it under the terms of the one of two licenses as you choose:
6
7
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
8
   (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
9
10
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
11
   (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
12
13
 */
14
15
#include "../../internal/dcraw_defs.h"
16
#include "../../internal/libraw_cameraids.h"
17
#include "../../internal/libraw_checked_buffer.h"
18
19
static ushort saneSonyCameraInfo(uchar a, uchar b, uchar c, uchar d, uchar e,
20
                                 uchar f)
21
3.85k
{
22
3.85k
  if ((a >> 4) > 9)
23
294
    return 0;
24
3.55k
  else if ((a & 0x0f) > 9)
25
364
    return 0;
26
3.19k
  else if ((b >> 4) > 9)
27
168
    return 0;
28
3.02k
  else if ((b & 0x0f) > 9)
29
284
    return 0;
30
2.74k
  else if ((c >> 4) > 9)
31
290
    return 0;
32
2.45k
  else if ((c & 0x0f) > 9)
33
210
    return 0;
34
2.24k
  else if ((d >> 4) > 9)
35
254
    return 0;
36
1.98k
  else if ((d & 0x0f) > 9)
37
210
    return 0;
38
1.77k
  else if ((e >> 4) > 9)
39
338
    return 0;
40
1.43k
  else if ((e & 0x0f) > 9)
41
368
    return 0;
42
1.07k
  else if ((f >> 4) > 9)
43
250
    return 0;
44
820
  else if ((f & 0x0f) > 9)
45
286
    return 0;
46
534
  return 1;
47
3.85k
}
48
static float my_roundf(float x)
49
24.7k
{
50
24.7k
  float t;
51
24.7k
  if (x >= 0.0)
52
24.7k
  {
53
24.7k
    t = ceilf(x);
54
24.7k
    if (t - x > 0.5)
55
16.9k
      t -= 1.0;
56
24.7k
    return t;
57
24.7k
  }
58
0
  else
59
0
  {
60
0
    t = ceilf(-x);
61
0
    if (t + x > 0.5)
62
0
      t -= 1.0;
63
0
    return -t;
64
0
  }
65
24.7k
}
66
67
static ushort bcd2dec(uchar data)
68
60.7k
{
69
60.7k
  if ((data >> 4) > 9)
70
24.7k
    return 0;
71
35.9k
  else if ((data & 0x0f) > 9)
72
11.3k
    return 0;
73
24.5k
  else
74
24.5k
    return (data >> 4) * 10 + (data & 0x0f);
75
60.7k
}
76
77
static uchar SonySubstitution[257] =
78
    "\x00\x01\x32\xb1\x0a\x0e\x87\x28\x02\xcc\xca\xad\x1b\xdc\x08\xed\x64\x86"
79
    "\xf0\x4f\x8c\x6c\xb8\xcb\x69\xc4\x2c\x03"
80
    "\x97\xb6\x93\x7c\x14\xf3\xe2\x3e\x30\x8e\xd7\x60\x1c\xa1\xab\x37\xec\x75"
81
    "\xbe\x23\x15\x6a\x59\x3f\xd0\xb9\x96\xb5"
82
    "\x50\x27\x88\xe3\x81\x94\xe0\xc0\x04\x5c\xc6\xe8\x5f\x4b\x70\x38\x9f\x82"
83
    "\x80\x51\x2b\xc5\x45\x49\x9b\x21\x52\x53"
84
    "\x54\x85\x0b\x5d\x61\xda\x7b\x55\x26\x24\x07\x6e\x36\x5b\x47\xb7\xd9\x4a"
85
    "\xa2\xdf\xbf\x12\x25\xbc\x1e\x7f\x56\xea"
86
    "\x10\xe6\xcf\x67\x4d\x3c\x91\x83\xe1\x31\xb3\x6f\xf4\x05\x8a\x46\xc8\x18"
87
    "\x76\x68\xbd\xac\x92\x2a\x13\xe9\x0f\xa3"
88
    "\x7a\xdb\x3d\xd4\xe7\x3a\x1a\x57\xaf\x20\x42\xb2\x9e\xc3\x8b\xf2\xd5\xd3"
89
    "\xa4\x7e\x1f\x98\x9c\xee\x74\xa5\xa6\xa7"
90
    "\xd8\x5e\xb0\xb4\x34\xce\xa8\x79\x77\x5a\xc1\x89\xae\x9a\x11\x33\x9d\xf5"
91
    "\x39\x19\x65\x78\x16\x71\xd2\xa9\x44\x63"
92
    "\x40\x29\xba\xa0\x8f\xe4\xd6\x3b\x84\x0d\xc2\x4e\x58\xdd\x99\x22\x6b\xc9"
93
    "\xbb\x17\x06\xe5\x7d\x66\x43\x62\xf6\xcd"
94
    "\x35\x90\x2e\x41\x8d\x6d\xaa\x09\x73\x95\x0c\xf1\x1d\xde\x4c\x2f\x2d\xf7"
95
    "\xd1\x72\xeb\xef\x48\xc7\xf8\xf9\xfa\xfb"
96
    "\xfc\xfd\xfe\xff";
97
98
void LibRaw::sony_decrypt(unsigned *data, int len, int start, int key)
99
7.04k
{
100
7.04k
#ifndef LIBRAW_NOTHREADS
101
117M
#define pad tls->sony_decrypt.pad
102
157M
#define p tls->sony_decrypt.p
103
#else
104
  static unsigned pad[128], p;
105
#endif
106
7.04k
  if (start)
107
1.15k
  {
108
5.76k
    for (p = 0; p < 4; p++)
109
4.60k
      pad[p] = key = key * 48828125ULL + 1;
110
1.15k
    pad[3] = pad[3] << 1 | (pad[0] ^ pad[2]) >> 31;
111
142k
    for (p = 4; p < 127; p++)
112
141k
      pad[p] = (pad[p - 4] ^ pad[p - 2]) << 1 | (pad[p - 3] ^ pad[p - 1]) >> 31;
113
147k
    for (p = 0; p < 127; p++)
114
146k
      pad[p] = htonl(pad[p]);
115
1.15k
  }
116
39.0M
  while (len--)
117
39.0M
  {
118
39.0M
    *data++ ^= pad[p & 127] = pad[(p + 1) & 127] ^ pad[(p + 65) & 127];
119
39.0M
    p++;
120
39.0M
  }
121
7.04k
#ifndef LIBRAW_NOTHREADS
122
7.04k
#undef pad
123
7.04k
#undef p
124
7.04k
#endif
125
7.04k
}
126
73.1k
void LibRaw::setSonyBodyFeatures(unsigned long long id) {
127
128
1.17M
#define sbfDSLR_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_DSLR,LIBRAW_MOUNT_Unknown
129
146k
#define sbfDSLR_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_DSLR,LIBRAW_MOUNT_Unknown
130
877k
#define sbfNEX_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_NEX,LIBRAW_MOUNT_Unknown
131
73.1k
#define sbfNEX_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_NEX,LIBRAW_MOUNT_Unknown
132
585k
#define sbfSLT_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_SLT,LIBRAW_MOUNT_Unknown
133
73.1k
#define sbfSLT_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_SLT,LIBRAW_MOUNT_Unknown
134
146k
#define sbfDSC_1div2p3in LIBRAW_FORMAT_1div2p3INCH,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens
135
1.17M
#define sbfDSC_1in LIBRAW_FORMAT_1INCH,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens
136
219k
#define sbfDSC_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_FixedLens,LIBRAW_SONY_DSC,LIBRAW_MOUNT_FixedLens
137
1.02M
#define sbfILCE_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_ILCE,LIBRAW_MOUNT_Unknown
138
1.97M
#define sbfILCE_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Sony_E,LIBRAW_SONY_ILCE,LIBRAW_MOUNT_Unknown
139
146k
#define sbfILCA_DX LIBRAW_FORMAT_APSC,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_ILCA,LIBRAW_MOUNT_Unknown
140
73.1k
#define sbfILCA_FF LIBRAW_FORMAT_FF,LIBRAW_MOUNT_Minolta_A,LIBRAW_SONY_ILCA,LIBRAW_MOUNT_Unknown
141
142
73.1k
  static const struct
143
73.1k
  {
144
73.1k
    ushort scf[11];
145
    /*
146
    scf[0]  camera id
147
    scf[1]  camera format
148
    scf[2]  camera mount: Minolta A, Sony E, fixed,
149
    scf[3]  camera type: DSLR, NEX, SLT, ILCE, ILCA, DSC
150
    scf[4]  lens mount, LIBRAW_MOUNT_FixedLens or LIBRAW_MOUNT_Unknown
151
    scf[5]  tag 0x2010 group (0 if not used)
152
    scf[6]  offset of Sony ISO in 0x2010 table, 0xffff if not valid
153
    scf[7]  offset of ShutterCount3 in 0x9050 table, 0xffff if not valid
154
    scf[8]  offset of MeteringMode in 0x2010 table, 0xffff if not valid
155
    scf[9]  offset of ExposureProgram in 0x2010 table, 0xffff if not valid
156
    scf[10] offset of ReleaseMode2 in 0x2010 table, 0xffff if not valid
157
    */
158
73.1k
  } SonyCamFeatures[] = {
159
73.1k
      {SonyID_DSLR_A100, sbfDSLR_DX,
160
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
161
73.1k
      {SonyID_DSLR_A900, sbfDSLR_FF,
162
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
163
73.1k
      {SonyID_DSLR_A700, sbfDSLR_DX,
164
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
165
73.1k
      {SonyID_DSLR_A200, sbfDSLR_DX,
166
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
167
73.1k
      {SonyID_DSLR_A350, sbfDSLR_DX,
168
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
169
73.1k
      {SonyID_DSLR_A300, sbfDSLR_DX,
170
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
171
73.1k
      {SonyID_DSLR_A900_APSC, sbfDSLR_DX,
172
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
173
73.1k
      {SonyID_DSLR_A380, sbfDSLR_DX,
174
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
175
73.1k
      {SonyID_DSLR_A330, sbfDSLR_DX,
176
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
177
73.1k
      {SonyID_DSLR_A230, sbfDSLR_DX,
178
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
179
73.1k
      {SonyID_DSLR_A290, sbfDSLR_DX,
180
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
181
73.1k
      {SonyID_DSLR_A850, sbfDSLR_FF,
182
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
183
73.1k
      {SonyID_DSLR_A850_APSC, sbfDSLR_DX,
184
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
185
73.1k
      {SonyID_DSLR_A550, sbfDSLR_DX,
186
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
187
73.1k
      {SonyID_DSLR_A500, sbfDSLR_DX,
188
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
189
73.1k
      {SonyID_DSLR_A450, sbfDSLR_DX,
190
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
191
73.1k
      {SonyID_NEX_5, sbfNEX_DX,
192
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
193
73.1k
      {SonyID_NEX_3, sbfNEX_DX,
194
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
195
73.1k
      {SonyID_SLT_A33, sbfSLT_DX,
196
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
197
73.1k
      {SonyID_SLT_A55, sbfSLT_DX,
198
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
199
73.1k
      {SonyID_DSLR_A560, sbfDSLR_DX,
200
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
201
73.1k
      {SonyID_DSLR_A580, sbfDSLR_DX,
202
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
203
73.1k
      {SonyID_NEX_C3, sbfNEX_DX,
204
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
205
73.1k
      {SonyID_SLT_A35, sbfSLT_DX,
206
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
207
73.1k
      {SonyID_SLT_A65, sbfSLT_DX,
208
73.1k
       LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c},
209
73.1k
      {SonyID_SLT_A77, sbfSLT_DX,
210
73.1k
       LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c},
211
73.1k
      {SonyID_NEX_5N, sbfNEX_DX,
212
73.1k
       LIBRAW_SONY_Tag2010a, 0x113e, 0x01bd, 0x1174, 0x1175, 0x112c},
213
73.1k
      {SonyID_NEX_7, sbfNEX_DX,
214
73.1k
       LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c},
215
73.1k
      {SonyID_NEX_VG20, sbfNEX_DX,
216
73.1k
       LIBRAW_SONY_Tag2010b, 0x1218, 0x01bd, 0x1178, 0x1179, 0x112c},
217
73.1k
      {SonyID_SLT_A37, sbfSLT_DX,
218
73.1k
       LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108},
219
73.1k
      {SonyID_SLT_A57, sbfSLT_DX,
220
73.1k
       LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108},
221
73.1k
      {SonyID_NEX_F3, sbfNEX_DX,
222
73.1k
       LIBRAW_SONY_Tag2010c, 0x11f4, 0x01bd, 0x1154, 0x1155, 0x1108},
223
73.1k
      {SonyID_SLT_A99, sbfSLT_FF,
224
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
225
73.1k
      {SonyID_NEX_6, sbfNEX_DX,
226
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
227
73.1k
      {SonyID_NEX_5R, sbfNEX_DX,
228
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
229
73.1k
      {SonyID_DSC_RX100, sbfDSC_1in,
230
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0xffff, 0x11ac, 0x11ad, 0x1160},
231
73.1k
      {SonyID_DSC_RX1, sbfDSC_FF,
232
73.1k
       LIBRAW_SONY_Tag2010e, 0x1258, 0xffff, 0x11ac, 0x11ad, 0x1160},
233
73.1k
      {SonyID_NEX_VG900, sbfNEX_FF,
234
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
235
73.1k
      {SonyID_NEX_VG30, sbfNEX_DX,
236
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
237
73.1k
      {SonyID_ILCE_3000, sbfILCE_DX,
238
73.1k
       LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160},
239
73.1k
      {SonyID_SLT_A58, sbfSLT_DX,
240
73.1k
       LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160},
241
73.1k
      {SonyID_NEX_3N, sbfNEX_DX,
242
73.1k
       LIBRAW_SONY_Tag2010e, 0x1280, 0x01aa, 0x11ac, 0x11ad, 0x1160},
243
73.1k
      {SonyID_ILCE_7, sbfILCE_FF,
244
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
245
73.1k
      {SonyID_NEX_5T, sbfNEX_DX,
246
73.1k
       LIBRAW_SONY_Tag2010e, 0x1254, 0x01aa, 0x11ac, 0x11ad, 0x1160},
247
73.1k
      {SonyID_DSC_RX100M2, sbfDSC_1in,
248
73.1k
       LIBRAW_SONY_Tag2010f, 0x113c, 0xffff, 0x1064, 0x1065, 0x1018},
249
73.1k
      {SonyID_DSC_RX10, sbfDSC_1in,
250
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
251
73.1k
      {SonyID_DSC_RX1R, sbfDSC_FF,
252
73.1k
       LIBRAW_SONY_Tag2010e, 0x1258, 0xffff, 0x11ac, 0x11ad, 0x1160},
253
73.1k
      {SonyID_ILCE_7R, sbfILCE_FF,
254
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
255
73.1k
      {SonyID_ILCE_6000, sbfILCE_DX,
256
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
257
73.1k
      {SonyID_ILCE_5000, sbfILCE_DX,
258
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0x01aa, 0x025c, 0x025d, 0x0210},
259
73.1k
      {SonyID_DSC_RX100M3, sbfDSC_1in,
260
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
261
73.1k
      {SonyID_ILCE_7S, sbfILCE_FF,
262
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
263
73.1k
      {SonyID_ILCA_77M2, sbfILCA_DX,
264
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210},
265
73.1k
      {SonyID_ILCE_5100, sbfILCE_DX,
266
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210},
267
73.1k
      {SonyID_ILCE_7M2, sbfILCE_FF,
268
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0xffff, 0x025c, 0x025d, 0x0210},
269
73.1k
      {SonyID_DSC_RX100M4, sbfDSC_1in,
270
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
271
73.1k
      {SonyID_DSC_RX10M2, sbfDSC_1in,
272
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
273
73.1k
      {SonyID_DSC_RX1RM2, sbfDSC_FF,
274
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
275
73.1k
      {SonyID_ILCE_QX1, sbfILCE_DX,
276
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210},
277
73.1k
      {SonyID_ILCE_7RM2, sbfILCE_FF,
278
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0x01cb, 0x025c, 0x025d, 0x0210},
279
73.1k
      {SonyID_ILCE_7SM2, sbfILCE_FF,
280
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0x01cb, 0x025c, 0x025d, 0x0210},
281
73.1k
      {SonyID_ILCA_68, sbfILCA_DX,
282
73.1k
       LIBRAW_SONY_Tag2010g, 0x0344, 0x01a0, 0x025c, 0x025d, 0x0210},
283
73.1k
      {SonyID_ILCA_99M2, sbfILCA_FF,
284
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210},
285
73.1k
      {SonyID_DSC_RX10M3, sbfDSC_1in,
286
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
287
73.1k
      {SonyID_DSC_RX100M5, sbfDSC_1in,
288
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
289
73.1k
      {SonyID_ILCE_6300, sbfILCE_DX,
290
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210},
291
73.1k
      {SonyID_ILCE_9, sbfILCE_FF,
292
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
293
73.1k
      {SonyID_ILCE_6500, sbfILCE_DX,
294
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0x01cd, 0x025c, 0x025d, 0x0210},
295
73.1k
      {SonyID_ILCE_7RM3, sbfILCE_FF,
296
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
297
73.1k
      {SonyID_ILCE_7M3, sbfILCE_FF,
298
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
299
73.1k
      {SonyID_DSC_RX0, sbfDSC_1in,
300
73.1k
       LIBRAW_SONY_Tag2010h, 0x0346, 0xffff, 0x025c, 0x025d, 0x0210},
301
73.1k
      {SonyID_DSC_RX10M4, sbfDSC_1in,
302
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
303
73.1k
      {SonyID_DSC_RX100M6, sbfDSC_1in,
304
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
305
73.1k
      {SonyID_DSC_HX99, sbfDSC_1div2p3in,
306
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
307
73.1k
      {SonyID_DSC_RX100M5A, sbfDSC_1in,
308
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
309
73.1k
      {SonyID_ILCE_6400, sbfILCE_DX,
310
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
311
73.1k
      {SonyID_DSC_RX0M2, sbfDSC_1in,
312
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
313
73.1k
      {SonyID_DSC_HX95, sbfDSC_1div2p3in,
314
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
315
73.1k
      {SonyID_DSC_RX100M7, sbfDSC_1in,
316
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
317
73.1k
      {SonyID_ILCE_7RM4, sbfILCE_FF,
318
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
319
73.1k
      {SonyID_ILCE_9M2, sbfILCE_FF,
320
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
321
73.1k
      {SonyID_ILCE_6600, sbfILCE_DX,
322
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
323
73.1k
      {SonyID_ILCE_6100, sbfILCE_DX,
324
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
325
73.1k
      {SonyID_ZV_1, sbfDSC_1in,
326
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
327
73.1k
      {SonyID_ILCE_7C, sbfILCE_FF,
328
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
329
73.1k
      {SonyID_ZV_E10, sbfILCE_DX,
330
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
331
73.1k
      {SonyID_ILCE_7SM3, sbfILCE_FF,
332
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
333
73.1k
      {SonyID_ILCE_1, sbfILCE_FF,
334
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
335
73.1k
      {SonyID_ILCE_1M2, sbfILCE_FF,
336
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
337
73.1k
      {SonyID_ILME_FX3, sbfILCE_FF,
338
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
339
73.1k
      {SonyID_ILME_FX2, sbfILCE_FF,
340
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
341
73.1k
      {SonyID_ILCE_7RM3A, sbfILCE_FF,
342
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
343
73.1k
      {SonyID_ILCE_7RM4A, sbfILCE_FF,
344
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0x019f, 0x024b, 0x024c, 0x0208},
345
73.1k
      {SonyID_ILCE_7M4, sbfILCE_FF,
346
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
347
73.1k
      {SonyID_ILCE_7RM5, sbfILCE_FF,
348
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
349
73.1k
      {SonyID_ILME_FX30, sbfILCE_DX,
350
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
351
73.1k
      {SonyID_ILCE_9M3, sbfILCE_FF,
352
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
353
73.1k
      {SonyID_ZV_E1, sbfILCE_FF,
354
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
355
73.1k
      {SonyID_ILCE_6700, sbfILCE_DX,
356
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
357
73.1k
      {SonyID_ZV_1M2, sbfDSC_1in,
358
73.1k
       LIBRAW_SONY_Tag2010i, 0x0320, 0xffff, 0x024b, 0x024c, 0x0208},
359
73.1k
      {SonyID_ILCE_7CR, sbfILCE_FF,
360
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
361
73.1k
      {SonyID_ILCE_7CM2, sbfILCE_FF,
362
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
363
73.1k
      {SonyID_ILX_LR1, sbfILCE_FF,
364
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
365
73.1k
      {SonyID_ZV_E10M2, sbfILCE_DX,
366
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
367
73.1k
      {SonyID_ILCE_7M5, sbfILCE_FF,
368
73.1k
       LIBRAW_SONY_Tag2010None, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
369
73.1k
  };
370
73.1k
  ilm.CamID = id;
371
73.1k
  int isPreProductionFW = 0;
372
73.1k
  if (
373
73.1k
         (!strncmp(model, "MODEL-NAME", 10))
374
73.0k
      || (!strncmp(model, "DSLR-A000", 9))
375
72.7k
      || (!strncmp(model, "SLT-A00", 7))
376
71.7k
      || (!strncmp(model, "NEX-00", 6))
377
73.1k
     ) {
378
1.73k
     isPreProductionFW = 1;
379
1.73k
  }
380
381
73.1k
  if (id == SonyID_DSC_R1)
382
904
  {
383
904
    ilm.CameraFormat = LIBRAW_FORMAT_APSC;
384
904
    ilm.CameraMount = ilm.LensMount = LIBRAW_MOUNT_FixedLens;
385
904
    imSony.CameraType = LIBRAW_SONY_DSC;
386
904
    imSony.group2010 = LIBRAW_SONY_Tag2010None;
387
904
    imSony.group9050 = LIBRAW_SONY_Tag9050None;
388
904
    return;
389
904
  }
390
391
5.05M
  for (unsigned i = 0; i < (sizeof SonyCamFeatures / sizeof *SonyCamFeatures); i++) {
392
5.03M
    if (SonyCamFeatures[i].scf[0] == id) {
393
49.1k
      ilm.CameraFormat = SonyCamFeatures[i].scf[1];
394
49.1k
      ilm.CameraMount = SonyCamFeatures[i].scf[2];
395
49.1k
      imSony.CameraType = SonyCamFeatures[i].scf[3];
396
49.1k
      if (SonyCamFeatures[i].scf[4])
397
2.85k
        ilm.LensMount = SonyCamFeatures[i].scf[4];
398
49.1k
      imSony.group2010 = SonyCamFeatures[i].scf[5];
399
49.1k
      imSony.real_iso_offset = SonyCamFeatures[i].scf[6];
400
49.1k
      imSony.ImageCount3_offset = SonyCamFeatures[i].scf[7];
401
49.1k
      imSony.MeteringMode_offset = SonyCamFeatures[i].scf[8];
402
49.1k
      imSony.ExposureProgram_offset = SonyCamFeatures[i].scf[9];
403
49.1k
      imSony.ReleaseMode2_offset = SonyCamFeatures[i].scf[10];
404
49.1k
      break;
405
49.1k
    }
406
5.03M
  }
407
408
72.2k
  switch (id) {
409
328
  case SonyID_ILCE_6100:
410
1.19k
  case SonyID_ILCE_6300:
411
1.59k
  case SonyID_ILCE_6400:
412
6.04k
  case SonyID_ILCE_6500:
413
6.36k
  case SonyID_ILCE_6600:
414
9.00k
  case SonyID_ILCE_7C:
415
9.67k
  case SonyID_ILCE_7M3:
416
10.8k
  case SonyID_ILCE_7RM2:
417
11.9k
  case SonyID_ILCE_7RM3:
418
12.4k
  case SonyID_ILCE_7RM3A:
419
12.6k
  case SonyID_ILCE_7RM4:
420
12.9k
  case SonyID_ILCE_7RM4A:
421
13.2k
  case SonyID_ILCE_7SM2:
422
13.3k
  case SonyID_ILCE_9:
423
14.4k
  case SonyID_ILCE_9M2:
424
14.9k
  case SonyID_ILCA_99M2:
425
15.6k
  case SonyID_ZV_E10:
426
15.6k
    if (!isPreProductionFW)
427
15.0k
    {
428
15.0k
      imSony.group9050 = LIBRAW_SONY_Tag9050b; // length: 944 bytes
429
15.0k
    }
430
568
    else
431
568
    {
432
568
      imSony.group9050 = LIBRAW_SONY_Tag9050a;
433
568
      imSony.ImageCount3_offset = 0xffff; // not valid
434
568
    }
435
15.6k
    break;
436
1.40k
  case SonyID_ILCE_1:
437
1.81k
  case SonyID_ILCE_7M4:
438
2.08k
  case SonyID_ILCE_7RM5:
439
2.35k
  case SonyID_ILCE_7SM3:
440
2.67k
  case SonyID_ILME_FX3:
441
3.20k
  case SonyID_ILX_LR1:
442
3.20k
    if (!isPreProductionFW)
443
2.83k
    {
444
2.83k
      imSony.group9050 = LIBRAW_SONY_Tag9050c; // length: 256 bytes
445
2.83k
    }
446
372
    else
447
372
    {
448
372
      imSony.group9050 = LIBRAW_SONY_Tag9050a;
449
372
      imSony.ImageCount3_offset = 0xffff; // not valid
450
372
    }
451
3.20k
    break;
452
330
  case SonyID_ILME_FX2:
453
592
  case SonyID_ILCE_1M2:
454
928
  case SonyID_ZV_E1:
455
1.03k
  case SonyID_ILCE_6700:
456
2.00k
  case SonyID_ILCE_7CR:
457
2.22k
  case SonyID_ILCE_7CM2:
458
2.72k
  case SonyID_ILCE_9M3:
459
2.97k
  case SonyID_ILCE_7M5:
460
3.30k
  case SonyID_ZV_E10M2:
461
3.30k
    imSony.group9050 = LIBRAW_SONY_Tag9050d;
462
3.30k
    break;
463
50.1k
  default: // see also process_Sony_0x9050
464
50.1k
    if (
465
50.1k
        (imSony.CameraType != LIBRAW_SONY_DSC) &&
466
46.6k
        (imSony.CameraType != LIBRAW_SONY_DSLR)
467
50.1k
       )
468
41.9k
      imSony.group9050 = LIBRAW_SONY_Tag9050a; // length: 3072 or 944 bytes
469
8.17k
    else
470
8.17k
      imSony.group9050 = LIBRAW_SONY_Tag9050None;
471
50.1k
    break;
472
72.2k
  }
473
474
72.2k
  if (isPreProductionFW) return;
475
476
70.5k
  char *sbstr = strstr(software, " v");
477
70.5k
  if (sbstr != NULL)
478
2.29k
  {
479
2.29k
    sbstr += 2;
480
2.29k
    strcpy(imCommon.firmware, sbstr);
481
2.29k
    imSony.firmware = float(atof(sbstr));
482
483
2.29k
    if ((id == SonyID_ILCE_7) ||
484
2.09k
        (id == SonyID_ILCE_7R))
485
392
    {
486
392
      if (imSony.firmware < 1.2f)
487
66
        imSony.ImageCount3_offset = 0x01aa;
488
326
      else
489
326
        imSony.ImageCount3_offset = 0x01c0;
490
392
    }
491
1.90k
    else if (id == SonyID_ILCE_6000)
492
378
    {
493
378
      if (imSony.firmware < 2.0f)
494
312
        imSony.ImageCount3_offset = 0x01aa;
495
66
      else
496
66
        imSony.ImageCount3_offset = 0x01c0;
497
378
    }
498
1.52k
    else if ((id == SonyID_ILCE_7S) ||
499
1.44k
             (id == SonyID_ILCE_7M2))
500
228
    {
501
228
      if (imSony.firmware < 1.2f)
502
72
        imSony.ImageCount3_offset = 0x01a0;
503
156
      else
504
156
        imSony.ImageCount3_offset = 0x01b6;
505
228
    }
506
2.29k
  }
507
508
70.5k
#undef sbfILCA_FF
509
70.5k
#undef sbfILCA_DX
510
70.5k
#undef sbfILCE_FF
511
70.5k
#undef sbfILCE_DX
512
70.5k
#undef sbfDSC_FF
513
70.5k
#undef sbfDSC_1in
514
70.5k
#undef sbfDSC_1div2p3in
515
70.5k
#undef sbfSLT_FF
516
70.5k
#undef sbfSLT_DX
517
70.5k
#undef sbfNEX_FF
518
70.5k
#undef sbfNEX_DX
519
70.5k
#undef sbfDSLR_FF
520
70.5k
#undef sbfDSLR_DX
521
70.5k
} // closing setSonyBodyFeatures()
522
523
void LibRaw::parseSonyLensType2(uchar a, uchar b)
524
22.8k
{
525
22.8k
  ushort lid2;
526
22.8k
  lid2 = (((ushort)a) << 8) | ((ushort)b);
527
22.8k
  if (!lid2)
528
3.98k
    return;
529
18.8k
  if (lid2 < 0x100)
530
7.36k
  {
531
7.36k
    if ((ilm.AdapterID != 0x4900) && (ilm.AdapterID != 0xef00))
532
6.72k
    {
533
6.72k
      ilm.AdapterID = lid2;
534
6.72k
      switch (lid2)
535
6.72k
      {
536
576
      case     1: // Sony LA-EA1 or Sigma MC-11 Adapter
537
1.55k
      case     2: // Sony LA-EA2
538
1.80k
      case     3: // Sony LA-EA3
539
2.38k
      case     6: // Sony LA-EA4
540
2.61k
      case     7: // Sony LA-EA5
541
2.61k
      case 24593: // LA-EA4r MonsterAdapter, id = 0x6011
542
2.61k
        ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
543
2.61k
        break;
544
678
      case  44: // Metabones Canon EF Smart Adapter
545
1.24k
      case  78: // Metabones Canon EF Smart Adapter Mark III or Other Adapter
546
2.38k
      case 184: // Metabones Canon EF Speed Booster Ultra
547
2.71k
      case 234: // Metabones Canon EF Smart Adapter Mark IV
548
3.04k
      case 239: // Metabones Canon EF Speed Booster
549
3.04k
        ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
550
3.04k
        break;
551
6.72k
      }
552
6.72k
    }
553
7.36k
  }
554
11.4k
  else
555
11.4k
    ilm.LensID = lid2;
556
557
18.8k
  if ((lid2 >= 50481) &&
558
3.72k
      (lid2 < 50500)) {
559
278
    strcpy(ilm.Adapter, "MC-11");
560
278
    ilm.AdapterID = 0x4900;
561
18.5k
  } else if ((lid2 > 0xef00) &&
562
3.09k
             (lid2 < 0xffff) &&
563
2.22k
             (lid2 != 0xff00)) {
564
1.60k
    ilm.AdapterID = 0xef00;
565
1.60k
    ilm.LensID -= ilm.AdapterID;
566
1.60k
    ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
567
1.60k
  }
568
569
18.8k
  return;
570
18.8k
}
571
572
void LibRaw::parseSonyLensFeatures(uchar a, uchar b)
573
40.9k
{
574
575
40.9k
  ushort features;
576
40.9k
  features = (((ushort)a) << 8) | ((ushort)b);
577
578
40.9k
  if ((ilm.LensMount == LIBRAW_MOUNT_Canon_EF) ||
579
35.9k
      (ilm.LensMount != LIBRAW_MOUNT_Sigma_X3F) || !features)
580
35.8k
    return;
581
582
5.06k
  ilm.LensFeatures_pre[0] = 0;
583
5.06k
  ilm.LensFeatures_suf[0] = 0;
584
5.06k
  if ((features & 0x0200) && (features & 0x0100))
585
472
    strcpy(ilm.LensFeatures_pre, "E");
586
4.59k
  else if (features & 0x0200)
587
2.13k
    strcpy(ilm.LensFeatures_pre, "FE");
588
2.46k
  else if (features & 0x0100)
589
938
    strcpy(ilm.LensFeatures_pre, "DT");
590
591
5.06k
  if (!ilm.LensFormat && !ilm.LensMount)
592
0
  {
593
0
    ilm.LensFormat = LIBRAW_FORMAT_FF;
594
0
    ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
595
596
0
    if ((features & 0x0200) && (features & 0x0100))
597
0
    {
598
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
599
0
      ilm.LensMount = LIBRAW_MOUNT_Sony_E;
600
0
    }
601
0
    else if (features & 0x0200)
602
0
    {
603
0
      ilm.LensMount = LIBRAW_MOUNT_Sony_E;
604
0
    }
605
0
    else if (features & 0x0100)
606
0
    {
607
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
608
0
    }
609
0
  }
610
611
5.06k
  if (features & 0x4000)
612
3.53k
    strnXcat(ilm.LensFeatures_pre, " PZ");
613
614
5.06k
  if (features & 0x0008)
615
972
    strnXcat(ilm.LensFeatures_suf, " G");
616
4.09k
  else if (features & 0x0004)
617
840
    strnXcat(ilm.LensFeatures_suf, " ZA");
618
619
5.06k
  if ((features & 0x0020) && (features & 0x0040))
620
704
    strnXcat(ilm.LensFeatures_suf, " Macro");
621
4.36k
  else if (features & 0x0020)
622
324
    strnXcat(ilm.LensFeatures_suf, " STF");
623
4.04k
  else if (features & 0x0040)
624
744
    strnXcat(ilm.LensFeatures_suf, " Reflex");
625
3.29k
  else if (features & 0x0080)
626
410
    strnXcat(ilm.LensFeatures_suf, " Fisheye");
627
628
5.06k
  if (features & 0x0001)
629
942
    strnXcat(ilm.LensFeatures_suf, " SSM");
630
4.12k
  else if (features & 0x0002)
631
1.13k
    strnXcat(ilm.LensFeatures_suf, " SAM");
632
633
5.06k
  if (features & 0x8000)
634
728
    strnXcat(ilm.LensFeatures_suf, " OSS");
635
636
5.06k
  if (features & 0x2000)
637
838
    strnXcat(ilm.LensFeatures_suf, " LE");
638
639
5.06k
  if (features & 0x0800)
640
1.69k
    strnXcat(ilm.LensFeatures_suf, " II");
641
642
5.06k
  if (ilm.LensFeatures_suf[0] == ' ')
643
2.95k
    memmove(ilm.LensFeatures_suf, ilm.LensFeatures_suf + 1,
644
2.95k
            strbuflen(ilm.LensFeatures_suf) - 1);
645
646
5.06k
  return;
647
40.9k
}
648
649
void LibRaw::process_Sony_0x0116(uchar *buf, ushort len, unsigned long long id)
650
8.30k
{
651
8.30k
  int i = 0;
652
653
8.30k
  if (((id == SonyID_DSLR_A900)      ||
654
7.44k
       (id == SonyID_DSLR_A900_APSC) ||
655
5.87k
       (id == SonyID_DSLR_A850)      ||
656
5.61k
       (id == SonyID_DSLR_A850_APSC)) &&
657
2.77k
      (len >= 2))
658
1.12k
    i = 1;
659
7.17k
  else if ((id >= SonyID_DSLR_A550) && (len >= 3))
660
1.96k
    i = 2;
661
5.21k
  else
662
5.21k
    return;
663
664
3.09k
  imCommon.BatteryTemperature = (float)(buf[i] - 32) / 1.8f;
665
3.09k
}
666
667
void LibRaw::process_Sony_0x2010(uchar *buf, ushort len)
668
11.8k
{
669
11.8k
  if (imSony.group2010 == LIBRAW_SONY_Tag2010None) return;
670
671
5.10k
  ushort ar_offset = 0;
672
5.10k
  if (imSony.group2010 == LIBRAW_SONY_Tag2010e) {
673
344
    if (ilm.CamID == SonyID_DSC_RX100) {
674
30
      ar_offset = 0x1a88;
675
314
    } else {
676
314
      ar_offset = 0x192c;
677
314
    }
678
4.75k
  } else if (imSony.group2010 == LIBRAW_SONY_Tag2010f) {
679
446
    ar_offset = 0x192c;
680
4.31k
  } else if (imSony.group2010 == LIBRAW_SONY_Tag2010g) {
681
248
    ar_offset = 0x1958;
682
4.06k
  } else if (imSony.group2010 == LIBRAW_SONY_Tag2010h) {
683
862
    ar_offset = 0x192c;
684
3.20k
  } else if (imSony.group2010 == LIBRAW_SONY_Tag2010i) {
685
2.74k
    ar_offset = 0x188c;
686
2.74k
  }
687
5.10k
  if (ar_offset != 0 && ar_offset<len) {
688
1.12k
    int s = (int)SonySubstitution[buf[ar_offset]];
689
1.12k
    if (s == 0) {
690
268
      imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_16to9;
691
860
    } else if (s == 1) {
692
264
    imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_4to3;
693
596
    }  else if (s == 2) {
694
276
    imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_3to2;
695
320
    } else if (s == 3) {
696
82
    imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_1to1;
697
238
    } else {
698
238
      imSony.AspectRatio = (float)s;
699
238
    }
700
1.12k
  }
701
702
5.10k
  if ((imSony.real_iso_offset != 0xffff) &&
703
5.10k
      (len >= (imSony.real_iso_offset + 2)) && (imCommon.real_ISO < 0.1f))
704
860
  {
705
860
    uchar s[2];
706
860
    s[0] = SonySubstitution[buf[imSony.real_iso_offset]];
707
860
    s[1] = SonySubstitution[buf[imSony.real_iso_offset + 1]];
708
860
    imCommon.real_ISO =
709
860
        100.0f * libraw_powf64l(2.0f, (16 - ((float)sget2(s)) / 256.0f));
710
860
  }
711
712
5.10k
  if ((imSony.MeteringMode_offset != 0xffff) &&
713
5.10k
      (imSony.ExposureProgram_offset != 0xffff) &&
714
5.10k
      (len > (imSony.MeteringMode_offset)) &&
715
2.26k
    (len > (imSony.ExposureProgram_offset))
716
5.10k
    )
717
2.26k
  {
718
2.26k
    imgdata.shootinginfo.MeteringMode =
719
2.26k
        SonySubstitution[buf[imSony.MeteringMode_offset]];
720
2.26k
    imgdata.shootinginfo.ExposureProgram =
721
2.26k
        SonySubstitution[buf[imSony.ExposureProgram_offset]];
722
2.26k
  }
723
724
5.10k
  if ((imSony.ReleaseMode2_offset != 0xffff) &&
725
5.10k
      (len > (imSony.ReleaseMode2_offset)))
726
2.26k
  {
727
2.26k
    imgdata.shootinginfo.DriveMode =
728
2.26k
        SonySubstitution[buf[imSony.ReleaseMode2_offset]];
729
2.26k
  }
730
5.10k
}
731
732
void LibRaw::process_Sony_0x9050(uchar *buf, ushort len, unsigned long long id)
733
37.4k
{
734
37.4k
  ushort lid;
735
37.4k
  uchar s[4];
736
37.4k
  int c;
737
738
739
37.4k
  if (
740
37.4k
      (imSony.group9050 == LIBRAW_SONY_Tag9050None) &&
741
1.39k
      (imSony.CameraType != LIBRAW_SONY_DSC) &&
742
718
      (imSony.CameraType != LIBRAW_SONY_DSLR)
743
37.4k
  ) {
744
364
    imSony.group9050 = LIBRAW_SONY_Tag9050a;
745
364
  }
746
747
/*
748
printf ("==>> Tag9050, len: 0x%04x, type: %s, model: =%s=, CamID: %llu, ARW version: %d\n",
749
                                  len,
750
                                  imSony.group9050==LIBRAW_SONY_Tag9050None?"None":
751
                                  imSony.group9050==LIBRAW_SONY_Tag9050a?"9050a":
752
                                  imSony.group9050==LIBRAW_SONY_Tag9050b?"9050b":
753
                                  imSony.group9050==LIBRAW_SONY_Tag9050c?"9050c":
754
                                  imSony.group9050==LIBRAW_SONY_Tag9050d?"9050d":
755
                                  "---",
756
                                  model, id,
757
                                  imSony.FileFormat);
758
*/
759
760
37.4k
  if (imSony.group9050 == LIBRAW_SONY_Tag9050None) return;
761
762
36.4k
  if ((ilm.CameraMount != LIBRAW_MOUNT_Sony_E) &&
763
17.5k
      (imSony.CameraType != LIBRAW_SONY_DSC))
764
17.5k
  {
765
17.5k
    if (len < 2)
766
1.47k
      return;
767
16.0k
    if (buf[0])
768
12.5k
      ilm.MaxAp4CurFocal =
769
12.5k
        my_roundf(
770
12.5k
          libraw_powf64l(2.0f, ((float)SonySubstitution[buf[0]] / 8.0f - 1.06f) / 2.0f) *
771
12.5k
             10.0f) / 10.0f;
772
773
16.0k
    if (buf[1])
774
12.1k
      ilm.MinAp4CurFocal =
775
12.1k
        my_roundf(
776
12.1k
          libraw_powf64l(2.0f, ((float)SonySubstitution[buf[1]] / 8.0f - 1.06f) / 2.0f) *
777
12.1k
             10.0f) / 10.0f;
778
16.0k
  }
779
780
34.9k
  if ((imSony.group9050 == LIBRAW_SONY_Tag9050b) ||
781
23.9k
      (imSony.group9050 == LIBRAW_SONY_Tag9050c)) {
782
12.1k
    unsigned start_InternalBodySerial = 0x88;
783
12.1k
    if (id == SonyID_ILCE_1) start_InternalBodySerial += 2;
784
12.1k
    if (len <= start_InternalBodySerial+5) return;
785
11.1k
    unsigned long long b88 = SonySubstitution[buf[start_InternalBodySerial]];
786
11.1k
    unsigned long long b89 = SonySubstitution[buf[start_InternalBodySerial+1]];
787
11.1k
    unsigned long long b8a = SonySubstitution[buf[start_InternalBodySerial+2]];
788
11.1k
    unsigned long long b8b = SonySubstitution[buf[start_InternalBodySerial+3]];
789
11.1k
    unsigned long long b8c = SonySubstitution[buf[start_InternalBodySerial+4]];
790
11.1k
    unsigned long long b8d = SonySubstitution[buf[start_InternalBodySerial+5]];
791
11.1k
    sprintf(imgdata.shootinginfo.InternalBodySerial, "%06llx",
792
11.1k
            (b88 << 40) + (b89 << 32) + (b8a << 24) + (b8b << 16) + (b8c << 8) + b8d);
793
794
22.8k
  } else if (imSony.group9050 == LIBRAW_SONY_Tag9050d) {
795
784
    unsigned start_InternalBodySerial = 0x38;
796
784
    if (len <= start_InternalBodySerial+5) return;
797
690
    unsigned long long b38 = SonySubstitution[buf[start_InternalBodySerial]];
798
690
    unsigned long long b39 = SonySubstitution[buf[start_InternalBodySerial+1]];
799
690
    unsigned long long b4a = SonySubstitution[buf[start_InternalBodySerial+2]];
800
690
    unsigned long long b4b = SonySubstitution[buf[start_InternalBodySerial+3]];
801
690
    unsigned long long b4c = SonySubstitution[buf[start_InternalBodySerial+4]];
802
690
    unsigned long long b4d = SonySubstitution[buf[start_InternalBodySerial+5]];
803
690
    sprintf(imgdata.shootinginfo.InternalBodySerial, "%06llx",
804
690
            (b38 << 40) + (b39 << 32) + (b4a << 24) + (b4b << 16) + (b4c << 8) + b4d);
805
806
22.0k
  } else if (imSony.group9050 == LIBRAW_SONY_Tag9050a) {
807
22.0k
      if ((ilm.CameraMount == LIBRAW_MOUNT_Sony_E) &&
808
6.34k
             (id != SonyID_NEX_5N) &&
809
5.34k
             (id != SonyID_NEX_7)  &&
810
5.20k
             (id != SonyID_NEX_VG20)) {
811
3.81k
      if (len <= 0x7f) return;
812
3.20k
      unsigned b7c = SonySubstitution[buf[0x7c]];
813
3.20k
      unsigned b7d = SonySubstitution[buf[0x7d]];
814
3.20k
      unsigned b7e = SonySubstitution[buf[0x7e]];
815
3.20k
      unsigned b7f = SonySubstitution[buf[0x7f]];
816
3.20k
      sprintf(imgdata.shootinginfo.InternalBodySerial, "%04x",
817
3.20k
              (b7c << 24) + (b7d << 16) + (b7e << 8) + b7f);
818
819
18.2k
    } else if (ilm.CameraMount == LIBRAW_MOUNT_Minolta_A) {
820
9.75k
      if (len <= 0xf4) return;
821
9.36k
      unsigned long long bf0 = SonySubstitution[buf[0xf0]];
822
9.36k
      unsigned long long bf1 = SonySubstitution[buf[0xf1]];
823
9.36k
      unsigned long long bf2 = SonySubstitution[buf[0xf2]];
824
9.36k
      unsigned long long bf3 = SonySubstitution[buf[0xf3]];
825
9.36k
      unsigned long long bf4 = SonySubstitution[buf[0xf4]];
826
9.36k
      sprintf(imgdata.shootinginfo.InternalBodySerial, "%05llx",
827
9.36k
              (bf0 << 32) + (bf1 << 24) + (bf2 << 16) + (bf3 << 8) + bf4);
828
9.36k
    }
829
22.0k
  }
830
831
32.9k
  if (imSony.CameraType != LIBRAW_SONY_DSC)
832
32.9k
  {
833
32.9k
    if (len <= 0x106)
834
750
      return;
835
32.1k
    if (buf[0x3d] | buf[0x3c])
836
28.5k
    {
837
28.5k
      lid = SonySubstitution[buf[0x3d]] << 8 | SonySubstitution[buf[0x3c]];
838
28.5k
      ilm.CurAp = libraw_powf64l(2.0f, ((float)lid / 256.0f - 16.0f) / 2.0f);
839
28.5k
    }
840
32.1k
    if (buf[0x105] &&
841
18.9k
        (ilm.LensMount != LIBRAW_MOUNT_Canon_EF) &&
842
15.8k
        (ilm.LensMount != LIBRAW_MOUNT_Sigma_X3F)) {
843
11.8k
      switch (SonySubstitution[buf[0x105]]) {
844
634
        case 1:
845
634
          ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
846
634
          break;
847
580
        case 2:
848
580
          ilm.LensMount = LIBRAW_MOUNT_Sony_E;
849
580
        break;
850
11.8k
      }
851
11.8k
    }
852
32.1k
    if (buf[0x106]) {
853
19.7k
      switch (SonySubstitution[buf[0x106]]) {
854
3.33k
        case 1:
855
3.33k
          ilm.LensFormat = LIBRAW_FORMAT_APSC;
856
3.33k
          break;
857
454
        case 2:
858
454
          ilm.LensFormat = LIBRAW_FORMAT_FF;
859
454
        break;
860
19.7k
      }
861
19.7k
    }
862
32.1k
  }
863
864
32.1k
  if (ilm.CameraMount == LIBRAW_MOUNT_Sony_E)
865
17.0k
  {
866
17.0k
    if (len <= 0x108)
867
72
      return;
868
16.9k
    parseSonyLensType2(
869
16.9k
        SonySubstitution[buf[0x0108]], // LensType2 - Sony lens ids
870
16.9k
        SonySubstitution[buf[0x0107]]);
871
16.9k
  }
872
873
32.1k
  if (len <= 0x10a)
874
268
    return;
875
31.8k
  if ((ilm.LensID == LIBRAW_LENS_NOT_SET) &&
876
11.8k
      (ilm.CameraMount == LIBRAW_MOUNT_Minolta_A) &&
877
1.87k
      (buf[0x010a] | buf[0x0109]))
878
492
  {
879
492
    ilm.LensID = // LensType - Minolta/Sony lens ids
880
492
        SonySubstitution[buf[0x010a]] << 8 | SonySubstitution[buf[0x0109]];
881
882
492
    if ((ilm.LensID > 0x4900) && (ilm.LensID <= 0x5900))
883
198
    {
884
198
      ilm.AdapterID = 0x4900;
885
198
      ilm.LensID -= ilm.AdapterID;
886
198
      ilm.LensMount = LIBRAW_MOUNT_Sigma_X3F;
887
198
      strcpy(ilm.Adapter, "MC-11");
888
198
    }
889
890
294
    else if ((ilm.LensID > 0xef00) && (ilm.LensID < 0xffff) &&
891
82
             (ilm.LensID != 0xff00))
892
80
    {
893
80
      ilm.AdapterID = 0xef00;
894
80
      ilm.LensID -= ilm.AdapterID;
895
80
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
896
80
    }
897
492
  }
898
899
31.8k
  if ((id >= SonyID_SLT_A65) && (id <= SonyID_NEX_F3))
900
10.8k
  {
901
10.8k
    if (len <= 0x116)
902
270
      return;
903
    // "SLT-A65", "SLT-A77", "NEX-7", "NEX-VG20",
904
    // "SLT-A37", "SLT-A57", "NEX-F3", "Lunar"
905
10.6k
    parseSonyLensFeatures(SonySubstitution[buf[0x115]],
906
10.6k
                          SonySubstitution[buf[0x116]]);
907
10.6k
  }
908
20.9k
  else if (ilm.CameraMount != LIBRAW_MOUNT_FixedLens)
909
18.3k
  {
910
18.3k
    if (len <= 0x117)
911
810
      return;
912
17.5k
    parseSonyLensFeatures(SonySubstitution[buf[0x116]],
913
17.5k
                          SonySubstitution[buf[0x117]]);
914
17.5k
  }
915
916
30.7k
  if ((imSony.ImageCount3_offset != 0xffff) &&
917
21.5k
      (len >= (imSony.ImageCount3_offset + 4)))
918
21.1k
  {
919
84.5k
    FORC4 s[c] = SonySubstitution[buf[imSony.ImageCount3_offset + c]];
920
21.1k
    imSony.ImageCount3 = sget4(s);
921
21.1k
  }
922
923
30.7k
  return;
924
31.8k
}
925
926
void LibRaw::process_Sony_0x9400(uchar *buf, ushort len, unsigned long long /*id*/)
927
8.09k
{
928
929
8.09k
  uchar s[4];
930
8.09k
  int c;
931
8.09k
  uchar bufx = buf[0];
932
933
8.09k
  if (((bufx == 0x23) ||
934
7.71k
       (bufx == 0x24) ||
935
7.35k
       (bufx == 0x26) ||
936
7.28k
       (bufx == 0x28) ||
937
7.21k
       (bufx == 0x31) ||
938
6.84k
       (bufx == 0x32) ||
939
6.49k
       (bufx == 0x33))
940
1.93k
    &&
941
1.93k
      (len >= 0x1f)) // 0x9400 'c' version
942
1.14k
  {
943
1.14k
    imSony.Sony0x9400_version = 0xc;
944
1.14k
    imSony.Sony0x9400_ReleaseMode2 = SonySubstitution[buf[0x09]];
945
946
1.14k
    if ((imSony.group2010 == LIBRAW_SONY_Tag2010g) ||
947
1.10k
        (imSony.group2010 == LIBRAW_SONY_Tag2010h)) {
948
1.51k
      FORC4 s[c] = SonySubstitution[buf[0x0a + c]];
949
378
      imSony.ShotNumberSincePowerUp = sget4(s);
950
762
    } else {
951
762
      imSony.ShotNumberSincePowerUp = SonySubstitution[buf[0x0a]];
952
762
    }
953
954
4.56k
    FORC4 s[c] = SonySubstitution[buf[0x12 + c]];
955
1.14k
    imSony.Sony0x9400_SequenceImageNumber = sget4(s);
956
957
1.14k
    imSony.Sony0x9400_SequenceLength1 = SonySubstitution[buf[0x16]]; // shots
958
959
4.56k
    FORC4 s[c] = SonySubstitution[buf[0x1a + c]];
960
1.14k
    imSony.Sony0x9400_SequenceFileNumber = sget4(s);
961
962
1.14k
    imSony.Sony0x9400_SequenceLength2 = SonySubstitution[buf[0x1e]]; // files //ilce-7m5 modifed here
963
1.14k
  }
964
965
6.95k
  else if ((bufx == 0x0c) && (len >= 0x1f)) // 0x9400 'b' version
966
228
  {
967
228
    imSony.Sony0x9400_version = 0xb;
968
969
912
    FORC4 s[c] = SonySubstitution[buf[0x08 + c]];
970
228
    imSony.Sony0x9400_SequenceImageNumber = sget4(s);
971
972
912
    FORC4 s[c] = SonySubstitution[buf[0x0c + c]];
973
228
    imSony.Sony0x9400_SequenceFileNumber = sget4(s);
974
975
228
    imSony.Sony0x9400_ReleaseMode2 = SonySubstitution[buf[0x10]];
976
977
228
    imSony.Sony0x9400_SequenceLength1 = SonySubstitution[buf[0x1e]];
978
228
  }
979
980
6.72k
  else if ((bufx == 0x0a) && (len >= 0x23)) // 0x9400 'a' version
981
1.16k
  {
982
1.16k
    imSony.Sony0x9400_version = 0xa;
983
984
4.67k
    FORC4 s[c] = SonySubstitution[buf[0x08 + c]];
985
1.16k
    imSony.Sony0x9400_SequenceImageNumber = sget4(s);
986
987
4.67k
    FORC4 s[c] = SonySubstitution[buf[0x0c + c]];
988
1.16k
    imSony.Sony0x9400_SequenceFileNumber = sget4(s);
989
990
1.16k
    imSony.Sony0x9400_ReleaseMode2 = SonySubstitution[buf[0x10]];
991
992
1.16k
    imSony.Sony0x9400_SequenceLength1 = SonySubstitution[buf[0x22]];
993
1.16k
  }
994
995
5.55k
  else
996
5.55k
    return;
997
8.09k
}
998
999
void LibRaw::process_Sony_0x9402(uchar *buf, ushort len)
1000
9.29k
{
1001
1002
9.29k
  if (len < 0x17)
1003
772
    return;
1004
1005
8.52k
  if ((imSony.CameraType == LIBRAW_SONY_SLT)  ||
1006
7.49k
      (imSony.CameraType == LIBRAW_SONY_ILCA) ||
1007
6.75k
      (buf[0x00] == 0x05)                     ||
1008
6.22k
      (buf[0x00] == 0xff))
1009
3.03k
    return;
1010
1011
5.49k
  if (buf[0x02] == 0xff)
1012
1.55k
  {
1013
1.55k
    imCommon.AmbientTemperature =
1014
1.55k
      (float)((short)SonySubstitution[buf[0x04]]);
1015
1.55k
  }
1016
1017
5.49k
  if (imgdata.shootinginfo.FocusMode == LIBRAW_SONY_FOCUSMODE_UNKNOWN)
1018
278
  {
1019
278
  imgdata.shootinginfo.FocusMode = SonySubstitution[buf[0x16]]&0x7f;
1020
278
  }
1021
5.49k
  if (len >= 0x18)
1022
5.26k
    imSony.AFAreaMode = (uint16_t)SonySubstitution[buf[0x17]];
1023
1024
5.49k
  if ((len >= 0x2e) &&
1025
2.35k
      (imSony.CameraType != LIBRAW_SONY_DSC))
1026
1.36k
  {
1027
1.36k
    imSony.FocusPosition = (ushort)SonySubstitution[buf[0x2d]]; // FocusPosition2
1028
1.36k
  }
1029
5.49k
  return;
1030
8.52k
}
1031
1032
void LibRaw::process_Sony_0x9403(uchar *buf, ushort len)
1033
4.47k
{
1034
4.47k
  if ((len < 6) || (unique_id == SonyID_ILCE_7C))
1035
970
    return;
1036
3.50k
  uchar bufx = SonySubstitution[buf[4]];
1037
3.50k
  if ((bufx == 0x00) || (bufx == 0x94))
1038
1.90k
    return;
1039
1040
1.60k
  imCommon.SensorTemperature = (float)((short)SonySubstitution[buf[5]]);
1041
1042
1.60k
  return;
1043
3.50k
}
1044
1045
void LibRaw::process_Sony_0x9406(uchar *buf, ushort len)
1046
2.49k
{
1047
2.49k
  if (len < 6)
1048
590
    return;
1049
1.90k
  uchar bufx = buf[0];
1050
1.90k
  if ((bufx != 0x01) && (bufx != 0x08) && (bufx != 0x1b))
1051
548
    return;
1052
1.35k
  bufx = buf[2];
1053
1.35k
  if ((bufx != 0x08) && (bufx != 0x1b))
1054
926
    return;
1055
1056
430
  imCommon.BatteryTemperature =
1057
430
      (float)(SonySubstitution[buf[5]] - 32) / 1.8f;
1058
1059
430
  return;
1060
1.35k
}
1061
1062
void LibRaw::process_Sony_0x940c(uchar *buf, ushort len)
1063
7.46k
{
1064
7.46k
  if ((imSony.CameraType != LIBRAW_SONY_ILCE) &&
1065
5.03k
      (imSony.CameraType != LIBRAW_SONY_NEX))
1066
3.41k
    return;
1067
4.05k
  if (len <= 0x000a)
1068
540
    return;
1069
3.51k
  ushort lid2;
1070
3.51k
  if ((ilm.LensMount != LIBRAW_MOUNT_Canon_EF) &&
1071
2.49k
      (ilm.LensMount != LIBRAW_MOUNT_Sigma_X3F))
1072
1.89k
  {
1073
1.89k
    switch (SonySubstitution[buf[0x0008]])
1074
1.89k
    {
1075
536
    case 1:
1076
602
    case 5:
1077
602
      ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
1078
602
      break;
1079
90
    case 4:
1080
90
      ilm.LensMount = LIBRAW_MOUNT_Sony_E;
1081
90
      break;
1082
1.89k
    }
1083
1.89k
  }
1084
3.51k
  if (ilm.LensMount != LIBRAW_MOUNT_Unknown) {
1085
2.74k
    lid2 = (((ushort)SonySubstitution[buf[0x000a]]) << 8) |
1086
2.74k
           ((ushort)SonySubstitution[buf[0x0009]]);
1087
2.74k
    if ((lid2 > 0) &&
1088
1.62k
        ((lid2 < 32784) || (ilm.LensID == 0x1999) || (ilm.LensID == 0xffff)))
1089
1.36k
      parseSonyLensType2(
1090
1.36k
          SonySubstitution[buf[0x000a]], // LensType2 - Sony lens ids
1091
1.36k
          SonySubstitution[buf[0x0009]]);
1092
2.74k
    if ((lid2 == 44) || (lid2 == 78) || (lid2 == 184) || (lid2 == 234) ||
1093
2.11k
        (lid2 == 239))
1094
724
      ilm.AdapterID = lid2;
1095
2.74k
    }
1096
3.51k
  return;
1097
3.51k
}
1098
1099
void LibRaw::process_Sony_0x940e(uchar *buf, ushort len, unsigned long long id)
1100
8.32k
{
1101
8.32k
  if (len < 3)
1102
888
    return;
1103
1104
7.43k
  if (((imSony.CameraType != LIBRAW_SONY_SLT) &&
1105
4.55k
       (imSony.CameraType != LIBRAW_SONY_ILCA)) ||
1106
5.44k
      (id == SonyID_SLT_A33)  ||
1107
4.83k
      (id == SonyID_SLT_A35)  ||
1108
4.76k
      (id == SonyID_SLT_A55))
1109
2.74k
    return;
1110
1111
4.68k
  int c;
1112
4.68k
  imSony.AFType = SonySubstitution[buf[0x02]];
1113
1114
4.68k
  if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT)
1115
452
  {
1116
452
    unsigned tag = 0x940e;
1117
452
    imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
1118
452
    imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
1119
452
    imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
1120
452
    imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length);
1121
452
    FORC((int)imCommon.afdata[imCommon.afcount].AFInfoData_length)
1122
1.12M
      imCommon.afdata[imCommon.afcount].AFInfoData[c] = SonySubstitution[buf[c]];
1123
452
    imCommon.afcount++;
1124
452
  }
1125
1126
4.68k
  if (imSony.CameraType == LIBRAW_SONY_ILCA)
1127
2.56k
  {
1128
2.56k
    if (len >= 0x0051)
1129
2.05k
    {
1130
2.05k
      imgdata.shootinginfo.FocusMode = SonySubstitution[buf[0x05]];
1131
2.05k
      imSony.nAFPointsUsed =
1132
2.05k
          MIN(10, sizeof imSony.AFPointsUsed);
1133
20.5k
      FORC(imSony.nAFPointsUsed) imSony.AFPointsUsed[c] = SonySubstitution[buf[0x10 +c]];
1134
2.05k
      imSony.AFAreaMode = (uint16_t)SonySubstitution[buf[0x3a]];
1135
2.05k
      imSony.AFMicroAdjValue = SonySubstitution[buf[0x0050]];
1136
2.05k
      if (!imSony.AFMicroAdjValue) imSony.AFMicroAdjValue = 0x7f;
1137
718
      else imSony.AFMicroAdjOn = 1;
1138
2.05k
    }
1139
2.56k
  }
1140
2.12k
  else
1141
2.12k
  {
1142
2.12k
    if (len >= 0x017e)
1143
1.85k
    {
1144
1.85k
      imSony.AFAreaMode = (uint16_t)SonySubstitution[buf[0x0a]];
1145
1.85k
      imgdata.shootinginfo.FocusMode = SonySubstitution[buf[0x0b]];
1146
1.85k
      imSony.nAFPointsUsed =
1147
1.85k
          MIN(4, sizeof imSony.AFPointsUsed);
1148
7.43k
      FORC(imSony.nAFPointsUsed) imSony.AFPointsUsed[c] = SonySubstitution[buf[0x016e +c]];
1149
1.85k
      imSony.AFMicroAdjValue = SonySubstitution[buf[0x017d]];
1150
1.85k
      if (!imSony.AFMicroAdjValue) imSony.AFMicroAdjValue = 0x7f;
1151
1.43k
      else imSony.AFMicroAdjOn = 1;
1152
1.85k
    }
1153
2.12k
  }
1154
1155
4.68k
}
1156
1157
void LibRaw::parseSonyMakernotes(
1158
    INT64 base, unsigned tag, unsigned type, unsigned len, unsigned dng_writer,
1159
    uchar *&table_buf_0x0116, ushort &table_buf_0x0116_len,
1160
    uchar *&table_buf_0x2010, ushort &table_buf_0x2010_len,
1161
    uchar *&table_buf_0x9050, ushort &table_buf_0x9050_len,
1162
    uchar *&table_buf_0x9400, ushort &table_buf_0x9400_len,
1163
    uchar *&table_buf_0x9402, ushort &table_buf_0x9402_len,
1164
    uchar *&table_buf_0x9403, ushort &table_buf_0x9403_len,
1165
    uchar *&table_buf_0x9406, ushort &table_buf_0x9406_len,
1166
    uchar *&table_buf_0x940c, ushort &table_buf_0x940c_len,
1167
    uchar *&table_buf_0x940e, ushort &table_buf_0x940e_len)
1168
7.77M
{
1169
7.77M
  ushort lid, a, c, d;
1170
7.77M
  uchar *table_buf;
1171
7.77M
  uchar uc;
1172
7.77M
  uchar s[2];
1173
7.77M
  int LensDataValid = 0;
1174
7.77M
  unsigned uitemp;
1175
7.77M
  ushort u16temp;
1176
1177
// printf ("==>> tag 0x%x, len %d, type %d, model =%s=, cam.id 0x%llx, cam.type %d, =%s=\n",
1178
// tag, len, type, model, ilm.CamID, imSony.CameraType, imSony.MetaVersion);
1179
1180
7.77M
  if (tag == 0xb000)
1181
6.74k
  {
1182
26.9k
    FORC4 imSony.FileFormat = imSony.FileFormat * 10 + fgetc(ifp);
1183
6.74k
  }
1184
7.76M
  else if (tag == 0xb001) // Sony ModelID
1185
73.1k
  {
1186
73.1k
    unique_id = get2();
1187
73.1k
    setSonyBodyFeatures(unique_id);
1188
1189
73.1k
    if (table_buf_0x0116_len)
1190
1.56k
    {
1191
1.56k
      process_Sony_0x0116(table_buf_0x0116, table_buf_0x0116_len, unique_id);
1192
1.56k
      free(table_buf_0x0116);
1193
1.56k
      table_buf_0x0116_len = 0;
1194
1.56k
    }
1195
1196
73.1k
    if (table_buf_0x2010_len)
1197
644
    {
1198
644
      process_Sony_0x2010(table_buf_0x2010, table_buf_0x2010_len);
1199
644
      free(table_buf_0x2010);
1200
644
      table_buf_0x2010_len = 0;
1201
644
    }
1202
1203
73.1k
    if (table_buf_0x9050_len)
1204
1.55k
    {
1205
1.55k
      imSony.len_group9050 = table_buf_0x9050_len;
1206
1.55k
      process_Sony_0x9050(table_buf_0x9050, table_buf_0x9050_len, unique_id);
1207
1.55k
      free(table_buf_0x9050);
1208
1.55k
      table_buf_0x9050_len = 0;
1209
1.55k
    }
1210
1211
73.1k
    if (table_buf_0x9400_len)
1212
992
    {
1213
992
      process_Sony_0x9400(table_buf_0x9400, table_buf_0x9400_len, unique_id);
1214
992
      free(table_buf_0x9400);
1215
992
      table_buf_0x9400_len = 0;
1216
992
    }
1217
1218
73.1k
    if (table_buf_0x9402_len)
1219
2.85k
    {
1220
2.85k
      process_Sony_0x9402(table_buf_0x9402, table_buf_0x9402_len);
1221
2.85k
      free(table_buf_0x9402);
1222
2.85k
      table_buf_0x9402_len = 0;
1223
2.85k
    }
1224
1225
73.1k
    if (table_buf_0x9403_len)
1226
1.32k
    {
1227
1.32k
      process_Sony_0x9403(table_buf_0x9403, table_buf_0x9403_len);
1228
1.32k
      free(table_buf_0x9403);
1229
1.32k
      table_buf_0x9403_len = 0;
1230
1.32k
    }
1231
1232
73.1k
    if (table_buf_0x9406_len)
1233
1.10k
    {
1234
1.10k
      process_Sony_0x9406(table_buf_0x9406, table_buf_0x9406_len);
1235
1.10k
      free(table_buf_0x9406);
1236
1.10k
      table_buf_0x9406_len = 0;
1237
1.10k
    }
1238
1239
73.1k
    if (table_buf_0x940c_len)
1240
584
    {
1241
584
      process_Sony_0x940c(table_buf_0x940c, table_buf_0x940c_len);
1242
584
      free(table_buf_0x940c);
1243
584
      table_buf_0x940c_len = 0;
1244
584
    }
1245
1246
73.1k
    if (table_buf_0x940e_len)
1247
714
    {
1248
714
      process_Sony_0x940e(table_buf_0x940e, table_buf_0x940e_len, unique_id);
1249
714
      free(table_buf_0x940e);
1250
714
      table_buf_0x940e_len = 0;
1251
714
    }
1252
73.1k
  }
1253
7.69M
  else if (tag == 0xb026)
1254
230
  {
1255
230
    uitemp = get4();
1256
230
    if (uitemp != 0xffffffff)
1257
154
      imgdata.shootinginfo.ImageStabilization = uitemp;
1258
230
  }
1259
7.69M
  else if (((tag == 0x0001) || // Minolta CameraSettings, big endian
1260
7.42M
            (tag == 0x0003)) &&
1261
324k
           (len >= 196))
1262
135k
  {
1263
135k
    table_buf = (uchar *)calloc(len,1);
1264
135k
    fread(table_buf, len, 1, ifp);
1265
1266
135k
    lid = 0x01 << 2;
1267
135k
    imgdata.shootinginfo.ExposureMode =
1268
135k
        (unsigned)table_buf[lid] << 24 | (unsigned)table_buf[lid + 1] << 16 |
1269
135k
        (unsigned)table_buf[lid + 2] << 8 | (unsigned)table_buf[lid + 3];
1270
1271
135k
    lid = 0x06 << 2;
1272
135k
    imgdata.shootinginfo.DriveMode =
1273
135k
        (unsigned)table_buf[lid] << 24 | (unsigned)table_buf[lid + 1] << 16 |
1274
135k
        (unsigned)table_buf[lid + 2] << 8 | (unsigned)table_buf[lid + 3];
1275
1276
135k
    lid = 0x07 << 2;
1277
135k
    imgdata.shootinginfo.MeteringMode =
1278
135k
        (unsigned)table_buf[lid] << 24 | (unsigned)table_buf[lid + 1] << 16 |
1279
135k
        (unsigned)table_buf[lid + 2] << 8 | (unsigned)table_buf[lid + 3];
1280
1281
135k
    lid = 0x25 << 2;
1282
135k
    imSony.MinoltaCamID =
1283
135k
        (unsigned)table_buf[lid] << 24 | (unsigned)table_buf[lid + 1] << 16 |
1284
135k
        (unsigned)table_buf[lid + 2] << 8 | (unsigned)table_buf[lid + 3];
1285
135k
    if (imSony.MinoltaCamID != 0xffffffff)
1286
131k
      ilm.CamID = imSony.MinoltaCamID;
1287
1288
135k
    lid = 0x30 << 2;
1289
135k
    imgdata.shootinginfo.FocusMode =
1290
135k
        table_buf[lid + 3]?LIBRAW_SONY_FOCUSMODE_MF:LIBRAW_SONY_FOCUSMODE_AF;
1291
135k
    free(table_buf);
1292
135k
  }
1293
7.55M
  else if ((tag == 0x0004) && // Minolta CameraSettings7D, big endian
1294
56.4k
           (len >= 227))
1295
24.3k
  {
1296
24.3k
    table_buf = (uchar *)calloc(len,1);
1297
24.3k
    fread(table_buf, len, 1, ifp);
1298
1299
24.3k
    lid = 0x0;
1300
24.3k
    imgdata.shootinginfo.ExposureMode =
1301
24.3k
        (ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1];
1302
1303
24.3k
    lid = 0x0e << 1;
1304
24.3k
    imgdata.shootinginfo.FocusMode = (short)table_buf[lid + 1];
1305
24.3k
    switch (imgdata.shootinginfo.FocusMode) {
1306
11.8k
      case 0: case 1: imgdata.shootinginfo.FocusMode += 2; break;
1307
728
      case 3: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_MF; break;
1308
24.3k
    }
1309
24.3k
    lid = 0x10 << 1;
1310
24.3k
    imgdata.shootinginfo.AFPoint =
1311
24.3k
        (ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1];
1312
1313
24.3k
    lid = 0x25 << 1;
1314
24.3k
    switch ((ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1]) {
1315
5.68k
    case 0:
1316
6.84k
    case 1:
1317
6.84k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1318
6.84k
      break;
1319
72
    case 4:
1320
72
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1321
72
      break;
1322
17.4k
    default:
1323
17.4k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1324
17.4k
      break;
1325
24.3k
    }
1326
1327
24.3k
    lid = 0x71 << 1;
1328
24.3k
    imgdata.shootinginfo.ImageStabilization =
1329
24.3k
        (ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1];
1330
1331
24.3k
    free(table_buf);
1332
24.3k
  }
1333
7.53M
  else if ((tag == 0x0010) && // CameraInfo
1334
35.6k
           strncasecmp(model, "DSLR-A100", 9) &&
1335
35.2k
           !strncasecmp(make, "SONY", 4) &&
1336
14.1k
           ((len == 368) ||  // a700                         : CameraInfo
1337
9.38k
            (len == 5478) || // a850, a900                   : CameraInfo
1338
9.30k
            (len == 5506) || // a200, a300, a350             : CameraInfo2
1339
7.64k
            (len == 6118) || // a230, a290, a330, a380, a390 : CameraInfo2
1340
7.64k
            (len == 15360))  // a450, a500, a550, a560, a580 : CameraInfo3
1341
                             // a33, a35, a55
1342
                             // NEX-3, NEX-5, NEX-5C, NEX-C3, NEX-VG10E
1343
1344
7.53M
  )
1345
9.40k
  {
1346
9.40k
    table_buf = (uchar *)calloc(len,1);
1347
9.40k
    fread(table_buf, len, 1, ifp);
1348
9.40k
    if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT)
1349
1.57k
    {
1350
1.57k
      imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
1351
1.57k
      imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
1352
1.57k
      imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
1353
1.57k
      imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)malloc(imCommon.afdata[imCommon.afcount].AFInfoData_length);
1354
1.57k
      memcpy(imCommon.afdata[imCommon.afcount].AFInfoData, table_buf, imCommon.afdata[imCommon.afcount].AFInfoData_length);
1355
1.57k
      imCommon.afcount++;
1356
1.57k
    }
1357
9.40k
    if (memcmp(table_buf, "\xff\xff\xff\xff\xff\xff\xff\xff", 8) &&
1358
8.63k
        memcmp(table_buf, "\x00\x00\x00\x00\x00\x00\x00\x00", 8))
1359
7.74k
    {
1360
7.74k
      LensDataValid = 1;
1361
7.74k
    }
1362
9.40k
    switch (len)
1363
9.40k
    {
1364
4.80k
    case 368:  // a700: CameraInfo
1365
4.87k
    case 5478: // a850, a900: CameraInfo
1366
4.87k
      if ((!dng_writer) ||
1367
160
          (saneSonyCameraInfo(table_buf[0], table_buf[3], table_buf[2],
1368
160
                              table_buf[5], table_buf[4], table_buf[7])))
1369
4.80k
      {
1370
4.80k
        if (LensDataValid)
1371
3.68k
        {
1372
3.68k
          if (table_buf[0] | table_buf[3])
1373
2.96k
            ilm.MinFocal = bcd2dec(table_buf[0]) * 100.f + bcd2dec(table_buf[3]);
1374
3.68k
          if (table_buf[2] | table_buf[5])
1375
2.91k
            ilm.MaxFocal = bcd2dec(table_buf[2]) * 100.f + bcd2dec(table_buf[5]);
1376
3.68k
          if (table_buf[4])
1377
2.50k
            ilm.MaxAp4MinFocal = bcd2dec(table_buf[4]) / 10.0f;
1378
3.68k
          if (table_buf[4])
1379
2.50k
            ilm.MaxAp4MaxFocal = bcd2dec(table_buf[7]) / 10.0f;
1380
3.68k
          parseSonyLensFeatures(table_buf[1], table_buf[6]);
1381
3.68k
        }
1382
1383
4.80k
        imSony.AFPointSelected = table_buf[21];
1384
4.80k
        imgdata.shootinginfo.AFPoint = (ushort)table_buf[25];
1385
1386
4.80k
        if (len == 5478)
1387
76
        {
1388
76
          imSony.AFMicroAdjValue = table_buf[0x130] - 20;
1389
76
          imSony.AFMicroAdjOn = (((table_buf[0x131] & 0x80) == 0x80) ? 1 : 0);
1390
76
          imSony.AFMicroAdjRegisteredLenses = table_buf[0x131] & 0x7f;
1391
76
        }
1392
4.80k
      }
1393
4.87k
      break;
1394
4.52k
    default:
1395
      // CameraInfo2 & 3
1396
4.52k
      if ((!dng_writer) ||
1397
188
          (saneSonyCameraInfo(table_buf[1], table_buf[2], table_buf[3],
1398
188
                              table_buf[4], table_buf[5], table_buf[6])))
1399
4.45k
      {
1400
4.45k
        if ((LensDataValid) && strncasecmp(model, "NEX-5C", 6))
1401
3.69k
        {
1402
3.69k
          if (table_buf[1] | table_buf[2])
1403
2.86k
            ilm.MinFocal = bcd2dec(table_buf[1]) * 100.f + bcd2dec(table_buf[2]);
1404
3.69k
          if (table_buf[3] | table_buf[4])
1405
2.90k
            ilm.MaxFocal = bcd2dec(table_buf[3]) * 100.f + bcd2dec(table_buf[4]);
1406
3.69k
          if (table_buf[5])
1407
2.26k
            ilm.MaxAp4MinFocal = bcd2dec(table_buf[5]) / 10.0f;
1408
3.69k
          if (table_buf[6])
1409
1.98k
            ilm.MaxAp4MaxFocal = bcd2dec(table_buf[6]) / 10.0f;
1410
3.69k
          parseSonyLensFeatures(table_buf[0], table_buf[7]);
1411
3.69k
        }
1412
1413
4.45k
        if (                 // CameraInfo2
1414
4.45k
            (len == 5506) || // a200, a300, a350
1415
2.86k
            (len == 6118))   // a230, a290, a330, a380, a390
1416
1.58k
        {
1417
1.58k
          imSony.AFPointSelected = table_buf[0x14];
1418
1.58k
        }
1419
2.86k
        else if (!strncasecmp(model, "DSLR-A450", 9) ||
1420
2.78k
                 !strncasecmp(model, "DSLR-A500", 9) ||
1421
2.50k
                 !strncasecmp(model, "DSLR-A550", 9))
1422
638
        {
1423
638
          imSony.AFPointSelected = table_buf[0x14];
1424
638
          if (table_buf[0x15]) /* focus mode values translated to values in tag 0x201b */
1425
300
            imgdata.shootinginfo.FocusMode = table_buf[0x15]+1;
1426
338
          else imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_MF;
1427
638
         imgdata.shootinginfo.AFPoint = (ushort)table_buf[0x18];
1428
638
        }
1429
2.22k
        else if (!strncasecmp(model, "SLT-", 4)      ||
1430
1.88k
                 !strncasecmp(model, "DSLR-A560", 9) ||
1431
1.81k
                 !strncasecmp(model, "DSLR-A580", 9))
1432
1.56k
        {
1433
1.56k
          imSony.AFPointSelected = table_buf[0x1c];
1434
1.56k
          if (table_buf[0x1d])
1435
714
            imgdata.shootinginfo.FocusMode = table_buf[0x1d]+1;
1436
852
          else imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_MF;
1437
1.56k
          imgdata.shootinginfo.AFPoint = (ushort)table_buf[0x20];
1438
1.56k
        }
1439
4.45k
      }
1440
9.40k
    }
1441
9.40k
    free(table_buf);
1442
9.40k
  }
1443
7.52M
  else if ((!dng_writer) &&
1444
7.34M
           ((tag == 0x0020) || (tag == 0xb0280020)))
1445
48.1k
  {
1446
48.1k
    if (!strncasecmp(model, "DSLR-A100", 9)) // WBInfoA100
1447
298
    {
1448
298
      fseek(ifp, 0x49dc, SEEK_CUR);
1449
298
      stmread(imgdata.shootinginfo.InternalBodySerial, 13, ifp);
1450
298
    }
1451
47.8k
    else if ((len == 19154) || // a200 a230 a290 a300 a330 a350 a380 a390 : FocusInfo
1452
47.8k
             (len == 19148))   // a700 a850 a900                          : FocusInfo
1453
0
    {
1454
0
      table_buf = (uchar *)calloc(0x0080,1);
1455
0
      fread(table_buf, 0x0080, 1, ifp);
1456
0
      imgdata.shootinginfo.DriveMode = table_buf[14];
1457
0
      imgdata.shootinginfo.ExposureProgram = table_buf[63];
1458
0
      free(table_buf);
1459
0
      fseek (ifp, 0x09bb - 0x0080, SEEK_CUR); // offset 2491 from the start of tag 0x0020
1460
0
      imSony.FocusPosition = (ushort)fgetc(ifp);
1461
0
    }
1462
47.8k
    else if (len == 20480) // a450 a500 a550 a560 a580 a33 a35 a55 : MoreInfo
1463
                           // NEX-3 NEX-5 NEX-C3 NEX-VG10E         : MoreInfo
1464
5.67k
    {
1465
5.67k
      a = get2();
1466
5.67k
      /*b =*/ get2();
1467
5.67k
      c = get2();
1468
5.67k
      d = get2();
1469
5.67k
      if ((a) && (c == 1))
1470
2.49k
      {
1471
2.49k
        fseek(ifp, INT64(d) - 8LL, SEEK_CUR);
1472
2.49k
        table_buf = (uchar *)calloc(256,1);
1473
2.49k
        fread(table_buf, 256, 1, ifp);
1474
2.49k
        imgdata.shootinginfo.DriveMode = table_buf[1];
1475
2.49k
        imgdata.shootinginfo.ExposureProgram = table_buf[2];
1476
2.49k
        imgdata.shootinginfo.MeteringMode = table_buf[3];
1477
2.49k
        switch (table_buf[6]) {
1478
76
        case 1:
1479
76
          imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1480
76
          break;
1481
80
        case 2:
1482
80
          imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1483
80
          break;
1484
2.33k
        default:
1485
2.33k
          imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1486
2.33k
          break;
1487
2.49k
        }
1488
2.49k
        if (strncasecmp(model, "DSLR-A450", 9) &&
1489
2.24k
            strncasecmp(model, "DSLR-A500", 9) &&
1490
1.67k
            strncasecmp(model, "DSLR-A550", 9))
1491
1.46k
        { // NEX-3, NEX-5, NEX-5C??, NEX-C3, NEX-VG10(E), a560, a580, a33, a35, a55
1492
1.46k
          imgdata.shootinginfo.FocusMode = table_buf[0x13];
1493
1.46k
          switch (table_buf[0x13]) {
1494
90
            case 17: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_AF_S; break;
1495
212
            case 18: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_AF_C; break;
1496
386
            case 19: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_AF_A; break;
1497
224
            case 32: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_MF; break;
1498
214
            case 48: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_DMF; break;
1499
334
            default: imgdata.shootinginfo.FocusMode = table_buf[0x13]; break;
1500
1.46k
          }
1501
1.46k
          if (!strncasecmp(model, "DSLR-A560", 9) ||
1502
1.25k
              !strncasecmp(model, "DSLR-A580", 9) ||
1503
1.03k
              !strncasecmp(model, "SLT-A33", 7)   ||
1504
962
              !strncasecmp(model, "SLT-A35", 7)   ||
1505
678
              !strncasecmp(model, "SLT-A55", 7)   ||
1506
608
              !strncasecmp(model, "NEX-VG10", 8)  ||
1507
518
              !strncasecmp(model, "NEX-C3", 6))
1508
1.19k
            imSony.FocusPosition = (ushort)table_buf[0x2f]; // FocusPosition2
1509
266
          else  // NEX-3, NEX-5, NEX-5C
1510
266
            imSony.FocusPosition = (ushort)table_buf[0x2b]; // FocusPosition2
1511
1.46k
        }
1512
1.03k
        else // a450 a500 a550
1513
1.03k
        {
1514
1.03k
          imSony.FocusPosition = (ushort)table_buf[0x29]; // FocusPosition2
1515
1.03k
        }
1516
2.49k
        free(table_buf);
1517
2.49k
      }
1518
5.67k
    }
1519
48.1k
  }
1520
7.47M
  else if (tag == 0x0102)
1521
14.7k
  {
1522
14.7k
    imSony.Quality = get4();
1523
14.7k
  }
1524
7.45M
  else if (tag == 0x0104)
1525
3.48k
  {
1526
3.48k
    imCommon.FlashEC = getrealf(type);
1527
3.48k
  }
1528
7.45M
  else if (tag == 0x0105) // Teleconverter
1529
1.20k
  {
1530
1.20k
    ilm.TeleconverterID = get4();
1531
1.20k
  }
1532
7.45M
  else if (tag == 0x0107)
1533
3.35k
  {
1534
3.35k
    uitemp = get4();
1535
3.35k
    if (uitemp == 1)
1536
322
      imgdata.shootinginfo.ImageStabilization = 0;
1537
3.03k
    else if (uitemp == 5)
1538
80
      imgdata.shootinginfo.ImageStabilization = 1;
1539
2.95k
    else
1540
2.95k
      imgdata.shootinginfo.ImageStabilization = uitemp;
1541
3.35k
  }
1542
7.44M
  else if ((tag == 0xb0280088) && (dng_writer == nonDNG))
1543
90
  {
1544
90
    thumb_offset = get4() + base;
1545
90
  }
1546
7.44M
  else if ((tag == 0xb0280089) && (dng_writer == nonDNG))
1547
502
  {
1548
502
    thumb_length = get4();
1549
502
  }
1550
7.44M
  else if (((tag == 0x0114) || // CameraSettings
1551
7.43M
            (tag == 0xb0280114)) &&
1552
16.2k
           (len < 256000))
1553
16.2k
  {
1554
16.2k
    table_buf = (uchar *)calloc(len,1);
1555
16.2k
    fread(table_buf, len, 1, ifp);
1556
16.2k
    switch (len)
1557
16.2k
    {
1558
3.13k
    case 260: // Sony a100, big endian
1559
3.13k
      imgdata.shootinginfo.ExposureMode =
1560
3.13k
          ((ushort)table_buf[0]) << 8 | ((ushort)table_buf[1]);
1561
3.13k
      lid = 0x0a << 1;
1562
3.13k
      imgdata.shootinginfo.DriveMode =
1563
3.13k
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1564
3.13k
      lid = 0x0c << 1;
1565
3.13k
      imgdata.shootinginfo.FocusMode =
1566
3.13k
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1567
3.13k
      switch (imgdata.shootinginfo.FocusMode) {
1568
422
        case 0: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_AF_S; break;
1569
374
        case 1: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_AF_C; break;
1570
252
        case 5: imgdata.shootinginfo.FocusMode = LIBRAW_SONY_FOCUSMODE_MF; break;
1571
3.13k
      }
1572
3.13k
      lid = 0x0d << 1;
1573
3.13k
      imSony.AFPointSelected = table_buf[lid + 1];
1574
3.13k
      lid = 0x0e << 1;
1575
3.13k
      imSony.AFAreaMode = (uint16_t)table_buf[lid + 1];
1576
3.13k
      lid = 0x12 << 1;
1577
3.13k
      imgdata.shootinginfo.MeteringMode =
1578
3.13k
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1579
1580
3.13k
      lid = 0x17 << 1;
1581
3.13k
      switch ((ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1]) {
1582
676
      case 0:
1583
676
        imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1584
676
        break;
1585
252
      case 2:
1586
252
        imCommon.ColorSpace = LIBRAW_COLORSPACE_MonochromeGamma;
1587
252
        break;
1588
244
      case 5:
1589
244
        imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1590
244
        break;
1591
1.96k
      default:
1592
1.96k
        imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1593
1.96k
        break;
1594
3.13k
      }
1595
1596
3.13k
      break;
1597
3.13k
    case 448: // Minolta "DYNAX 5D" and its aliases, big endian
1598
534
      lid = 0x0a << 1;
1599
534
      imgdata.shootinginfo.ExposureMode =
1600
534
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1601
534
      lid = 0x25 << 1;
1602
534
      imgdata.shootinginfo.MeteringMode =
1603
534
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1604
1605
534
      lid = 0x2f << 1;
1606
534
      switch ((ushort)table_buf[lid] << 8 | (ushort)table_buf[lid + 1]) {
1607
236
      case 0:
1608
308
      case 1:
1609
308
        imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1610
308
        break;
1611
76
      case 2:
1612
76
        imCommon.ColorSpace = LIBRAW_COLORSPACE_MonochromeGamma;
1613
76
        break;
1614
0
      case 4:
1615
72
      case 5:
1616
72
        imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1617
72
        break;
1618
78
      default:
1619
78
        imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1620
78
        break;
1621
534
      }
1622
1623
534
      lid = 0xbd << 1;
1624
534
      imgdata.shootinginfo.ImageStabilization =
1625
534
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1626
534
      break;
1627
928
    case 280: // a200 a300 a350 a700
1628
3.34k
    case 364: // a850 a900
1629
      // CameraSettings and CameraSettings2 are big endian
1630
3.34k
      if (table_buf[2] | table_buf[3])
1631
2.89k
      {
1632
2.89k
        lid = (((ushort)table_buf[2]) << 8) | ((ushort)table_buf[3]);
1633
2.89k
        ilm.CurAp = libraw_powf64l(2.0f, ((float)lid / 8.0f - 1.0f) / 2.0f);
1634
2.89k
      }
1635
3.34k
      lid = 0x04 << 1;
1636
3.34k
      imgdata.shootinginfo.DriveMode = table_buf[lid + 1];
1637
3.34k
      lid = 0x11 << 1;
1638
3.34k
      imSony.AFAreaMode = (uint16_t)table_buf[lid + 1];
1639
3.34k
      lid = 0x1b << 1;
1640
3.34k
      switch (((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1])) {
1641
612
      case 0:
1642
612
        imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1643
612
        break;
1644
106
      case 1:
1645
120
      case 5:
1646
120
        imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1647
120
        break;
1648
2.61k
      default:
1649
2.61k
        imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1650
2.61k
        break;
1651
3.34k
      }
1652
3.34k
      lid = 0x4d << 1;
1653
3.34k
      imgdata.shootinginfo.FocusMode =
1654
3.34k
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1655
3.34k
      switch (imgdata.shootinginfo.FocusMode) {
1656
1.47k
        case 1: case 2: case 3: imgdata.shootinginfo.FocusMode++; break;
1657
204
        case 4: imgdata.shootinginfo.FocusMode +=2; break;
1658
3.34k
      }
1659
3.34k
      lid = 0x55 << 1;
1660
3.34k
      u16temp = ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1661
3.34k
      switch (u16temp) {
1662
250
      case 1:
1663
250
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_3to2;
1664
250
        break;
1665
356
      case 2:
1666
356
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_16to9;
1667
356
        break;
1668
2.73k
      default:
1669
2.73k
        imSony.AspectRatio = (float)u16temp;
1670
2.73k
        break;
1671
3.34k
      }
1672
3.34k
      if (!imCommon.ColorSpace ||
1673
3.34k
          (imCommon.ColorSpace == LIBRAW_COLORSPACE_Unknown)) {
1674
2.61k
        lid = 0x83 << 1;
1675
2.61k
        switch (((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1])) {
1676
306
        case 6:
1677
306
          imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1678
306
          break;
1679
346
        case 5:
1680
346
          imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1681
346
          break;
1682
1.95k
        default:
1683
1.95k
          imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1684
1.95k
          break;
1685
2.61k
        }
1686
2.61k
      }
1687
3.34k
      break;
1688
3.34k
    case 332: // a230 a290 a330 a380 a390
1689
      // CameraSettings and CameraSettings2 are big endian
1690
2.17k
      if (table_buf[2] | table_buf[3])
1691
1.68k
      {
1692
1.68k
        lid = (((ushort)table_buf[2]) << 8) | ((ushort)table_buf[3]);
1693
1.68k
        ilm.CurAp = libraw_powf64l(2.0f, ((float)lid / 8.0f - 1.0f) / 2.0f);
1694
1.68k
      }
1695
2.17k
      lid = 0x10 << 1;
1696
2.17k
      imSony.AFAreaMode = (uint16_t)table_buf[lid + 1];
1697
2.17k
      lid = 0x4d << 1;
1698
2.17k
      imgdata.shootinginfo.FocusMode =
1699
2.17k
          ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1700
2.17k
      switch (imgdata.shootinginfo.FocusMode) {
1701
600
        case 1: case 2: case 3: imgdata.shootinginfo.FocusMode++; break;
1702
102
        case 4: imgdata.shootinginfo.FocusMode +=2; break;
1703
2.17k
     }
1704
2.17k
      lid = 0x55 << 1;
1705
2.17k
      u16temp = ((ushort)table_buf[lid]) << 8 | ((ushort)table_buf[lid + 1]);
1706
2.17k
      switch (u16temp) {
1707
346
      case 1:
1708
346
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_3to2;
1709
346
        break;
1710
286
      case 2:
1711
286
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_16to9;
1712
286
        break;
1713
1.53k
      default:
1714
1.53k
        imSony.AspectRatio = (float)u16temp;
1715
1.53k
        break;
1716
2.17k
      }
1717
2.17k
      lid = 0x7e << 1;
1718
2.17k
      imgdata.shootinginfo.DriveMode = table_buf[lid + 1];
1719
2.17k
      break;
1720
3.80k
    case 1536: // a560 a580 a33 a35 a55 NEX-3 NEX-5 NEX-5C NEX-C3 NEX-VG10E
1721
4.23k
    case 2048: // a450 a500 a550
1722
      // CameraSettings3 are little endian
1723
4.23k
      switch (table_buf[0x0a]) {
1724
492
      case 4:
1725
492
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_3to2;
1726
492
        break;
1727
276
      case 8:
1728
276
        imSony.AspectRatio = LIBRAW_IMAGE_ASPECT_16to9;
1729
276
        break;
1730
3.46k
      default:
1731
3.46k
        imSony.AspectRatio = (float)table_buf[0x0a];
1732
3.46k
        break;
1733
4.23k
      }
1734
4.23k
      switch (table_buf[0x0e]) {
1735
338
      case 1:
1736
338
        imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1737
338
        break;
1738
378
      case 2:
1739
378
        imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1740
378
        break;
1741
3.51k
      default:
1742
3.51k
        imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1743
3.51k
        break;
1744
4.23k
      }
1745
4.23k
      imSony.AFAreaMode = (uint16_t)table_buf[0x24];
1746
4.23k
      imgdata.shootinginfo.DriveMode = table_buf[0x34];
1747
4.23k
      parseSonyLensType2(table_buf[1016], table_buf[1015]);
1748
4.23k
      if (ilm.LensMount != LIBRAW_MOUNT_Canon_EF)
1749
3.51k
      {
1750
3.51k
        switch (table_buf[153])
1751
3.51k
        {
1752
234
        case 16:
1753
234
          ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
1754
234
          break;
1755
318
        case 17:
1756
318
          ilm.LensMount = LIBRAW_MOUNT_Sony_E;
1757
318
          break;
1758
3.51k
        }
1759
3.51k
      }
1760
4.23k
      break;
1761
16.2k
    }
1762
16.2k
    free(table_buf);
1763
16.2k
  }
1764
7.43M
  else if ((tag == 0x3000) && (len < 256000))
1765
13.2k
  {
1766
13.2k
    table_buf = (uchar *)calloc(len,1);
1767
13.2k
    fread(table_buf, len, 1, ifp);
1768
13.2k
    if (len >= 0x19)
1769
9.24k
    {
1770
194k
      for (int i = 0; i < 20; i++)
1771
184k
        imSony.SonyDateTime[i] = table_buf[6 + i];
1772
9.24k
    }
1773
13.2k
    if (len >= 0x43) // MetaVersion: (unique_id >= 286)
1774
8.82k
    {
1775
8.82k
      memcpy (imSony.MetaVersion, table_buf+0x34, 15);
1776
8.82k
      imSony.MetaVersion[15] = 0;
1777
8.82k
    }
1778
13.2k
    free(table_buf);
1779
13.2k
  }
1780
7.41M
  else if (tag == 0x0116 && len < 256000)
1781
9.34k
  {
1782
9.34k
    table_buf_0x0116 = (uchar *)calloc(len,1);
1783
9.34k
    table_buf_0x0116_len = len;
1784
9.34k
    fread(table_buf_0x0116, len, 1, ifp);
1785
9.34k
    if (ilm.CamID)
1786
6.73k
    {
1787
6.73k
      process_Sony_0x0116(table_buf_0x0116, table_buf_0x0116_len, ilm.CamID);
1788
6.73k
      free(table_buf_0x0116);
1789
6.73k
      table_buf_0x0116_len = 0;
1790
6.73k
    }
1791
9.34k
  }
1792
7.41M
  else if (tag == 0x2008)
1793
5.25k
  {
1794
5.25k
    imSony.LongExposureNoiseReduction = get4();
1795
5.25k
  }
1796
7.40M
  else if (tag == 0x2009)
1797
826
  {
1798
826
    imSony.HighISONoiseReduction = get2();
1799
826
  }
1800
7.40M
  else if (tag == 0x200a)
1801
806
  {
1802
806
    imSony.HDR[0] = get2();
1803
806
    imSony.HDR[1] = get2();
1804
806
  }
1805
7.40M
  else if (tag == 0x2010 && len < 256000)
1806
17.2k
  {
1807
17.2k
    table_buf_0x2010 = (uchar *)calloc(len,1);
1808
17.2k
    table_buf_0x2010_len = len;
1809
17.2k
    fread(table_buf_0x2010, len, 1, ifp);
1810
17.2k
    if (ilm.CamID)
1811
11.2k
    {
1812
11.2k
      process_Sony_0x2010(table_buf_0x2010, table_buf_0x2010_len);
1813
11.2k
      free(table_buf_0x2010);
1814
11.2k
      table_buf_0x2010_len = 0;
1815
11.2k
    }
1816
17.2k
  }
1817
7.38M
  else if (tag == 0x201a)
1818
500
  {
1819
500
    imSony.ElectronicFrontCurtainShutter = get4();
1820
500
  }
1821
7.38M
  else if (tag == 0x201b)
1822
4.41k
  {
1823
4.41k
    if ((imSony.CameraType != LIBRAW_SONY_DSC) ||
1824
800
        (imSony.group2010 == LIBRAW_SONY_Tag2010i))
1825
4.13k
    {
1826
4.13k
      short t = (short)fgetc(ifp);
1827
4.13k
      if (imgdata.shootinginfo.FocusMode != t)
1828
2.59k
      {
1829
2.59k
        imgdata.shootinginfo.FocusMode = t;
1830
2.59k
      }
1831
4.13k
    }
1832
4.41k
  }
1833
7.38M
  else if ((tag == 0x201c) &&
1834
558
           (len == 1) &&
1835
260
           tagtypeIs(LIBRAW_EXIFTAG_TYPE_BYTE))
1836
72
  {
1837
72
    imSony.AFAreaModeSetting = (uint8_t)fgetc(ifp);
1838
72
  }
1839
7.38M
  else if ((tag == 0x201d) &&
1840
832
           (len == 2) &&
1841
442
           tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
1842
16
  {
1843
16
      imSony.FlexibleSpotPosition[0] = get2();
1844
16
      imSony.FlexibleSpotPosition[1] = get2();
1845
16
  }
1846
7.38M
  else if (tag == 0x201e)
1847
1.48k
  {
1848
1.48k
    if (imSony.CameraType != LIBRAW_SONY_DSC)
1849
1.13k
    {
1850
1.13k
      imSony.AFPointSelected = imSony.AFPointSelected_0x201e = fgetc(ifp);
1851
1.13k
    }
1852
1.48k
  }
1853
7.37M
  else if (tag == 0x2020) // AFPointsUsed
1854
18.5k
  {
1855
18.5k
    if (imSony.CameraType != LIBRAW_SONY_DSC)
1856
15.3k
    {
1857
15.3k
      if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT)
1858
1.65k
      {
1859
1.65k
        imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
1860
1.65k
        imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
1861
1.65k
        imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
1862
1.65k
        imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length+1,1);
1863
1.65k
        fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp);
1864
1.65k
        imSony.nAFPointsUsed =
1865
1.65k
            short(MIN(imCommon.afdata[imCommon.afcount].AFInfoData_length, sizeof imSony.AFPointsUsed));
1866
1.65k
        memcpy(imSony.AFPointsUsed, imCommon.afdata[imCommon.afcount].AFInfoData, imSony.nAFPointsUsed);
1867
1.65k
        imCommon.afcount++;
1868
1.65k
      }
1869
15.3k
    }
1870
18.5k
  }
1871
7.36M
  else if (tag == 0x2021) // AFTracking
1872
2.36k
  {
1873
2.36k
    if ((imSony.CameraType != LIBRAW_SONY_DSC) ||
1874
1.32k
        (imSony.group2010 == LIBRAW_SONY_Tag2010i))
1875
1.81k
    {
1876
1.81k
      imSony.AFTracking = fgetc(ifp);
1877
1.81k
    }
1878
2.36k
  }
1879
7.35M
  else if (tag == 0x2022) // FocalPlaneAFPointsUsed
1880
1.84k
  {
1881
1.84k
    if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT)
1882
802
    {
1883
802
      imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
1884
802
      imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
1885
802
      imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
1886
802
      imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length+1,1);
1887
802
      fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp);
1888
802
      imCommon.afcount++;
1889
802
    }
1890
1.84k
  }
1891
7.35M
  else if (tag == 0x2027)
1892
404
  {
1893
1.61k
    FORC4 imSony.FocusLocation[c] = get2();
1894
404
  }
1895
7.35M
  else if (tag == 0x2028)
1896
3.53k
  {
1897
3.53k
    if (get2())
1898
2.99k
    {
1899
2.99k
      imSony.VariableLowPassFilter = get2();
1900
2.99k
    }
1901
3.53k
  }
1902
7.35M
  else if (tag == 0x2029)
1903
274
  {
1904
274
    imSony.RAWFileType = get2();
1905
274
  }
1906
7.35M
  else if (tag == 0x202c)
1907
596
  {
1908
596
    imSony.MeteringMode2 = get2();
1909
596
  }
1910
1911
7.35M
  else if (tag == 0x202a) // FocalPlaneAFPointsUsed, newer??
1912
968
  {
1913
968
    if (imCommon.afcount < LIBRAW_AFDATA_MAXCOUNT)
1914
132
    {
1915
132
      imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
1916
132
      imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
1917
132
      imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
1918
132
      imCommon.afdata[imCommon.afcount].AFInfoData = (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length+1,1);
1919
132
      fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1, ifp);
1920
132
      imCommon.afcount++;
1921
132
    }
1922
968
  }
1923
7.35M
  else if (tag == 0x202e)
1924
284
  {
1925
284
    imSony.RawSizeType = get2();
1926
284
  }
1927
7.35M
  else if (tag == 0x202f)
1928
736
  {
1929
736
    imSony.PixelShiftGroupID = get4();
1930
736
    imSony.PixelShiftGroupPrefix = imSony.PixelShiftGroupID >> 22;
1931
736
    imSony.PixelShiftGroupID =
1932
736
        ((imSony.PixelShiftGroupID >> 17) & (unsigned)0x1f) *
1933
736
            (unsigned)1000000 +
1934
736
        ((imSony.PixelShiftGroupID >> 12) & (unsigned)0x1f) * (unsigned)10000 +
1935
736
        ((imSony.PixelShiftGroupID >> 6) & (unsigned)0x3f) * (unsigned)100 +
1936
736
        (imSony.PixelShiftGroupID & (unsigned)0x3f);
1937
1938
736
    imSony.numInPixelShiftGroup = fgetc(ifp);
1939
736
    imSony.nShotsInPixelShiftGroup = fgetc(ifp);
1940
736
  }
1941
7.35M
  else if (tag == 0x9050 && len < 256000) // little endian
1942
41.4k
  {
1943
41.4k
    table_buf_0x9050 = (uchar *)calloc(len,1);
1944
41.4k
    table_buf_0x9050_len = len;
1945
41.4k
    fread(table_buf_0x9050, len, 1, ifp);
1946
1947
41.4k
    if (ilm.CamID)
1948
35.9k
    {
1949
35.9k
      imSony.len_group9050 = table_buf_0x9050_len;
1950
35.9k
      process_Sony_0x9050(table_buf_0x9050, table_buf_0x9050_len, ilm.CamID);
1951
35.9k
      free(table_buf_0x9050);
1952
35.9k
      table_buf_0x9050_len = 0;
1953
35.9k
    }
1954
41.4k
  }
1955
7.30M
  else if (tag == 0x9400 && len < 256000)
1956
9.43k
  {
1957
9.43k
    table_buf_0x9400 = (uchar *)calloc(len,1);
1958
9.43k
    table_buf_0x9400_len = len;
1959
9.43k
    fread(table_buf_0x9400, len, 1, ifp);
1960
9.43k
    if (ilm.CamID)
1961
7.10k
    {
1962
7.10k
      process_Sony_0x9400(table_buf_0x9400, table_buf_0x9400_len, unique_id);
1963
7.10k
      free(table_buf_0x9400);
1964
7.10k
      table_buf_0x9400_len = 0;
1965
7.10k
    }
1966
9.43k
  }
1967
7.29M
  else if (tag == 0x9402 && len < 256000)
1968
11.8k
  {
1969
11.8k
    table_buf_0x9402 = (uchar *)calloc(len,1);
1970
11.8k
    table_buf_0x9402_len = len;
1971
11.8k
    fread(table_buf_0x9402, len, 1, ifp);
1972
11.8k
    if (ilm.CamID)
1973
6.44k
    {
1974
6.44k
      process_Sony_0x9402(table_buf_0x9402, table_buf_0x9402_len);
1975
6.44k
      free(table_buf_0x9402);
1976
6.44k
      table_buf_0x9402_len = 0;
1977
6.44k
    }
1978
11.8k
  }
1979
7.28M
  else if (tag == 0x9403 && len < 256000)
1980
5.63k
  {
1981
5.63k
    table_buf_0x9403 = (uchar *)calloc(len,1);
1982
5.63k
    table_buf_0x9403_len = len;
1983
5.63k
    fread(table_buf_0x9403, len, 1, ifp);
1984
5.63k
    if (ilm.CamID)
1985
3.14k
    {
1986
3.14k
      process_Sony_0x9403(table_buf_0x9403, table_buf_0x9403_len);
1987
3.14k
      free(table_buf_0x9403);
1988
3.14k
      table_buf_0x9403_len = 0;
1989
3.14k
    }
1990
5.63k
  }
1991
7.28M
  else if ((tag == 0x9405) && (len < 256000) && (len > 0x64))
1992
3.17k
  {
1993
3.17k
    table_buf = (uchar *)calloc(len,1);
1994
3.17k
    fread(table_buf, len, 1, ifp);
1995
3.17k
    uc = table_buf[0x0];
1996
3.17k
    if (imCommon.real_ISO < 0.1f)
1997
2.23k
    {
1998
2.23k
      if ((uc == 0x25) || (uc == 0x3a) || (uc == 0x76) || (uc == 0x7e) ||
1999
1.55k
          (uc == 0x8b) || (uc == 0x9a) || (uc == 0xb3) || (uc == 0xe1))
2000
1.18k
      {
2001
1.18k
        s[0] = SonySubstitution[table_buf[0x04]];
2002
1.18k
        s[1] = SonySubstitution[table_buf[0x05]];
2003
1.18k
        imCommon.real_ISO =
2004
1.18k
            100.0f * libraw_powf64l(2.0f, (16 - ((float)sget2(s)) / 256.0f));
2005
1.18k
      }
2006
2.23k
    }
2007
3.17k
    free(table_buf);
2008
3.17k
  }
2009
7.27M
  else if ((tag == 0x9404) && (len < 256000) && (len > 0x21))
2010
2.21k
  {
2011
2.21k
    table_buf = (uchar *)calloc(len,1);
2012
2.21k
    fread(table_buf, len, 1, ifp);
2013
2.21k
    uc = table_buf[0x00];
2014
2.21k
    if (((uc == 0x70) ||
2015
1.96k
         (uc == 0x8a) ||
2016
1.88k
         (uc == 0xcd) ||
2017
1.79k
         (uc == 0xe7) ||
2018
1.20k
         (uc == 0xea)) &&
2019
1.10k
         (table_buf[0x03] == 0x08))
2020
584
    {
2021
584
      if ((imSony.CameraType == LIBRAW_SONY_ILCA) ||
2022
570
          (imSony.CameraType == LIBRAW_SONY_SLT))
2023
358
      {
2024
358
        imSony.FocusPosition = (ushort)SonySubstitution[table_buf[0x20]]; // FocusPosition2
2025
358
      }
2026
584
    }
2027
2.21k
    free(table_buf);
2028
2.21k
  }
2029
7.27M
  else if (tag == 0x9406 && len < 256000)
2030
2.74k
  {
2031
2.74k
    table_buf_0x9406 = (uchar *)calloc(len,1);
2032
2.74k
    table_buf_0x9406_len = len;
2033
2.74k
    fread(table_buf_0x9406, len, 1, ifp);
2034
2.74k
    if (ilm.CamID)
2035
1.39k
    {
2036
1.39k
      process_Sony_0x9406(table_buf_0x9406, table_buf_0x9406_len);
2037
1.39k
      free(table_buf_0x9406);
2038
1.39k
      table_buf_0x9406_len = 0;
2039
1.39k
    }
2040
2.74k
  }
2041
7.27M
  else if (tag == 0x940c && len < 256000)
2042
9.27k
  {
2043
9.27k
    table_buf_0x940c = (uchar *)calloc(len,1);
2044
9.27k
    table_buf_0x940c_len = len;
2045
9.27k
    fread(table_buf_0x940c, len, 1, ifp);
2046
9.27k
    if (ilm.CamID)
2047
6.87k
    {
2048
6.87k
      process_Sony_0x940c(table_buf_0x940c, table_buf_0x940c_len);
2049
6.87k
      free(table_buf_0x940c);
2050
6.87k
      table_buf_0x940c_len = 0;
2051
6.87k
    }
2052
9.27k
  }
2053
7.26M
  else if (tag == 0x940e && len < 256000)
2054
8.77k
  {
2055
8.77k
    table_buf_0x940e = (uchar *)calloc(len,1);
2056
8.77k
    table_buf_0x940e_len = len;
2057
8.77k
    fread(table_buf_0x940e, len, 1, ifp);
2058
8.77k
    if (ilm.CamID)
2059
7.60k
    {
2060
7.60k
      process_Sony_0x940e(table_buf_0x940e, table_buf_0x940e_len, ilm.CamID);
2061
7.60k
      free(table_buf_0x940e);
2062
7.60k
      table_buf_0x940e_len = 0;
2063
7.60k
    }
2064
8.77k
  }
2065
7.25M
  else if ((tag == 0x9416) && (len < 256000) && (len > 0x0076)) {
2066
2.48k
    table_buf = (uchar *)calloc(len,1);
2067
2.48k
    fread(table_buf, len, 1, ifp);
2068
2.48k
    if (imCommon.real_ISO < 0.1f) {
2069
1.55k
      s[0] = SonySubstitution[table_buf[0x04]];
2070
1.55k
      s[1] = SonySubstitution[table_buf[0x05]];
2071
1.55k
      imCommon.real_ISO =
2072
1.55k
          100.0f * libraw_powf64l(2.0f, (16 - ((float)sget2(s)) / 256.0f));
2073
1.55k
    }
2074
2.48k
    imgdata.shootinginfo.ExposureProgram = SonySubstitution[table_buf[0x35]];
2075
2.48k
    if ((ilm.LensMount != LIBRAW_MOUNT_Canon_EF) &&
2076
2.26k
        (ilm.LensMount != LIBRAW_MOUNT_Sigma_X3F)) {
2077
2.01k
      switch (SonySubstitution[table_buf[0x0048]]) {
2078
298
      case 1:
2079
406
      case 3:
2080
406
        ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
2081
406
        break;
2082
238
      case 2:
2083
238
        ilm.LensMount = LIBRAW_MOUNT_Sony_E;
2084
238
        break;
2085
2.01k
      }
2086
2.01k
    }
2087
2.48k
    switch (SonySubstitution[table_buf[0x0049]]) {
2088
266
      case 1:
2089
266
        ilm.LensFormat = LIBRAW_FORMAT_APSC;
2090
266
        break;
2091
298
      case 2:
2092
298
        ilm.LensFormat = LIBRAW_FORMAT_FF;
2093
298
        break;
2094
2.48k
    }
2095
2.48k
    if (ilm.LensMount == LIBRAW_MOUNT_Sony_E)
2096
238
      parseSonyLensType2(SonySubstitution[table_buf[0x4c]], SonySubstitution[table_buf[0x4b]]);
2097
2.48k
    free(table_buf);
2098
2.48k
  }
2099
7.25M
  else if (((tag == 0xb027) ||
2100
7.25M
            (tag == 0x010c)) &&
2101
2.82k
           (ilm.LensID == LIBRAW_LENS_NOT_SET))
2102
546
  {
2103
546
    ilm.LensID = get4();
2104
546
    if ((ilm.LensID > 0x4900) && (ilm.LensID <= 0x5900))
2105
176
    {
2106
176
      ilm.AdapterID = 0x4900;
2107
176
      ilm.LensID -= ilm.AdapterID;
2108
176
      ilm.LensMount = LIBRAW_MOUNT_Sigma_X3F;
2109
176
      strcpy(ilm.Adapter, "MC-11");
2110
176
    }
2111
2112
370
    else if ((ilm.LensID > 0xef00) &&
2113
254
             (ilm.LensID < 0xffff) &&
2114
84
             (ilm.LensID != 0xff00))
2115
82
    {
2116
82
      ilm.AdapterID = 0xef00;
2117
82
      ilm.LensID -= ilm.AdapterID;
2118
82
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
2119
82
    }
2120
2121
288
    else if (((ilm.LensID != LIBRAW_LENS_NOT_SET) && (ilm.LensID < 0xef00)) ||
2122
172
             (ilm.LensID == 0xff00))
2123
118
      ilm.LensMount = LIBRAW_MOUNT_Minolta_A;
2124
    /*
2125
        if (tag == 0x010c)
2126
          ilm.CameraMount = LIBRAW_MOUNT_Minolta_A;
2127
    */
2128
546
  }
2129
7.25M
  else if (tag == 0xb02a && len < 256000) // Sony LensSpec
2130
8.58k
  {
2131
8.58k
    table_buf = (uchar *)calloc(len,1);
2132
8.58k
    fread(table_buf, len, 1, ifp);
2133
8.58k
    if ((!dng_writer) ||
2134
3.50k
        (saneSonyCameraInfo(table_buf[1], table_buf[2], table_buf[3],
2135
3.50k
                            table_buf[4], table_buf[5], table_buf[6])))
2136
5.41k
    {
2137
5.41k
      if (table_buf[1] | table_buf[2])
2138
5.01k
        ilm.MinFocal = bcd2dec(table_buf[1]) * 100.f + bcd2dec(table_buf[2]);
2139
5.41k
      if (table_buf[3] | table_buf[4])
2140
4.78k
        ilm.MaxFocal = bcd2dec(table_buf[3]) * 100.f + bcd2dec(table_buf[4]);
2141
5.41k
      if (table_buf[5])
2142
4.35k
        ilm.MaxAp4MinFocal = bcd2dec(table_buf[5]) / 10.0f;
2143
5.41k
      if (table_buf[6])
2144
4.20k
        ilm.MaxAp4MaxFocal = bcd2dec(table_buf[6]) / 10.0f;
2145
5.41k
      parseSonyLensFeatures(table_buf[0], table_buf[7]);
2146
5.41k
    }
2147
8.58k
    free(table_buf);
2148
8.58k
  }
2149
7.24M
  else if ((tag == 0xb02b) && !imgdata.sizes.raw_inset_crops[0].cwidth &&
2150
808
           (len == 2))
2151
248
  {
2152
248
    imgdata.sizes.raw_inset_crops[0].cheight = get4();
2153
248
    imgdata.sizes.raw_inset_crops[0].cwidth = get4();
2154
248
  }
2155
7.24M
  else if (tag == 0xb041)
2156
2.85k
  {
2157
2.85k
    imgdata.shootinginfo.ExposureMode = get2();
2158
2.85k
  }
2159
7.24M
  else if ((tag == 0xb043) &&
2160
738
           (len == 1) &&
2161
408
           tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
2162
74
  {
2163
74
    imSony.AFAreaMode = get2();
2164
74
  }
2165
7.77M
}
2166
2167
2168
void LibRaw::parseSonySR2(uchar *_cbuf_SR2, unsigned SR2SubIFDOffset,
2169
                          unsigned SR2SubIFDLength, unsigned dng_writer)
2170
470
{
2171
470
  unsigned c;
2172
470
  unsigned entries, tag_id, tag_type, tag_datalen;
2173
470
  INT64 tag_offset, tag_dataoffset;
2174
470
  int TagProcessed;
2175
470
  int tag_dataunitlen;
2176
470
  float num;
2177
470
  int i;
2178
470
  int WBCTC_count;
2179
470
  try
2180
470
  {
2181
470
      checked_buffer_t cbuf_SR2(order, _cbuf_SR2, SR2SubIFDLength);
2182
470
      entries = cbuf_SR2.sget2(0);
2183
470
      if (entries > 1000)
2184
254
          return;
2185
216
      tag_offset = 2;
2186
216
      WBCTC_count = 0;
2187
19.9k
      while (entries--) {
2188
19.7k
          if (cbuf_SR2.tiff_sget(SR2SubIFDOffset,
2189
19.7k
              &tag_offset, &tag_id, &tag_type, &tag_dataoffset,
2190
19.7k
              &tag_datalen, &tag_dataunitlen) == 0) {
2191
0
              TagProcessed = 0;
2192
0
              if (dng_writer == nonDNG) {
2193
0
                  switch (tag_id) {
2194
0
                  case 0x7300:
2195
0
                      FORC4 cblack[c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2196
0
                      TagProcessed = 1;
2197
0
                      break;
2198
0
                  case 0x7303:
2199
0
                      FORC4 cam_mul[GRBG_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2200
0
                      TagProcessed = 1;
2201
0
                      break;
2202
0
                  case 0x7310:
2203
0
                      FORC4 cblack[RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2204
0
                      i = cblack[3];
2205
0
                      FORC3 if (i > (int)cblack[c]) i = cblack[c];
2206
0
                      FORC4 cblack[c] -= i;
2207
0
                      black = i;
2208
0
                      TagProcessed = 1;
2209
0
                      break;
2210
0
                  case 0x7313:
2211
0
                      FORC4 cam_mul[RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2212
0
                      TagProcessed = 1;
2213
0
                      break;
2214
0
                  case 0x74a0:
2215
0
                      ilm.MaxAp4MaxFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset));
2216
0
                      TagProcessed = 1;
2217
0
                      break;
2218
0
                  case 0x74a1:
2219
0
                      ilm.MaxAp4MinFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset));
2220
0
                      TagProcessed = 1;
2221
0
                      break;
2222
0
                  case 0x74a2:
2223
0
                      ilm.MaxFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset));
2224
0
                      TagProcessed = 1;
2225
0
                      break;
2226
0
                  case 0x74a3:
2227
0
                      ilm.MinFocal = cbuf_SR2.sgetrealf(tag_type, int(tag_dataoffset));
2228
0
                      TagProcessed = 1;
2229
0
                      break;
2230
0
                  case 0x7800:
2231
0
                      for (i = 0; i < 3; i++)
2232
0
                      {
2233
0
                          num = 0.0;
2234
0
                          for (c = 0; c < 3; c++)
2235
0
                          {
2236
0
                              imgdata.color.ccm[i][c] =
2237
0
                                  (float)((short)cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * (i * 3 + c)));
2238
0
                              num += imgdata.color.ccm[i][c];
2239
0
                          }
2240
0
                          if (num > 0.01)
2241
0
                              FORC3 imgdata.color.ccm[i][c] = imgdata.color.ccm[i][c] / num;
2242
0
                      }
2243
0
                      TagProcessed = 1;
2244
0
                      break;
2245
0
                  case 0x787f:
2246
0
                      if (tag_datalen == 3)
2247
0
                      {
2248
0
                          FORC3 imgdata.color.linear_max[c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2249
0
                          imgdata.color.linear_max[3] = imgdata.color.linear_max[1];
2250
0
                      }
2251
0
                      else if (tag_datalen == 1)
2252
0
                      {
2253
0
                          imgdata.color.linear_max[0] = imgdata.color.linear_max[1] =
2254
0
                              imgdata.color.linear_max[2] = imgdata.color.linear_max[3] =
2255
0
                              cbuf_SR2.sget2LL(tag_dataoffset);
2256
0
                      }
2257
0
                      TagProcessed = 1;
2258
0
                      break;
2259
0
                  }
2260
0
              }
2261
2262
0
              if (!TagProcessed) {
2263
0
                  if ((tag_id >= 0x7480) && (tag_id <= 0x7486)) {
2264
0
                      i = tag_id - 0x7480;
2265
0
                      if (Sony_SR2_wb_list[i] > 255) {
2266
0
              if (WBCTC_count < 64) {
2267
0
                icWBCCTC[WBCTC_count][0] = float(Sony_SR2_wb_list[i]);
2268
0
                FORC3 icWBCCTC[WBCTC_count][c + 1] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2269
0
                icWBCCTC[WBCTC_count][4] = icWBCCTC[WBCTC_count][2];
2270
0
              }
2271
0
                          WBCTC_count++;
2272
0
                      }
2273
0
                      else {
2274
0
                          FORC3 icWBC[Sony_SR2_wb_list[i]][c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2275
0
                          icWBC[Sony_SR2_wb_list[i]][3] = icWBC[Sony_SR2_wb_list[i]][1];
2276
0
                      }
2277
0
                  }
2278
0
                  else if ((tag_id >= 0x7820) && (tag_id <= 0x782d)) {
2279
0
                      i = tag_id - 0x7820;
2280
0
                      if (Sony_SR2_wb_list1[i] > 255) {
2281
0
              if (WBCTC_count < 64) {
2282
0
                icWBCCTC[WBCTC_count][0] = float(Sony_SR2_wb_list1[i]);
2283
0
                FORC3 icWBCCTC[WBCTC_count][c + 1] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2284
0
                icWBCCTC[WBCTC_count][4] = icWBCCTC[WBCTC_count][2];
2285
0
                if (Sony_SR2_wb_list1[i] == 3200)
2286
0
                {
2287
0
                  FORC3 icWBC[LIBRAW_WBI_StudioTungsten][c] = int(icWBCCTC[WBCTC_count][c + 1]);
2288
0
                  icWBC[LIBRAW_WBI_StudioTungsten][3] = icWBC[LIBRAW_WBI_StudioTungsten][1];
2289
0
                }
2290
0
              }
2291
0
                          WBCTC_count++;
2292
0
                      }
2293
0
                      else {
2294
0
                          FORC3 icWBC[Sony_SR2_wb_list1[i]][c] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2295
0
                          icWBC[Sony_SR2_wb_list1[i]][3] = icWBC[Sony_SR2_wb_list1[i]][1];
2296
0
                      }
2297
0
                  }
2298
0
                  else if (tag_id == 0x7302) {
2299
0
                      FORC4 icWBC[LIBRAW_WBI_Auto][GRBG_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2300
0
                  }
2301
0
                  else if (tag_id == 0x7312) {
2302
0
                      FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = cbuf_SR2.sget2LL(tag_dataoffset + tag_dataunitlen * c);
2303
0
                  }
2304
0
              }
2305
0
          }
2306
19.7k
      }
2307
216
  }
2308
470
  catch (...)
2309
470
  {
2310
74
      return;
2311
74
  }
2312
470
}
2313
2314
void LibRaw::parseSonySRF(unsigned len)
2315
17.7k
{
2316
2317
17.7k
  if ((len > 0xfffff) || (len == 0))
2318
326
    return;
2319
2320
17.4k
  INT64 save = ftell(ifp);
2321
17.4k
  INT64 offset =  0x0310c0 - save; /* for non-DNG this value normally is 0x8ddc */
2322
17.4k
  if (len < offset || offset < 0)
2323
16.3k
    return;
2324
1.09k
  try {
2325
2326
1.09k
      INT64 decrypt_len = offset >> 2; /* master key offset value is the next
2327
                                          un-encrypted metadata field after SRF0 */
2328
2329
1.09k
      unsigned i, nWB;
2330
1.09k
      unsigned MasterKey, SRF2Key=0;
2331
1.09k
      INT64 srf_offset, tag_offset, tag_dataoffset;
2332
1.09k
      int tag_dataunitlen;
2333
      //uchar *srf_buf;
2334
1.09k
      ushort entries;
2335
1.09k
      unsigned tag_id, tag_type, tag_datalen;
2336
2337
      //srf_buf = (uchar *)malloc(len+64);
2338
1.09k
      checked_buffer_t srf_buf(order, len);
2339
1.09k
      fread(srf_buf.data(), len, 1, ifp);
2340
2341
1.09k
      offset += srf_buf[int(offset)] << 2;
2342
2343
1.09k
    int ioffset = int(offset);
2344
    
2345
1.09k
    if (ioffset + 3 >= len)
2346
16
        goto restore_after_parseSonySRF;
2347
      /* master key is stored in big endian */
2348
1.07k
      MasterKey = ((unsigned)srf_buf[ioffset] << 24) |
2349
1.07k
          ((unsigned)srf_buf[ioffset + 1] << 16) |
2350
1.07k
          ((unsigned)srf_buf[ioffset + 2] << 8) |
2351
1.07k
          (unsigned)srf_buf[ioffset + 3];
2352
2353
      /* skip SRF0 */
2354
1.07k
      srf_offset = 0;
2355
1.07k
      entries = srf_buf.sget2LL(srf_offset);
2356
1.07k
      if (entries > 1000)
2357
126
          goto restore_after_parseSonySRF;
2358
948
      offset = srf_offset + 2;
2359
948
      srf_offset = srf_buf.sget4LL(offset + 12 * entries) - save; /* SRF0 ends with SRF1 abs. position */
2360
2361
      /* get SRF1, it has fixed 40 bytes length and contains keys to decode metadata
2362
       * and raw data */
2363
948
      if (srf_offset < 0 || decrypt_len < srf_offset / 4)
2364
322
          goto restore_after_parseSonySRF;
2365
626
      sony_decrypt((unsigned *)(srf_buf.data() + int(srf_offset)), int(decrypt_len - srf_offset / 4),
2366
626
          1, MasterKey);
2367
626
      entries = srf_buf.sget2LL(srf_offset);
2368
626
      if (entries > 1000)
2369
554
          goto restore_after_parseSonySRF;
2370
72
      offset = srf_offset + 2;
2371
72
      tag_offset = offset;
2372
2373
72
      while (entries--) {
2374
70
          if (tiff_sget(unsigned(save), srf_buf.data(), len,
2375
70
              &tag_offset, &tag_id, &tag_type, &tag_dataoffset,
2376
70
              &tag_datalen, &tag_dataunitlen) == 0) {
2377
0
              if (tag_id == 0x0000) {
2378
0
                  SRF2Key = srf_buf.sget4LL(tag_dataoffset);
2379
0
              }
2380
0
              else if (tag_id == 0x0001) {
2381
0
                  /*RawDataKey =*/ srf_buf.sget4LL(tag_dataoffset);
2382
0
              }
2383
0
          }
2384
70
          else goto restore_after_parseSonySRF;
2385
70
      }
2386
2
      offset = tag_offset;
2387
2388
      /* get SRF2 */
2389
2
      srf_offset = srf_buf.sget4LL(offset) - save; /* SRFn ends with SRFn+1 position */
2390
2
      if (srf_offset < 0 || decrypt_len < srf_offset / 4)
2391
0
          goto restore_after_parseSonySRF;
2392
2
      sony_decrypt((unsigned *)(srf_buf.data() + srf_offset), int(decrypt_len - srf_offset / 4),
2393
2
          1, SRF2Key);
2394
2395
2
      entries = srf_buf.sget2(int(srf_offset));
2396
2
      if (entries > 1000)
2397
0
          goto restore_after_parseSonySRF;
2398
2
      offset = srf_offset + 2;
2399
2
      tag_offset = offset;
2400
2401
2
      while (entries--) {
2402
0
          if (srf_buf.tiff_sget(unsigned(save),
2403
0
              &tag_offset, &tag_id, &tag_type, &tag_dataoffset,
2404
0
              &tag_datalen, &tag_dataunitlen) == 0) {
2405
0
              if ((tag_id >= 0x00c0) && (tag_id <= 0x00ce)) {
2406
0
                  i = (tag_id - 0x00c0) % 3;
2407
0
                  nWB = (tag_id - 0x00c0) / 3;
2408
0
                  icWBC[Sony_SRF_wb_list[nWB]][i] = srf_buf.sget4LL(tag_dataoffset);
2409
0
                  if (i == 1) {
2410
0
                      icWBC[Sony_SRF_wb_list[nWB]][3] =
2411
0
                          icWBC[Sony_SRF_wb_list[nWB]][i];
2412
0
                  }
2413
0
              }
2414
0
              else if ((tag_id >= 0x00d0) && (tag_id <= 0x00d2)) {
2415
0
                  i = (tag_id - 0x00d0) % 3;
2416
0
                  cam_mul[i] = float(srf_buf.sget4LL(tag_dataoffset));
2417
0
                  if (i == 1) {
2418
0
                      cam_mul[3] = cam_mul[i];
2419
0
                  }
2420
0
              }
2421
0
              else switch (tag_id) {
2422
                  /*
2423
                  0x0002  SRF6Offset
2424
                  0x0003  SRFDataOffset (?)
2425
                  0x0004  RawDataOffset
2426
                  0x0005  RawDataLength
2427
                  */
2428
0
              case 0x0043:
2429
0
                  ilm.MaxAp4MaxFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset));
2430
0
                  break;
2431
0
              case 0x0044:
2432
0
                  ilm.MaxAp4MinFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset));
2433
0
                  break;
2434
0
              case 0x0045:
2435
0
                  ilm.MinFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset));
2436
0
                  break;
2437
0
              case 0x0046:
2438
0
                  ilm.MaxFocal = srf_buf.sgetrealf(tag_type, int(tag_dataoffset));
2439
0
                  break;
2440
0
              }
2441
0
          }
2442
0
          else goto restore_after_parseSonySRF;
2443
0
      }
2444
2
      offset = tag_offset;
2445
2446
1.08k
  restore_after_parseSonySRF:;
2447
1.08k
  }
2448
1.09k
  catch (...) // srf_buf can raise IO_EOF exception, catch it and return usual way
2449
1.09k
  {
2450
2
      fseek(ifp, save, SEEK_SET);
2451
2
      return;
2452
2
  }
2453
1.08k
  fseek(ifp, save, SEEK_SET);
2454
1.08k
}