Coverage Report

Created: 2026-03-12 07:14

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