Coverage Report

Created: 2026-08-14 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libraw/src/utils/phaseone_processing.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/libraw_cxx_defs.h"
20
21
22
void LibRaw::phase_one_allocate_tempbuffer()
23
1.17k
{
24
  // Allocate temp raw_image buffer
25
1.17k
  if (imgdata.process_warnings & LIBRAW_WARN_RAWSPEED3_PROCESSED)
26
0
  {
27
    // Processed by RawSpeed, raw_image contains ptr to rawspeed internals
28
0
    imgdata.rawdata.raw_alloc = imgdata.rawdata.raw_image; // save for data processing and future reuse
29
0
  }
30
1.17k
    imgdata.rawdata.raw_image = (ushort *)malloc(UINT64(S.raw_pitch) * UINT64(S.raw_height));
31
1.17k
}
32
void LibRaw::phase_one_free_tempbuffer()
33
1.17k
{
34
1.17k
  free(imgdata.rawdata.raw_image);
35
1.17k
    imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc;
36
1.17k
  if (imgdata.process_warnings & LIBRAW_WARN_RAWSPEED3_PROCESSED)
37
0
    imgdata.rawdata.raw_alloc = 0;
38
1.17k
}
39
40
int LibRaw::phase_one_subtract_black(ushort *src, ushort *dest)
41
1.17k
{
42
43
1.17k
  try
44
1.17k
  {
45
1.17k
    if (O.user_black < 0 && O.user_cblack[0] <= -1000000 &&
46
925
        O.user_cblack[1] <= -1000000 && O.user_cblack[2] <= -1000000 &&
47
925
        O.user_cblack[3] <= -1000000)
48
925
    {
49
925
      if (!imgdata.rawdata.ph1_cblack || !imgdata.rawdata.ph1_rblack)
50
784
      {
51
784
        int bl = imgdata.color.phase_one_data.t_black;
52
577k
        for (int row = 0; row < S.raw_height; row++)
53
576k
        {
54
576k
          checkCancel();
55
77.3M
          for (int col = 0; col < S.raw_width; col++)
56
76.7M
          {
57
76.7M
            int idx = row * S.raw_width + col;
58
76.7M
            int val = int(src[idx]) - bl;
59
76.7M
            dest[idx] = val > 0 ? val : 0;
60
76.7M
          }
61
576k
        }
62
784
      }
63
141
      else
64
141
      {
65
141
        int bl = imgdata.color.phase_one_data.t_black;
66
15.6k
        for (int row = 0; row < S.raw_height; row++)
67
15.5k
        {
68
15.5k
          checkCancel();
69
1.69M
          for (int col = 0; col < S.raw_width; col++)
70
1.67M
          {
71
1.67M
            int idx = row * S.raw_width + col;
72
1.67M
            int val =
73
1.67M
                int(src[idx]) - bl +
74
1.67M
                imgdata.rawdata
75
1.67M
                    .ph1_cblack[row][col >= imgdata.rawdata.color.phase_one_data
76
1.67M
                                                .split_col] +
77
1.67M
                imgdata.rawdata
78
1.67M
                    .ph1_rblack[col][row >= imgdata.rawdata.color.phase_one_data
79
1.67M
                                                .split_row];
80
1.67M
            dest[idx] = val > 0 ? val : 0;
81
1.67M
          }
82
15.5k
        }
83
141
      }
84
925
    }
85
246
    else // black set by user interaction
86
246
    {
87
      // Black level in cblack!
88
151k
      for (int row = 0; row < S.raw_height; row++)
89
151k
      {
90
151k
        checkCancel();
91
151k
        unsigned short cblk[16];
92
2.57M
        for (int cc = 0; cc < 16; cc++)
93
2.42M
          cblk[cc] = C.cblack[fcol(row, cc)];
94
20.0M
        for (int col = 0; col < S.raw_width; col++)
95
19.9M
        {
96
19.9M
          int idx = row * S.raw_width + col;
97
19.9M
          ushort val = src[idx];
98
19.9M
          ushort bl = cblk[col & 0xf];
99
19.9M
          dest[idx] = val > bl ? val - bl : 0;
100
19.9M
        }
101
151k
      }
102
246
    }
103
1.17k
    return 0;
104
1.17k
  }
105
1.17k
  catch (const LibRaw_exceptions& )
106
1.17k
  {
107
0
    return LIBRAW_CANCELLED_BY_CALLBACK;
108
0
  }
109
1.17k
}