Kstars

stretch.h
1/* Stretch
2
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#pragma once
7
8#include <memory>
9#include <QImage>
10
11struct StretchParams1Channel
12{
13 // Stretch algorithm parameters
14 float shadows;;
15 float highlights;
16 float midtones;
17 // The extension parameters are not yet used.
18 float shadows_expansion;
19 float highlights_expansion;
20
21 // The default parameters result in no stretch at all.
22 StretchParams1Channel()
23 {
24 shadows = 0.0;
25 highlights = 1.0;
26 midtones = 0.5;
27 shadows_expansion = 0.0;
28 highlights_expansion = 1.0;
29 }
30};
31
32struct StretchParams
33{
34 StretchParams1Channel grey_red, green, blue;
35};
36
37class Stretch
38{
39 public:
40 /**
41 * @brief Stretch Constructor for Stretch class
42 * @param image_buffer pointer to the image memory
43 * @param width the image width
44 * @param height the image height
45 * @param channels should be 1 or 3
46 * @note The image should either be 1-channel or 3-channel
47 * The image buffer is not copied, so it should not be deleted while the object is in use
48 */
49 explicit Stretch(int width, int height, int channels, int data_type);
50 ~Stretch() {}
51
52 /**
53 * @brief setParams Sets the stretch parameters.
54 * @param param The desired parameter values.
55 * @note This set method used for both 1-channel and 3-channel images.
56 * In 1-channel images, the _g and _b parameters are ignored.
57 * The parameter scale is 0-1 for all data types.
58 */
59 void setParams(StretchParams input_params) { params = input_params; }
60
61 /**
62 * @brief getParams Returns the stretch parameters (computed by computeParameters()).
63 */
64 StretchParams getParams() { return params; }
65
66 /**
67 * @brief computeParams Automatically generates and sets stretch parameters from the image.
68 */
69 StretchParams computeParams(const uint8_t *input);
70
71 /**
72 * @brief run run the stretch algorithm according to the params given
73 * placing the output in output_image.
74 * @param input the raw data buffer.
75 * @param output_image a QImage pointer that should be the same size as the input if
76 * sampling is 1 otherwise, the proper size if the input is downsampled by sampling.
77 * @param sampling The sampling parameter. Applies to both width and height.
78 * Sampling is applied to the output (that is, with sampling=2, we compute every other output
79 * sample both in width and height, so the output would have about 4X fewer pixels.
80 */
81 void run(uint8_t const *input, QImage *output_image, int sampling=1);
82
83 private:
84 // Adjusts input_range for float and double types.
85 void recalculateInputRange(const uint8_t *input);
86
87 // Inputs.
88 int image_width;
89 int image_height;
90 int image_channels;
91 int input_range;
92 int dataType;
93
94 // Parameters.
95 StretchParams params;
96};
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.