1 //     ____   ______ __
2 //    / __ \ / ____// /
3 //   / /_/ // /    / /
4 //  / ____// /___ / /___   PixInsight Class Library
5 // /_/     \____//_____/   PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // Standard RAW_compat File Format Module Version 1.5.3
8 // ----------------------------------------------------------------------------
9 // RawPreferencesDialog.cpp - Released 2020-01-14T11:57:23Z
10 // ----------------------------------------------------------------------------
11 // This file is part of the standard RAW_compat PixInsight module.
12 //
13 // Copyright (c) 2003-2020 Pleiades Astrophoto S.L. All Rights Reserved.
14 //
15 // Redistribution and use in both source and binary forms, with or without
16 // modification, is permitted provided that the following conditions are met:
17 //
18 // 1. All redistributions of source code must retain the above copyright
19 //    notice, this list of conditions and the following disclaimer.
20 //
21 // 2. All redistributions in binary form must reproduce the above copyright
22 //    notice, this list of conditions and the following disclaimer in the
23 //    documentation and/or other materials provided with the distribution.
24 //
25 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
26 //    of their contributors, may be used to endorse or promote products derived
27 //    from this software without specific prior written permission. For written
28 //    permission, please contact info@pixinsight.com.
29 //
30 // 4. All products derived from this software, in any form whatsoever, must
31 //    reproduce the following acknowledgment in the end-user documentation
32 //    and/or other materials provided with the product:
33 //
34 //    "This product is based on software from the PixInsight project, developed
35 //    by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
36 //
37 //    Alternatively, if that is where third-party acknowledgments normally
38 //    appear, this acknowledgment must be reproduced in the product itself.
39 //
40 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
41 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
44 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
46 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
47 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50 // POSSIBILITY OF SUCH DAMAGE.
51 // ----------------------------------------------------------------------------
52 
53 #include "RawPreferencesDialog.h"
54 
55 namespace pcl
56 {
57 
58 // ----------------------------------------------------------------------------
59 
RawPreferencesDialog(RawPreferences & prf)60 RawPreferencesDialog::RawPreferencesDialog( RawPreferences& prf )
61    : preferences( prf )
62    , savedPreferences( prf )
63 {
64    pcl::Font fnt = Font();
65    int labelWidth1 = fnt.Width( String( "FBDD noise reduction:" ) + 'M' );
66    int ui4 = LogicalPixelsToPhysical( 4 );
67 
68    //
69 
70    CreateSuperPixels_CheckBox.SetText( "Create super-pixels" );
71    CreateSuperPixels_CheckBox.SetToolTip(
72       "<p>This option uses the Bayer matrix to create one <i>super-pixel</i> from each group of four pixels "
73       "(for example, RGGB) without interpolation. The dimensions of the resulting image are thus divided by two.</p>"
74       "<p>This option is ignored for frames acquired with X-Trans sensors.</p>" );
75    CreateSuperPixels_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
76 
77    CreateSuperPixels_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
78    CreateSuperPixels_Sizer.Add( CreateSuperPixels_CheckBox );
79    CreateSuperPixels_Sizer.AddStretch();
80 
81    OutputRawRGB_CheckBox.SetText( "Create raw RGB image" );
82    OutputRawRGB_CheckBox.SetToolTip(
83       "<p>This option creates an RGB color image from the CFA matrix <i>as is</i>. No interpolation is done and each pixel "
84       "is either red, green or blue, as defined by the CFA pattern.</p>" );
85    OutputRawRGB_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
86 
87    OutputRawRGB_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
88    OutputRawRGB_Sizer.Add( OutputRawRGB_CheckBox );
89    OutputRawRGB_Sizer.AddStretch();
90 
91    OutputCFA_CheckBox.SetText( "Create raw CFA image" );
92    OutputCFA_CheckBox.SetToolTip(
93       "<p>This option creates a grayscale image from the CFA matrix <i>as is</i>. No interpolation is done and the output "
94       "is a monochrome image reproducing the CFA pattern, as stored in the device.</p>" );
95    OutputCFA_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
96 
97    OutputCFA_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
98    OutputCFA_Sizer.Add( OutputCFA_CheckBox );
99    OutputCFA_Sizer.AddStretch();
100 
101    NoAutoFlip_CheckBox.SetText( "No image flip" );
102    NoAutoFlip_CheckBox.SetToolTip(
103       "<p>Do not flip the output image. If you disable this option, the flip operation specified by the camera "
104       "(0, 90, 180 or 270 degrees) will be applied to the output image.</p>" );
105    NoAutoFlip_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
106 
107    NoAutoFlip_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
108    NoAutoFlip_Sizer.Add( NoAutoFlip_CheckBox );
109    NoAutoFlip_Sizer.AddStretch();
110 
111    NoAutoCrop_CheckBox.SetText( "No image crop" );
112    NoAutoCrop_CheckBox.SetToolTip(
113       "<p>Do not crop unused areas of raw frames. If you enable this option, the dimensions of the output image will be the "
114       "width and height of the whole raw frame stored in the device, including unused margins. This option is always disabled "
115       "by default, and can only be applied when no interpolation is selected. When this option is enabled, no white balancing "
116       "can be applied.</p>" );
117    NoAutoCrop_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
118 
119    NoAutoCrop_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
120    NoAutoCrop_Sizer.Add( NoAutoCrop_CheckBox );
121    NoAutoCrop_Sizer.AddStretch();
122 
123    NoBlackPointCorrection_CheckBox.SetText( "No black point correction" );
124    NoBlackPointCorrection_CheckBox.SetToolTip(
125       "<p>When this option is enabled, no black point correction is applied to raw images to remove "
126       "<i>darkness level pedestals</i>. This option must be enabled to load all raw images referred to a fixed "
127       "zero black point value.</p>" );
128    NoBlackPointCorrection_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
129 
130    NoBlackPointCorrection_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
131    NoBlackPointCorrection_Sizer.Add( NoBlackPointCorrection_CheckBox );
132    NoBlackPointCorrection_Sizer.AddStretch();
133 
134    NoClipHighlights_CheckBox.SetText( "No highlights clipping" );
135    NoClipHighlights_CheckBox.SetToolTip(
136       "<p>When this option is enabled, highlights will be left unclipped resulting in various shades of pink. "
137       "With this option disabled, highlights will be clipped automatically to solid white.</p>" );
138    NoClipHighlights_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
139 
140    NoClipHighlights_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
141    NoClipHighlights_Sizer.Add( NoClipHighlights_CheckBox );
142    NoClipHighlights_Sizer.AddStretch();
143 
144    NoiseThreshold_NumericControl.label.SetText( "Noise threshold:" );
145    NoiseThreshold_NumericControl.label.SetMinWidth( labelWidth1 );
146    NoiseThreshold_NumericControl.slider.SetRange( 0, 200 );
147    NoiseThreshold_NumericControl.slider.SetScaledMinWidth( 250 );
148    NoiseThreshold_NumericControl.SetInteger();
149    NoiseThreshold_NumericControl.SetRange( 0, 2000 );
150    NoiseThreshold_NumericControl.SetToolTip(
151       "<p>Apply a wavelet-based noise reduction. The optimal noise threshold depends on the camera and the "
152       "ISO speed used, but should normally be somewhere between 100 and 1000.</p>"
153       "<p>Set this parameter to zero to disable noise reduction.</p>" );
154    NoiseThreshold_NumericControl.OnValueUpdated( (NumericControl::value_event_handler)&RawPreferencesDialog::NumericControl_ValueUpdated, *this );
155 
156    OutputOptions_Sizer.SetMargin( 6 );
157    OutputOptions_Sizer.SetSpacing( 6 );
158    OutputOptions_Sizer.Add( CreateSuperPixels_Sizer );
159    OutputOptions_Sizer.Add( OutputRawRGB_Sizer );
160    OutputOptions_Sizer.Add( OutputCFA_Sizer );
161    OutputOptions_Sizer.Add( NoAutoFlip_Sizer );
162    OutputOptions_Sizer.Add( NoAutoCrop_Sizer );
163    OutputOptions_Sizer.Add( NoBlackPointCorrection_Sizer );
164    OutputOptions_Sizer.Add( NoClipHighlights_Sizer );
165    OutputOptions_Sizer.Add( NoiseThreshold_NumericControl );
166 
167    OutputOptions_GroupBox.SetTitle( "Output Options" );
168    OutputOptions_GroupBox.SetSizer( OutputOptions_Sizer );
169 
170    //
171 
172    Bilinear_RadioButton.SetText( "Bilinear" );
173    Bilinear_RadioButton.SetToolTip( "<p>Bilinear interpolation. Very fast, "
174       "but generates aliasing artifacts that degrade small-scale image structures.</p>" );
175    Bilinear_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
176 
177    Bilinear_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
178    Bilinear_Sizer.Add( Bilinear_RadioButton );
179    Bilinear_Sizer.AddStretch();
180 
181    VNG_RadioButton.SetText( "VNG" );
182    VNG_RadioButton.SetToolTip( "<p>Variable Number of Gradients interpolation algorithm.</p>" );
183    VNG_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
184 
185    VNG_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
186    VNG_Sizer.Add( VNG_RadioButton );
187    VNG_Sizer.AddStretch();
188 
189    PPG_RadioButton.SetText( "PPG" );
190    PPG_RadioButton.SetToolTip( "<p>Patterned Pixel Grouping interpolation algorithm.</p>" );
191    PPG_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
192 
193    PPG_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
194    PPG_Sizer.Add( PPG_RadioButton );
195    PPG_Sizer.AddStretch();
196 
197    AHD_RadioButton.SetText( "AHD" );
198    AHD_RadioButton.SetToolTip( "<p>Adaptive Homogeneity-Directed demosaicing algorithm.</p>" );
199    AHD_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
200 
201    AHD_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
202    AHD_Sizer.Add( AHD_RadioButton );
203    AHD_Sizer.AddStretch();
204 
205    DCB_RadioButton.SetText( "DCB" );
206    DCB_RadioButton.SetToolTip( "<p>DCB demosaicing algorithm by Jacek Gozdz.</p>" );
207    DCB_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
208 
209    DCB_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
210    DCB_Sizer.Add( DCB_RadioButton );
211    DCB_Sizer.AddStretch();
212 
213    DCBIterations_Label.SetText( "DCB iterations:" );
214    DCBIterations_Label.SetTextAlignment( TextAlign::Right|TextAlign::VertCenter );
215    DCBIterations_Label.SetMinWidth( labelWidth1 );
216    DCBIterations_Label.SetToolTip( "<p>Number of iterations for the DCB interpolation algorithm.</p>" );
217 
218    DCBIterations_SpinBox.SetRange( 1, 5 );
219    DCBIterations_SpinBox.SetToolTip( "<p>Number of iterations for the DCB interpolation algorithm.</p>" );
220    DCBIterations_SpinBox.OnValueUpdated( (SpinBox::value_event_handler)&RawPreferencesDialog::SpinBox_ValueUpdated, *this );
221 
222    DCBIterations_Sizer.SetSpacing( 4 );
223    DCBIterations_Sizer.Add( DCBIterations_Label );
224    DCBIterations_Sizer.Add( DCBIterations_SpinBox );
225    DCBIterations_Sizer.AddStretch();
226 
227    DCBRefinement_CheckBox.SetText( "DCB refinement" );
228    DCBRefinement_CheckBox.SetToolTip( "<p>Optional DCB refinement step.</p>" );
229    DCBRefinement_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
230 
231    DCBRefinement_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
232    DCBRefinement_Sizer.Add( DCBRefinement_CheckBox );
233    DCBRefinement_Sizer.AddStretch();
234 
235    DHT_RadioButton.SetText( "DHT" );
236    DHT_RadioButton.SetToolTip( "<p>DHT demosaicing algorithm by Anton Petrusevich.</p>" );
237    DHT_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
238 
239    DHT_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
240    DHT_Sizer.Add( DHT_RadioButton );
241    DHT_Sizer.AddStretch();
242 
243    AAHD_RadioButton.SetText( "AAHD" );
244    AAHD_RadioButton.SetToolTip( "<p>Modified AHD demosaicing algorithm by Anton Petrusevich.</p>" );
245    AAHD_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
246 
247    AAHD_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
248    AAHD_Sizer.Add( AAHD_RadioButton );
249    AAHD_Sizer.AddStretch();
250 
251    HalfSize_RadioButton.SetText( "Half-size color image" );
252    HalfSize_RadioButton.SetToolTip( "<p>This option generates a demosaiced RGB color image with half "
253       "the dimensions of the original raw frame. It is the fastest option available (twice as fast as bilinear) "
254       "and is useful to load quick image previews.</p>" );
255    HalfSize_RadioButton.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
256 
257    HalfSize_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
258    HalfSize_Sizer.Add( HalfSize_RadioButton );
259    HalfSize_Sizer.AddStretch();
260 
261    InterpolateAs4Colors_CheckBox.SetText( "Interpolate RGB as four colors" );
262    InterpolateAs4Colors_CheckBox.SetToolTip( "<p>Use this option if the output shows false 2x2 meshes with VNG, or mazes with AHD.</p>" );
263    InterpolateAs4Colors_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
264 
265    InterpolateAs4Colors_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
266    InterpolateAs4Colors_Sizer.Add( InterpolateAs4Colors_CheckBox );
267    InterpolateAs4Colors_Sizer.AddStretch();
268 
269    const char* fbddToolTip = "<p>FBDD noise reduction iterations.</p>"
270       "<p>Jacek Gozdz's FBDD noise reduction algorithm is very efficient at removing small-scale bright artifacts, such as "
271       "hot pixels in underexposed raw data. Quoted from the author's website (http://www.linuxphoto.org/html/fbdd.html):</p>"
272       "<p><em>It works before demosaicing and can be followed by any demosaicing method. FBDD eliminates the most "
273       "visible impulse noise leaving 99% of the details intact and significantly reduces chroma noise - this helps "
274       "getting good results using different denoising techniques applied after demosaicing. It doesn't affect "
275       "contrast or saturation of the image therefore no post processing is requied. The resulting image looks "
276       "grainy and natural.</em></p>"
277       "<p>A parameter value of zero will disable FBDD noise reduction. A value of one will apply the algorithm to the raw image. "
278       "A value of two will apply an additional noise reduction step to the chroma components.</p>";
279 
280    FBDDNoiseReduction_Label.SetText( "FBDD noise reduction:" );
281    FBDDNoiseReduction_Label.SetTextAlignment( TextAlign::Right|TextAlign::VertCenter );
282    FBDDNoiseReduction_Label.SetMinWidth( labelWidth1 );
283    FBDDNoiseReduction_Label.SetToolTip( fbddToolTip );
284 
285    FBDDNoiseReduction_SpinBox.SetRange( 0, 2 );
286    FBDDNoiseReduction_SpinBox.SetToolTip( fbddToolTip );
287    FBDDNoiseReduction_SpinBox.OnValueUpdated( (SpinBox::value_event_handler)&RawPreferencesDialog::SpinBox_ValueUpdated, *this );
288 
289    FBDDNoiseReduction_Sizer.SetSpacing( 4 );
290    FBDDNoiseReduction_Sizer.Add( FBDDNoiseReduction_Label );
291    FBDDNoiseReduction_Sizer.Add( FBDDNoiseReduction_SpinBox );
292    FBDDNoiseReduction_Sizer.AddStretch();
293 
294    Interpolation_Sizer.SetMargin( 6 );
295    Interpolation_Sizer.SetSpacing( 6 );
296    Interpolation_Sizer.Add( Bilinear_Sizer );
297    Interpolation_Sizer.Add( VNG_Sizer );
298    Interpolation_Sizer.Add( PPG_Sizer );
299    Interpolation_Sizer.Add( AHD_Sizer );
300    Interpolation_Sizer.Add( DCB_Sizer );
301    Interpolation_Sizer.Add( DCBIterations_Sizer );
302    Interpolation_Sizer.Add( DCBRefinement_Sizer );
303    Interpolation_Sizer.Add( DHT_Sizer );
304    Interpolation_Sizer.Add( AAHD_Sizer );
305    Interpolation_Sizer.Add( HalfSize_Sizer );
306    Interpolation_Sizer.Add( InterpolateAs4Colors_Sizer );
307    Interpolation_Sizer.Add( FBDDNoiseReduction_Sizer );
308 
309    Interpolation_GroupBox.SetTitle( "Interpolation" );
310    Interpolation_GroupBox.SetSizer( Interpolation_Sizer );
311 
312    //
313 
314    UseAutoWhiteBalance_CheckBox.SetText( "Automatic white balance" );
315    UseAutoWhiteBalance_CheckBox.SetToolTip(
316       "<p>Calculate white balancing factors by averaging the entire image.</p>" );
317    UseAutoWhiteBalance_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
318 
319    UseAutoWhiteBalance_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
320    UseAutoWhiteBalance_Sizer.Add( UseAutoWhiteBalance_CheckBox );
321    UseAutoWhiteBalance_Sizer.AddStretch();
322 
323    UseCameraWhiteBalance_CheckBox.SetText( "Camera white balance" );
324    UseCameraWhiteBalance_CheckBox.SetToolTip(
325       "<p>Use the white balance specified by the camera, when available.</p>" );
326    UseCameraWhiteBalance_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
327 
328    UseCameraWhiteBalance_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
329    UseCameraWhiteBalance_Sizer.Add( UseCameraWhiteBalance_CheckBox );
330    UseCameraWhiteBalance_Sizer.AddStretch();
331 
332    NoWhiteBalance_CheckBox.SetText( "No white balance" );
333    NoWhiteBalance_CheckBox.SetToolTip(
334       "<p>Do not apply any white balance scaling.</p>" );
335    NoWhiteBalance_CheckBox.OnClick( (Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
336 
337    NoWhiteBalance_Sizer.AddUnscaledSpacing( labelWidth1 + ui4 );
338    NoWhiteBalance_Sizer.Add( NoWhiteBalance_CheckBox );
339    NoWhiteBalance_Sizer.AddStretch();
340 
341    WhiteBalance_Sizer.SetMargin( 6 );
342    WhiteBalance_Sizer.SetSpacing( 6 );
343    WhiteBalance_Sizer.Add( UseAutoWhiteBalance_Sizer );
344    WhiteBalance_Sizer.Add( UseCameraWhiteBalance_Sizer );
345    WhiteBalance_Sizer.Add( NoWhiteBalance_Sizer );
346 
347    WhiteBalance_GroupBox.SetTitle( "White Balance" );
348    WhiteBalance_GroupBox.SetSizer( WhiteBalance_Sizer );
349 
350    //
351 
352    PureRaw_PushButton.SetText( "Pure Raw" );
353    PureRaw_PushButton.SetToolTip(
354       "<p>Load a predefined set of options to read RAW digital camera files as pure raw data.</p>" );
355    PureRaw_PushButton.OnClick( (pcl::Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
356 
357    PureRGB_PushButton.SetText( "Demosaiced RGB" );
358    PureRGB_PushButton.SetToolTip(
359       "<p>Load a predefined set of options to read RAW digital camera files as demosaiced RGB images.</p>" );
360    PureRGB_PushButton.OnClick( (pcl::Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
361 
362    OK_PushButton.SetText( "OK" );
363    OK_PushButton.SetCursor( StdCursor::Checkmark );
364    OK_PushButton.SetDefault();
365    OK_PushButton.OnClick( (pcl::Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
366 
367    Cancel_PushButton.SetText( "Cancel" );
368    Cancel_PushButton.SetCursor( StdCursor::Crossmark );
369    Cancel_PushButton.OnClick( (pcl::Button::click_event_handler)&RawPreferencesDialog::Button_Click, *this );
370 
371    BottomRow_Sizer.SetSpacing( 8 );
372    BottomRow_Sizer.Add( PureRaw_PushButton );
373    BottomRow_Sizer.Add( PureRGB_PushButton );
374    BottomRow_Sizer.AddSpacing( 32 );
375    BottomRow_Sizer.AddStretch();
376    BottomRow_Sizer.Add( OK_PushButton );
377    BottomRow_Sizer.Add( Cancel_PushButton );
378 
379    //
380 
381    Global_Sizer.SetMargin( 8 );
382    Global_Sizer.SetSpacing( 8 );
383    Global_Sizer.Add( OutputOptions_GroupBox );
384    Global_Sizer.Add( Interpolation_GroupBox );
385    Global_Sizer.Add( WhiteBalance_GroupBox );
386    Global_Sizer.AddSpacing( 8 );
387    Global_Sizer.Add( BottomRow_Sizer );
388 
389    SetSizer( Global_Sizer );
390 
391    EnsureLayoutUpdated();
392    AdjustToContents();
393    SetFixedSize();
394 
395 //    PureRGB_PushButton.SetMinWidth( Font().Width( PureRGB_PushButton.Text() + "MMMM" ) );
396 
397    SetWindowTitle( "RAW Format Preferences" );
398 
399    OnReturn( (Dialog::return_event_handler)&RawPreferencesDialog::Dialog_Return, *this );
400 
401    UpdateControls();
402 }
403 
404 // ----------------------------------------------------------------------------
405 
UpdateControls()406 void RawPreferencesDialog::UpdateControls()
407 {
408    CreateSuperPixels_CheckBox.SetChecked( preferences.createSuperPixels );
409    OutputRawRGB_CheckBox.SetChecked( preferences.outputRawRGB );
410    OutputCFA_CheckBox.SetChecked( preferences.outputCFA );
411    NoAutoFlip_CheckBox.SetChecked( preferences.noAutoFlip );
412    NoAutoCrop_CheckBox.SetChecked( preferences.noAutoCrop );
413    NoBlackPointCorrection_CheckBox.SetChecked( preferences.noBlackPointCorrection );
414    NoClipHighlights_CheckBox.SetChecked( preferences.noClipHighlights );
415    NoiseThreshold_NumericControl.SetValue( preferences.noiseThreshold );
416 
417    Bilinear_RadioButton.SetChecked( preferences.interpolation == RawPreferences::Bilinear );
418    VNG_RadioButton.SetChecked( preferences.interpolation == RawPreferences::VNG );
419    PPG_RadioButton.SetChecked( preferences.interpolation == RawPreferences::PPG );
420    AHD_RadioButton.SetChecked( preferences.interpolation == RawPreferences::AHD );
421 
422    bool dcb = preferences.interpolation == RawPreferences::DCB;
423    DCB_RadioButton.SetChecked( dcb );
424    DCBIterations_Label.Enable( dcb );
425    DCBIterations_SpinBox.Enable( dcb );
426    DCBIterations_SpinBox.SetValue( preferences.dcbIterations );
427    DCBRefinement_CheckBox.Enable( dcb );
428    DCBRefinement_CheckBox.SetChecked( preferences.dcbRefinement );
429 
430    DHT_RadioButton.SetChecked( preferences.interpolation == RawPreferences::DHT );
431    AAHD_RadioButton.SetChecked( preferences.interpolation == RawPreferences::AAHD );
432    HalfSize_RadioButton.SetChecked( preferences.interpolation == RawPreferences::HalfSize );
433    InterpolateAs4Colors_CheckBox.SetChecked( preferences.interpolateAs4Colors );
434    FBDDNoiseReduction_SpinBox.SetValue( Range( preferences.fbddNoiseReduction, 0, 2 ) );
435 
436    UseAutoWhiteBalance_CheckBox.SetChecked( preferences.useAutoWhiteBalance );
437    UseCameraWhiteBalance_CheckBox.SetChecked( preferences.useCameraWhiteBalance );
438    NoWhiteBalance_CheckBox.SetChecked( preferences.noWhiteBalance );
439 
440    bool raw = preferences.createSuperPixels ||
441               preferences.outputRawRGB ||
442               preferences.outputCFA;
443 
444    NoAutoCrop_CheckBox.Enable( raw && preferences.noWhiteBalance
445                                    && preferences.noBlackPointCorrection
446                                    && preferences.noClipHighlights
447                                    && preferences.noiseThreshold == 0 );
448    Interpolation_GroupBox.Enable( !raw );
449    UseAutoWhiteBalance_CheckBox.Enable( !preferences.noWhiteBalance );
450    UseCameraWhiteBalance_CheckBox.Enable( !preferences.noWhiteBalance );
451 }
452 
453 // ----------------------------------------------------------------------------
454 // ----------------------------------------------------------------------------
455 
NumericControl_ValueUpdated(NumericControl & sender,double value)456 void RawPreferencesDialog::NumericControl_ValueUpdated( NumericControl& sender, double value )
457 {
458    if ( sender == NoiseThreshold_NumericControl )
459       preferences.noiseThreshold = value;
460    UpdateControls();
461 }
462 
463 // ----------------------------------------------------------------------------
464 
SpinBox_ValueUpdated(SpinBox & sender,int value)465 void RawPreferencesDialog::SpinBox_ValueUpdated( SpinBox& sender, int value )
466 {
467    if ( sender == DCBIterations_SpinBox )
468       preferences.dcbIterations = value;
469    else if ( sender == FBDDNoiseReduction_SpinBox )
470       preferences.fbddNoiseReduction = value;
471 }
472 
473 // ----------------------------------------------------------------------------
474 
Button_Click(Button & sender,bool checked)475 void RawPreferencesDialog::Button_Click( Button& sender, bool checked )
476 {
477    if ( sender == UseAutoWhiteBalance_CheckBox )
478    {
479       preferences.useAutoWhiteBalance = checked;
480    }
481    else if ( sender == UseCameraWhiteBalance_CheckBox )
482    {
483       preferences.useCameraWhiteBalance = checked;
484    }
485    else if ( sender == NoWhiteBalance_CheckBox )
486    {
487       preferences.noWhiteBalance = checked;
488       if ( !preferences.noWhiteBalance )
489          if ( !preferences.useCameraWhiteBalance )
490             if ( !preferences.useAutoWhiteBalance )
491                preferences.useCameraWhiteBalance = true;
492    }
493    else if ( sender == CreateSuperPixels_CheckBox )
494    {
495       preferences.createSuperPixels = checked;
496       if ( checked )
497       {
498          preferences.outputRawRGB = false;
499          preferences.outputCFA = false;
500       }
501    }
502    else if ( sender == OutputRawRGB_CheckBox )
503    {
504       preferences.outputRawRGB = checked;
505       if ( checked )
506       {
507          preferences.outputCFA = false;
508          preferences.createSuperPixels = false;
509       }
510    }
511    else if ( sender == OutputCFA_CheckBox )
512    {
513       preferences.outputCFA = checked;
514       if ( checked )
515       {
516          preferences.outputRawRGB = false;
517          preferences.createSuperPixels = false;
518       }
519    }
520    else if ( sender == NoAutoFlip_CheckBox )
521    {
522       preferences.noAutoFlip = checked;
523    }
524    else if ( sender == NoAutoCrop_CheckBox )
525    {
526       preferences.noAutoCrop = checked;
527    }
528    else if ( sender == NoBlackPointCorrection_CheckBox )
529    {
530       preferences.noBlackPointCorrection = checked;
531    }
532    else if ( sender == NoClipHighlights_CheckBox )
533    {
534       preferences.noClipHighlights = checked;
535    }
536    else if ( sender == Bilinear_RadioButton )
537    {
538       preferences.interpolation = RawPreferences::Bilinear;
539    }
540    else if ( sender == VNG_RadioButton )
541    {
542       preferences.interpolation = RawPreferences::VNG;
543    }
544    else if ( sender == PPG_RadioButton )
545    {
546       preferences.interpolation = RawPreferences::PPG;
547    }
548    else if ( sender == AHD_RadioButton )
549    {
550       preferences.interpolation = RawPreferences::AHD;
551    }
552    else if ( sender == DCB_RadioButton )
553    {
554       preferences.interpolation = RawPreferences::DCB;
555    }
556    else if ( sender == DCBRefinement_CheckBox )
557    {
558       preferences.dcbRefinement = checked;
559    }
560    else if ( sender == DHT_RadioButton )
561    {
562       preferences.interpolation = RawPreferences::DHT;
563    }
564    else if ( sender == AAHD_RadioButton )
565    {
566       preferences.interpolation = RawPreferences::AAHD;
567    }
568    else if ( sender == HalfSize_RadioButton )
569    {
570       preferences.interpolation = RawPreferences::HalfSize;
571    }
572    else if ( sender == InterpolateAs4Colors_CheckBox )
573    {
574       preferences.interpolateAs4Colors = checked;
575    }
576    else if ( sender == PureRaw_PushButton )
577    {
578       preferences.interpolateAs4Colors = false;
579       preferences.useAutoWhiteBalance = false;
580       preferences.useCameraWhiteBalance = false;
581       preferences.noWhiteBalance = true;
582       preferences.createSuperPixels = false;
583       preferences.outputRawRGB = false;
584       preferences.outputCFA = true;
585       preferences.noAutoFlip = true;
586       preferences.noAutoCrop = false;
587       preferences.noBlackPointCorrection = true;
588       preferences.noClipHighlights = true;
589       preferences.noiseThreshold = 0;
590    }
591    else if ( sender == PureRGB_PushButton )
592    {
593       preferences.interpolation = RawPreferences::VNG;
594       preferences.interpolateAs4Colors = false;
595       preferences.useAutoWhiteBalance = false;
596       preferences.useCameraWhiteBalance = true;
597       preferences.noWhiteBalance = false;
598       preferences.createSuperPixels = false;
599       preferences.outputRawRGB = false;
600       preferences.outputCFA = false;
601       preferences.noAutoFlip = false;
602       preferences.noAutoCrop = false;
603       preferences.noBlackPointCorrection = false;
604       preferences.noClipHighlights = false;
605       preferences.noiseThreshold = 0;
606       preferences.dcbIterations = 3;
607       preferences.dcbRefinement = false;
608       preferences.fbddNoiseReduction = 0;
609    }
610    else if ( sender == OK_PushButton )
611    {
612       Ok();
613    }
614    else if ( sender == Cancel_PushButton )
615    {
616       Cancel();
617    }
618 
619    UpdateControls();
620 }
621 
622 // ----------------------------------------------------------------------------
623 
Dialog_Return(Dialog & sender,int retVal)624 void RawPreferencesDialog::Dialog_Return( Dialog& sender, int retVal )
625 {
626    if ( retVal != StdDialogCode::Ok )
627       preferences = savedPreferences;
628 }
629 
630 // ----------------------------------------------------------------------------
631 
632 } // pcl
633 
634 // ----------------------------------------------------------------------------
635 // EOF RawPreferencesDialog.cpp - Released 2020-01-14T11:57:23Z
636