Coverage Report

Created: 2026-10-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/LibRaw/src/metadata/samsung.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
16
#include "../../internal/dcraw_defs.h"
17
18
void LibRaw::parseSamsungMakernotes(INT64 /*base*/, unsigned tag, unsigned type,
19
                                    unsigned len, unsigned dng_writer)
20
328k
{
21
328k
  int i, c;
22
328k
  if (tag == 0x0002)
23
3.61k
  {
24
3.61k
    imSamsung.DeviceType = get4();
25
3.61k
    if (imSamsung.DeviceType == 0x2000)
26
74
    {
27
74
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
28
74
      ilm.CameraFormat = LIBRAW_FORMAT_APSC;
29
74
    }
30
3.54k
    else if (!strncmp(model, "NX mini", 7))
31
2.12k
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
2.12k
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
2.12k
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
2.12k
    }
35
1.41k
    else
36
1.41k
    {
37
1.41k
      ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
38
1.41k
      ilm.LensMount = LIBRAW_MOUNT_FixedLens;
39
1.41k
    }
40
3.61k
  }
41
325k
  else if (tag == 0x0003)
42
4.98k
  {
43
4.98k
    ilm.CamID = unique_id = get4();
44
4.98k
  }
45
320k
  else if (tag == 0x0043)
46
818
  {
47
818
    if ((i = get4()))
48
312
    {
49
312
      imCommon.CameraTemperature = (float)i;
50
312
      if (get4() == 10)
51
6
        imCommon.CameraTemperature /= 10.0f;
52
312
    }
53
818
  }
54
319k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
1.45k
  {
56
1.45k
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
1.45k
  }
58
317k
  else if (tag == 0xa003)
59
1.98k
  {
60
1.98k
    ilm.LensID = get2();
61
1.98k
    if (ilm.LensID)
62
1.22k
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
1.98k
  }
64
315k
  else if (tag == 0xa004)
65
820
  { // LensFirmware
66
820
    stmread(imSamsung.LensFirmware, len, ifp);
67
820
  }
68
314k
  else if (tag == 0xa005)
69
964
  {
70
964
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
964
  }
72
314k
  else if (tag == 0xa010)
73
360
  {
74
1.44k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
1.44k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
360
  }
77
313k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
720
  {
79
720
    imSamsung.ColorSpace[0] = (int)get2();
80
720
    switch (imSamsung.ColorSpace[0]) {
81
400
    case 0:
82
400
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
400
      break;
84
114
    case 1:
85
114
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
114
      break;
87
206
    default:
88
206
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
206
      break;
90
720
    }
91
720
    if (len == 2)
92
206
      imSamsung.ColorSpace[1] = (int)get2();
93
720
  }
94
312k
  else if (tag == 0xa019)
95
840
  {
96
840
    ilm.CurAp = getrealf(type);
97
840
  }
98
312k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
1.17k
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
1.15k
  {
101
1.15k
    ilm.FocalLengthIn35mmFormat = float(get4());
102
1.15k
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
1.12k
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
1.15k
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
666
        (imSamsung.LensFirmware[10] < '6'))
106
666
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
1.15k
  }
108
310k
  else if (tag == 0xa020)
109
426
  {
110
4.68k
    FORC(11) imSamsung.key[c] = get4();
111
426
  }
112
310k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
820
  {
114
3.28k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
820
  }
116
309k
  else if (tag == 0xa022)
117
1.08k
  {
118
4.34k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
4.34k
        get4() - imSamsung.key[c + 4];
120
1.08k
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
1.08k
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
598
    {
123
598
      icWBC[LIBRAW_WBI_Auto][1] =
124
598
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
598
      icWBC[LIBRAW_WBI_Auto][3] =
126
598
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
598
    }
128
1.08k
  }
129
308k
  else if (tag == 0xa023)
130
962
  {
131
962
    ushort ki[4] = {8, 9, 10, 0};
132
3.84k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
3.84k
        get4() - imSamsung.key[ki[c]];
134
962
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
962
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
242
    {
137
242
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
242
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
242
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
242
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
242
    }
142
962
  }
143
307k
  else if (tag == 0xa024)
144
714
  {
145
2.85k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
2.85k
        get4() - imSamsung.key[c + 1];
147
714
    if (icWBC[LIBRAW_WBI_D65][0] <
148
714
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
338
    {
150
338
      icWBC[LIBRAW_WBI_D65][1] =
151
338
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
338
      icWBC[LIBRAW_WBI_D65][3] =
153
338
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
338
    }
155
714
  }
156
306k
  else if (tag == 0xa025)
157
664
  {
158
664
    unsigned t = get4() + imSamsung.key[0];
159
664
    if (t == 4096)
160
224
      imSamsung.DigitalGain = 1.0;
161
440
    else
162
440
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
664
  }
164
306k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
460
  {
166
1.84k
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
460
  }
168
305k
  else if ((tag == 0xa030) && (len == 9))
169
850
  {
170
3.40k
    for (i = 0; i < 3; i++)
171
7.65k
      FORC3 imgdata.color.ccm[i][c] =
172
7.65k
          (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f;
173
850
  }
174
304k
  else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
175
902
  {
176
902
    double aRGB_cam[3][3];
177
902
    FORC(9)
178
8.11k
    ((double *)aRGB_cam)[c] =
179
8.11k
        ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
180
902
    aRGB_coeff(aRGB_cam);
181
902
  }
182
328k
}