Coverage Report

Created: 2025-12-01 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libraw/src/metadata/makernotes.cpp
Line
Count
Source
1
/* -*- C++ -*-
2
 * Copyright 2019-2025 LibRaw LLC (info@libraw.org)
3
 *
4
 LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder,
5
 dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net.
6
 LibRaw do not use RESTRICTED code from dcraw.c
7
8
 LibRaw is free software; you can redistribute it and/or modify
9
 it under the terms of the one of two licenses as you choose:
10
11
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
12
   (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
13
14
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
15
   (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
16
17
 */
18
19
#include "../../internal/dcraw_defs.h"
20
21
5.93k
void LibRaw::parseSigmaMakernote (INT64 base, int uptag, unsigned /*dng_writer*/) {
22
5.93k
unsigned wb_table1 [] = {
23
5.93k
  LIBRAW_WBI_Auto, LIBRAW_WBI_Daylight, LIBRAW_WBI_Shade, LIBRAW_WBI_Cloudy,
24
5.93k
  LIBRAW_WBI_Tungsten, LIBRAW_WBI_Fluorescent, LIBRAW_WBI_Flash,
25
5.93k
  LIBRAW_WBI_Custom, LIBRAW_WBI_Custom1, LIBRAW_WBI_Custom2
26
5.93k
};
27
28
5.93k
  unsigned entries, tag, type, len;
29
5.93k
  INT64 save;
30
5.93k
  unsigned i;
31
32
5.93k
  entries = get2();
33
5.93k
  if (entries > 1000)
34
1.68k
    return;
35
263k
  while (entries--) {
36
259k
    tiff_get(base, &tag, &type, &len, &save);
37
38
259k
  if (callbacks.makernotes_cb)
39
0
    {
40
0
      INT64 _savepos = ifp->tell();
41
0
      callbacks.makernotes_cb(callbacks.makernotesparser_data, tag | (uptag << 16), type, len, order, ifp, base);
42
0
      fseek(ifp, _savepos, SEEK_SET);
43
0
    }
44
45
259k
    if (tag == 0x0027) {
46
739
      ilm.LensID = get2();
47
258k
    } else if (tag == 0x002a) {
48
1.26k
      ilm.MinFocal = getrealf(type);
49
1.26k
      ilm.MaxFocal = getrealf(type);
50
257k
    } else if (tag == 0x002b) {
51
1.13k
      ilm.MaxAp4MinFocal = getrealf(type);
52
1.13k
      ilm.MaxAp4MaxFocal = getrealf(type);
53
256k
    } else if (tag == 0x0120) {
54
2.60k
      const unsigned tblsz = (sizeof wb_table1 / sizeof wb_table1[0]);
55
2.60k
      if ((len >= tblsz) && (len%3 == 0) && len/3 <= tblsz) {
56
2.48k
        for (i=0; i<(len/3); i++) {
57
2.16k
          icWBC[wb_table1[i]][0] = (int)(getreal(type)*10000.0);
58
2.16k
          icWBC[wb_table1[i]][1] = icWBC[wb_table1[i]][3] = (int)(getreal(type)*10000.0);
59
2.16k
          icWBC[wb_table1[i]][2] = (int)(getreal(type)*10000.0);
60
2.16k
        }
61
316
      }
62
2.60k
    }
63
259k
    fseek(ifp, save, SEEK_SET);
64
259k
  }
65
66
4.25k
  return;
67
5.93k
}
68
69
void LibRaw::parse_makernote_0xc634(INT64 base, int uptag, unsigned dng_writer)
70
111k
{
71
72
111k
  if (metadata_blocks++ > LIBRAW_MAX_METADATA_BLOCKS)
73
6
    throw LIBRAW_EXCEPTION_IO_CORRUPT;
74
75
111k
  if (!strncmp(make, "NIKON", 5))
76
1.59k
  {
77
1.59k
    parseNikonMakernote(base, uptag, AdobeDNG);
78
1.59k
    return;
79
1.59k
  }
80
110k
  else if (!strncasecmp(make, "LEICA", 5))
81
364
  {
82
364
    parseLeicaMakernote(base, uptag, is_0xc634);
83
364
    return;
84
364
  }
85
86
109k
  short morder, sorder = order;
87
109k
  char buf[10];
88
109k
  INT64 fsize = ifp->size();
89
90
109k
  fread(buf, 1, 10, ifp);
91
92
109k
  if (!strcmp(buf, "EPSON"))
93
155
  {
94
155
    parseEpsonMakernote(base, uptag, AdobeDNG);
95
155
    return;
96
155
  }
97
109k
  else if (!strcmp(buf, "SIGMA"))
98
121
  {
99
121
    parseSigmaMakernote(base, uptag, AdobeDNG);
100
121
    return;
101
121
  }
102
103
109k
  unsigned entries, tag, type, len, c;
104
109k
  INT64 save;
105
106
109k
  uchar *CanonCameraInfo = NULL;
107
109k
  unsigned lenCanonCameraInfo = 0;
108
109k
  unsigned typeCanonCameraInfo = 0;
109
110
109k
  uchar *table_buf_0x0116;
111
109k
  ushort table_buf_0x0116_len = 0;
112
109k
  uchar *table_buf_0x2010;
113
109k
  ushort table_buf_0x2010_len = 0;
114
109k
  uchar *table_buf_0x9050;
115
109k
  ushort table_buf_0x9050_len = 0;
116
109k
  uchar *table_buf_0x9400;
117
109k
  ushort table_buf_0x9400_len = 0;
118
109k
  uchar *table_buf_0x9402;
119
109k
  ushort table_buf_0x9402_len = 0;
120
109k
  uchar *table_buf_0x9403;
121
109k
  ushort table_buf_0x9403_len = 0;
122
109k
  uchar *table_buf_0x9406;
123
109k
  ushort table_buf_0x9406_len = 0;
124
109k
  uchar *table_buf_0x940c;
125
109k
  ushort table_buf_0x940c_len = 0;
126
109k
  uchar *table_buf_0x940e;
127
109k
  ushort table_buf_0x940e_len = 0;
128
129
109k
  if (!strcmp(buf, "OLYMPUS") || !strcmp(buf, "PENTAX ") || !strncmp(buf,"OM SYS",6)||
130
78.8k
      (!strncmp(make, "SAMSUNG", 7) && (dng_writer == CameraDNG)))
131
32.4k
  {
132
32.4k
    base = ftell(ifp) - 10;
133
32.4k
    fseek(ifp, -2, SEEK_CUR);
134
32.4k
    order = get2();
135
32.4k
    if (buf[0] == 'O')
136
1.41k
      get2();
137
31.0k
    else if (buf[0] == 'P')
138
29.3k
      is_PentaxRicohMakernotes = 1;
139
32.4k
  }
140
77.1k
  else if (is_PentaxRicohMakernotes && (dng_writer == CameraDNG))
141
30.2k
  {
142
30.2k
    base = ftell(ifp) - 10;
143
30.2k
    fseek(ifp, -4, SEEK_CUR);
144
30.2k
    order = get2();
145
30.2k
  }
146
46.9k
  else if (!strncmp(buf, "SONY", 4) ||
147
43.9k
           !strcmp(buf, "Panasonic"))
148
3.50k
  {
149
3.50k
    order = 0x4949;
150
3.50k
    fseek(ifp, 2, SEEK_CUR);
151
3.50k
  }
152
43.4k
  else if (!strncmp(buf, "FUJIFILM", 8))
153
294
  {
154
294
    base = ftell(ifp) - 10;
155
294
    order = 0x4949;
156
294
    fseek(ifp, 2, SEEK_CUR);
157
294
  }
158
43.1k
  else if (!strcmp(buf, "OLYMP") ||
159
43.0k
           !strcmp(buf, "Ricoh"))
160
268
  {
161
268
    fseek(ifp, -2, SEEK_CUR);
162
268
  }
163
42.9k
  else if (!strcmp(buf, "AOC") || !strcmp(buf, "QVC"))
164
2.60k
  {
165
2.60k
    fseek(ifp, -4, SEEK_CUR);
166
2.60k
  }
167
40.3k
  else
168
40.3k
  {
169
40.3k
    fseek(ifp, -10, SEEK_CUR);
170
40.3k
    if ((!strncmp(make, "SAMSUNG", 7) && (dng_writer == AdobeDNG)))
171
1.01k
      base = ftell(ifp);
172
40.3k
  }
173
174
109k
  entries = get2();
175
109k
  if (entries > 1000)
176
17.9k
    return;
177
178
91.6k
  if (!strncasecmp(make, "SONY", 4) ||
179
81.7k
      !strncasecmp(make, "Konica", 6) ||
180
80.4k
      !strncasecmp(make, "Minolta", 7) ||
181
76.8k
      (!strncasecmp(make, "Hasselblad", 10) &&
182
3.70k
       (!strncasecmp(model, "Stellar", 7) ||
183
3.15k
        !strncasecmp(model, "Lunar", 5) ||
184
2.61k
        !strncasecmp(model, "Lusso", 5) ||
185
2.51k
        !strncasecmp(model, "HV", 2))))
186
16.2k
    is_Sony = 1;
187
188
91.6k
  if (!is_Olympus &&
189
61.5k
      (!strncmp(make, "OLYMPUS", 7) || !strncmp(make, "OM Digi", 7) ||
190
60.7k
      (!strncasecmp(make, "CLAUSS", 6) && !strncasecmp(model, "piX 5oo", 7)))) {
191
823
    is_Olympus = 1;
192
823
    OlympusDNG_SubDirOffsetValid =
193
823
          strncmp(model, "E-300", 5) && strncmp(model, "E-330", 5) &&
194
821
          strncmp(model, "E-400", 5) && strncmp(model, "E-500", 5) &&
195
817
          strncmp(model, "E-1", 3);
196
823
  }
197
198
91.6k
  morder = order;
199
20.0M
  while (entries--)
200
19.9M
  {
201
19.9M
    order = morder;
202
203
19.9M
    tiff_get(base, &tag, &type, &len, &save);
204
205
19.9M
    INT64 pos = ifp->tell();
206
19.9M
    if (len > 8 && pos + len > 2 * fsize)
207
16.1M
    {
208
16.1M
      fseek(ifp, save, SEEK_SET); // Recover tiff-read position!!
209
16.1M
      continue;
210
16.1M
    }
211
3.79M
    tag |= uptag << 16;
212
3.79M
    if (len > 100 * 1024 * 1024)
213
0
      goto next; // 100Mb tag? No!
214
215
3.79M
  if (callbacks.makernotes_cb)
216
0
    {
217
0
      INT64 _savepos = ifp->tell();
218
0
      callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base);
219
0
      fseek(ifp, _savepos, SEEK_SET);
220
0
    }
221
222
3.79M
    if (!strncmp(make, "Canon", 5))
223
447k
    {
224
447k
      if (tag == 0x000d && len < 256000)
225
3.06k
      { // camera info
226
3.06k
        if (!tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG))
227
2.00k
        {
228
2.00k
          CanonCameraInfo = (uchar *)calloc(MAX(16, len),1);
229
2.00k
          fread(CanonCameraInfo, len, 1, ifp);
230
2.00k
        }
231
1.05k
        else
232
1.05k
        {
233
1.05k
          CanonCameraInfo = (uchar *)calloc(MAX(16, len * 4),1);
234
1.05k
          fread(CanonCameraInfo, len, 4, ifp);
235
1.05k
        }
236
3.06k
        lenCanonCameraInfo = len;
237
3.06k
        typeCanonCameraInfo = type;
238
3.06k
      }
239
240
444k
      else if (tag == 0x0010) // Canon ModelID
241
5.15k
      {
242
5.15k
        unique_id = get4();
243
5.15k
        setCanonBodyFeatures(unique_id);
244
5.15k
        if (lenCanonCameraInfo)
245
2.07k
        {
246
2.07k
          processCanonCameraInfo(unique_id, CanonCameraInfo, lenCanonCameraInfo,
247
2.07k
                                 typeCanonCameraInfo, AdobeDNG);
248
2.07k
          free(CanonCameraInfo);
249
2.07k
          CanonCameraInfo = 0;
250
2.07k
          lenCanonCameraInfo = 0;
251
2.07k
        }
252
5.15k
      }
253
254
439k
      else
255
439k
        parseCanonMakernotes(tag, type, len, AdobeDNG);
256
447k
    }
257
258
3.34M
    else if (!strncmp(make, "FUJI", 4)) {
259
40.7k
      parseFujiMakernotes(tag, type, len, AdobeDNG);
260
261
3.30M
    } else if (!strncasecmp(make, "Hasselblad", 10) && !is_Sony) {
262
124k
      if (tag == 0x0011) {
263
881
        imHassy.SensorCode = getint(type);
264
123k
      } else if ((tag == 0x0015) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_ASCII)) {
265
1.46k
        stmread (imHassy.SensorUnitConnector, len, ifp);
266
5.24k
        for (int i=0; i<(int)len; i++) {
267
5.04k
          if(!isalnum(imHassy.SensorUnitConnector[i]) &&
268
3.77k
             (imHassy.SensorUnitConnector[i]!=' ')    &&
269
3.16k
             (imHassy.SensorUnitConnector[i]!='/')    &&
270
2.00k
             (imHassy.SensorUnitConnector[i]!='-')) {
271
1.26k
            imHassy.SensorUnitConnector[0] = 0;
272
1.26k
            break;
273
1.26k
          }
274
5.04k
        }
275
121k
      } else if (tag == 0x0016) {
276
191
        imHassy.CoatingCode = getint(type);
277
121k
      } else if ((tag == 0x002a) &&
278
1.42k
                 tagtypeIs(LIBRAW_EXIFTAG_TYPE_SRATIONAL) &&
279
889
                 (len == 12) &&
280
345
                 imHassy.SensorUnitConnector[0]) {
281
2.68k
        FORC4 for (int i = 0; i < 3; i++)
282
2.01k
                imHassy.mnColorMatrix[c][i] = getreal(type);
283
284
121k
      } else if ((tag == 0x0031) &&
285
404
                 imHassy.SensorUnitConnector[0]) {
286
162
        imHassy.RecommendedCrop[0] = getint(type);
287
162
        imHassy.RecommendedCrop[1] = getint(type);
288
162
      }
289
290
3.18M
    } else if (is_Olympus) {
291
292
1.99M
      if ((tag == 0x2010) || (tag == 0x2020) || (tag == 0x2030) ||
293
1.97M
          (tag == 0x2031) || (tag == 0x2040) || (tag == 0x2050) ||
294
1.96M
          (tag == 0x3000))
295
27.9k
      {
296
27.9k
        fseek(ifp, save - 4, SEEK_SET);
297
27.9k
        fseek(ifp, base + get4(), SEEK_SET);
298
27.9k
        parse_makernote_0xc634(base, tag, dng_writer);
299
27.9k
      }
300
301
1.99M
      if (!OlympusDNG_SubDirOffsetValid &&
302
272k
          ((len > 4) ||
303
177k
           ((tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT) ||
304
175k
            tagtypeIs(LIBRAW_EXIFTAG_TYPE_SSHORT)) && (len > 2)) ||
305
177k
           ((tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG) ||
306
174k
             tagtypeIs(LIBRAW_EXIFTAG_TYPE_SLONG)) && (len > 1)) ||
307
176k
           tagtypeIs(LIBRAW_EXIFTAG_TYPE_RATIONAL) ||
308
176k
           (type > LIBRAW_EXIFTAG_TYPE_SLONG))) {
309
152k
        goto skip_Oly_broken_tags;
310
152k
      }
311
1.84M
      else {
312
1.84M
        parseOlympusMakernotes(base, tag, type, len, AdobeDNG);
313
1.84M
      }
314
1.99M
    skip_Oly_broken_tags:;
315
1.99M
    }
316
317
1.18M
    else if (!strncmp(make, "PENTAX", 6)  ||
318
1.17M
             !strncmp(model, "PENTAX", 6) ||
319
1.16M
             is_PentaxRicohMakernotes)
320
548k
    {
321
548k
      parsePentaxMakernotes(base, tag, type, len, dng_writer);
322
548k
    }
323
638k
    else if (!strncmp(make, "SAMSUNG", 7))
324
46.9k
    {
325
46.9k
      if (dng_writer == AdobeDNG)
326
31.2k
        parseSamsungMakernotes(base, tag, type, len, dng_writer);
327
15.7k
      else
328
15.7k
        parsePentaxMakernotes(base, tag, type, len, dng_writer);
329
46.9k
    }
330
591k
    else if (is_Sony)
331
422k
    {
332
422k
      parseSonyMakernotes(
333
422k
          base, tag, type, len, AdobeDNG,
334
422k
          table_buf_0x0116, table_buf_0x0116_len,
335
422k
          table_buf_0x2010, table_buf_0x2010_len,
336
422k
          table_buf_0x9050, table_buf_0x9050_len,
337
422k
          table_buf_0x9400, table_buf_0x9400_len,
338
422k
          table_buf_0x9402, table_buf_0x9402_len,
339
422k
          table_buf_0x9403, table_buf_0x9403_len,
340
422k
          table_buf_0x9406, table_buf_0x9406_len,
341
422k
          table_buf_0x940c, table_buf_0x940c_len,
342
422k
          table_buf_0x940e, table_buf_0x940e_len);
343
422k
    }
344
3.79M
  next:
345
3.79M
    fseek(ifp, save, SEEK_SET);
346
3.79M
  }
347
348
90.5k
  order = sorder;
349
90.5k
}
350
351
void LibRaw::parse_makernote(INT64 base, int uptag)
352
1.24M
{
353
354
1.24M
  if (metadata_blocks++ > LIBRAW_MAX_METADATA_BLOCKS)
355
157
    throw LIBRAW_EXCEPTION_IO_CORRUPT;
356
357
1.24M
  if (!strncmp(make, "NIKON", 5))
358
93.8k
  {
359
93.8k
    parseNikonMakernote(base, uptag, nonDNG);
360
93.8k
    return;
361
93.8k
  }
362
1.15M
  else if (!strncasecmp(make, "LEICA", 5))
363
38.9k
  {
364
38.9k
    parseLeicaMakernote(base, uptag, is_0x927c);
365
38.9k
    return;
366
38.9k
  }
367
368
1.11M
  if (!strncmp(make, "Nokia", 5))
369
1.62k
    return;
370
371
1.11M
  char buf[10];
372
1.11M
  char another_buf[128];
373
374
1.11M
  fseek(ifp, -12, SEEK_CUR);
375
1.11M
  fread (another_buf, 1, 12, ifp);
376
1.11M
  if (!strncmp(another_buf, "SONY", 4) ||
377
1.10M
      !strncmp(another_buf, "VHAB", 4)) { // Sony branded as Hasselblad
378
16.2k
    is_Sony = 1;
379
16.2k
  }
380
381
1.11M
  fread(buf, 1, 10, ifp);
382
383
1.11M
  if (!strncmp(buf, "KDK", 3)  || /* these aren't TIFF tables */
384
1.10M
      !strncmp(buf, "VER", 3)  ||
385
1.10M
      !strncmp(buf, "IIII", 4) ||
386
1.10M
      !strncmp(buf, "MMMM", 4))
387
5.91k
    return;
388
389
1.10M
  if (!strcmp(buf, "EPSON"))
390
8.51k
  {
391
8.51k
    parseEpsonMakernote(base, uptag, nonDNG);
392
8.51k
    return;
393
8.51k
  }
394
1.09M
  else if (!strcmp(buf, "SIGMA"))
395
5.81k
  {
396
5.81k
    parseSigmaMakernote(base, uptag, CameraDNG);
397
5.81k
    return;
398
5.81k
  }
399
400
401
1.09M
  unsigned entries, tag, type, len, c;
402
1.09M
  INT64 save;
403
1.09M
  unsigned wb[4] = {0, 0, 0, 0};
404
1.09M
  short morder, sorder = order;
405
406
1.09M
  uchar *CanonCameraInfo = 0;;
407
1.09M
  unsigned lenCanonCameraInfo = 0;
408
1.09M
  unsigned typeCanonCameraInfo = 0;
409
1.09M
  imCanon.wbi = 0;
410
411
1.09M
  uchar *table_buf_0x0116;
412
1.09M
  ushort table_buf_0x0116_len = 0;
413
1.09M
  uchar *table_buf_0x2010;
414
1.09M
  ushort table_buf_0x2010_len = 0;
415
1.09M
  uchar *table_buf_0x9050;
416
1.09M
  ushort table_buf_0x9050_len = 0;
417
1.09M
  uchar *table_buf_0x9400;
418
1.09M
  ushort table_buf_0x9400_len = 0;
419
1.09M
  uchar *table_buf_0x9402;
420
1.09M
  ushort table_buf_0x9402_len = 0;
421
1.09M
  uchar *table_buf_0x9403;
422
1.09M
  ushort table_buf_0x9403_len = 0;
423
1.09M
  uchar *table_buf_0x9406;
424
1.09M
  ushort table_buf_0x9406_len = 0;
425
1.09M
  uchar *table_buf_0x940c;
426
1.09M
  ushort table_buf_0x940c_len = 0;
427
1.09M
  uchar *table_buf_0x940e;
428
1.09M
  ushort table_buf_0x940e_len = 0;
429
430
1.09M
  INT64 fsize = ifp->size();
431
432
  /*
433
       The MakerNote might have its own TIFF header (possibly with
434
       its own byte-order!), or it might just be a table.
435
  */
436
437
1.09M
  if (!strncmp(buf, "KC", 2) || /* Konica KD-400Z, KD-510Z */
438
1.08M
      !strncmp(buf, "MLY", 3))  /* Minolta DiMAGE G series */
439
5.98k
  {
440
5.98k
    order = 0x4d4d;
441
5.98k
  INT64 ii;
442
4.47M
    while ((ii = ftell(ifp)) < data_offset && ii < 16384LL)
443
4.46M
    {
444
4.46M
      wb[0] = wb[2];
445
4.46M
      wb[2] = wb[1];
446
4.46M
      wb[1] = wb[3];
447
4.46M
    if (feof(ifp))
448
1.56k
      break;
449
4.46M
      wb[3] = get2();
450
4.46M
      if (wb[1] == 256 && wb[3] == 256 && wb[0] > 256 && wb[0] < 640 &&
451
3.14k
          wb[2] > 256 && wb[2] < 640)
452
5.95k
        FORC4 cam_mul[c] = float(wb[c]);
453
4.46M
    }
454
5.98k
    goto quit;
455
5.98k
  }
456
457
1.08M
  if (!strcmp(buf, "OLYMPUS") || !strncmp(buf, "OM SYS",6) ||
458
1.08M
      !strcmp(buf, "PENTAX "))
459
2.83k
  {
460
2.83k
    base = ftell(ifp) - 10;
461
2.83k
    fseek(ifp, -2, SEEK_CUR);
462
2.83k
  if (buf[1] == 'M')
463
1.92k
    get4();
464
2.83k
    order = get2();
465
2.83k
    if (buf[0] == 'O')
466
2.16k
      get2();
467
2.83k
  }
468
1.08M
  else if (!strncmp(buf, "SONY", 4) || // DSLR-A100
469
1.06M
           !strcmp(buf, "Panasonic")) {
470
20.4k
    if (buf[0] == 'S')
471
19.3k
      is_Sony = 1;
472
20.4k
    goto nf;
473
20.4k
  }
474
1.06M
  else if (!strncmp(buf, "FUJIFILM", 8))
475
2.53k
  {
476
2.53k
    base = ftell(ifp) - 10;
477
22.9k
  nf:
478
22.9k
    order = 0x4949;
479
22.9k
    fseek(ifp, 2, SEEK_CUR);
480
22.9k
  }
481
1.05M
  else if (!strcmp (buf, "OLYMP")    ||
482
1.05M
           !strncmp(buf, "LEICA", 5) ||
483
1.04M
           !strcmp (buf, "Ricoh"))
484
18.1k
  {
485
18.1k
    fseek(ifp, -2, SEEK_CUR);
486
18.1k
  }
487
1.04M
  else if (!strcmp(buf, "AOC") || // Pentax, tribute to Asahi Optical Co.
488
1.04M
           !strcmp(buf, "QVC"))   // Casio, from "QV-Camera"
489
2.46k
  {
490
2.46k
    fseek(ifp, -4, SEEK_CUR);
491
2.46k
  }
492
1.03M
  else if (!strncmp(buf, "CMT3", 4))
493
1.18k
  {
494
1.18k
    order = sget2((uchar *)(buf + 4));
495
1.18k
    fseek(ifp, 2L, SEEK_CUR);
496
1.18k
  }
497
1.03M
  else if (libraw_internal_data.unpacker_data.CR3_CTMDtag)
498
0
  {
499
0
    order = sget2((uchar *)buf);
500
0
    fseek(ifp, -2L, SEEK_CUR);
501
0
  }
502
1.03M
  else
503
1.03M
  {
504
1.03M
    fseek(ifp, -10, SEEK_CUR);
505
1.03M
    if (!strncmp(make, "SAMSUNG", 7))
506
59.0k
      base = ftell(ifp);
507
1.03M
  }
508
509
1.08M
  if (!is_Olympus &&
510
665k
      (!strncasecmp(make, "Olympus", 7) || !strncmp(make, "OM Digi", 7) ||
511
661k
      (!strncasecmp(make, "CLAUSS", 6) && !strncasecmp(model, "piX 5oo", 7)))) {
512
4.11k
    is_Olympus = 1;
513
4.11k
  }
514
515
1.08M
  if (!is_Sony &&
516
509k
      (!strncasecmp(make, "SONY", 4) ||
517
504k
       !strncasecmp(make, "Konica", 6) ||
518
503k
       !strncasecmp(make, "Minolta", 7) ||
519
502k
       (!strncasecmp(make, "Hasselblad", 10) &&
520
10.3k
        (!strncasecmp(model, "Stellar", 7) ||
521
10.3k
         !strncasecmp(model, "Lunar", 5) ||
522
10.3k
         !strncasecmp(model, "Lusso", 5) ||
523
10.3k
         !strncasecmp(model, "HV", 2))))) {
524
6.23k
    is_Sony = 1;
525
6.23k
  }
526
527
1.08M
  if (strcasestr(make, "Kodak") &&
528
87.7k
      (sget2((uchar *)buf) > 1) && // check number of entries
529
84.1k
      (sget2((uchar *)buf) < 128) &&
530
39.9k
      (sget2((uchar *)(buf + 4)) > 0) && // check type
531
33.0k
      (sget2((uchar *)(buf + 4)) < 13) &&
532
7.28k
      (sget4((uchar *)(buf + 6)) < 256) // check count
533
1.08M
  )
534
3.35k
    imKodak.MakerNoteKodak8a = 1; // Kodak P712 / P850 / P880
535
536
1.08M
  entries = get2();
537
1.08M
  if (entries > 1000)
538
159k
    return;
539
540
925k
  morder = order;
541
168M
  while (entries--)
542
167M
  {
543
167M
    order = morder;
544
167M
    tiff_get(base, &tag, &type, &len, &save);
545
167M
    tag |= uptag << 16;
546
547
167M
    INT64 _pos = ftell(ifp);
548
167M
    if (len > 100 * 1024 * 1024)
549
85.1M
  goto next; // 100Mb tag? No!
550
82.4M
    if (len > 8 && _pos + len > 2 * fsize)
551
43.1M
    {
552
43.1M
      fseek(ifp, save, SEEK_SET); // Recover tiff-read position!!
553
43.1M
      continue;
554
43.1M
    }
555
556
39.2M
  if (callbacks.makernotes_cb)
557
0
    {
558
0
      INT64 _savepos = ifp->tell();
559
0
      callbacks.makernotes_cb(callbacks.makernotesparser_data, tag, type, len, order, ifp, base);
560
0
      fseek(ifp, _savepos, SEEK_SET);
561
0
    }
562
563
39.2M
    if (imKodak.MakerNoteKodak8a)
564
446k
    {
565
446k
      if ((tag == 0xff00) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG) && (len == 1))
566
2.48k
      {
567
2.48k
        INT64 _pos1 = get4();
568
2.48k
        if ((_pos1 < fsize) && (_pos1 > 0))
569
1.19k
        {
570
1.19k
          fseek(ifp, _pos1, SEEK_SET);
571
1.19k
          parse_makernote(base, tag);
572
1.19k
        }
573
2.48k
      }
574
444k
      else if (tag == 0xff00f90b)
575
328
      {
576
328
        imKodak.clipBlack = get2();
577
328
      }
578
444k
      else if (tag == 0xff00f90c)
579
484
      {
580
484
        imKodak.clipWhite = imgdata.color.linear_max[0] =
581
484
            imgdata.color.linear_max[1] = imgdata.color.linear_max[2] =
582
484
                imgdata.color.linear_max[3] = get2();
583
484
      }
584
446k
    }
585
38.8M
    else if (!strncmp(make, "Canon", 5))
586
6.39M
    {
587
6.39M
      if (tag == 0x000d && len < 256000) // camera info
588
65.4k
      {
589
65.4k
        if (!tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG))
590
35.6k
        {
591
35.6k
          CanonCameraInfo = (uchar *)calloc(MAX(16, len),1);
592
35.6k
          fread(CanonCameraInfo, len, 1, ifp);
593
35.6k
        }
594
29.7k
        else
595
29.7k
        {
596
29.7k
          CanonCameraInfo = (uchar *)calloc(MAX(16, len * 4),1);
597
29.7k
          fread(CanonCameraInfo, len, 4, ifp);
598
29.7k
        }
599
65.4k
        lenCanonCameraInfo = len;
600
65.4k
        typeCanonCameraInfo = type;
601
65.4k
      }
602
603
6.32M
      else if (tag == 0x0010) // Canon ModelID
604
80.8k
      {
605
80.8k
        unique_id = get4();
606
80.8k
        setCanonBodyFeatures(unique_id);
607
80.8k
        if (lenCanonCameraInfo)
608
42.9k
        {
609
42.9k
          processCanonCameraInfo(unique_id, CanonCameraInfo, lenCanonCameraInfo,
610
42.9k
                                 typeCanonCameraInfo, nonDNG);
611
42.9k
    if(CanonCameraInfo)
612
42.9k
            free(CanonCameraInfo);
613
42.9k
          CanonCameraInfo = 0;
614
42.9k
          lenCanonCameraInfo = 0;
615
42.9k
        }
616
80.8k
      }
617
618
6.24M
      else
619
6.24M
        parseCanonMakernotes(tag, type, len, nonDNG);
620
6.39M
    }
621
622
32.4M
    else if (!strncmp(make, "FUJI", 4))
623
1.06M
      parseFujiMakernotes(tag, type, len, nonDNG);
624
625
31.3M
    else if (!strncasecmp(model, "Hasselblad X1D", 14) ||
626
31.3M
             !strncasecmp(model, "Hasselblad H6D", 14) ||
627
31.3M
             !strncasecmp(model, "Hasselblad A6D", 14))
628
79.6k
    {
629
79.6k
      if (tag == 0x0045)
630
499
      {
631
499
        imHassy.BaseISO = get4();
632
499
      }
633
79.1k
      else if (tag == 0x0046)
634
451
      {
635
451
        imHassy.Gain = getreal(type);
636
451
      }
637
79.6k
    }
638
639
31.2M
    else if (!strncmp(make, "PENTAX", 6) ||
640
26.7M
             !strncmp(make, "RICOH", 5) ||
641
25.0M
             !strncmp(model, "PENTAX", 6))
642
6.30M
    {
643
6.30M
      if (!strncmp(model, "GR", 2) ||
644
5.63M
          !strncmp(model, "GXR", 3))
645
1.15M
      {
646
1.15M
        parseRicohMakernotes(base, tag, type, len, CameraDNG);
647
1.15M
      }
648
5.14M
      else
649
5.14M
      {
650
5.14M
        parsePentaxMakernotes(base, tag, type, len, nonDNG);
651
5.14M
      }
652
6.30M
    }
653
654
24.9M
    else if (!strncmp(make, "SAMSUNG", 7))
655
1.76M
    {
656
1.76M
      if (!dng_version)
657
1.04M
        parseSamsungMakernotes(base, tag, type, len, nonDNG);
658
719k
      else
659
719k
        parsePentaxMakernotes(base, tag, type, len, CameraDNG);
660
1.76M
    }
661
662
23.2M
    else if (is_Sony)
663
16.9M
    {
664
16.9M
      if ((tag == 0xb028) && (len == 1) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG)) // DSLR-A100
665
4.26k
      {
666
4.26k
        if ((c = get4()))
667
3.46k
        {
668
3.46k
          fseek(ifp, c, SEEK_SET);
669
3.46k
          parse_makernote(base, tag);
670
3.46k
        }
671
4.26k
      }
672
16.9M
      else
673
16.9M
      {
674
16.9M
        parseSonyMakernotes(
675
16.9M
            base, tag, type, len, nonDNG,
676
16.9M
            table_buf_0x0116, table_buf_0x0116_len,
677
16.9M
            table_buf_0x2010, table_buf_0x2010_len,
678
16.9M
            table_buf_0x9050, table_buf_0x9050_len,
679
16.9M
            table_buf_0x9400, table_buf_0x9400_len,
680
16.9M
            table_buf_0x9402, table_buf_0x9402_len,
681
16.9M
            table_buf_0x9403, table_buf_0x9403_len,
682
16.9M
            table_buf_0x9406, table_buf_0x9406_len,
683
16.9M
            table_buf_0x940c, table_buf_0x940c_len,
684
16.9M
            table_buf_0x940e, table_buf_0x940e_len);
685
16.9M
      }
686
16.9M
    }
687
39.2M
    fseek(ifp, _pos, SEEK_SET);
688
689
39.2M
    if (!strncasecmp(make, "Hasselblad", 10) && !is_Sony) {
690
341k
      if (tag == 0x0011)
691
1.21k
        imHassy.SensorCode = getint(type);
692
339k
      else if (tag == 0x0016)
693
890
        imHassy.CoatingCode = getint(type);
694
338k
      else if ((tag == 0x002a) &&
695
2.52k
               tagtypeIs(LIBRAW_EXIFTAG_TYPE_SRATIONAL) &&
696
1.44k
               (len == 12)) {
697
6.99k
        FORC4 for (int ii = 0; ii < 3; ii++)
698
5.24k
                imHassy.mnColorMatrix[c][ii] = getreal(type);
699
700
338k
      } else if (tag == 0x0031) {
701
1.11k
        imHassy.RecommendedCrop[0] = getint(type);
702
1.11k
        imHassy.RecommendedCrop[1] = getint(type);
703
1.11k
      }
704
341k
    }
705
706
39.2M
    if ((tag == 0x0004 || tag == 0x0114) && !strncmp(make, "KONICA", 6))
707
21.8k
    {
708
21.8k
      fseek(ifp, tag == 0x0004 ? 140 : 160, SEEK_CUR);
709
21.8k
      switch (get2())
710
21.8k
      {
711
631
      case 72:
712
631
        flip = 0;
713
631
        break;
714
631
      case 76:
715
631
        flip = 6;
716
631
        break;
717
103
      case 82:
718
103
        flip = 5;
719
103
        break;
720
21.8k
      }
721
21.8k
    }
722
723
39.2M
    if (is_Olympus) {
724
18.0M
      INT64 _pos2 = ftell(ifp);
725
18.0M
      if ((tag == 0x2010) || (tag == 0x2020) || (tag == 0x2030) ||
726
17.9M
          (tag == 0x2031) || (tag == 0x2040) || (tag == 0x2050) ||
727
17.8M
          (tag == 0x3000))
728
192k
      {
729
192k
        if (tagtypeIs(LIBRAW_EXIFTOOLTAGTYPE_binary)) {
730
131k
          parse_makernote(base, tag);
731
732
131k
        } else if (tagtypeIs(LIBRAW_EXIFTOOLTAGTYPE_ifd) ||
733
60.3k
                   tagtypeIs(LIBRAW_EXIFTOOLTAGTYPE_int32u)) {
734
2.10k
          fseek(ifp, base + get4(), SEEK_SET);
735
2.10k
          parse_makernote(base, tag);
736
2.10k
        }
737
738
17.8M
      } else {
739
17.8M
        parseOlympusMakernotes(base, tag, type, len, nonDNG);
740
17.8M
      }
741
18.0M
      fseek(ifp, _pos2, SEEK_SET);
742
18.0M
    }
743
744
39.2M
    if ((tag == 0x0015) &&
745
48.6k
        tagtypeIs(LIBRAW_EXIFTAG_TYPE_ASCII) &&
746
9.67k
        is_raw)
747
7.71k
    { // Hasselblad
748
7.71k
      stmread (imHassy.SensorUnitConnector, len, ifp);
749
7.71k
    }
750
751
39.2M
    if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED) &&
752
669k
        ((tag == 0x0081) || // Minolta
753
669k
         (tag == 0x0100)))  // Olympus
754
3.17k
    {
755
3.17k
      thumb_offset = ftell(ifp);
756
3.17k
      thumb_length = len;
757
3.17k
    }
758
39.2M
    if ((tag == 0x0088) && // Minolta, possibly Olympus too
759
11.0k
        tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG) &&
760
3.12k
        (thumb_offset = get4()))
761
2.17k
      thumb_offset += base;
762
763
39.2M
    if ((tag == 0x0089) && // Minolta, possibly Olympus too
764
3.77k
        tagtypeIs(LIBRAW_EXIFTAG_TYPE_LONG))
765
480
      thumb_length = get4();
766
767
39.2M
    if (tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED) &&  // Nikon
768
669k
        ((tag == 0x008c) ||
769
668k
         (tag == 0x0096))) {
770
3.28k
      meta_offset = ftell(ifp);
771
3.28k
    }
772
773
39.2M
    if ((tag == 0x00a1) &&
774
3.78k
        tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED) &&
775
849
        strncasecmp(make, "Samsung", 7))
776
427
    {
777
427
      order = 0x4949;
778
427
      fseek(ifp, 140, SEEK_CUR);
779
1.28k
      FORC3 cam_mul[c] = float(get4());
780
427
    }
781
782
39.2M
    if (tag == 0xb001 && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT)) // Sony ModelID
783
2.40k
    {
784
2.40k
      unique_id = get2();
785
2.40k
    }
786
39.2M
    if (tag == 0x0200 && len == 3) // Olympus
787
3.18k
      shot_order = (get4(), get4());
788
789
39.2M
    if (tag == 0x0f00 && tagtypeIs(LIBRAW_EXIFTAG_TYPE_UNDEFINED))
790
2.27k
    {
791
2.27k
      if (len == 614)
792
82
        fseek(ifp, 176, SEEK_CUR);
793
2.18k
      else if (len == 734 || len == 1502) // Kodak, Minolta, Olympus
794
576
        fseek(ifp, 148, SEEK_CUR);
795
1.61k
      else
796
1.61k
        goto next;
797
658
      goto get2_256;
798
2.27k
    }
799
800
39.2M
    if (tag == 0x2011 && len == 2) // Casio
801
869
    {
802
1.52k
    get2_256:
803
1.52k
      order = 0x4d4d;
804
1.52k
      cam_mul[0] = float(get2()) / 256.0f;
805
1.52k
      cam_mul[2] = float(get2()) / 256.0f;
806
1.52k
    }
807
808
124M
  next:
809
124M
    fseek(ifp, save, SEEK_SET);
810
124M
  }
811
927k
quit:
812
927k
  order = sorder;
813
927k
}