Coverage Report

Created: 2026-09-15 07:01

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
766k
{
21
766k
  int i, c;
22
766k
  if (tag == 0x0002)
23
8.20k
  {
24
8.20k
    imSamsung.DeviceType = get4();
25
8.20k
    if (imSamsung.DeviceType == 0x2000)
26
936
    {
27
936
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
28
936
      ilm.CameraFormat = LIBRAW_FORMAT_APSC;
29
936
    }
30
7.27k
    else if (!strncmp(model, "NX mini", 7))
31
1.78k
    { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
32
1.78k
      ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
33
1.78k
      ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
34
1.78k
    }
35
5.48k
    else
36
5.48k
    {
37
5.48k
      ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
38
5.48k
      ilm.LensMount = LIBRAW_MOUNT_FixedLens;
39
5.48k
    }
40
8.20k
  }
41
758k
  else if (tag == 0x0003)
42
5.28k
  {
43
5.28k
    ilm.CamID = unique_id = get4();
44
5.28k
  }
45
752k
  else if (tag == 0x0043)
46
3.87k
  {
47
3.87k
    if ((i = get4()))
48
1.94k
    {
49
1.94k
      imCommon.CameraTemperature = (float)i;
50
1.94k
      if (get4() == 10)
51
184
        imCommon.CameraTemperature /= 10.0f;
52
1.94k
    }
53
3.87k
  }
54
749k
  else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
55
5.30k
  {
56
5.30k
    stmread(imgdata.shootinginfo.BodySerial, len, ifp);
57
5.30k
  }
58
743k
  else if (tag == 0xa003)
59
4.63k
  {
60
4.63k
    ilm.LensID = get2();
61
4.63k
    if (ilm.LensID)
62
2.82k
      ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
63
4.63k
  }
64
739k
  else if (tag == 0xa004)
65
4.06k
  { // LensFirmware
66
4.06k
    stmread(imSamsung.LensFirmware, len, ifp);
67
4.06k
  }
68
735k
  else if (tag == 0xa005)
69
2.05k
  {
70
2.05k
    stmread(imgdata.lens.InternalLensSerial, len, ifp);
71
2.05k
  }
72
732k
  else if (tag == 0xa010)
73
3.51k
  {
74
14.0k
    FORC4 imSamsung.ImageSizeFull[c] = get4();
75
14.0k
    FORC4 imSamsung.ImageSizeCrop[c] = get4();
76
3.51k
  }
77
729k
  else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
78
4.52k
  {
79
4.52k
    imSamsung.ColorSpace[0] = (int)get2();
80
4.52k
    switch (imSamsung.ColorSpace[0]) {
81
1.10k
    case 0:
82
1.10k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
83
1.10k
      break;
84
1.52k
    case 1:
85
1.52k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
86
1.52k
      break;
87
1.89k
    default:
88
1.89k
      imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
89
1.89k
      break;
90
4.52k
    }
91
4.52k
    if (len == 2)
92
2.31k
      imSamsung.ColorSpace[1] = (int)get2();
93
4.52k
  }
94
724k
  else if (tag == 0xa019)
95
1.67k
  {
96
1.67k
    ilm.CurAp = getrealf(type);
97
1.67k
  }
98
723k
  else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
99
5.87k
           (!imgdata.lens.FocalLengthIn35mmFormat))
100
3.36k
  {
101
3.36k
    ilm.FocalLengthIn35mmFormat = float(get4());
102
3.36k
    if (ilm.FocalLengthIn35mmFormat >= 160)
103
1.82k
      ilm.FocalLengthIn35mmFormat /= 10.0f;
104
3.36k
    if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
105
867
        (imSamsung.LensFirmware[10] < '6'))
106
710
      ilm.FocalLengthIn35mmFormat *= 1.6f;
107
3.36k
  }
108
719k
  else if (tag == 0xa020)
109
1.40k
  {
110
15.4k
    FORC(11) imSamsung.key[c] = get4();
111
1.40k
  }
112
718k
  else if ((tag == 0xa021) && (dng_writer == nonDNG))
113
1.54k
  {
114
6.19k
    FORC4 cam_mul[RGGB_2_RGBG(c)] = float(get4() - imSamsung.key[c]);
115
1.54k
  }
116
716k
  else if (tag == 0xa022)
117
5.68k
  {
118
22.7k
    FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
119
22.7k
        get4() - imSamsung.key[c + 4];
120
5.68k
    if (icWBC[LIBRAW_WBI_Auto][0] <
121
5.68k
        (icWBC[LIBRAW_WBI_Auto][1] >> 1))
122
1.47k
    {
123
1.47k
      icWBC[LIBRAW_WBI_Auto][1] =
124
1.47k
          icWBC[LIBRAW_WBI_Auto][1] >> 4;
125
1.47k
      icWBC[LIBRAW_WBI_Auto][3] =
126
1.47k
          icWBC[LIBRAW_WBI_Auto][3] >> 4;
127
1.47k
    }
128
5.68k
  }
129
711k
  else if (tag == 0xa023)
130
2.92k
  {
131
2.92k
    ushort ki[4] = {8, 9, 10, 0};
132
11.6k
    FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
133
11.6k
        get4() - imSamsung.key[ki[c]];
134
2.92k
    if (icWBC[LIBRAW_WBI_Ill_A][0] <
135
2.92k
        (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
136
1.45k
    {
137
1.45k
      icWBC[LIBRAW_WBI_Ill_A][1] =
138
1.45k
          icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
139
1.45k
      icWBC[LIBRAW_WBI_Ill_A][3] =
140
1.45k
          icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
141
1.45k
    }
142
2.92k
  }
143
708k
  else if (tag == 0xa024)
144
6.27k
  {
145
25.1k
    FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
146
25.1k
        get4() - imSamsung.key[c + 1];
147
6.27k
    if (icWBC[LIBRAW_WBI_D65][0] <
148
6.27k
        (icWBC[LIBRAW_WBI_D65][1] >> 1))
149
2.59k
    {
150
2.59k
      icWBC[LIBRAW_WBI_D65][1] =
151
2.59k
          icWBC[LIBRAW_WBI_D65][1] >> 4;
152
2.59k
      icWBC[LIBRAW_WBI_D65][3] =
153
2.59k
          icWBC[LIBRAW_WBI_D65][3] >> 4;
154
2.59k
    }
155
6.27k
  }
156
702k
  else if (tag == 0xa025)
157
2.27k
  {
158
2.27k
    unsigned t = get4() + imSamsung.key[0];
159
2.27k
    if (t == 4096)
160
808
      imSamsung.DigitalGain = 1.0;
161
1.46k
    else
162
1.46k
      imSamsung.DigitalGain = ((double)t) / 4096.0;
163
2.27k
  }
164
699k
  else if ((tag == 0xa028) && (dng_writer == nonDNG))
165
1.32k
  {
166
5.30k
    FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
167
1.32k
  }
168
698k
  else if ((tag == 0xa030) && (len == 9))
169
1.38k
  {
170
5.55k
    for (i = 0; i < 3; i++)
171
12.4k
      FORC3 imgdata.color.ccm[i][c] =
172
12.4k
          (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.f;
173
1.38k
  }
174
697k
  else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
175
1.74k
  {
176
1.74k
    double aRGB_cam[3][3];
177
1.74k
    FORC(9)
178
15.6k
    ((double *)aRGB_cam)[c] =
179
15.6k
        ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
180
1.74k
    aRGB_coeff(aRGB_cam);
181
1.74k
  }
182
766k
}