File indexing completed on 2025-01-05 03:57:03

0001 /* -*- C++ -*-
0002  * Copyright 2019-2021 LibRaw LLC (info@libraw.org)
0003  *
0004 
0005  LibRaw is free software; you can redistribute it and/or modify
0006  it under the terms of the one of two licenses as you choose:
0007 
0008 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
0009    (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
0010 
0011 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
0012    (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
0013 
0014  */
0015 
0016 #include "../../internal/dcraw_defs.h"
0017 
0018 void LibRaw::parseSamsungMakernotes(int /*base*/, unsigned tag, unsigned type,
0019                                     unsigned len, unsigned dng_writer)
0020 {
0021   int i, c;
0022   if (tag == 0x0002)
0023   {
0024     imSamsung.DeviceType = get4();
0025     if (imSamsung.DeviceType == 0x2000)
0026     {
0027       ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX;
0028       ilm.CameraFormat = LIBRAW_FORMAT_APSC;
0029     }
0030     else if (!strncmp(model, "NX mini", 7))
0031     { // device type 0x1000: 'NX mini', EX2F, EX1, WB2000
0032       ilm.CameraMount = LIBRAW_MOUNT_Samsung_NX_M;
0033       ilm.CameraFormat = LIBRAW_FORMAT_1INCH;
0034     }
0035     else
0036     {
0037       ilm.CameraMount = LIBRAW_MOUNT_FixedLens;
0038       ilm.LensMount = LIBRAW_MOUNT_FixedLens;
0039     }
0040   }
0041   else if (tag == 0x0003)
0042   {
0043     ilm.CamID = unique_id = get4();
0044   }
0045   else if (tag == 0x0043)
0046   {
0047     if ((i = get4()))
0048     {
0049       imCommon.CameraTemperature = (float)i;
0050       if (get4() == 10)
0051         imCommon.CameraTemperature /= 10.0f;
0052     }
0053   }
0054   else if ((tag == 0xa002) && (dng_writer != AdobeDNG))
0055   {
0056     stmread(imgdata.shootinginfo.BodySerial, len, ifp);
0057   }
0058   else if (tag == 0xa003)
0059   {
0060     ilm.LensID = get2();
0061     if (ilm.LensID)
0062       ilm.LensMount = LIBRAW_MOUNT_Samsung_NX;
0063   }
0064   else if (tag == 0xa004)
0065   { // LensFirmware
0066     stmread(imSamsung.LensFirmware, len, ifp);
0067   }
0068   else if (tag == 0xa005)
0069   {
0070     stmread(imgdata.lens.InternalLensSerial, len, ifp);
0071   }
0072   else if (tag == 0xa010)
0073   {
0074     FORC4 imSamsung.ImageSizeFull[c] = get4();
0075     FORC4 imSamsung.ImageSizeCrop[c] = get4();
0076   }
0077   else if ((tag == 0xa011) && ((len == 1) || (len == 2)) && tagtypeIs(LIBRAW_EXIFTAG_TYPE_SHORT))
0078   {
0079     imSamsung.ColorSpace[0] = (int)get2();
0080         switch (imSamsung.ColorSpace[0]) {
0081         case 0:
0082             imCommon.ColorSpace = LIBRAW_COLORSPACE_sRGB;
0083             break;
0084         case 1:
0085             imCommon.ColorSpace = LIBRAW_COLORSPACE_AdobeRGB;
0086             break;
0087         default:
0088             imCommon.ColorSpace = LIBRAW_COLORSPACE_Unknown;
0089             break;
0090         }
0091     if (len == 2)
0092       imSamsung.ColorSpace[1] = (int)get2();
0093   }
0094   else if (tag == 0xa019)
0095   {
0096     ilm.CurAp = getreal(type);
0097   }
0098   else if ((tag == 0xa01a) && (unique_id != 0x5000000) &&
0099            (!imgdata.lens.FocalLengthIn35mmFormat))
0100   {
0101     ilm.FocalLengthIn35mmFormat = get4();
0102     if (ilm.FocalLengthIn35mmFormat >= 160)
0103       ilm.FocalLengthIn35mmFormat /= 10.0f;
0104     if ((ilm.CameraMount == LIBRAW_MOUNT_Samsung_NX_M) &&
0105         (imSamsung.LensFirmware[10] < '6'))
0106       ilm.FocalLengthIn35mmFormat *= 1.6f;
0107   }
0108   else if (tag == 0xa020)
0109   {
0110     FORC(11) imSamsung.key[c] = get4();
0111   }
0112   else if ((tag == 0xa021) && (dng_writer == nonDNG))
0113   {
0114     FORC4 cam_mul[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
0115   }
0116   else if (tag == 0xa022)
0117   {
0118     FORC4 icWBC[LIBRAW_WBI_Auto][RGGB_2_RGBG(c)] =
0119         get4() - imSamsung.key[c + 4];
0120     if (icWBC[LIBRAW_WBI_Auto][0] <
0121         (icWBC[LIBRAW_WBI_Auto][1] >> 1))
0122     {
0123       icWBC[LIBRAW_WBI_Auto][1] =
0124           icWBC[LIBRAW_WBI_Auto][1] >> 4;
0125       icWBC[LIBRAW_WBI_Auto][3] =
0126           icWBC[LIBRAW_WBI_Auto][3] >> 4;
0127     }
0128   }
0129   else if (tag == 0xa023)
0130   {
0131     ushort ki[4] = {8, 9, 10, 0};
0132     FORC4 icWBC[LIBRAW_WBI_Ill_A][RGGB_2_RGBG(c)] =
0133         get4() - imSamsung.key[ki[c]];
0134     if (icWBC[LIBRAW_WBI_Ill_A][0] <
0135         (icWBC[LIBRAW_WBI_Ill_A][1] >> 1))
0136     {
0137       icWBC[LIBRAW_WBI_Ill_A][1] =
0138           icWBC[LIBRAW_WBI_Ill_A][1] >> 4;
0139       icWBC[LIBRAW_WBI_Ill_A][3] =
0140           icWBC[LIBRAW_WBI_Ill_A][3] >> 4;
0141     }
0142   }
0143   else if (tag == 0xa024)
0144   {
0145     FORC4 icWBC[LIBRAW_WBI_D65][RGGB_2_RGBG(c)] =
0146         get4() - imSamsung.key[c + 1];
0147     if (icWBC[LIBRAW_WBI_D65][0] <
0148         (icWBC[LIBRAW_WBI_D65][1] >> 1))
0149     {
0150       icWBC[LIBRAW_WBI_D65][1] =
0151           icWBC[LIBRAW_WBI_D65][1] >> 4;
0152       icWBC[LIBRAW_WBI_D65][3] =
0153           icWBC[LIBRAW_WBI_D65][3] >> 4;
0154     }
0155   }
0156   else if (tag == 0xa025)
0157   {
0158     unsigned t = get4() + imSamsung.key[0];
0159     if (t == 4096)
0160       imSamsung.DigitalGain = 1.0;
0161     else
0162       imSamsung.DigitalGain = ((double)t) / 4096.0;
0163   }
0164   else if ((tag == 0xa028) && (dng_writer == nonDNG))
0165   {
0166     FORC4 cblack[RGGB_2_RGBG(c)] = get4() - imSamsung.key[c];
0167   }
0168   else if ((tag == 0xa030) && (len == 9))
0169   {
0170     for (i = 0; i < 3; i++)
0171       FORC3 imgdata.color.ccm[i][c] =
0172           (float)((short)((get4() + imSamsung.key[i * 3 + c]))) / 256.0;
0173   }
0174   else if ((tag == 0xa032) && (len == 9) && (dng_writer == nonDNG))
0175   {
0176     double aRGB_cam[3][3];
0177     FORC(9)
0178     ((double *)aRGB_cam)[c] =
0179         ((double)((short)((get4() + imSamsung.key[c])))) / 256.0;
0180     aRGB_coeff(aRGB_cam);
0181   }
0182 }