Coverage Report

Created: 2026-06-14 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/LibRaw/src/metadata/canon.cpp
Line
Count
Source
1
/* -*- C++ -*-
2
 * Copyright 2019-2025 LibRaw LLC (info@libraw.org)
3
 *
4
5
 LibRaw is free software; you can redistribute it and/or modify
6
 it under the terms of the one of two licenses as you choose:
7
8
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
9
   (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
10
11
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
12
   (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
13
14
 */
15
#include "../../internal/dcraw_defs.h"
16
#include "../../internal/libraw_cameraids.h"
17
18
18.8k
libraw_area_t LibRaw::get_CanonArea() {
19
18.8k
  libraw_area_t la = {};
20
18.8k
  la.l = get2();
21
18.8k
  la.t = get2();
22
18.8k
  la.r = get2();
23
18.8k
  la.b = get2();
24
18.8k
  return la;
25
18.8k
}
26
27
float LibRaw::_CanonConvertAperture(ushort in)
28
296k
{
29
296k
  if ((in == (ushort)0xffe0) || (in == (ushort)0x7fff))
30
3.39k
    return 0.0f;
31
292k
  return LibRaw::libraw_powf64l(2.f, float(in) / 64.f);
32
296k
}
33
34
static float _CanonConvertEV(short in)
35
36.9k
{
36
36.9k
  short EV, Sign, Frac;
37
36.9k
  float Frac_f;
38
36.9k
  EV = in;
39
36.9k
  if (EV < 0)
40
9.16k
  {
41
9.16k
    EV = -EV;
42
9.16k
    Sign = -1;
43
9.16k
  }
44
27.8k
  else
45
27.8k
  {
46
27.8k
    Sign = 1;
47
27.8k
  }
48
36.9k
  Frac = EV & 0x1f;
49
36.9k
  EV -= Frac; // remove fraction
50
51
36.9k
  if (Frac == 0x0c)
52
754
  { // convert 1/3 and 2/3 codes
53
754
    Frac_f = 32.0f / 3.0f;
54
754
  }
55
36.2k
  else if (Frac == 0x14)
56
294
  {
57
294
    Frac_f = 64.0f / 3.0f;
58
294
  }
59
35.9k
  else
60
35.9k
    Frac_f = (float)Frac;
61
62
36.9k
  return ((float)Sign * ((float)EV + Frac_f)) / 32.0f;
63
36.9k
}
64
65
void LibRaw::setCanonBodyFeatures(unsigned long long id)
66
47.0k
{
67
68
47.0k
  ilm.CamID = id;
69
47.0k
  if ((id == CanonID_EOS_1D)           ||
70
44.4k
      (id == CanonID_EOS_1D_Mark_II)   ||
71
44.1k
      (id == CanonID_EOS_1D_Mark_II_N) ||
72
44.0k
      (id == CanonID_EOS_1D_Mark_III)  ||
73
42.9k
      (id == CanonID_EOS_1D_Mark_IV))
74
4.99k
  {
75
4.99k
    ilm.CameraFormat = LIBRAW_FORMAT_APSH;
76
4.99k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_EF;
77
4.99k
  }
78
42.0k
  else if ((id == CanonID_EOS_1Ds)           ||
79
41.9k
           (id == CanonID_EOS_1Ds_Mark_II)   ||
80
41.3k
           (id == CanonID_EOS_1Ds_Mark_III)  ||
81
41.2k
           (id == CanonID_EOS_1D_X)          ||
82
40.1k
           (id == CanonID_EOS_1D_X_Mark_II)  ||
83
40.0k
           (id == CanonID_EOS_1D_X_Mark_III) ||
84
36.3k
           (id == CanonID_EOS_1D_C)          ||
85
36.2k
           (id == CanonID_EOS_5D)            ||
86
35.9k
           (id == CanonID_EOS_5D_Mark_II)    ||
87
35.6k
           (id == CanonID_EOS_5D_Mark_III)   ||
88
33.9k
           (id == CanonID_EOS_5D_Mark_IV)    ||
89
33.8k
           (id == CanonID_EOS_5DS)           ||
90
33.0k
           (id == CanonID_EOS_5DS_R)         ||
91
31.4k
           (id == CanonID_EOS_6D)            ||
92
31.1k
           (id == CanonID_EOS_6D_Mark_II))
93
11.2k
  {
94
11.2k
    ilm.CameraFormat = LIBRAW_FORMAT_FF;
95
11.2k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_EF;
96
11.2k
  }
97
30.8k
  else if ((id == CanonID_EOS_M)             ||
98
27.5k
           (id == CanonID_EOS_M2)            ||
99
27.5k
           (id == CanonID_EOS_M3)            ||
100
27.2k
           (id == CanonID_EOS_M5)            ||
101
26.9k
           (id == CanonID_EOS_M10)           ||
102
26.8k
           (id == CanonID_EOS_M50)           ||
103
26.8k
           (id == CanonID_EOS_M50_Mark_II)   ||
104
26.7k
           (id == CanonID_EOS_M6)            ||
105
26.6k
           (id == CanonID_EOS_M6_Mark_II)    ||
106
26.5k
           (id == CanonID_EOS_M100))
107
4.53k
  {
108
4.53k
    ilm.CameraFormat = LIBRAW_FORMAT_APSC;
109
4.53k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_EF_M;
110
4.53k
  }
111
26.2k
  else if (
112
26.2k
              (id == CanonID_EOS_R)
113
26.2k
           || (id == CanonID_EOS_RP)
114
26.2k
           || (id == CanonID_EOS_R1)
115
26.0k
           || (id == CanonID_EOS_R3)
116
26.0k
           || (id == CanonID_EOS_R5)
117
25.9k
           || (id == CanonID_EOS_R5_Mark_II)
118
25.8k
           || (id == CanonID_EOS_R5_C)
119
25.5k
           || (id == CanonID_EOS_R6)
120
25.3k
           || (id == CanonID_EOS_R6m2)
121
25.1k
           || (id == CanonID_EOS_R8)
122
26.2k
          )
123
1.43k
  {
124
1.43k
    ilm.CameraFormat = LIBRAW_FORMAT_FF;
125
1.43k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_RF;
126
1.43k
    ilm.LensFormat = LIBRAW_FORMAT_FF;
127
1.43k
    ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
128
1.43k
  }
129
130
24.8k
  else if (
131
24.8k
              (id == CanonID_EOS_R7)
132
23.5k
           || (id == CanonID_EOS_R10)
133
23.2k
           || (id == CanonID_EOS_R50)
134
23.2k
           || (id == CanonID_EOS_R100)
135
24.8k
          )
136
1.77k
  {
137
1.77k
    ilm.CameraFormat = LIBRAW_FORMAT_APSC;
138
1.77k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_RF;
139
1.77k
    ilm.LensFormat = LIBRAW_FORMAT_APSC;
140
1.77k
    ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
141
1.77k
  }
142
143
23.0k
  else if ((id == CanonID_EOS_D30) ||
144
22.8k
           (id == CanonID_EOS_D60) ||
145
22.6k
           (id > 0x80000000ULL))
146
14.6k
  {
147
14.6k
    ilm.CameraFormat = LIBRAW_FORMAT_APSC;
148
14.6k
    ilm.CameraMount = LIBRAW_MOUNT_Canon_EF;
149
14.6k
  }
150
47.0k
}
151
152
static int CanonCameraInfo_checkFirmwareRecordLocation (uchar *data, size_t _offset, size_t size) 
153
11.8k
{
154
11.8k
  if (size < _offset + 5) return 0; // overrun
155
9.50k
  uchar *offset = data + _offset;
156
// firmware record location allows
157
// to determine the subversion of the CameraInfo table
158
// and to adjust offsets accordingly
159
9.50k
  if (
160
9.50k
        isdigit(*offset)     &&
161
2.01k
        isdigit(*(offset+2)) &&
162
1.66k
        isdigit(*(offset+4)) &&
163
1.40k
        (*(offset+1) == '.') &&
164
1.15k
        (*(offset+3) == '.') &&
165
1.08k
        ((*(offset+5) == 0) || isspace(*(offset+5)))
166
9.50k
      ) return 1;
167
8.71k
  else return 0; // error
168
9.50k
}
169
170
void LibRaw::processCanonCameraInfo(unsigned long long id, uchar *CameraInfo,
171
                                    unsigned maxlen, unsigned type, unsigned dng_writer)
172
24.5k
{
173
24.5k
  ushort iCanonLensID = 0, iCanonMaxFocal = 0, iCanonMinFocal = 0,
174
24.5k
         iCanonLens = 0, iCanonCurFocal = 0, iCanonFocalType = 0,
175
24.5k
         iMakernotesFlip = 0,
176
24.5k
         iHTP = 0, iALO = 0,
177
24.5k
         iAutoRotateMode = 0;
178
24.5k
  short SubVersion_offset = 0;
179
24.5k
  ushort SubVersion = 0, mgck = 0;
180
181
// printf ("==>> CanonCameraInfo len: %d\n", maxlen);
182
24.5k
  if (maxlen < 16)
183
382
    return; // too short
184
185
24.1k
  mgck = sget2(CameraInfo);
186
24.1k
  CameraInfo[0] = 0;
187
24.1k
  CameraInfo[1] = 0;
188
24.1k
  if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) {
189
8.07k
    if ((maxlen == 94)  || (maxlen == 138) || (maxlen == 148) ||
190
7.73k
        (maxlen == 156) || (maxlen == 162) || (maxlen == 167) ||
191
3.52k
        (maxlen == 171) || (maxlen == 264) || (maxlen > 400))
192
5.25k
      imCommon.CameraTemperature = float(sget4(CameraInfo + ((maxlen - 3) << 2)));
193
2.82k
    else if (maxlen == 72)
194
70
      imCommon.CameraTemperature = float(sget4(CameraInfo + ((maxlen - 1) << 2)));
195
2.75k
    else if ((maxlen == 85) || (maxlen == 93))
196
1.40k
      imCommon.CameraTemperature = float(sget4(CameraInfo + ((maxlen - 2) << 2)));
197
1.34k
    else if ((maxlen == 96) || (maxlen == 104))
198
698
      imCommon.CameraTemperature = float(sget4(CameraInfo + ((maxlen - 4) << 2)));
199
8.07k
  }
200
201
24.1k
  switch (id)
202
24.1k
  {
203
2.19k
  case CanonID_EOS_1D:
204
2.23k
  case CanonID_EOS_1Ds:
205
2.23k
    iCanonCurFocal  =  0x0a;
206
2.23k
    iCanonLensID    =  0x0d;
207
2.23k
    iCanonMinFocal  =  0x0e;
208
2.23k
    iCanonMaxFocal  =  0x10;
209
2.23k
    if (!ilm.CurFocal && iCanonCurFocal < maxlen - 1)
210
868
      ilm.CurFocal = sget2(CameraInfo + iCanonCurFocal);
211
2.23k
    if (!ilm.MinFocal && iCanonMinFocal < maxlen - 1)
212
584
      ilm.MinFocal = sget2(CameraInfo + iCanonMinFocal);
213
2.23k
    if (!ilm.MaxFocal && iCanonMaxFocal < maxlen - 1)
214
904
      ilm.MaxFocal = sget2(CameraInfo + iCanonMaxFocal);
215
2.23k
    imCommon.CameraTemperature = 0.0f;
216
2.23k
    break;
217
218
392
  case CanonID_EOS_1D_Mark_II:
219
1.03k
  case CanonID_EOS_1Ds_Mark_II:
220
1.03k
    iCanonCurFocal  =  0x09;
221
1.03k
    iCanonLensID    =  0x0c;
222
1.03k
    iCanonMinFocal  =  0x11;
223
1.03k
    iCanonMaxFocal  =  0x13;
224
1.03k
    iCanonFocalType =  0x2d;
225
1.03k
    break;
226
227
78
  case CanonID_EOS_1D_Mark_II_N:
228
78
    iCanonCurFocal  =  0x09;
229
78
    iCanonLensID    =  0x0c;
230
78
    iCanonMinFocal  =  0x11;
231
78
    iCanonMaxFocal  =  0x13;
232
78
    break;
233
234
1.04k
  case CanonID_EOS_1D_Mark_III:
235
1.16k
  case CanonID_EOS_1Ds_Mark_III:
236
1.16k
    iCanonCurFocal  =  0x1d;
237
1.16k
    iMakernotesFlip =  0x30;
238
1.16k
    iCanonLensID    = 0x111;
239
1.16k
    iCanonMinFocal  = 0x113;
240
1.16k
    iCanonMaxFocal  = 0x115;
241
1.16k
    break;
242
243
884
  case CanonID_EOS_1D_Mark_IV:
244
884
    if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1e8, maxlen))
245
0
      SubVersion = 1;
246
884
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1ed, maxlen))
247
0
      SubVersion = 2;
248
// printf ("==>> CanonID_EOS_1D_Mark_IV, SubVersion: %d\n", SubVersion);
249
884
    iHTP            =  0x07;
250
884
    iCanonCurFocal  =  0x1e;
251
884
    iMakernotesFlip =  0x35;
252
253
884
    if (!SubVersion)
254
884
      break;
255
0
    else if (SubVersion < 2)
256
0
      SubVersion_offset += -1;
257
258
0
    iCanonLensID    = 0x14f+SubVersion_offset;
259
0
    iCanonMinFocal  = 0x151+SubVersion_offset;
260
0
    iCanonMaxFocal  = 0x153+SubVersion_offset;
261
0
    break;
262
263
1.04k
  case CanonID_EOS_1D_X:
264
1.04k
    if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x271, maxlen))
265
0
      SubVersion = 1;
266
1.04k
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x279, maxlen))
267
0
      SubVersion = 2;
268
1.04k
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x280, maxlen))
269
0
      SubVersion = 3;
270
1.04k
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x285, maxlen))
271
0
      SubVersion = 4;
272
// printf ("==>> CanonID_EOS_1D_X, SubVersion: %d\n", SubVersion);
273
274
1.04k
    if (SubVersion < 3)
275
1.04k
      SubVersion_offset += -3;
276
277
1.04k
    iCanonCurFocal  =  0x23+SubVersion_offset;
278
1.04k
    iMakernotesFlip =  0x7d+SubVersion_offset;
279
280
1.04k
    if (SubVersion < 3)
281
1.04k
      SubVersion_offset += -4;
282
0
    else if (SubVersion == 4)
283
0
      SubVersion_offset += 5;
284
285
1.04k
    iCanonLensID    = 0x1a7+SubVersion_offset;
286
1.04k
    iCanonMinFocal  = 0x1a9+SubVersion_offset;
287
1.04k
    iCanonMaxFocal  = 0x1ab+SubVersion_offset;
288
1.04k
    break;
289
290
368
  case CanonID_EOS_5D:
291
368
    iMakernotesFlip =  0x27;
292
368
    iCanonCurFocal  =  0x28;
293
368
    iCanonLensID    =  0x0c;
294
368
    if (!sget2Rev(CameraInfo + iCanonLensID))
295
70
      iCanonLensID  =  0x97;
296
368
    iCanonMinFocal  =  0x93;
297
368
    iCanonMaxFocal  =  0x95;
298
368
    break;
299
300
266
  case CanonID_EOS_5D_Mark_II:
301
266
    iHTP            =  0x07;
302
266
    iCanonCurFocal  =  0x1e;
303
266
    iMakernotesFlip =  0x31;
304
266
    iALO            =  0xbf;
305
266
    iCanonLensID    =  0xe6;
306
266
    iCanonMinFocal  =  0xe8;
307
266
    iCanonMaxFocal  =  0xea;
308
266
    break;
309
310
1.43k
  case CanonID_EOS_5D_Mark_III:
311
1.43k
    if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x22c, maxlen))
312
250
      SubVersion = 1;
313
1.18k
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x22d, maxlen))
314
232
      SubVersion = 2;
315
948
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x23c, maxlen))
316
78
      SubVersion = 3;
317
870
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x242, maxlen))
318
66
      SubVersion = 4;
319
804
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x247, maxlen))
320
164
      SubVersion = 5;
321
// printf ("==>> CanonID_EOS_5D_Mark_III, SubVersion: %d\n", SubVersion);
322
323
1.43k
    if (!SubVersion)
324
640
      break;
325
790
    else if (SubVersion < 3)
326
482
      SubVersion_offset += -1;
327
328
790
    iCanonCurFocal  =  0x23+SubVersion_offset;
329
330
790
    if (SubVersion == 1)
331
250
      SubVersion_offset += -3;
332
540
    else if (SubVersion == 2)
333
232
      SubVersion_offset += -2;
334
308
    else if (SubVersion >= 4)
335
230
      SubVersion_offset += 6;
336
337
790
    iMakernotesFlip =  0x7d+SubVersion_offset;
338
339
790
    if (SubVersion < 3)
340
482
      SubVersion_offset += -4;
341
308
    else if (SubVersion > 4)
342
164
      SubVersion_offset += 5;
343
344
790
    iCanonLensID    = 0x153+SubVersion_offset;
345
790
    iCanonMinFocal  = 0x155+SubVersion_offset;
346
790
    iCanonMaxFocal  = 0x157+SubVersion_offset;
347
790
    break;
348
349
72
  case CanonID_EOS_5D_Mark_IV:
350
72
    iMakernotesFlip =  0x96;
351
72
    iAutoRotateMode = 0x5da;
352
    //printf ("==>> 5DMkIV: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
353
72
    break;
354
355
422
  case CanonID_EOS_5DS:
356
900
  case CanonID_EOS_5DS_R:
357
900
    iMakernotesFlip =  0x96;
358
900
    iAutoRotateMode = 0x580;
359
    //printf ("==>> 5DS/5DS R: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
360
900
    break;
361
362
30
  case CanonID_EOS_6D:
363
30
    iCanonCurFocal  =  0x23;
364
30
    iMakernotesFlip =  0x83;
365
30
    iCanonLensID    = 0x161;
366
30
    iCanonMinFocal  = 0x163;
367
30
    iCanonMaxFocal  = 0x165;
368
30
    iAutoRotateMode = 0x3b2;
369
    //printf ("==>> 6D: MakernotesFlip: %d; AutoRotateMode: %d\n", CameraInfo[iMakernotesFlip], CameraInfo[iAutoRotateMode]);
370
30
    break;
371
372
330
  case CanonID_EOS_7D:
373
330
    if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1a8, maxlen))
374
0
      SubVersion = 1;
375
330
    else if (CanonCameraInfo_checkFirmwareRecordLocation(CameraInfo, 0x1ac, maxlen))
376
0
      SubVersion = 2;
377
// printf ("==>> CanonID_EOS_7D, SubVersion: %d\n", SubVersion);
378
330
    iHTP            =  0x07;
379
330
    iCanonCurFocal  =  0x1e;
380
381
330
    if (!SubVersion)
382
330
      break;
383
0
    else if (SubVersion < 2)
384
0
      SubVersion_offset += -4;
385
386
0
    iMakernotesFlip =  0x35+SubVersion_offset;
387
0
    iCanonLensID    = 0x112+SubVersion_offset;
388
0
    iCanonMinFocal  = 0x114+SubVersion_offset;
389
0
    iCanonMaxFocal  = 0x116+SubVersion_offset;
390
0
    break;
391
392
526
  case CanonID_EOS_40D:
393
526
    iCanonCurFocal  =  0x1d;
394
526
    iMakernotesFlip =  0x30;
395
526
    iCanonLensID    =  0xd6;
396
526
    iCanonMinFocal  =  0xd8;
397
526
    iCanonMaxFocal  =  0xda;
398
526
    iCanonLens      = 0x92b;
399
526
    break;
400
401
1.11k
  case CanonID_EOS_50D:
402
1.11k
    iHTP            =  0x07;
403
1.11k
    iCanonCurFocal  =  0x1e;
404
1.11k
    iMakernotesFlip =  0x31;
405
1.11k
    iALO            =  0xbf;
406
1.11k
    iCanonLensID    =  0xea;
407
1.11k
    iCanonMinFocal  =  0xec;
408
1.11k
    iCanonMaxFocal  =  0xee;
409
1.11k
    break;
410
411
526
  case CanonID_EOS_60D:
412
570
  case CanonID_EOS_1200D:
413
570
    iCanonCurFocal  =  0x1e;
414
570
    if (id == CanonID_EOS_60D)
415
526
      iMakernotesFlip =  0x36;
416
44
    else
417
44
      iMakernotesFlip =  0x3a;
418
570
    iCanonLensID    =  0xe8;
419
570
    iCanonMinFocal  =  0xea;
420
570
    iCanonMaxFocal  =  0xec;
421
570
    break;
422
423
14
  case CanonID_EOS_70D:
424
14
    iCanonCurFocal  =  0x23;
425
14
    iMakernotesFlip =  0x84;
426
14
    iCanonLensID    = 0x166;
427
14
    iCanonMinFocal  = 0x168;
428
14
    iCanonMaxFocal  = 0x16a;
429
14
    break;
430
431
550
  case CanonID_EOS_80D:
432
550
    iCanonCurFocal  =  0x23;
433
550
    iMakernotesFlip =  0x96;
434
550
    iCanonLensID    = 0x189;
435
550
    iCanonMinFocal  = 0x18b;
436
550
    iCanonMaxFocal  = 0x18d;
437
550
    break;
438
439
190
  case CanonID_EOS_450D:
440
190
    iCanonCurFocal  =  0x1d;
441
190
    iMakernotesFlip =  0x30;
442
190
    iCanonLensID    =  0xde;
443
190
    iCanonLens      = 0x933;
444
190
    break;
445
446
2.07k
  case CanonID_EOS_500D:
447
2.07k
    iHTP            =  0x07;
448
2.07k
    iCanonCurFocal  =  0x1e;
449
2.07k
    iMakernotesFlip =  0x31;
450
2.07k
    iALO            =  0xbe;
451
2.07k
    iCanonLensID    =  0xf6;
452
2.07k
    iCanonMinFocal  =  0xf8;
453
2.07k
    iCanonMaxFocal  =  0xfa;
454
2.07k
    break;
455
456
68
  case CanonID_EOS_550D:
457
68
    iHTP            =  0x07;
458
68
    iCanonCurFocal  =  0x1e;
459
68
    iMakernotesFlip =  0x35;
460
68
    iCanonLensID    =  0xff;
461
68
    iCanonMinFocal  = 0x101;
462
68
    iCanonMaxFocal  = 0x103;
463
68
    break;
464
465
90
  case CanonID_EOS_600D:
466
900
  case CanonID_EOS_1100D:
467
900
    iHTP            =  0x07;
468
900
    iCanonCurFocal  =  0x1e;
469
900
    iMakernotesFlip =  0x38;
470
900
    iCanonLensID    =  0xea;
471
900
    iCanonMinFocal  =  0xec;
472
900
    iCanonMaxFocal  =  0xee;
473
900
    break;
474
475
74
  case CanonID_EOS_650D:
476
248
  case CanonID_EOS_700D:
477
248
    iCanonCurFocal  =  0x23;
478
248
    iMakernotesFlip =  0x7d;
479
248
    iCanonLensID    = 0x127;
480
248
    iCanonMinFocal  = 0x129;
481
248
    iCanonMaxFocal  = 0x12b;
482
248
    break;
483
484
72
  case CanonID_EOS_750D:
485
438
  case CanonID_EOS_760D:
486
438
    iCanonCurFocal  =  0x23;
487
438
    iMakernotesFlip =  0x96;
488
438
    iCanonLensID    = 0x184;
489
438
    iCanonMinFocal  = 0x186;
490
438
    iCanonMaxFocal  = 0x188;
491
438
    break;
492
493
222
  case CanonID_EOS_1000D:
494
222
    iCanonCurFocal  =  0x1d;
495
222
    iMakernotesFlip =  0x30;
496
222
    iCanonLensID    =  0xe2;
497
222
    iCanonMinFocal  =  0xe4;
498
222
    iCanonMaxFocal  =  0xe6;
499
222
    iCanonLens      = 0x937;
500
222
    break;
501
24.1k
  }
502
503
24.1k
  if (iMakernotesFlip && iMakernotesFlip < maxlen && (CameraInfo[iMakernotesFlip] < 3)) {
504
5.24k
    imCanon.MakernotesFlip = "065"[CameraInfo[iMakernotesFlip]] - '0';
505
18.9k
  } else if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED) &&
506
7.43k
     (mgck == 0xaaaa) && (dng_writer == nonDNG)) { // CameraOrientation
507
1.09k
    int c, i;
508
1.77M
    for (i = 2; (sget2(CameraInfo+i) != 0xbbbb) && i < (int)maxlen; i++);
509
1.09k
    i+=2;
510
538k
    while (i < int(maxlen - 5))
511
538k
      if ((sget4(CameraInfo+i) == 257) && ((c = CameraInfo[i+8]) < 3)) {
512
274
        imCanon.MakernotesFlip = "065"[c] - '0';
513
274
        break;
514
537k
      } else i+=4;
515
1.09k
  }
516
517
24.1k
  if (iAutoRotateMode && iAutoRotateMode < maxlen && CameraInfo[iAutoRotateMode] < 3)
518
76
    imCanon.AutoRotateMode = CameraInfo[iAutoRotateMode];
519
520
24.1k
  if (iHTP && iHTP < maxlen)
521
5.63k
  {
522
5.63k
    imCanon.HighlightTonePriority = CameraInfo[iHTP];
523
5.63k
    if ((imCanon.HighlightTonePriority > 5) ||
524
3.04k
        (imCanon.HighlightTonePriority < 0))
525
2.58k
      imCanon.HighlightTonePriority = 0;
526
5.63k
    if (imCanon.HighlightTonePriority) {
527
458
      imCommon.ExposureCalibrationShift -= float(imCanon.HighlightTonePriority);
528
458
    }
529
5.63k
  }
530
24.1k
  if (iALO && iALO < maxlen)
531
2.34k
  {
532
2.34k
    imCanon.AutoLightingOptimizer = CameraInfo[iALO];
533
2.34k
    if ((imCanon.AutoLightingOptimizer > 3) ||
534
766
        (imCanon.AutoLightingOptimizer < 0))
535
1.58k
      imCanon.AutoLightingOptimizer = 3;
536
2.34k
  }
537
24.1k
  if (iCanonFocalType)
538
1.03k
  {
539
1.03k
    if (iCanonFocalType >= maxlen)
540
472
      return; // broken;
541
566
    ilm.FocalType = CameraInfo[iCanonFocalType];
542
566
    if (!ilm.FocalType) // zero means 'prime' here, replacing with standard '1'
543
308
      ilm.FocalType = LIBRAW_FT_PRIME_LENS;
544
566
  }
545
23.6k
  if (!ilm.CurFocal && iCanonCurFocal)
546
6.02k
  {
547
6.02k
    if (iCanonCurFocal >= maxlen)
548
266
      return; // broken;
549
5.75k
    ilm.CurFocal = sget2Rev(CameraInfo + iCanonCurFocal);
550
5.75k
  }
551
23.4k
  if (!ilm.LensID && iCanonLensID)
552
2.73k
  {
553
2.73k
    if (iCanonLensID >= maxlen)
554
534
      return; // broken;
555
2.20k
    ilm.LensID = sget2Rev(CameraInfo + iCanonLensID);
556
2.20k
  }
557
22.8k
  if (!ilm.MinFocal && iCanonMinFocal)
558
4.12k
  {
559
4.12k
    if (iCanonMinFocal >= maxlen)
560
1.08k
      return; // broken;
561
3.04k
    ilm.MinFocal = sget2Rev(CameraInfo + iCanonMinFocal);
562
3.04k
  }
563
21.7k
  if (!ilm.MaxFocal && iCanonMaxFocal)
564
3.64k
  {
565
3.64k
    if (iCanonMaxFocal >= maxlen)
566
718
      return; // broken;
567
2.92k
    ilm.MaxFocal = sget2Rev(CameraInfo + iCanonMaxFocal);
568
2.92k
  }
569
21.0k
  if (!ilm.Lens[0] && iCanonLens)
570
826
  {
571
826
    if (iCanonLens + 64 >= (int)maxlen) // broken;
572
528
      return;
573
574
298
    char *pl = (char *)CameraInfo + iCanonLens;
575
298
    if (!strncmp(pl, "EF-S", 4))
576
0
    {
577
0
      memcpy(ilm.Lens, pl, 4);
578
0
      ilm.Lens[4] = ' ';
579
0
      memcpy(ilm.LensFeatures_pre, pl, 4);
580
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF_S;
581
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
582
0
      memcpy(ilm.Lens + 5, pl + 4, 60);
583
0
    }
584
298
    else if (!strncmp(pl, "EF-M", 4))
585
0
    {
586
0
      memcpy(ilm.Lens, pl, 4);
587
0
      ilm.Lens[4] = ' ';
588
0
      memcpy(ilm.LensFeatures_pre, pl, 4);
589
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF_M;
590
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
591
0
      memcpy(ilm.Lens + 5, pl + 4, 60);
592
0
    }
593
298
    else if (!strncmp(pl, "EF", 2))
594
0
    {
595
0
      memcpy(ilm.Lens, pl, 2);
596
0
      ilm.Lens[2] = ' ';
597
0
      memcpy(ilm.LensFeatures_pre, pl, 2);
598
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
599
0
      ilm.LensFormat = LIBRAW_FORMAT_FF;
600
0
      memcpy(ilm.Lens + 3, pl + 2, 62);
601
0
    }
602
298
    else if (!strncmp(ilm.Lens, "CN-E", 4))
603
0
    {
604
0
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
605
0
      ilm.Lens[4] = ' ';
606
0
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
607
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
608
0
      ilm.LensFormat = LIBRAW_FORMAT_FF;
609
0
    }
610
298
    else if (!strncmp(pl, "TS-E", 4))
611
0
    {
612
0
      memcpy(ilm.Lens, pl, 4);
613
0
      ilm.Lens[4] = ' ';
614
0
      memcpy(ilm.LensFeatures_pre, pl, 4);
615
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
616
0
      ilm.LensFormat = LIBRAW_FORMAT_FF;
617
0
      memcpy(ilm.Lens + 5, pl + 4, 60);
618
0
    }
619
298
    else if (!strncmp(pl, "MP-E", 4))
620
0
    {
621
0
      memcpy(ilm.Lens, pl, 4);
622
0
      ilm.Lens[4] = ' ';
623
0
      memcpy(ilm.LensFeatures_pre, pl, 4);
624
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
625
0
      ilm.LensFormat = LIBRAW_FORMAT_FF;
626
0
      memcpy(ilm.Lens + 5, pl + 4, 60);
627
0
    }
628
298
    else // non-Canon lens
629
298
      memcpy(ilm.Lens, pl, 64);
630
298
  }
631
20.5k
  return;
632
21.0k
}
633
634
void LibRaw::Canon_CameraSettings(unsigned len)
635
101k
{
636
101k
  fseek(ifp, 6, SEEK_CUR);
637
101k
  imCanon.Quality = get2();   // 3
638
101k
  get2();
639
101k
  imgdata.shootinginfo.DriveMode = get2(); // 5
640
101k
  get2();
641
101k
  imgdata.shootinginfo.FocusMode = get2(); // 7
642
101k
  imCanon.RecordMode = (get2(), get2());   // 9, format
643
101k
  fseek(ifp, 14, SEEK_CUR);
644
101k
  imgdata.shootinginfo.MeteringMode = get2(); // 17
645
101k
  get2();
646
101k
  imgdata.shootinginfo.AFPoint = get2();      // 19
647
101k
  imgdata.shootinginfo.ExposureMode = get2(); // 20
648
101k
  get2();
649
101k
  ilm.LensID = get2();          // 22
650
101k
  ilm.MaxFocal = get2();        // 23
651
101k
  ilm.MinFocal = get2();        // 24
652
101k
  ilm.FocalUnits = get2();      // 25
653
101k
  if (ilm.FocalUnits > 1)
654
76.2k
  {
655
76.2k
    ilm.MaxFocal /= (float)ilm.FocalUnits;
656
76.2k
    ilm.MinFocal /= (float)ilm.FocalUnits;
657
76.2k
  }
658
101k
  ilm.MaxAp = _CanonConvertAperture(get2()); // 26
659
101k
  ilm.MinAp = _CanonConvertAperture(get2()); // 27
660
101k
  if (len >= 36)
661
42.6k
  {
662
42.6k
    fseek(ifp, 12, SEEK_CUR);
663
42.6k
    imgdata.shootinginfo.ImageStabilization = get2(); // 34
664
42.6k
  }
665
59.1k
  else
666
59.1k
    return;
667
42.6k
  if (len >= 48)
668
41.8k
  {
669
41.8k
    fseek(ifp, 22, SEEK_CUR);
670
41.8k
    imCanon.SRAWQuality = get2(); // 46
671
41.8k
  }
672
42.6k
}
673
674
void LibRaw::Canon_WBpresets(int skip1, int skip2)
675
23.5k
{
676
23.5k
  int c;
677
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Daylight][RGGB_2_RGBG(c)] = get2();
678
679
23.5k
  if (skip1)
680
15.6k
    fseek(ifp, skip1, SEEK_CUR);
681
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Shade][RGGB_2_RGBG(c)] = get2();
682
683
23.5k
  if (skip1)
684
15.6k
    fseek(ifp, skip1, SEEK_CUR);
685
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Cloudy][RGGB_2_RGBG(c)] = get2();
686
687
23.5k
  if (skip1)
688
15.6k
    fseek(ifp, skip1, SEEK_CUR);
689
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Tungsten][RGGB_2_RGBG(c)] = get2();
690
691
23.5k
  if (skip1)
692
15.6k
    fseek(ifp, skip1, SEEK_CUR);
693
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_FL_W][RGGB_2_RGBG(c)] = get2();
694
695
23.5k
  if (skip2)
696
15.6k
    fseek(ifp, skip2, SEEK_CUR);
697
94.3k
  FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Flash][RGGB_2_RGBG(c)] = get2();
698
699
23.5k
  return;
700
23.5k
}
701
702
void LibRaw::Canon_WBCTpresets(short WBCTversion)
703
15.6k
{
704
705
15.6k
  int i;
706
15.6k
  float norm;
707
708
15.6k
  if (WBCTversion == 0)
709
13.9k
  { // tint, as shot R, as shot B, CСT
710
223k
    for (i = 0; i < 15; i++)
711
209k
    {
712
209k
      icWBCCTC[i][2] = icWBCCTC[i][4] = 1.0f;
713
209k
      fseek(ifp, 2, SEEK_CUR);
714
209k
      icWBCCTC[i][1] = 1024.0f / fMAX(get2(), 1.f);
715
209k
      icWBCCTC[i][3] = 1024.0f / fMAX(get2(), 1.f);
716
209k
      icWBCCTC[i][0] = get2();
717
209k
    }
718
13.9k
  }
719
1.70k
  else if (WBCTversion == 1)
720
932
  { // as shot R, as shot B, tint, CСT
721
14.9k
    for (i = 0; i < 15; i++)
722
13.9k
    {
723
13.9k
      icWBCCTC[i][2] = icWBCCTC[i][4] = 1.0f;
724
13.9k
      icWBCCTC[i][1] = 1024.0f / fMAX(get2(), 1.f);
725
13.9k
      icWBCCTC[i][3] = 1024.0f / fMAX(get2(), 1.f);
726
13.9k
      fseek(ifp, 2, SEEK_CUR);
727
13.9k
      icWBCCTC[i][0] = get2();
728
13.9k
    }
729
932
  }
730
768
  else if (WBCTversion == 2)
731
768
  { // tint, offset, as shot R, as shot B, CСT
732
768
    if ((unique_id == CanonID_EOS_M3)  ||
733
768
        (unique_id == CanonID_EOS_M10) ||
734
768
        (imCanon.ColorDataSubVer == 0xfffc))
735
498
    {
736
7.96k
      for (i = 0; i < 15; i++)
737
7.47k
      {
738
7.47k
        fseek(ifp, 4, SEEK_CUR);
739
7.47k
        icWBCCTC[i][2] = icWBCCTC[i][4] =
740
7.47k
            1.0f;
741
7.47k
        icWBCCTC[i][1] = 1024.0f / fMAX(1.f, get2());
742
7.47k
        icWBCCTC[i][3] = 1024.0f / fMAX(1.f, get2());
743
7.47k
        icWBCCTC[i][0] = get2();
744
7.47k
      }
745
498
    }
746
270
    else if (imCanon.ColorDataSubVer == 0xfffd)
747
270
    {
748
4.32k
      for (i = 0; i < 15; i++)
749
4.05k
      {
750
4.05k
        fseek(ifp, 2, SEEK_CUR);
751
4.05k
        norm = (signed short)get2();
752
4.05k
        norm = 512.0f + norm / 8.0f;
753
4.05k
        icWBCCTC[i][2] = icWBCCTC[i][4] =
754
4.05k
            1.0f;
755
4.05k
        icWBCCTC[i][1] = (float)get2();
756
4.05k
        if (norm > 0.001f)
757
3.20k
          icWBCCTC[i][1] /= norm;
758
4.05k
        icWBCCTC[i][3] = (float)get2();
759
4.05k
        if (norm > 0.001f)
760
3.20k
          icWBCCTC[i][3] /= norm;
761
4.05k
        icWBCCTC[i][0] = get2();
762
4.05k
      }
763
270
    }
764
768
  }
765
15.6k
  return;
766
15.6k
}
767
768
void LibRaw::parseCanonMakernotes(unsigned tag, unsigned type, unsigned len, unsigned dng_writer)
769
2.64M
{
770
771
2.64M
#define AsShot_Auto_MeasuredWB(offset)                       \
772
2.64M
  imCanon.ColorDataSubVer = get2();                          \
773
13.9k
  fseek(ifp, save1 + (offset << 1), SEEK_SET);               \
774
55.9k
  FORC4 cam_mul[RGGB_2_RGBG(c)] = (float)get2();             \
775
13.9k
  get2();                                                    \
776
55.9k
  FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();     \
777
13.9k
  get2();                                                    \
778
55.9k
  FORC4 icWBC[LIBRAW_WBI_Measured][RGGB_2_RGBG(c)] = get2();
779
780
2.64M
#define sRAW_WB(offset)                                      \
781
2.64M
  fseek(ifp, save1 + (offset << 1), SEEK_SET);               \
782
43.4k
  FORC4 {                                                    \
783
43.4k
    sraw_mul[RGGB_2_RGBG(c)] = get2();                       \
784
43.4k
    if ((float)sraw_mul[RGGB_2_RGBG(c)] > sraw_mul_max) {    \
785
21.1k
      sraw_mul_max = (float)sraw_mul[RGGB_2_RGBG(c)];        \
786
21.1k
    }                                                        \
787
43.4k
  }                                                          \
788
10.8k
  sraw_mul_max /= 1024.f;                                    \
789
43.4k
  FORC4 sraw_mul[c] = (ushort)((float)sraw_mul[c] * sraw_mul_max);
790
791
2.64M
#define CR3_ColorData(offset)                                \
792
2.64M
  fseek(ifp, save1 + ((offset+0x0041) << 1), SEEK_SET);      \
793
2.36k
  Canon_WBpresets(2, 12);                                    \
794
2.36k
  fseek(ifp, save1 + ((offset+0x00c3) << 1), SEEK_SET);      \
795
2.36k
  Canon_WBCTpresets(0);                                      \
796
2.36k
  offsetChannelBlackLevel2 = save1 + ((offset+0x0102) << 1); \
797
2.36k
  offsetChannelBlackLevel  = save1 + ((offset+0x02d1) << 1); \
798
2.36k
  offsetWhiteLevels        = save1 + ((offset+0x02d5) << 1);
799
800
2.64M
  int c;
801
2.64M
  unsigned i;
802
803
2.64M
  if (tag == 0x0001) {
804
93.5k
    Canon_CameraSettings(len);
805
806
2.55M
  } else if (tag == 0x0002) { // focal length
807
21.2k
    ilm.FocalType = get2();
808
21.2k
    ilm.CurFocal = get2();
809
21.2k
    if (ilm.FocalUnits > 1) {
810
11.1k
      ilm.CurFocal /= (float)ilm.FocalUnits;
811
11.1k
    }
812
813
2.53M
  } else if (tag == 0x0004) { // subdir, ShotInfo
814
36.9k
    short tempAp;
815
36.9k
    if (dng_writer == nonDNG) {
816
35.6k
      get2();
817
35.6k
      imCanon.ISOgain[0] = get2();
818
35.6k
      imCanon.ISOgain[1] = get2();
819
35.6k
      if (imCanon.ISOgain[1] != 0x7fff) {
820
35.1k
        imCommon.real_ISO = floorf(100.f * libraw_powf64l(2.f, float(imCanon.ISOgain[0]+imCanon.ISOgain[1]) / 32.f - 5.f));
821
35.1k
        if (!iso_speed || (iso_speed == 65535))
822
9.72k
          iso_speed = imCommon.real_ISO;
823
35.1k
      }
824
35.6k
      get4();
825
35.6k
      if (((i = get2()) != 0xffff) && !shutter) {
826
10.2k
        shutter = libraw_powf64l(2.f, float((short)i) / -32.0f);
827
10.2k
      }
828
35.6k
      imCanon.wbi = (get2(), get2());
829
35.6k
      shot_order = (get2(), get2());
830
35.6k
      fseek(ifp, 4, SEEK_CUR);
831
35.6k
    } else
832
1.35k
      fseek(ifp, 24, SEEK_CUR);
833
36.9k
    tempAp = get2();
834
36.9k
    if (tempAp != 0)
835
28.9k
      imCommon.CameraTemperature = (float)(tempAp - 128);
836
36.9k
    tempAp = get2();
837
36.9k
    if (tempAp != -1)
838
34.8k
      imCommon.FlashGN = ((float)tempAp) / 32;
839
36.9k
    get2();
840
841
36.9k
    imCommon.FlashEC = _CanonConvertEV((signed short)get2());
842
36.9k
    fseek(ifp, 8 - 32, SEEK_CUR);
843
36.9k
    if ((tempAp = get2()) != 0x7fff)
844
36.7k
      ilm.CurAp = _CanonConvertAperture(tempAp);
845
36.9k
    if (ilm.CurAp < 0.7f) {
846
14.3k
      fseek(ifp, 32, SEEK_CUR);
847
14.3k
      ilm.CurAp = _CanonConvertAperture(get2());
848
14.3k
    }
849
36.9k
    if (!aperture)
850
6.00k
      aperture = ilm.CurAp;
851
852
2.49M
  } else if ((tag == 0x0007) && (dng_writer == nonDNG)) {
853
10.0k
    fgets(model2, 64, ifp);
854
855
2.48M
  } else if ((tag == 0x0008) && (dng_writer == nonDNG)) {
856
6.70k
    shot_order = get4();
857
858
2.47M
  } else if ((tag == 0x0009)  && (dng_writer == nonDNG)) {
859
5.32k
    fread(artist, 64, 1, ifp);
860
5.32k
    artist[63] = 0;
861
862
2.47M
  } else if (tag == 0x000c) {
863
9.32k
    unsigned tS = get4();
864
9.32k
    sprintf(imgdata.shootinginfo.BodySerial, "%d", tS);
865
866
2.46M
  } else if ((tag == 0x0012) ||
867
2.45M
             (tag == 0x0026) ||
868
2.44M
             (tag == 0x003c)) {
869
15.3k
    if (!imCommon.afcount) {
870
2.56k
      imCommon.afdata[imCommon.afcount].AFInfoData_tag = tag;
871
2.56k
      imCommon.afdata[imCommon.afcount].AFInfoData_order = order;
872
2.56k
    imCommon.afdata[imCommon.afcount].AFInfoData_length = len;
873
2.56k
    if (libraw_tagtype_dataunit_bytes(type)) // returns 0 on unknown type
874
2.56k
      imCommon.afdata[imCommon.afcount].AFInfoData_length *= libraw_tagtype_dataunit_bytes(type);
875
876
2.56k
    unsigned datalen = 0;
877
2.56k
    if (tag == 0x0026 || tag == 0x003c) // AFInfo2 bytes 0-1 contains AFSize
878
2.15k
    {
879
2.15k
      INT64 here = ftell(ifp);
880
2.15k
      datalen = get2();
881
2.15k
      fseek(ifp, here, SEEK_SET);
882
2.15k
    }
883
2.56k
    if (!datalen || datalen == imCommon.afdata[imCommon.afcount].AFInfoData_length) // data check not performed or passed
884
606
    {
885
606
        imCommon.afdata[imCommon.afcount].AFInfoData =
886
606
            (uchar *)calloc(imCommon.afdata[imCommon.afcount].AFInfoData_length+1, 1);
887
606
        fread(imCommon.afdata[imCommon.afcount].AFInfoData, imCommon.afdata[imCommon.afcount].AFInfoData_length, 1,
888
606
              ifp);
889
606
        imCommon.afcount = 1;
890
606
    }
891
1.96k
    else
892
1.96k
    {
893
      // check not passed: clean up afdata inited
894
1.96k
        imCommon.afdata[imCommon.afcount].AFInfoData_tag = 0;
895
1.96k
        imCommon.afdata[imCommon.afcount].AFInfoData_order = 0;
896
1.96k
        imCommon.afdata[imCommon.afcount].AFInfoData_length = 0;
897
1.96k
    }
898
2.56k
    }
899
900
2.44M
  } else if ((tag == 0x0029) && (dng_writer == nonDNG)) { // PowerShot G9
901
20.8k
    int Got_AsShotWB = 0;
902
20.8k
    fseek(ifp, 8, SEEK_CUR);
903
229k
    for (unsigned linenum = 0; linenum < Canon_G9_linenums_2_StdWBi.size(); linenum++) {
904
208k
      if (Canon_G9_linenums_2_StdWBi[linenum] != LIBRAW_WBI_Unknown ) {
905
835k
        FORC4 icWBC[Canon_G9_linenums_2_StdWBi[linenum]][GRBG_2_RGBG(c)] = get4();
906
208k
        if (Canon_wbi2std[imCanon.wbi] == Canon_G9_linenums_2_StdWBi[linenum]) {
907
82.5k
          FORC4 cam_mul[c] = float(icWBC[Canon_G9_linenums_2_StdWBi[linenum]][c]);
908
20.6k
          Got_AsShotWB = 1;
909
20.6k
        }
910
208k
      }
911
208k
      fseek(ifp, 16, SEEK_CUR);
912
208k
    }
913
20.8k
    if (!Got_AsShotWB)
914
1.07k
      FORC4 cam_mul[c] = float(icWBC[LIBRAW_WBI_Auto][c]);
915
916
2.42M
  } else if ((tag == 0x0081) && (dng_writer == nonDNG)) { // -1D, -1Ds
917
1.71k
    data_offset = get4();
918
1.71k
    fseek(ifp, data_offset + 41, SEEK_SET);
919
1.71k
    raw_height = get2() * 2;
920
1.71k
    raw_width = get2();
921
1.71k
    filters = 0x61616161;
922
923
2.42M
  } else if (tag == 0x0093) {
924
3.27k
    if (!imCanon.RF_lensID) {
925
1.69k
      fseek(ifp, 0x03d<<1, SEEK_CUR);
926
1.69k
      imCanon.RF_lensID = get2();
927
1.69k
    }
928
929
2.42M
  } else if (tag == 0x0095 && !ilm.Lens[0])
930
3.33k
  { // lens model tag
931
3.33k
    fread(ilm.Lens, 64, 1, ifp);
932
3.33k
    ilm.Lens[63] = 0;
933
3.33k
    if (!strncmp(ilm.Lens, "EF-S", 4))
934
0
    {
935
0
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
936
0
      ilm.Lens[4] = ' ';
937
0
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
938
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF_S;
939
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
940
0
    }
941
3.33k
    else if (!strncmp(ilm.Lens, "EF-M", 4))
942
0
    {
943
0
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
944
0
      ilm.Lens[4] = ' ';
945
0
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
946
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF_M;
947
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
948
0
    }
949
3.33k
    else if (!strncmp(ilm.Lens, "EF", 2))
950
2
    {
951
2
      memmove(ilm.Lens + 3, ilm.Lens + 2, 62);
952
2
      ilm.Lens[2] = ' ';
953
2
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 2);
954
2
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
955
2
      ilm.LensFormat = LIBRAW_FORMAT_FF;
956
2
    }
957
3.33k
    else if (!strncmp(ilm.Lens, "CN-E", 4))
958
12
    {
959
12
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
960
12
      ilm.Lens[4] = ' ';
961
12
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
962
12
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
963
12
      ilm.LensFormat = LIBRAW_FORMAT_FF;
964
12
    }
965
3.32k
    else if (!strncmp(ilm.Lens, "TS-E", 4))
966
0
    {
967
0
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
968
0
      ilm.Lens[4] = ' ';
969
0
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
970
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
971
0
      ilm.LensFormat = LIBRAW_FORMAT_FF;
972
0
    }
973
3.32k
    else if (!strncmp(ilm.Lens, "MP-E", 4))
974
2
    {
975
2
      memmove(ilm.Lens + 5, ilm.Lens + 4, 60);
976
2
      ilm.Lens[4] = ' ';
977
2
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
978
2
      ilm.LensMount = LIBRAW_MOUNT_Canon_EF;
979
2
      ilm.LensFormat = LIBRAW_FORMAT_FF;
980
2
    }
981
982
3.32k
    else if (!strncmp(ilm.Lens, "RF-S", 4))
983
0
    {
984
0
      memmove(ilm.Lens + 5, ilm.Lens + 4, 62);
985
0
      ilm.Lens[4] = ' ';
986
0
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 4);
987
0
      ilm.LensMount = LIBRAW_MOUNT_Canon_RF;
988
0
      ilm.LensFormat = LIBRAW_FORMAT_APSC;
989
0
    }
990
991
3.32k
    else if (!strncmp(ilm.Lens, "RF", 2))
992
6
    {
993
6
      memmove(ilm.Lens + 3, ilm.Lens + 2, 62);
994
6
      ilm.Lens[2] = ' ';
995
6
      memcpy(ilm.LensFeatures_pre, ilm.Lens, 2);
996
6
      ilm.LensMount = LIBRAW_MOUNT_Canon_RF;
997
6
      ilm.LensFormat = LIBRAW_FORMAT_FF;
998
6
    }
999
3.33k
  }
1000
2.41M
  else if (tag == 0x009a)
1001
1.98k
  { // AspectInfo
1002
1.98k
    i = get4();
1003
1.98k
    switch (i)
1004
1.98k
    {
1005
204
    case 0:
1006
478
    case 12: /* APS-H crop */
1007
574
    case 13: /* APS-C crop */
1008
574
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_3to2;
1009
574
      break;
1010
230
    case 1:
1011
230
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_1to1;
1012
230
      break;
1013
344
    case 2:
1014
460
    case 0x102:
1015
460
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_4to3;
1016
460
      break;
1017
112
    case 7:
1018
112
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_16to9;
1019
112
      break;
1020
114
    case 8:
1021
114
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_5to4;
1022
114
      break;
1023
498
    default:
1024
498
      imgdata.sizes.raw_aspect = LIBRAW_IMAGE_ASPECT_OTHER;
1025
498
      break;
1026
1.98k
    }
1027
1.98k
    imgdata.sizes.raw_inset_crops[0].cwidth = get4();
1028
1.98k
    imgdata.sizes.raw_inset_crops[0].cheight = get4();
1029
1.98k
    imgdata.sizes.raw_inset_crops[0].cleft = get4();
1030
1.98k
    imgdata.sizes.raw_inset_crops[0].ctop = get4();
1031
1032
2.41M
  } else if ((tag == 0x00a4) && (dng_writer == nonDNG)) { // -1D, -1Ds
1033
742
    fseek(ifp, imCanon.wbi * 48, SEEK_CUR);
1034
2.22k
    FORC3 cam_mul[c] = get2();
1035
1036
2.41M
  } else if (tag == 0x00a9) {
1037
630
    INT64 save1 = ftell(ifp);
1038
630
    fseek(ifp, (0x1 << 1), SEEK_CUR);
1039
2.52k
    FORC4 imgdata.color.WB_Coeffs[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();
1040
630
    Canon_WBpresets(0, 0);
1041
630
    fseek(ifp, save1, SEEK_SET);
1042
630
  }
1043
2.41M
  else if (tag == 0x00b4)
1044
5.00k
  {
1045
5.00k
    switch (get2()) {
1046
530
    case 1:
1047
530
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
1048
530
      break;
1049
2.12k
    case 2:
1050
2.12k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
1051
2.12k
      break;
1052
2.34k
    default:
1053
2.34k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
1054
2.34k
      break;
1055
5.00k
    }
1056
5.00k
  }
1057
2.40M
  else if (tag == 0x00e0) // SensorInfo
1058
3.54k
  {
1059
3.54k
    imCanon.SensorWidth  = (get2(), get2());
1060
3.54k
    imCanon.SensorHeight = get2();
1061
3.54k
    fseek(ifp, 4, SEEK_CUR);
1062
3.54k
    imCanon.DefaultCropAbsolute = get_CanonArea();
1063
3.54k
    imCanon.LeftOpticalBlack    = get_CanonArea();
1064
3.54k
  }
1065
2.40M
  else if (tag == 0x4001 && len > 500)
1066
17.2k
  {
1067
17.2k
    float sraw_mul_max = 0.f;
1068
17.2k
    int bls = 0;
1069
17.2k
    INT64 offsetChannelBlackLevel = 0L;
1070
17.2k
    INT64 offsetChannelBlackLevel2 = 0L;
1071
17.2k
    INT64 offsetWhiteLevels = 0L;
1072
17.2k
    INT64 save1 = ftell(ifp);
1073
1074
17.2k
    switch (len)
1075
17.2k
    {
1076
1077
456
    case 582:
1078
456
      imCanon.ColorDataVer = 1; // 20D, 350D
1079
1080
456
      fseek(ifp, save1 + (0x0019 << 1), SEEK_SET);
1081
1.82k
      FORC4 cam_mul[RGGB_2_RGBG(c)] = (float)get2();
1082
456
      fseek(ifp, save1 + (0x001e << 1), SEEK_SET);
1083
1.82k
      FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();
1084
456
      fseek(ifp, save1 + (0x0041 << 1), SEEK_SET);
1085
1.82k
      FORC4 icWBC[LIBRAW_WBI_Custom1][RGGB_2_RGBG(c)] = get2();
1086
456
      fseek(ifp, save1 + (0x0046 << 1), SEEK_SET);
1087
1.82k
      FORC4 icWBC[LIBRAW_WBI_Custom2][RGGB_2_RGBG(c)] = get2();
1088
1089
456
      fseek(ifp, save1 + (0x0023 << 1), SEEK_SET);
1090
456
      Canon_WBpresets(2, 2);
1091
456
      fseek(ifp, save1 + (0x004b << 1), SEEK_SET);
1092
456
      Canon_WBCTpresets(1); // ABCT
1093
456
      offsetChannelBlackLevel = save1 + (0x00a6 << 1);
1094
456
      break;
1095
1096
476
    case 653:
1097
476
      imCanon.ColorDataVer = 2; // -1D Mark II, -1Ds Mark II
1098
1099
476
      fseek(ifp, save1 + (0x0018 << 1), SEEK_SET);
1100
1.90k
      FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();
1101
476
      fseek(ifp, save1 + (0x0022 << 1), SEEK_SET);
1102
1.90k
      FORC4 cam_mul[RGGB_2_RGBG(c)] = (float)get2();
1103
476
      fseek(ifp, save1 + (0x0090 << 1), SEEK_SET);
1104
1.90k
      FORC4 icWBC[LIBRAW_WBI_Custom1][RGGB_2_RGBG(c)] = get2();
1105
476
      fseek(ifp, save1 + (0x0095 << 1), SEEK_SET);
1106
1.90k
      FORC4 icWBC[LIBRAW_WBI_Custom2][RGGB_2_RGBG(c)] = get2();
1107
476
      fseek(ifp, save1 + (0x009a << 1), SEEK_SET);
1108
1.90k
      FORC4 icWBC[LIBRAW_WBI_Custom3][RGGB_2_RGBG(c)] = get2();
1109
1110
476
      fseek(ifp, save1 + (0x0027 << 1), SEEK_SET);
1111
476
      Canon_WBpresets(2, 12);
1112
476
      fseek(ifp, save1 + (0x00a4 << 1), SEEK_SET);
1113
476
      Canon_WBCTpresets(1); // ABCT
1114
476
      offsetChannelBlackLevel = save1 + (0x011e << 1);
1115
476
      break;
1116
1117
748
    case 796:
1118
748
      imCanon.ColorDataVer = 3; // -1D Mark II N, 5D, 30D, 400D; ColorDataSubVer: 1
1119
748
      AsShot_Auto_MeasuredWB(0x003f);
1120
1121
748
      fseek(ifp, save1 + (0x0071 << 1), SEEK_SET);
1122
2.99k
      FORC4 icWBC[LIBRAW_WBI_Custom1][RGGB_2_RGBG(c)] = get2();
1123
748
      fseek(ifp, save1 + (0x0076 << 1), SEEK_SET);
1124
2.99k
      FORC4 icWBC[LIBRAW_WBI_Custom2][RGGB_2_RGBG(c)] = get2();
1125
748
      fseek(ifp, save1 + (0x007b << 1), SEEK_SET);
1126
2.99k
      FORC4 icWBC[LIBRAW_WBI_Custom3][RGGB_2_RGBG(c)] = get2();
1127
748
      fseek(ifp, save1 + (0x0080 << 1), SEEK_SET);
1128
2.99k
      FORC4 icWBC[LIBRAW_WBI_Custom][RGGB_2_RGBG(c)] = get2();
1129
1130
748
      fseek(ifp, save1 + (0x004e << 1), SEEK_SET);
1131
748
      Canon_WBpresets(2, 12);
1132
748
      fseek(ifp, save1 + (0x0085 << 1), SEEK_SET);
1133
748
      Canon_WBCTpresets(0); // BCAT
1134
748
      offsetChannelBlackLevel = save1 + (0x00c4 << 1);
1135
748
      break;
1136
1137
138
    case 674:  // -1D Mark III; ColorDataSubVer: 2
1138
798
    case 692:  // 40D; ColorDataSubVer: 3
1139
1.04k
    case 702:  // -1Ds Mark III; ColorDataSubVer: 4
1140
1.54k
    case 1227: // 450D, 1000D; ColorDataSubVer: 5
1141
1.96k
    case 1250: // 5D Mark II, 50D; ColorDataSubVer: 6
1142
2.28k
    case 1251: // 500D; ColorDataSubVer: 7
1143
5.04k
    case 1337: // -1D Mark IV, 7D; ColorDataSubVer: 7
1144
5.65k
    case 1338: // 550D; ColorDataSubVer: 7
1145
6.16k
    case 1346: // 1100D, 60D; ColorDataSubVer: 9
1146
6.16k
      imCanon.ColorDataVer = 4;
1147
6.16k
      AsShot_Auto_MeasuredWB(0x003f);
1148
6.16k
      sRAW_WB(0x004e);
1149
6.16k
      fseek(ifp, save1 + (0x0053 << 1), SEEK_SET);
1150
6.16k
      Canon_WBpresets(2, 12);
1151
6.16k
      fseek(ifp, save1 + (0x00a8 << 1), SEEK_SET);
1152
6.16k
      Canon_WBCTpresets(0); // BCAT
1153
1154
6.16k
      if ((imCanon.ColorDataSubVer == 4) ||
1155
5.85k
          (imCanon.ColorDataSubVer == 5))
1156
382
      {
1157
382
        offsetChannelBlackLevel = save1 + (0x02b4 << 1);
1158
382
        offsetWhiteLevels = save1 + (0x02b8 << 1);
1159
382
      }
1160
5.78k
      else if ((imCanon.ColorDataSubVer == 6) ||
1161
5.70k
               (imCanon.ColorDataSubVer == 7))
1162
340
      {
1163
340
        offsetChannelBlackLevel = save1 + (0x02cb << 1);
1164
340
        offsetWhiteLevels = save1 + (0x02cf << 1);
1165
340
      }
1166
5.44k
      else if (imCanon.ColorDataSubVer == 9)
1167
300
      {
1168
300
        offsetChannelBlackLevel = save1 + (0x02cf << 1);
1169
300
        offsetWhiteLevels = save1 + (0x02d3 << 1);
1170
300
      }
1171
5.14k
      else
1172
5.14k
        offsetChannelBlackLevel = save1 + (0x00e7 << 1);
1173
6.16k
      break;
1174
1175
1.51k
    case 5120: // G10, G11, G12, G15, G16
1176
               // G1 X, G1 X Mark II, G1 X Mark III
1177
               // G3 X, G5 X
1178
               // G7 X, G7 X Mark II
1179
               // G9 X, G9 X Mark II
1180
               // S90, S95, S100, S100V, S110, S120
1181
               // SX1 IS, SX50 HS, SX60 HS
1182
               // M3, M5, M6, M10, M100
1183
1.51k
      imCanon.ColorDataVer = 5;
1184
1.51k
      imCanon.ColorDataSubVer = get2();
1185
1186
1.51k
      fseek(ifp, save1 + (0x0047 << 1), SEEK_SET);
1187
6.04k
      FORC4 cam_mul[RGGB_2_RGBG(c)] = (float)get2();
1188
1189
1.51k
      if (imCanon.ColorDataSubVer == 0xfffc) // ColorDataSubVer: 65532 (-4)
1190
                                             // G7 X Mark II, G9 X Mark II, G1 X Mark III
1191
                                             // M5, M100, M6
1192
498
      {
1193
498
        fseek(ifp, save1 + (0x004f << 1), SEEK_SET);
1194
1.99k
        FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();
1195
498
        fseek(ifp, 8, SEEK_CUR);
1196
1.99k
        FORC4 icWBC[LIBRAW_WBI_Measured][RGGB_2_RGBG(c)] =
1197
1.99k
            get2();
1198
498
        fseek(ifp, 8, SEEK_CUR);
1199
1.99k
        FORC4 icWBC[LIBRAW_WBI_Other][RGGB_2_RGBG(c)] = get2();
1200
498
        fseek(ifp, 8, SEEK_CUR);
1201
498
        Canon_WBpresets(8, 24);
1202
498
        fseek(ifp, 168, SEEK_CUR);
1203
1.99k
        FORC4 icWBC[LIBRAW_WBI_FL_WW][RGGB_2_RGBG(c)] = get2();
1204
498
        fseek(ifp, 24, SEEK_CUR);
1205
498
        Canon_WBCTpresets(2); // BCADT
1206
498
        offsetChannelBlackLevel = save1 + (0x014d << 1);
1207
498
        offsetWhiteLevels = save1 + (0x0569 << 1);
1208
498
      }
1209
1.01k
      else if (imCanon.ColorDataSubVer == 0xfffd) // ColorDataSubVer: 65533 (-3)
1210
                                                  // M10, M3
1211
                                                  // G1 X, G1 X Mark II
1212
                                                  // G3 X, G5 X, G7 X, G9 X
1213
                                                  // G10, G11, G12, G15, G16
1214
                                                  // S90, S95, S100, S100V, S110, S120
1215
                                                  // SX1 IS, SX50 HS, SX60 HS
1216
270
      {
1217
270
        fseek(ifp, save1 + (0x004c << 1), SEEK_SET);
1218
1.08k
        FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] = get2();
1219
270
        get2();
1220
1.08k
        FORC4 icWBC[LIBRAW_WBI_Measured][RGGB_2_RGBG(c)] =
1221
1.08k
            get2();
1222
270
        get2();
1223
1.08k
        FORC4 icWBC[LIBRAW_WBI_Other][RGGB_2_RGBG(c)] = get2();
1224
270
        get2();
1225
270
        Canon_WBpresets(2, 12);
1226
270
        fseek(ifp, save1 + (0x00ba << 1), SEEK_SET);
1227
270
        Canon_WBCTpresets(2); // BCADT
1228
270
        offsetChannelBlackLevel = save1 + (0x0108 << 1);
1229
270
      }
1230
1.51k
      break;
1231
1232
454
    case 1273: // 600D; ColorDataSubVer: 10
1233
1.22k
    case 1275: // 1200D; ColorDataSubVer: 10
1234
1.22k
      imCanon.ColorDataVer = 6;
1235
1.22k
      AsShot_Auto_MeasuredWB(0x003f);
1236
1.22k
      sRAW_WB(0x0062);
1237
1.22k
      fseek(ifp, save1 + (0x0067 << 1), SEEK_SET);
1238
1.22k
      Canon_WBpresets(2, 12);
1239
1.22k
      fseek(ifp, save1 + (0x00bc << 1), SEEK_SET);
1240
1.22k
      Canon_WBCTpresets(0); // BCAT
1241
1.22k
      offsetChannelBlackLevel = save1 + (0x01df << 1);
1242
1.22k
      offsetWhiteLevels = save1 + (0x01e3 << 1);
1243
1.22k
      break;
1244
1245
110
    case 1312: // 5D Mark III, 650D, 700D, M; ColorDataSubVer: 10
1246
694
    case 1313: // 100D, 6D, 70D, EOS M2; ColorDataSubVer: 10
1247
770
    case 1316: // -1D C, -1D X; ColorDataSubVer: 10
1248
1.07k
    case 1506: // 750D, 760D, 7D Mark II; ColorDataSubVer: 11
1249
1.07k
      imCanon.ColorDataVer = 7;
1250
1.07k
      AsShot_Auto_MeasuredWB(0x003f);
1251
1.07k
      sRAW_WB(0x007b);
1252
1.07k
      fseek(ifp, save1 + (0x0080 << 1), SEEK_SET);
1253
1.07k
      Canon_WBpresets(2, 12);
1254
1.07k
      fseek(ifp, save1 + (0x00d5 << 1), SEEK_SET);
1255
1.07k
      Canon_WBCTpresets(0); // BCAT
1256
1257
1.07k
      if (imCanon.ColorDataSubVer == 10)
1258
36
      {
1259
36
        offsetChannelBlackLevel = save1 + (0x01f8 << 1);
1260
36
        offsetWhiteLevels = save1 + (0x01fc << 1);
1261
36
      }
1262
1.03k
      else if (imCanon.ColorDataSubVer == 11)
1263
76
      {
1264
76
        offsetChannelBlackLevel = save1 + (0x02d8 << 1);
1265
76
        offsetWhiteLevels = save1 + (0x02dc << 1);
1266
76
      }
1267
1.07k
      break;
1268
1269
552
    case 1560: // 5DS, 5DS R; ColorDataSubVer: 12
1270
678
    case 1592: // 5D Mark IV, 80D, -1D X Mark II; ColorDataSubVer: 13
1271
2.31k
    case 1353: // 1300D, 1500D, 3000D; ColorDataSubVer: 14
1272
2.40k
    case 1602: // 200D, 6D Mark II, 77D, 800D; ColorDataSubVer: 15
1273
2.40k
      imCanon.ColorDataVer = 8;
1274
2.40k
      AsShot_Auto_MeasuredWB(0x003f);
1275
2.40k
      sRAW_WB(0x0080);
1276
2.40k
      fseek(ifp, save1 + (0x0085 << 1), SEEK_SET);
1277
2.40k
      Canon_WBpresets(2, 12);
1278
2.40k
      fseek(ifp, save1 + (0x0107 << 1), SEEK_SET);
1279
2.40k
      Canon_WBCTpresets(0); // BCAT
1280
1281
2.40k
      if (imCanon.ColorDataSubVer == 14) // 1300D, 1500D, 3000D
1282
120
      {
1283
120
        offsetChannelBlackLevel = save1 + (0x022c << 1);
1284
120
        offsetWhiteLevels = save1 + (0x0230 << 1);
1285
120
      }
1286
2.28k
      else
1287
2.28k
      {
1288
2.28k
        offsetChannelBlackLevel = save1 + (0x030a << 1);
1289
2.28k
        offsetWhiteLevels = save1 + (0x030e << 1);
1290
2.28k
      }
1291
2.40k
      break;
1292
1293
998
    case 1820: // M50; ColorDataSubVer: 16
1294
1.48k
    case 1824: // R, Ra; ColorDataSubVer: 17
1295
1.92k
    case 1816: // RP, 250D, SX70 HS; ColorDataSubVer: 18
1296
               // R100, M6 Mark II, M200, 90D, G5 X Mark II, G7 X Mark III, 850D; ColorDataSubVer: 19
1297
1.92k
      imCanon.ColorDataVer = 9;
1298
1.92k
      AsShot_Auto_MeasuredWB(0x0047);
1299
1.92k
      CR3_ColorData(0x0047);
1300
1.92k
      break;
1301
1302
140
    case 1770: // R5 CRM
1303
442
    case 2024: // -1D X Mark III; ColorDataSubVer: 32
1304
442
    case 3656: // R5, R6; ColorDataSubVer: 33
1305
442
      imCanon.ColorDataVer = 10;
1306
442
      AsShot_Auto_MeasuredWB(0x0055);
1307
442
      CR3_ColorData(0x0055);
1308
442
      break;
1309
1310
0
    case 3973: // R3; ColorDataSubVer: 34
1311
0
    case 3778: // R6 Mark II, R7, R8, R10, R50; ColorDataSubVer: 48
1312
0
      imCanon.ColorDataVer = 11;
1313
0
      AsShot_Auto_MeasuredWB(0x0069);
1314
1315
0
      fseek(ifp, save1 + ((0x0069+0x0064) << 1), SEEK_SET);
1316
0
      Canon_WBpresets(2, 12);
1317
0
      fseek(ifp, save1 + ((0x0069+0x00c3) << 1), SEEK_SET);
1318
0
      Canon_WBCTpresets(0);
1319
0
      offsetChannelBlackLevel2 = save1 + ((0x0069+0x0102) << 1);
1320
0
      offsetChannelBlackLevel  = save1 + ((0x0069+0x0213) << 1);
1321
0
      offsetWhiteLevels        = save1 + ((0x0069+0x0217) << 1);
1322
0
      break;
1323
1324
0
    case 4528: // R1, R5 Mark II; ColorDataSubVer: 64
1325
0
      imCanon.ColorDataVer = 12;
1326
0
      AsShot_Auto_MeasuredWB(0x0069);
1327
0
      fseek(ifp, save1 + ((0x006d+0x0001) << 1), SEEK_SET);
1328
0
      Canon_WBpresets(2, 12);
1329
0
      fseek(ifp, save1 + ((0x0069+0x00d7) << 1), SEEK_SET);
1330
0
      Canon_WBCTpresets(0);
1331
0
      offsetChannelBlackLevel2 = save1 + ((0x0069+0x0116) << 1);
1332
0
      offsetChannelBlackLevel  = save1 + ((0x0069+0x0227) << 1);
1333
0
      offsetWhiteLevels        = save1 + ((0x0069+0x022b) << 1);
1334
0
      break;
1335
1336
818
   default:
1337
818
      imCanon.ColorDataSubVer = get2();
1338
818
      break;
1339
17.2k
    }
1340
1341
17.2k
    if (offsetChannelBlackLevel)
1342
14.7k
    {
1343
14.7k
      fseek(ifp, offsetChannelBlackLevel, SEEK_SET);
1344
14.7k
      FORC4
1345
58.8k
        bls += (imCanon.ChannelBlackLevel[RGGB_2_RGBG(c)] = get2());
1346
14.7k
      imCanon.AverageBlackLevel = bls / 4;
1347
14.7k
    }
1348
17.2k
    if (offsetWhiteLevels)
1349
7.62k
    {
1350
7.62k
      if ((offsetWhiteLevels - offsetChannelBlackLevel) != 8L)
1351
498
        fseek(ifp, offsetWhiteLevels, SEEK_SET);
1352
7.62k
      imCanon.NormalWhiteLevel = get2();
1353
7.62k
      imCanon.SpecularWhiteLevel = get2();
1354
7.62k
      FORC4
1355
30.5k
        imgdata.color.linear_max[c] = imCanon.SpecularWhiteLevel;
1356
7.62k
    }
1357
1358
17.2k
    if(!imCanon.AverageBlackLevel && offsetChannelBlackLevel2)
1359
276
    {
1360
276
        fseek(ifp, offsetChannelBlackLevel2, SEEK_SET);
1361
276
        FORC4
1362
1.10k
            bls += (imCanon.ChannelBlackLevel[RGGB_2_RGBG(c)] = get2());
1363
276
        imCanon.AverageBlackLevel = bls / 4;
1364
276
    }
1365
17.2k
    fseek(ifp, save1, SEEK_SET);
1366
1367
2.38M
  } else if (tag == 0x4013) {
1368
2.49k
    get4();
1369
2.49k
    imCanon.AFMicroAdjMode = get4();
1370
2.49k
    float a = float(get4());
1371
2.49k
    float b = float(get4());
1372
2.49k
    if (fabsf(b) > 0.001f)
1373
1.61k
      imCanon.AFMicroAdjValue = a / b;
1374
1375
2.38M
  } else if (tag == 0x4018) {
1376
2.41k
    fseek(ifp, 8, SEEK_CUR);
1377
2.41k
    imCanon.AutoLightingOptimizer = get4();
1378
2.41k
    if ((imCanon.AutoLightingOptimizer > 3) ||
1379
1.33k
        (imCanon.AutoLightingOptimizer < 0))
1380
1.83k
      imCanon.AutoLightingOptimizer = 3;
1381
2.41k
    imCanon.HighlightTonePriority = get4();
1382
2.41k
    if ((imCanon.HighlightTonePriority > 5) ||
1383
1.25k
        (imCanon.HighlightTonePriority < 0))
1384
1.68k
      imCanon.HighlightTonePriority = 0;
1385
2.41k
    if (imCanon.HighlightTonePriority) {
1386
234
      imCommon.ExposureCalibrationShift -= float(imCanon.HighlightTonePriority);
1387
234
    }
1388
1389
2.38M
  } else if ((tag == 0x4021) && (dng_writer == nonDNG) &&
1390
1.73k
             (imCanon.multishot[0] = get4()) &&
1391
1.50k
             (imCanon.multishot[1] = get4())) {
1392
1.12k
    if (len >= 4) {
1393
786
      imCanon.multishot[2] = get4();
1394
786
      imCanon.multishot[3] = get4();
1395
786
    }
1396
4.48k
    FORC4 cam_mul[c] = 1024;
1397
2.38M
  } else if (tag == 0x4026) {
1398
74
    fseek(ifp, 44, SEEK_CUR);
1399
74
    imCanon.CanonLog = get4();
1400
74
  }
1401
2.64M
#undef CR3_ColorData
1402
2.64M
#undef sRAW_WB
1403
2.64M
#undef AsShot_Auto_MeasuredWB
1404
2.64M
}