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