Coverage Report

Created: 2026-01-10 06:27

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
2.23k
{
24
  // Allocate temp raw_image buffer
25
2.23k
  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
2.23k
    imgdata.rawdata.raw_image = (ushort *)malloc(S.raw_pitch * S.raw_height);
31
2.23k
}
32
void LibRaw::phase_one_free_tempbuffer()
33
2.23k
{
34
2.23k
  free(imgdata.rawdata.raw_image);
35
2.23k
    imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc;
36
2.23k
  if (imgdata.process_warnings & LIBRAW_WARN_RAWSPEED3_PROCESSED)
37
0
    imgdata.rawdata.raw_alloc = 0;
38
2.23k
}
39
40
int LibRaw::phase_one_subtract_black(ushort *src, ushort *dest)
41
2.23k
{
42
43
2.23k
  try
44
2.23k
  {
45
2.23k
    if (O.user_black < 0 && O.user_cblack[0] <= -1000000 &&
46
1.73k
        O.user_cblack[1] <= -1000000 && O.user_cblack[2] <= -1000000 &&
47
1.73k
        O.user_cblack[3] <= -1000000)
48
1.73k
    {
49
1.73k
      if (!imgdata.rawdata.ph1_cblack || !imgdata.rawdata.ph1_rblack)
50
1.32k
      {
51
1.32k
        int bl = imgdata.color.phase_one_data.t_black;
52
1.33M
        for (int row = 0; row < S.raw_height; row++)
53
1.33M
        {
54
1.33M
          checkCancel();
55
135M
          for (int col = 0; col < S.raw_width; col++)
56
133M
          {
57
133M
            int idx = row * S.raw_width + col;
58
133M
            int val = int(src[idx]) - bl;
59
133M
            dest[idx] = val > 0 ? val : 0;
60
133M
          }
61
1.33M
        }
62
1.32k
      }
63
414
      else
64
414
      {
65
414
        int bl = imgdata.color.phase_one_data.t_black;
66
150k
        for (int row = 0; row < S.raw_height; row++)
67
149k
        {
68
149k
          checkCancel();
69
7.19M
          for (int col = 0; col < S.raw_width; col++)
70
7.04M
          {
71
7.04M
            int idx = row * S.raw_width + col;
72
7.04M
            int val =
73
7.04M
                int(src[idx]) - bl +
74
7.04M
                imgdata.rawdata
75
7.04M
                    .ph1_cblack[row][col >= imgdata.rawdata.color.phase_one_data
76
7.04M
                                                .split_col] +
77
7.04M
                imgdata.rawdata
78
7.04M
                    .ph1_rblack[col][row >= imgdata.rawdata.color.phase_one_data
79
7.04M
                                                .split_row];
80
7.04M
            dest[idx] = val > 0 ? val : 0;
81
7.04M
          }
82
149k
        }
83
414
      }
84
1.73k
    }
85
497
    else // black set by user interaction
86
497
    {
87
      // Black level in cblack!
88
60.8k
      for (int row = 0; row < S.raw_height; row++)
89
60.3k
      {
90
60.3k
        checkCancel();
91
60.3k
        unsigned short cblk[16];
92
1.02M
        for (int cc = 0; cc < 16; cc++)
93
965k
          cblk[cc] = C.cblack[fcol(row, cc)];
94
22.9M
        for (int col = 0; col < S.raw_width; col++)
95
22.9M
        {
96
22.9M
          int idx = row * S.raw_width + col;
97
22.9M
          ushort val = src[idx];
98
22.9M
          ushort bl = cblk[col & 0xf];
99
22.9M
          dest[idx] = val > bl ? val - bl : 0;
100
22.9M
        }
101
60.3k
      }
102
497
    }
103
2.23k
    return 0;
104
2.23k
  }
105
2.23k
  catch (const LibRaw_exceptions& )
106
2.23k
  {
107
0
    return LIBRAW_CANCELLED_BY_CALLBACK;
108
0
  }
109
2.23k
}