Coverage Report

Created: 2026-04-01 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/LibRaw/src/metadata/minolta.cpp
Line
Count
Source
1
/* -*- C++ -*-
2
 * Copyright 2019-2025 LibRaw LLC (info@libraw.org)
3
 *
4
 LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder,
5
 dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net.
6
 LibRaw do not use RESTRICTED code from dcraw.c
7
8
 LibRaw is free software; you can redistribute it and/or modify
9
 it under the terms of the one of two licenses as you choose:
10
11
1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1
12
   (See file LICENSE.LGPL provided in LibRaw distribution archive for details).
13
14
2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
15
   (See file LICENSE.CDDL provided in LibRaw distribution archive for details).
16
17
 */
18
19
#include "../../internal/dcraw_defs.h"
20
21
void LibRaw::parse_minolta(INT64 base)
22
20.3k
{
23
20.3k
  int tag, len, high = 0, wide = 0, i, c;
24
20.3k
  short sorder = order;
25
20.3k
  INT64 save,offset;
26
27
20.3k
  fseek(ifp, base, SEEK_SET);
28
20.3k
  if (fgetc(ifp) || fgetc(ifp) - 'M' || fgetc(ifp) - 'R')
29
19.8k
    return;
30
540
  order = fgetc(ifp) * 0x101;
31
540
  offset = base + get4() + 8;
32
540
  INT64 fsize = ifp->size();
33
540
  if (offset > fsize - 8LL) // At least 8 bytes for tag/len
34
340
    offset = fsize - 8LL;
35
36
1.40k
  while ((save = ftell(ifp)) < offset)
37
1.30k
  {
38
6.52k
    for (tag = i = 0; i < 4; i++)
39
5.21k
      tag = tag << 8 | fgetc(ifp);
40
1.30k
    len = get4();
41
1.30k
    if (len < 0)
42
276
      return; // just ignore wrong len?? or raise bad file exception?
43
1.02k
    if ((INT64)len + save + 8LL > fsize)
44
166
      return; // just ignore out of file metadata, stop parse
45
862
    switch (tag)
46
862
    {
47
14
    case 0x505244: /* PRD */
48
14
      fseek(ifp, 8, SEEK_CUR);
49
14
      high = get2();
50
14
      wide = get2();
51
14
      imSony.prd_ImageHeight = get2();
52
14
      imSony.prd_ImageWidth = get2();
53
14
      imSony.prd_Total_bps = (ushort)fgetc(ifp);
54
14
      imSony.prd_Active_bps = (ushort)fgetc(ifp);
55
14
      imSony.prd_StorageMethod = (ushort)fgetc(ifp);
56
14
      fseek(ifp, 4L, SEEK_CUR);
57
14
      imSony.prd_BayerPattern = (ushort)fgetc(ifp);
58
14
      break;
59
8
    case 0x524946: /* RIF */
60
8
      fseek(ifp, 8, SEEK_CUR);
61
8
      icWBC[LIBRAW_WBI_Tungsten][0] = get2();
62
8
      icWBC[LIBRAW_WBI_Tungsten][2] = get2();
63
8
      icWBC[LIBRAW_WBI_Daylight][0] = get2();
64
8
      icWBC[LIBRAW_WBI_Daylight][2] = get2();
65
8
      icWBC[LIBRAW_WBI_Cloudy][0] = get2();
66
8
      icWBC[LIBRAW_WBI_Cloudy][2] = get2();
67
8
      icWBC[LIBRAW_WBI_FL_W][0] = get2();
68
8
      icWBC[LIBRAW_WBI_FL_W][2] = get2();
69
8
      icWBC[LIBRAW_WBI_Flash][0] = get2();
70
8
      icWBC[LIBRAW_WBI_Flash][2] = get2();
71
8
      icWBC[LIBRAW_WBI_Custom][0] = get2();
72
8
      icWBC[LIBRAW_WBI_Custom][2] = get2();
73
8
      icWBC[LIBRAW_WBI_Tungsten][1] = icWBC[LIBRAW_WBI_Tungsten][3] =
74
8
        icWBC[LIBRAW_WBI_Daylight][1] = icWBC[LIBRAW_WBI_Daylight][3] =
75
8
        icWBC[LIBRAW_WBI_Cloudy][1] = icWBC[LIBRAW_WBI_Cloudy][3] =
76
8
        icWBC[LIBRAW_WBI_FL_W][1] = icWBC[LIBRAW_WBI_FL_W][3] =
77
8
        icWBC[LIBRAW_WBI_Flash][1] = icWBC[LIBRAW_WBI_Flash][3] =
78
8
        icWBC[LIBRAW_WBI_Custom][1] = icWBC[LIBRAW_WBI_Custom][3] = 0x100;
79
8
      if (!strncasecmp(model, "DSLR-A100", 9)) {
80
0
        icWBC[LIBRAW_WBI_Shade][0] = get2();
81
0
        icWBC[LIBRAW_WBI_Shade][2] = get2();
82
0
        icWBC[LIBRAW_WBI_FL_D][0] = get2();
83
0
        icWBC[LIBRAW_WBI_FL_D][2] = get2();
84
0
        icWBC[LIBRAW_WBI_FL_N][0] = get2();
85
0
        icWBC[LIBRAW_WBI_FL_N][2] = get2();
86
0
        icWBC[LIBRAW_WBI_FL_WW][0] = get2();
87
0
        icWBC[LIBRAW_WBI_FL_WW][2] = get2();
88
0
        icWBC[LIBRAW_WBI_Shade][1] = icWBC[LIBRAW_WBI_Shade][3] =
89
0
          icWBC[LIBRAW_WBI_FL_D][1] = icWBC[LIBRAW_WBI_FL_D][3] =
90
0
          icWBC[LIBRAW_WBI_FL_N][1] = icWBC[LIBRAW_WBI_FL_N][3] =
91
0
          icWBC[LIBRAW_WBI_FL_WW][1] = icWBC[LIBRAW_WBI_FL_WW][3] = 0x0100;
92
0
      }
93
8
      break;
94
90
    case 0x574247: /* WBG */
95
90
      get4();
96
90
      if (imSony.prd_BayerPattern == LIBRAW_MINOLTA_G2BRG1)
97
0
        FORC4 cam_mul[G2BRG1_2_RGBG(c)] = get2();
98
90
      else
99
360
        FORC4 cam_mul[RGGB_2_RGBG(c)] = get2();
100
90
      break;
101
36
    case 0x545457: /* TTW */
102
36
      parse_tiff(ftell(ifp));
103
36
      data_offset = offset;
104
862
    }
105
862
    fseek(ifp, save + len + 8, SEEK_SET);
106
862
  }
107
98
  raw_height = high;
108
98
  raw_width = wide;
109
98
  order = sorder;
110
98
}