Coverage Report

Created: 2026-10-27 06:57

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-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::unpacked_load_raw()
22
282
{
23
282
  int row, col, bits = 0;
24
3.93k
  while (1 << ++bits < (int)maximum)
25
3.64k
    ;
26
282
  read_shorts(raw_image, raw_width * raw_height);
27
282
  fseek(ifp, -2, SEEK_CUR); // avoid EOF error
28
282
  if (maximum < 0xffff || load_flags)
29
5.78k
    for (row = 0; row < raw_height; row++)
30
5.68k
    {
31
5.68k
      checkCancel();
32
174k
      for (col = 0; col < raw_width; col++)
33
168k
        if ((RAW(row, col) >>= load_flags) >> bits &&
34
30.5k
            (unsigned)(row - top_margin) < height &&
35
27.9k
            (unsigned)(col - left_margin) < width)
36
25.7k
          derror();
37
5.68k
    }
38
282
}
39
40
void LibRaw::packed_load_raw()
41
107
{
42
107
  int vbits = 0, bwide, rbits, bite, half, irow, row, col, val, i;
43
107
  UINT64 bitbuf = 0;
44
45
107
  bwide = raw_width * tiff_bps / 8;
46
107
  bwide += bwide & load_flags >> 7;
47
107
  rbits = bwide * 8 - raw_width * tiff_bps;
48
107
  if (load_flags & 1)
49
42
    bwide = bwide * 16 / 15;
50
107
  bite = 8 + (load_flags & 24);
51
107
  half = (raw_height + 1) >> 1;
52
2.42k
  for (irow = 0; irow < raw_height; irow++)
53
2.41k
  {
54
2.41k
    checkCancel();
55
2.41k
    row = irow;
56
2.41k
    if (load_flags & 2 && (row = irow % half * 2 + irow / half) == 1 &&
57
3
        load_flags & 4)
58
2
    {
59
2
      if (vbits = 0, tiff_compress)
60
1
        fseek(ifp, data_offset - (-half * bwide & -2048), SEEK_SET);
61
1
      else
62
1
      {
63
1
        fseek(ifp, 0, SEEK_END);
64
1
        fseek(ifp, ftell(ifp) >> 3 << 2, SEEK_SET);
65
1
      }
66
2
    }
67
2.41k
    if (feof(ifp))
68
101
      throw LIBRAW_EXCEPTION_IO_EOF;
69
389k
    for (col = 0; col < raw_width; col++)
70
386k
    {
71
667k
      for (vbits -= tiff_bps; vbits < 0; vbits += bite)
72
280k
      {
73
280k
        bitbuf <<= bite;
74
607k
        for (i = 0; i < bite; i += 8)
75
326k
          bitbuf |= (unsigned(fgetc(ifp)) << i);
76
280k
      }
77
386k
      val = int((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0x7fffffff);
78
386k
      RAW(row, col ^ (load_flags >> 6 & 1)) = val;
79
386k
      if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) &&
80
16.2k
          row < height + top_margin && col < width + left_margin)
81
15.5k
        derror();
82
386k
    }
83
2.31k
    vbits -= rbits;
84
2.31k
  }
85
107
}
86
87
void LibRaw::eight_bit_load_raw()
88
76
{
89
76
  unsigned row, col;
90
91
76
  std::vector<uchar> pixel(raw_width);
92
10.8k
  for (row = 0; row < raw_height; row++)
93
10.8k
  {
94
10.8k
      checkCancel();
95
10.8k
      if (fread(pixel.data(), 1, raw_width, ifp) < raw_width)
96
73
          derror();
97
366k
      for (col = 0; col < raw_width; col++)
98
356k
          RAW(row, col) = curve[pixel[col]];
99
10.8k
  }
100
76
  maximum = curve[0xff];
101
76
}