Coverage Report

Created: 2026-06-30 07:12

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
112k
{
21
112k
  int i, c;
22
112k
  if (tag == 0x0002)
23
2.10k
  {
24
2.10k
    imSamsung.DeviceType = get4();
25
2.10k
    if (imSamsung.DeviceType == 0x2000)
26
78
    {
27
78
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
28
78
      ilm.CameraFormat = LIBRAW_FORMAT_APSC;
29
78
    }
30
2.02k
    else if (!strncmp(model, "NX mini", 7))
31
381
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
381
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
381
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
381
    }
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.10k
  }
41
110k
  else if (tag == 0x0003)
42
523
  {
43
523
    ilm.CamID = unique_id = get4();
44
523
  }
45
109k
  else if (tag == 0x0043)
46
1.09k
  {
47
1.09k
    if ((i = get4()))
48
774
    {
49
774
      imCommon.CameraTemperature = (float)i;
50
774
      if (get4() == 10)
51
36
        imCommon.CameraTemperature /= 10.0f;
52
774
    }
53
1.09k
  }
54
108k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
259
  {
56
259
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
259
  }
58
108k
  else if (tag == 0xa003)
59
1.65k
  {
60
1.65k
    ilm.LensID = get2();
61
1.65k
    if (ilm.LensID)
62
588
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
1.65k
  }
64
106k
  else if (tag == 0xa004)
65
940
  { // LensFirmware
66
940
    stmread(imSamsung.LensFirmware, len, ifp);
67
940
  }
68
105k
  else if (tag == 0xa005)
69
386
  {
70
386
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
386
  }
72
105k
  else if (tag == 0xa010)
73
1.32k
  {
74
5.29k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
5.29k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
1.32k
  }
77
104k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
621
  {
79
621
    imSamsung.ColorSpace[0] = (int)get2();
80
621
    switch (imSamsung.ColorSpace[0]) {
81
46
    case 0:
82
46
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
46
      break;
84
145
    case 1:
85
145
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
145
      break;
87
430
    default:
88
430
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
430
      break;
90
621
    }
91
621
    if (len == 2)
92
46
      imSamsung.ColorSpace[1] = (int)get2();
93
621
  }
94
103k
  else if (tag == 0xa019)
95
588
  {
96
588
    ilm.CurAp = getrealf(type);
97
588
  }
98
102k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
454
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
417
  {
101
417
    ilm.FocalLengthIn35mmFormat = float(get4());
102
417
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
106
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
417
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
238
        (imSamsung.LensFirmware[10] < '6'))
106
238
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
417
  }
108
102k
  else if (tag == 0xa020)
109
171
  {
110
1.88k
    FORC(11) imSamsung.key[c] = get4();
111
171
  }
112
102k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
324
  {
114
1.29k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
324
  }
116
101k
  else if (tag == 0xa022)
117
500
  {
118
2.00k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
2.00k
        get4() - imSamsung.key[c + 4];
120
500
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
500
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
134
    {
123
134
      icWBC[LIBRAW_WBI_Auto][1] =
124
134
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
134
      icWBC[LIBRAW_WBI_Auto][3] =
126
134
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
134
    }
128
500
  }
129
101k
  else if (tag == 0xa023)
130
2.01k
  {
131
2.01k
    ushort ki[4] = {8, 9, 10, 0};
132
8.04k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
8.04k
        get4() - imSamsung.key[ki[c]];
134
2.01k
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
2.01k
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
1.07k
    {
137
1.07k
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
1.07k
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
1.07k
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
1.07k
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
1.07k
    }
142
2.01k
  }
143
99.4k
  else if (tag == 0xa024)
144
1.17k
  {
145
4.68k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
4.68k
        get4() - imSamsung.key[c + 1];
147
1.17k
    if (icWBC[LIBRAW_WBI_D65][0] <
148
1.17k
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
567
    {
150
567
      icWBC[LIBRAW_WBI_D65][1] =
151
567
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
567
      icWBC[LIBRAW_WBI_D65][3] =
153
567
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
567
    }
155
1.17k
  }
156
98.2k
  else if (tag == 0xa025)
157
683
  {
158
683
    unsigned t = get4() + imSamsung.key[0];
159
683
    if (t == 4096)
160
102
      imSamsung.DigitalGain = 1.0;
161
581
    else
162
581
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
683
  }
164
97.6k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
100
  {
166
400
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
100
  }
168
97.5k
  else if ((tag == 0xa030) && (len == 9))
169
275
  {
170
1.10k
    for (i = 0; i < 3; i++)
171
2.47k
      FORC3 imgdata.color.ccm[i][c] =
172
2.47k
          (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f;
173
275
  }
174
97.2k
  else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
175
470
  {
176
470
    double aRGB_cam[3][3];
177
470
    FORC(9)
178
4.23k
    ((double *)aRGB_cam)[c] =
179
4.23k
        ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
180
470
    aRGB_coeff(aRGB_cam);
181
470
  }
182
112k
}