File indexing completed on 2025-01-05 03:57:08
0001 /* -*- C++ -*- 0002 * Copyright 2019-2021 LibRaw LLC (info@libraw.org) 0003 * 0004 LibRaw uses code from dcraw.c -- Dave Coffin's raw photo decoder, 0005 dcraw.c is copyright 1997-2018 by Dave Coffin, dcoffin a cybercom o net. 0006 LibRaw do not use RESTRICTED code from dcraw.c 0007 0008 LibRaw is free software; you can redistribute it and/or modify 0009 it under the terms of the one of two licenses as you choose: 0010 0011 1. GNU LESSER GENERAL PUBLIC LICENSE version 2.1 0012 (See file LICENSE.LGPL provided in LibRaw distribution archive for details). 0013 0014 2. COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 0015 (See file LICENSE.CDDL provided in LibRaw distribution archive for details). 0016 0017 */ 0018 0019 #include "../../internal/libraw_cxx_defs.h" 0020 0021 void LibRaw::phase_one_allocate_tempbuffer() 0022 { 0023 // Allocate temp raw_image buffer 0024 imgdata.rawdata.raw_image = (ushort *)malloc(S.raw_pitch * S.raw_height); 0025 } 0026 void LibRaw::phase_one_free_tempbuffer() 0027 { 0028 free(imgdata.rawdata.raw_image); 0029 imgdata.rawdata.raw_image = (ushort *)imgdata.rawdata.raw_alloc; 0030 } 0031 0032 int LibRaw::phase_one_subtract_black(ushort *src, ushort *dest) 0033 { 0034 0035 try 0036 { 0037 if (O.user_black < 0 && O.user_cblack[0] <= -1000000 && 0038 O.user_cblack[1] <= -1000000 && O.user_cblack[2] <= -1000000 && 0039 O.user_cblack[3] <= -1000000) 0040 { 0041 if (!imgdata.rawdata.ph1_cblack || !imgdata.rawdata.ph1_rblack) 0042 { 0043 int bl = imgdata.color.phase_one_data.t_black; 0044 for (int row = 0; row < S.raw_height; row++) 0045 { 0046 checkCancel(); 0047 for (int col = 0; col < S.raw_width; col++) 0048 { 0049 int idx = row * S.raw_width + col; 0050 int val = int(src[idx]) - bl; 0051 dest[idx] = val > 0 ? val : 0; 0052 } 0053 } 0054 } 0055 else 0056 { 0057 int bl = imgdata.color.phase_one_data.t_black; 0058 for (int row = 0; row < S.raw_height; row++) 0059 { 0060 checkCancel(); 0061 for (int col = 0; col < S.raw_width; col++) 0062 { 0063 int idx = row * S.raw_width + col; 0064 int val = 0065 int(src[idx]) - bl + 0066 imgdata.rawdata 0067 .ph1_cblack[row][col >= imgdata.rawdata.color.phase_one_data 0068 .split_col] + 0069 imgdata.rawdata 0070 .ph1_rblack[col][row >= imgdata.rawdata.color.phase_one_data 0071 .split_row]; 0072 dest[idx] = val > 0 ? val : 0; 0073 } 0074 } 0075 } 0076 } 0077 else // black set by user interaction 0078 { 0079 // Black level in cblack! 0080 for (int row = 0; row < S.raw_height; row++) 0081 { 0082 checkCancel(); 0083 unsigned short cblk[16]; 0084 for (int cc = 0; cc < 16; cc++) 0085 cblk[cc] = C.cblack[fcol(row, cc)]; 0086 for (int col = 0; col < S.raw_width; col++) 0087 { 0088 int idx = row * S.raw_width + col; 0089 ushort val = src[idx]; 0090 ushort bl = cblk[col & 0xf]; 0091 dest[idx] = val > bl ? val - bl : 0; 0092 } 0093 } 0094 } 0095 return 0; 0096 } 0097 catch (const LibRaw_exceptions& ) 0098 { 0099 return LIBRAW_CANCELLED_BY_CALLBACK; 0100 } 0101 }