PCL
Resample.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/Resample.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_Resample_h
53 #define __PCL_Resample_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
61 #include <pcl/ImageResolution.h>
62 #include <pcl/ParallelProcess.h>
63 
64 namespace pcl
65 {
66 
67 // ----------------------------------------------------------------------------
68 
82 namespace ResizeMode
83 {
84  enum value_type
85  {
86  RelativeDimensions, // Resize relative to current image dimensions
87  AbsolutePixels, // ... to absolute dimensions in pixels
88  AbsoluteCentimeters, // ... to absolute dimensions in centimeters
89  AbsoluteInches, // ... to absolute dimensions in inches
90  ForceArea, // Force number of pixels, keep aspect ratio
91  NumberOfResizeModes,
92  Default = RelativeDimensions
93  };
94 }
95 
96 // ----------------------------------------------------------------------------
97 
113 namespace AbsoluteResizeMode
114 {
115  enum value_type
116  {
117  ForceWidthAndHeight, // Force both dimensions
118  ForceWidth, // Force width, preserve aspect ratio
119  ForceHeight, // Force height, preserve aspect ratio
120  NumberOfAbsoluteResizeModes,
121  Default = ForceWidthAndHeight
122  };
123 }
124 
125 // ----------------------------------------------------------------------------
126 
134  public ImageResolution,
135  public ParallelProcess
136 {
137 public:
138 
142  using resize_mode = ResizeMode::value_type;
143 
147  using abs_resize_mode = AbsoluteResizeMode::value_type;
148 
158  Resample( PixelInterpolation& p, double scale = 1.0 )
160  , m_xSize( scale )
161  , m_ySize( scale )
162  {
163  }
164 
175  Resample( PixelInterpolation& p, double scaleX, double scaleY )
177  , m_xSize( scaleX )
178  , m_ySize( scaleY )
179  {
180  }
181 
185  Resample( const Resample& ) = default;
186 
193  void GetSizes( double& width, double& height ) const
194  {
195  width = m_xSize; height = m_ySize;
196  }
197 
204  double XSize() const
205  {
206  return m_xSize;
207  }
208 
215  double YSize() const
216  {
217  return m_ySize;
218  }
219 
226  void SetSizes( double width, double height )
227  {
228  m_xSize = width; m_ySize = height;
229  }
230 
237  void SetXSize( double width )
238  {
239  m_xSize = width;
240  }
241 
248  void SetYSize( double height )
249  {
250  m_ySize = height;
251  }
252 
261  void GetScalingFactors( double& sx, double& sy ) const
262  {
263  GetSizes( sx, sy );
264  }
265 
273  double XScale() const
274  {
275  return XSize();
276  }
277 
285  double YScale() const
286  {
287  return YSize();
288  }
289 
298  void SetScalingFactors( double sx, double sy )
299  {
300  SetSizes( sx, sy );
301  }
302 
310  void SetXScale( double sx )
311  {
312  SetXSize( sx );
313  }
314 
322  void SetYScale( double sy )
323  {
324  SetYSize( sy );
325  }
326 
330  resize_mode Mode() const
331  {
332  return m_mode;
333  }
334 
340  bool IsRelative() const
341  {
342  return m_mode == ResizeMode::RelativeDimensions;
343  }
344 
349  bool IsAbsolute() const
350  {
351  return !IsRelative();
352  }
353 
357  void SetMode( resize_mode mode )
358  {
359  m_mode = mode;
360  }
361 
366  abs_resize_mode AbsMode() const
367  {
368  return m_absMode;
369  }
370 
375  void SetAbsMode( abs_resize_mode absMode )
376  {
377  m_absMode = absMode;
378  }
379 
382  void GetNewSizes( int& width, int& height ) const override;
383 
386  bool SupportsGammaCorrection() const override
387  {
388  return true;
389  }
390 
391 protected:
392 
393  double m_xSize = 1.0;
394  double m_ySize = 1.0;
395  resize_mode m_mode = ResizeMode::Default;
396  abs_resize_mode m_absMode = AbsoluteResizeMode::Default;
397 
398  // Inherited from ImageTransformation.
399  void Apply( pcl::Image& ) const override;
400  void Apply( pcl::DImage& ) const override;
401  void Apply( pcl::UInt8Image& ) const override;
402  void Apply( pcl::UInt16Image& ) const override;
403  void Apply( pcl::UInt32Image& ) const override;
404 };
405 
406 // ----------------------------------------------------------------------------
407 
408 } // pcl
409 
410 #endif // __PCL_Resample_h
411 
412 // ----------------------------------------------------------------------------
413 // EOF pcl/Resample.h - Released 2024-06-18T15:48:54Z
Implements a generic, two-dimensional, shared or local image.
Definition: Image.h:278
Image resolution data
Abstract base class of all PCL interpolating geometric image transformations.
A process using multiple concurrent execution threads.
Abstract root base class for all pixel interpolation algorithms.
Image resampling algorithm.
Definition: Resample.h:136
void SetAbsMode(abs_resize_mode absMode)
Definition: Resample.h:375
void Apply(pcl::UInt8Image &) const override
bool IsRelative() const
Definition: Resample.h:340
void Apply(pcl::UInt32Image &) const override
void Apply(pcl::UInt16Image &) const override
void SetScalingFactors(double sx, double sy)
Definition: Resample.h:298
void SetYSize(double height)
Definition: Resample.h:248
Resample(PixelInterpolation &p, double scale=1.0)
Definition: Resample.h:158
void GetScalingFactors(double &sx, double &sy) const
Definition: Resample.h:261
void SetYScale(double sy)
Definition: Resample.h:322
resize_mode Mode() const
Definition: Resample.h:330
double YSize() const
Definition: Resample.h:215
void SetXSize(double width)
Definition: Resample.h:237
void GetNewSizes(int &width, int &height) const override
double YScale() const
Definition: Resample.h:285
void Apply(pcl::Image &) const override
abs_resize_mode AbsMode() const
Definition: Resample.h:366
Resample(const Resample &)=default
Resample(PixelInterpolation &p, double scaleX, double scaleY)
Definition: Resample.h:175
void SetMode(resize_mode mode)
Definition: Resample.h:357
void SetXScale(double sx)
Definition: Resample.h:310
void GetSizes(double &width, double &height) const
Definition: Resample.h:193
void SetSizes(double width, double height)
Definition: Resample.h:226
double XScale() const
Definition: Resample.h:273
double XSize() const
Definition: Resample.h:204
void Apply(pcl::DImage &) const override
bool IsAbsolute() const
Definition: Resample.h:349
PCL root namespace.
Definition: AbstractImage.h:77