Coverage Report

Created: 2026-08-17 07:50

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