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

0001 /* -*- C++ -*-
0002  * Copyright 2019-2021 LibRaw LLC (info@libraw.org)
0003  *
0004  LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder,
0005  dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net.
0006  LibRaw do not use RESTRICTED code from dcraw.c
0007 
0008  LibRaw is free software; you can redistribute it and/or modify
0009  it under the terms of the one of two licenses as you choose:
0010 
0011 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
0012    (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
0013 
0014 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
0015    (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
0016 
0017  */
0018 
0019 #include "../../internal/dcraw_defs.h"
0020 
0021 void LibRaw::parse_minolta(int base)
0022 {
0023   int tag, len, offset, high = 0, wide = 0, i, c;
0024   short sorder = order;
0025   INT64 save;
0026 
0027   fseek(ifp, base, SEEK_SET);
0028   if (fgetc(ifp) || fgetc(ifp) - 'M' || fgetc(ifp) - 'R')
0029     return;
0030   order = fgetc(ifp) * 0x101;
0031   offset = base + get4() + 8;
0032   INT64 fsize = ifp->size();
0033   if (offset > fsize - 8) // At least 8 bytes for tag/len
0034     offset = fsize - 8;
0035 
0036   while ((save = ftell(ifp)) < offset)
0037   {
0038     for (tag = i = 0; i < 4; i++)
0039       tag = tag << 8 | fgetc(ifp);
0040     len = get4();
0041     if (len < 0)
0042       return; // just ignore wrong len?? or raise bad file exception?
0043     if ((INT64)len + save + 8LL > fsize)
0044       return; // just ignore out of file metadata, stop parse
0045     switch (tag)
0046     {
0047     case 0x505244: /* PRD */
0048       fseek(ifp, 8, SEEK_CUR);
0049       high = get2();
0050       wide = get2();
0051       imSony.prd_ImageHeight = get2();
0052       imSony.prd_ImageWidth = get2();
0053       imSony.prd_Total_bps = (ushort)fgetc(ifp);
0054       imSony.prd_Active_bps = (ushort)fgetc(ifp);
0055       imSony.prd_StorageMethod = (ushort)fgetc(ifp);
0056       fseek(ifp, 4L, SEEK_CUR);
0057       imSony.prd_BayerPattern = (ushort)fgetc(ifp);
0058       break;
0059     case 0x524946: /* RIF */
0060       fseek(ifp, 8, SEEK_CUR);
0061       icWBC[LIBRAW_WBI_Tungsten][0] = get2();
0062       icWBC[LIBRAW_WBI_Tungsten][2] = get2();
0063       icWBC[LIBRAW_WBI_Daylight][0] = get2();
0064       icWBC[LIBRAW_WBI_Daylight][2] = get2();
0065       icWBC[LIBRAW_WBI_Cloudy][0] = get2();
0066       icWBC[LIBRAW_WBI_Cloudy][2] = get2();
0067       icWBC[LIBRAW_WBI_FL_W][0] = get2();
0068       icWBC[LIBRAW_WBI_FL_W][2] = get2();
0069       icWBC[LIBRAW_WBI_Flash][0] = get2();
0070       icWBC[LIBRAW_WBI_Flash][2] = get2();
0071       icWBC[LIBRAW_WBI_Custom][0] = get2();
0072       icWBC[LIBRAW_WBI_Custom][2] = get2();
0073       icWBC[LIBRAW_WBI_Tungsten][1] = icWBC[LIBRAW_WBI_Tungsten][3] =
0074         icWBC[LIBRAW_WBI_Daylight][1] = icWBC[LIBRAW_WBI_Daylight][3] =
0075         icWBC[LIBRAW_WBI_Cloudy][1] = icWBC[LIBRAW_WBI_Cloudy][3] =
0076         icWBC[LIBRAW_WBI_FL_W][1] = icWBC[LIBRAW_WBI_FL_W][3] =
0077         icWBC[LIBRAW_WBI_Flash][1] = icWBC[LIBRAW_WBI_Flash][3] =
0078         icWBC[LIBRAW_WBI_Custom][1] = icWBC[LIBRAW_WBI_Custom][3] = 0x100;
0079       if (!strncasecmp(model, "DSLR-A100", 9)) {
0080         icWBC[LIBRAW_WBI_Shade][0] = get2();
0081         icWBC[LIBRAW_WBI_Shade][2] = get2();
0082         icWBC[LIBRAW_WBI_FL_D][0] = get2();
0083         icWBC[LIBRAW_WBI_FL_D][2] = get2();
0084         icWBC[LIBRAW_WBI_FL_N][0] = get2();
0085         icWBC[LIBRAW_WBI_FL_N][2] = get2();
0086         icWBC[LIBRAW_WBI_FL_WW][0] = get2();
0087         icWBC[LIBRAW_WBI_FL_WW][2] = get2();
0088         icWBC[LIBRAW_WBI_Shade][1] = icWBC[LIBRAW_WBI_Shade][3] =
0089           icWBC[LIBRAW_WBI_FL_D][1] = icWBC[LIBRAW_WBI_FL_D][3] =
0090           icWBC[LIBRAW_WBI_FL_N][1] = icWBC[LIBRAW_WBI_FL_N][3] =
0091           icWBC[LIBRAW_WBI_FL_WW][1] = icWBC[LIBRAW_WBI_FL_WW][3] = 0x0100;
0092       }
0093       break;
0094     case 0x574247: /* WBG */
0095       get4();
0096       if (imSony.prd_BayerPattern == LIBRAW_MINOLTA_G2BRG1)
0097         FORC4 cam_mul[G2BRG1_2_RGBG(c)] = get2();
0098       else
0099         FORC4 cam_mul[RGGB_2_RGBG(c)] = get2();
0100       break;
0101     case 0x545457: /* TTW */
0102       parse_tiff(ftell(ifp));
0103       data_offset = offset;
0104     }
0105     fseek(ifp, save + len + 8, SEEK_SET);
0106   }
0107   raw_height = high;
0108   raw_width = wide;
0109   order = sorder;
0110 }