Coverage Report

Created: 2026-07-20 07:19

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
146k
{
21
146k
  int i, c;
22
146k
  if (tag == 0x0002)
23
2.12k
  {
24
2.12k
    imSamsung.DeviceType = get4();
25
2.12k
    if (imSamsung.DeviceType == 0x2000)
26
80
    {
27
80
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
28
80
      ilm.CameraFormat = LIBRAW_FORMAT_APSC;
29
80
    }
30
2.04k
    else if (!strncmp(model, "NX mini", 7))
31
398
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
398
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
398
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
398
    }
35
1.64k
    else
36
1.64k
    {
37
1.64k
      ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
38
1.64k
      ilm.LensMount = LIBRAW_MOUNT_FixedLens;
39
1.64k
    }
40
2.12k
  }
41
144k
  else if (tag == 0x0003)
42
794
  {
43
794
    ilm.CamID = unique_id = get4();
44
794
  }
45
143k
  else if (tag == 0x0043)
46
1.17k
  {
47
1.17k
    if ((i = get4()))
48
791
    {
49
791
      imCommon.CameraTemperature = (float)i;
50
791
      if (get4() == 10)
51
118
        imCommon.CameraTemperature /= 10.0f;
52
791
    }
53
1.17k
  }
54
142k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
555
  {
56
555
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
555
  }
58
142k
  else if (tag == 0xa003)
59
2.31k
  {
60
2.31k
    ilm.LensID = get2();
61
2.31k
    if (ilm.LensID)
62
856
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
2.31k
  }
64
139k
  else if (tag == 0xa004)
65
1.18k
  { // LensFirmware
66
1.18k
    stmread(imSamsung.LensFirmware, len, ifp);
67
1.18k
  }
68
138k
  else if (tag == 0xa005)
69
471
  {
70
471
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
471
  }
72
138k
  else if (tag == 0xa010)
73
1.89k
  {
74
7.59k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
7.59k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
1.89k
  }
77
136k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
742
  {
79
742
    imSamsung.ColorSpace[0] = (int)get2();
80
742
    switch (imSamsung.ColorSpace[0]) {
81
64
    case 0:
82
64
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
64
      break;
84
145
    case 1:
85
145
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
145
      break;
87
533
    default:
88
533
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
533
      break;
90
742
    }
91
742
    if (len == 2)
92
324
      imSamsung.ColorSpace[1] = (int)get2();
93
742
  }
94
135k
  else if (tag == 0xa019)
95
591
  {
96
591
    ilm.CurAp = getrealf(type);
97
591
  }
98
134k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
465
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
428
  {
101
428
    ilm.FocalLengthIn35mmFormat = float(get4());
102
428
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
94
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
428
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
238
        (imSamsung.LensFirmware[10] < '6'))
106
238
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
428
  }
108
134k
  else if (tag == 0xa020)
109
114
  {
110
1.25k
    FORC(11) imSamsung.key[c] = get4();
111
114
  }
112
134k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
481
  {
114
1.92k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
481
  }
116
133k
  else if (tag == 0xa022)
117
552
  {
118
2.20k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
2.20k
        get4() - imSamsung.key[c + 4];
120
552
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
552
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
168
    {
123
168
      icWBC[LIBRAW_WBI_Auto][1] =
124
168
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
168
      icWBC[LIBRAW_WBI_Auto][3] =
126
168
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
168
    }
128
552
  }
129
133k
  else if (tag == 0xa023)
130
2.55k
  {
131
2.55k
    ushort ki[4] = {8, 9, 10, 0};
132
10.2k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
10.2k
        get4() - imSamsung.key[ki[c]];
134
2.55k
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
2.55k
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
1.33k
    {
137
1.33k
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
1.33k
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
1.33k
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
1.33k
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
1.33k
    }
142
2.55k
  }
143
130k
  else if (tag == 0xa024)
144
1.45k
  {
145
5.82k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
5.82k
        get4() - imSamsung.key[c + 1];
147
1.45k
    if (icWBC[LIBRAW_WBI_D65][0] <
148
1.45k
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
676
    {
150
676
      icWBC[LIBRAW_WBI_D65][1] =
151
676
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
676
      icWBC[LIBRAW_WBI_D65][3] =
153
676
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
676
    }
155
1.45k
  }
156
129k
  else if (tag == 0xa025)
157
830
  {
158
830
    unsigned t = get4() + imSamsung.key[0];
159
830
    if (t == 4096)
160
102
      imSamsung.DigitalGain = 1.0;
161
728
    else
162
728
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
830
  }
164
128k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
154
  {
166
616
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
154
  }
168
128k
  else if ((tag == 0xa030) && (len == 9))
169
345
  {
170
1.38k
    for (i = 0; i < 3; i++)
171
3.10k
      FORC3 imgdata.color.ccm[i][c] =
172
3.10k
          (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f;
173
345
  }
174
128k
  else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
175
410
  {
176
410
    double aRGB_cam[3][3];
177
410
    FORC(9)
178
3.69k
    ((double *)aRGB_cam)[c] =
179
3.69k
        ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
180
410
    aRGB_coeff(aRGB_cam);
181
410
  }
182
146k
}