Coverage Report

Created: 2026-09-13 07:02

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
162k
{
21
162k
  int i, c;
22
162k
  if (tag == 0x0002)
23
2.51k
  {
24
2.51k
    imSamsung.DeviceType = get4();
25
2.51k
    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.43k
    else if (!strncmp(model, "NX mini", 7))
31
358
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
358
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
358
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
358
    }
35
2.08k
    else
36
2.08k
    {
37
2.08k
      ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
38
2.08k
      ilm.LensMount = LIBRAW_MOUNT_FixedLens;
39
2.08k
    }
40
2.51k
  }
41
159k
  else if (tag == 0x0003)
42
1.02k
  {
43
1.02k
    ilm.CamID = unique_id = get4();
44
1.02k
  }
45
158k
  else if (tag == 0x0043)
46
1.70k
  {
47
1.70k
    if ((i = get4()))
48
1.30k
    {
49
1.30k
      imCommon.CameraTemperature = (float)i;
50
1.30k
      if (get4() == 10)
51
118
        imCommon.CameraTemperature /= 10.0f;
52
1.30k
    }
53
1.70k
  }
54
156k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
883
  {
56
883
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
883
  }
58
156k
  else if (tag == 0xa003)
59
2.44k
  {
60
2.44k
    ilm.LensID = get2();
61
2.44k
    if (ilm.LensID)
62
1.00k
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
2.44k
  }
64
153k
  else if (tag == 0xa004)
65
1.04k
  { // LensFirmware
66
1.04k
    stmread(imSamsung.LensFirmware, len, ifp);
67
1.04k
  }
68
152k
  else if (tag == 0xa005)
69
651
  {
70
651
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
651
  }
72
151k
  else if (tag == 0xa010)
73
1.66k
  {
74
6.67k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
6.67k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
1.66k
  }
77
150k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
760
  {
79
760
    imSamsung.ColorSpace[0] = (int)get2();
80
760
    switch (imSamsung.ColorSpace[0]) {
81
68
    case 0:
82
68
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
68
      break;
84
145
    case 1:
85
145
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
145
      break;
87
547
    default:
88
547
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
547
      break;
90
760
    }
91
760
    if (len == 2)
92
325
      imSamsung.ColorSpace[1] = (int)get2();
93
760
  }
94
149k
  else if (tag == 0xa019)
95
593
  {
96
593
    ilm.CurAp = getrealf(type);
97
593
  }
98
148k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
478
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
438
  {
101
438
    ilm.FocalLengthIn35mmFormat = float(get4());
102
438
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
101
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
438
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
238
        (imSamsung.LensFirmware[10] < '6'))
106
238
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
438
  }
108
148k
  else if (tag == 0xa020)
109
163
  {
110
1.79k
    FORC(11) imSamsung.key[c] = get4();
111
163
  }
112
148k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
492
  {
114
1.96k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
492
  }
116
147k
  else if (tag == 0xa022)
117
798
  {
118
3.19k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
3.19k
        get4() - imSamsung.key[c + 4];
120
798
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
798
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
403
    {
123
403
      icWBC[LIBRAW_WBI_Auto][1] =
124
403
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
403
      icWBC[LIBRAW_WBI_Auto][3] =
126
403
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
403
    }
128
798
  }
129
146k
  else if (tag == 0xa023)
130
2.34k
  {
131
2.34k
    ushort ki[4] = {8, 9, 10, 0};
132
9.36k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
9.36k
        get4() - imSamsung.key[ki[c]];
134
2.34k
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
2.34k
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
1.30k
    {
137
1.30k
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
1.30k
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
1.30k
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
1.30k
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
1.30k
    }
142
2.34k
  }
143
144k
  else if (tag == 0xa024)
144
1.48k
  {
145
5.93k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
5.93k
        get4() - imSamsung.key[c + 1];
147
1.48k
    if (icWBC[LIBRAW_WBI_D65][0] <
148
1.48k
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
675
    {
150
675
      icWBC[LIBRAW_WBI_D65][1] =
151
675
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
675
      icWBC[LIBRAW_WBI_D65][3] =
153
675
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
675
    }
155
1.48k
  }
156
143k
  else if (tag == 0xa025)
157
821
  {
158
821
    unsigned t = get4() + imSamsung.key[0];
159
821
    if (t == 4096)
160
102
      imSamsung.DigitalGain = 1.0;
161
719
    else
162
719
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
821
  }
164
142k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
140
  {
166
560
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
140
  }
168
142k
  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
141k
  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
162k
}