Coverage Report

Created: 2026-09-13 07:02

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
286
{
23
286
  int row, col, bits = 0;
24
3.76k
  while (1 << ++bits < (int)maximum)
25
3.48k
    ;
26
286
  read_shorts(raw_image, raw_width * raw_height);
27
286
  fseek(ifp, -2, SEEK_CUR); // avoid EOF error
28
286
  if (maximum < 0xffff || load_flags)
29
3.58k
    for (row = 0; row < raw_height; row++)
30
3.46k
    {
31
3.46k
      checkCancel();
32
108k
      for (col = 0; col < raw_width; col++)
33
104k
        if ((RAW(row, col) >>= load_flags) >> bits &&
34
46.2k
            (unsigned)(row - top_margin) < height &&
35
45.6k
            (unsigned)(col - left_margin) < width)
36
45.0k
          derror();
37
3.46k
    }
38
286
}
39
40
void LibRaw::packed_load_raw()
41
280
{
42
280
  int vbits = 0, bwide, rbits, bite, half, irow, row, col, val, i;
43
280
  UINT64 bitbuf = 0;
44
45
280
  bwide = raw_width * tiff_bps / 8;
46
280
  bwide += bwide & load_flags >> 7;
47
280
  rbits = bwide * 8 - raw_width * tiff_bps;
48
280
  if (load_flags & 1)
49
72
    bwide = bwide * 16 / 15;
50
280
  bite = 8 + (load_flags & 24);
51
280
  half = (raw_height + 1) >> 1;
52
4.54k
  for (irow = 0; irow < raw_height; irow++)
53
4.51k
  {
54
4.51k
    checkCancel();
55
4.51k
    row = irow;
56
4.51k
    if (load_flags & 2 && (row = irow % half * 2 + irow / half) == 1 &&
57
4
        load_flags & 4)
58
3
    {
59
3
      if (vbits = 0, tiff_compress)
60
1
        fseek(ifp, data_offset - (-half * bwide & -2048), SEEK_SET);
61
2
      else
62
2
      {
63
2
        fseek(ifp, 0, SEEK_END);
64
2
        fseek(ifp, ftell(ifp) >> 3 << 2, SEEK_SET);
65
2
      }
66
3
    }
67
4.51k
    if (feof(ifp))
68
254
      throw LIBRAW_EXCEPTION_IO_EOF;
69
714k
    for (col = 0; col < raw_width; col++)
70
710k
    {
71
959k
      for (vbits -= tiff_bps; vbits < 0; vbits += bite)
72
249k
      {
73
249k
        bitbuf <<= bite;
74
665k
        for (i = 0; i < bite; i += 8)
75
416k
          bitbuf |= (unsigned(fgetc(ifp)) << i);
76
249k
      }
77
710k
      val = int((bitbuf << (64 - tiff_bps - vbits) >> (64 - tiff_bps)) & 0x7fffffff);
78
710k
      RAW(row, col ^ (load_flags >> 6 & 1)) = val;
79
710k
      if (load_flags & 1 && (col % 10) == 9 && fgetc(ifp) &&
80
11.6k
          row < height + top_margin && col < width + left_margin)
81
10.7k
        derror();
82
710k
    }
83
4.26k
    vbits -= rbits;
84
4.26k
  }
85
280
}
86
87
void LibRaw::eight_bit_load_raw()
88
62
{
89
62
  unsigned row, col;
90
91
62
  std::vector<uchar> pixel(raw_width);
92
1.54k
  for (row = 0; row < raw_height; row++)
93
1.48k
  {
94
1.48k
      checkCancel();
95
1.48k
      if (fread(pixel.data(), 1, raw_width, ifp) < raw_width)
96
50
          derror();
97
68.9k
      for (col = 0; col < raw_width; col++)
98
67.4k
          RAW(row, col) = curve[pixel[col]];
99
1.48k
  }
100
62
  maximum = curve[0xff];
101
62
}