Coverage Report

Created: 2026-11-12 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libraw/src/decoders/generic.cpp
Line
Count
Source
1
/* -*- C++ -*-
2
 * Copyright 2019-2026 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::unpacked_load_raw()
22
129
{
23
129
  int row, col, bits = 0;
24
1.73k
  while (1 << ++bits < (int)maximum)
25
1.60k
    ;
26
129
  read_shorts(raw_image, raw_width * raw_height);
27
129
  fseek(ifp, -2, SEEK_CUR); // avoid EOF error
28
129
  if (maximum < 0xffff || load_flags)
29
1.91k
    for (row = 0; row < raw_height; row++)
30
1.85k
    {
31
1.85k
      checkCancel();
32
52.4k
      for (col = 0; col < raw_width; col++)
33
50.5k
        if ((RAW(row, col) >>= load_flags) >> bits &&
34
28.2k
            (unsigned)(row - top_margin) < height &&
35
27.7k
            (unsigned)(col - left_margin) < width)
36
27.1k
          derror();
37
1.85k
    }
38
129
}
39
40
void LibRaw::packed_load_raw()
41
87
{
42
87
  int vbits = 0, bwide, rbits, bite, half, irow, row, col, val, i;
43
87
  UINT64 bitbuf = 0;
44
45
87
  bwide = raw_width * tiff_bps / 8;
46
87
  bwide += bwide & load_flags >> 7;
47
87
  rbits = bwide * 8 - raw_width * tiff_bps;
48
87
  if (load_flags & 1)
49
35
    bwide = bwide * 16 / 15;
50
87
  bite = 8 + (load_flags & 24);
51
87
  half = (raw_height + 1) >> 1;
52
1.71k
  for (irow = 0; irow < raw_height; irow++)
53
1.69k
  {
54
1.69k
    checkCancel();
55
1.69k
    row = irow;
56
1.69k
    if (load_flags & 2 && (row = irow % half * 2 + irow / half) == 1 &&
57
2
        load_flags & 4)
58
1
    {
59
1
      if (vbits = 0, tiff_compress)
60
1
        fseek(ifp, data_offset - (-half * bwide & -2048), SEEK_SET);
61
0
      else
62
0
      {
63
0
        fseek(ifp, 0, SEEK_END);
64
0
        fseek(ifp, ftell(ifp) >> 3 << 2, SEEK_SET);
65
0
      }
66
1
    }
67
1.69k
    if (feof(ifp))
68
74
      throw LIBRAW_EXCEPTION_IO_EOF;
69
191k
    for (col = 0; col < raw_width; col++)
70
189k
    {
71
264k
      for (vbits -= tiff_bps; vbits < 0; vbits += bite)
72
74.8k
      {
73
74.8k
        bitbuf <<= bite;
74
166k
        for (i = 0; i < bite; i += 8)
75
91.6k
          bitbuf |= (unsigned(fgetc(ifp)) << i);
76
74.8k
      }
77
189k
      val = int((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0x7fffffff);
78
189k
      RAW(row, col ^ (load_flags >> 6 & 1)) = val;
79
189k
      if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) &&
80
7.73k
          row < height + top_margin && col < width + left_margin)
81
7.11k
        derror();
82
189k
    }
83
1.62k
    vbits -= rbits;
84
1.62k
  }
85
87
}
86
87
void LibRaw::eight_bit_load_raw()
88
21
{
89
21
  unsigned row, col;
90
91
21
  std::vector<uchar> pixel(raw_width);
92
333
  for (row = 0; row < raw_height; row++)
93
312
  {
94
312
      checkCancel();
95
312
      if (fread(pixel.data(), 1, raw_width, ifp) < raw_width)
96
18
          derror();
97
8.66k
      for (col = 0; col < raw_width; col++)
98
8.35k
          RAW(row, col) = curve[pixel[col]];
99
312
  }
100
21
  maximum = curve[0xff];
101
21
}