Coverage Report

Created: 2026-03-20 07:18

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
786k
{
21
786k
  int i, c;
22
786k
  if (tag == 0x0002)
23
10.4k
  {
24
10.4k
    imSamsung.DeviceType = get4();
25
10.4k
    if (imSamsung.DeviceType == 0x2000)
26
941
    {
27
941
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
28
941
      ilm.CameraFormat = LIBRAW_FORMAT_APSC;
29
941
    }
30
9.49k
    else if (!strncmp(model, "NX mini", 7))
31
1.13k
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
1.13k
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
1.13k
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
1.13k
    }
35
8.35k
    else
36
8.35k
    {
37
8.35k
      ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
38
8.35k
      ilm.LensMount = LIBRAW_MOUNT_FixedLens;
39
8.35k
    }
40
10.4k
  }
41
776k
  else if (tag == 0x0003)
42
4.74k
  {
43
4.74k
    ilm.CamID = unique_id = get4();
44
4.74k
  }
45
771k
  else if (tag == 0x0043)
46
5.76k
  {
47
5.76k
    if ((i = get4()))
48
1.96k
    {
49
1.96k
      imCommon.CameraTemperature = (float)i;
50
1.96k
      if (get4() == 10)
51
187
        imCommon.CameraTemperature /= 10.0f;
52
1.96k
    }
53
5.76k
  }
54
765k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
3.37k
  {
56
3.37k
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
3.37k
  }
58
762k
  else if (tag == 0xa003)
59
4.03k
  {
60
4.03k
    ilm.LensID = get2();
61
4.03k
    if (ilm.LensID)
62
2.51k
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
4.03k
  }
64
758k
  else if (tag == 0xa004)
65
4.51k
  { // LensFirmware
66
4.51k
    stmread(imSamsung.LensFirmware, len, ifp);
67
4.51k
  }
68
753k
  else if (tag == 0xa005)
69
1.77k
  {
70
1.77k
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
1.77k
  }
72
752k
  else if (tag == 0xa010)
73
3.43k
  {
74
13.7k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
13.7k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
3.43k
  }
77
748k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
3.66k
  {
79
3.66k
    imSamsung.ColorSpace[0] = (int)get2();
80
3.66k
    switch (imSamsung.ColorSpace[0]) {
81
735
    case 0:
82
735
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
735
      break;
84
899
    case 1:
85
899
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
899
      break;
87
2.02k
    default:
88
2.02k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
2.02k
      break;
90
3.66k
    }
91
3.66k
    if (len == 2)
92
1.03k
      imSamsung.ColorSpace[1] = (int)get2();
93
3.66k
  }
94
744k
  else if (tag == 0xa019)
95
831
  {
96
831
    ilm.CurAp = getrealf(type);
97
831
  }
98
744k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
3.33k
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
2.38k
  {
101
2.38k
    ilm.FocalLengthIn35mmFormat = float(get4());
102
2.38k
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
1.67k
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
2.38k
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
465
        (imSamsung.LensFirmware[10] < '6'))
106
365
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
2.38k
  }
108
741k
  else if (tag == 0xa020)
109
659
  {
110
7.24k
    FORC(11) imSamsung.key[c] = get4();
111
659
  }
112
741k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
2.29k
  {
114
9.19k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
2.29k
  }
116
738k
  else if (tag == 0xa022)
117
6.17k
  {
118
24.7k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
24.7k
        get4() - imSamsung.key[c + 4];
120
6.17k
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
6.17k
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
2.44k
    {
123
2.44k
      icWBC[LIBRAW_WBI_Auto][1] =
124
2.44k
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
2.44k
      icWBC[LIBRAW_WBI_Auto][3] =
126
2.44k
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
2.44k
    }
128
6.17k
  }
129
732k
  else if (tag == 0xa023)
130
2.83k
  {
131
2.83k
    ushort ki[4] = {8, 9, 10, 0};
132
11.3k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
11.3k
        get4() - imSamsung.key[ki[c]];
134
2.83k
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
2.83k
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
1.44k
    {
137
1.44k
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
1.44k
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
1.44k
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
1.44k
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
1.44k
    }
142
2.83k
  }
143
729k
  else if (tag == 0xa024)
144
4.44k
  {
145
17.7k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
17.7k
        get4() - imSamsung.key[c + 1];
147
4.44k
    if (icWBC[LIBRAW_WBI_D65][0] <
148
4.44k
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
2.53k
    {
150
2.53k
      icWBC[LIBRAW_WBI_D65][1] =
151
2.53k
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
2.53k
      icWBC[LIBRAW_WBI_D65][3] =
153
2.53k
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
2.53k
    }
155
4.44k
  }
156
725k
  else if (tag == 0xa025)
157
1.58k
  {
158
1.58k
    unsigned t = get4() + imSamsung.key[0];
159
1.58k
    if (t == 4096)
160
445
      imSamsung.DigitalGain = 1.0;
161
1.14k
    else
162
1.14k
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
1.58k
  }
164
723k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
1.01k
  {
166
4.06k
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
1.01k
  }
168
722k
  else if ((tag == 0xa030) && (len == 9))
169
949
  {
170
3.79k
    for (i = 0; i < 3; i++)
171
8.54k
      FORC3 imgdata.color.ccm[i][c] =
172
8.54k
          (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f;
173
949
  }
174
721k
  else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
175
1.72k
  {
176
1.72k
    double aRGB_cam[3][3];
177
1.72k
    FORC(9)
178
15.4k
    ((double *)aRGB_cam)[c] =
179
15.4k
        ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
180
1.72k
    aRGB_coeff(aRGB_cam);
181
1.72k
  }
182
786k
}