Coverage Report

Created: 2025-07-11 06:35

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