Coverage Report

Created: 2026-02-26 07:48

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