File indexing completed on 2024-03-24 15:17:03
0001 /* Stretch 0002 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include <memory> 0009 #include <QImage> 0010 0011 struct StretchParams1Channel 0012 { 0013 // Stretch algorithm parameters 0014 float shadows;; 0015 float highlights; 0016 float midtones; 0017 // The extension parameters are not yet used. 0018 float shadows_expansion; 0019 float highlights_expansion; 0020 0021 // The default parameters result in no stretch at all. 0022 StretchParams1Channel() 0023 { 0024 shadows = 0.0; 0025 highlights = 1.0; 0026 midtones = 0.5; 0027 shadows_expansion = 0.0; 0028 highlights_expansion = 1.0; 0029 } 0030 }; 0031 0032 struct StretchParams 0033 { 0034 StretchParams1Channel grey_red, green, blue; 0035 }; 0036 0037 class Stretch 0038 { 0039 public: 0040 /** 0041 * @brief Stretch Constructor for Stretch class 0042 * @param image_buffer pointer to the image memory 0043 * @param width the image width 0044 * @param height the image height 0045 * @param channels should be 1 or 3 0046 * @note The image should either be 1-channel or 3-channel 0047 * The image buffer is not copied, so it should not be deleted while the object is in use 0048 */ 0049 explicit Stretch(int width, int height, int channels, int data_type); 0050 ~Stretch() {} 0051 0052 /** 0053 * @brief setParams Sets the stretch parameters. 0054 * @param param The desired parameter values. 0055 * @note This set method used for both 1-channel and 3-channel images. 0056 * In 1-channel images, the _g and _b parameters are ignored. 0057 * The parameter scale is 0-1 for all data types. 0058 */ 0059 void setParams(StretchParams input_params) { params = input_params; } 0060 0061 /** 0062 * @brief getParams Returns the stretch parameters (computed by computeParameters()). 0063 */ 0064 StretchParams getParams() { return params; } 0065 0066 /** 0067 * @brief computeParams Automatically generates and sets stretch parameters from the image. 0068 */ 0069 StretchParams computeParams(const uint8_t *input); 0070 0071 /** 0072 * @brief run run the stretch algorithm according to the params given 0073 * placing the output in output_image. 0074 * @param input the raw data buffer. 0075 * @param output_image a QImage pointer that should be the same size as the input if 0076 * sampling is 1 otherwise, the proper size if the input is downsampled by sampling. 0077 * @param sampling The sampling parameter. Applies to both width and height. 0078 * Sampling is applied to the output (that is, with sampling=2, we compute every other output 0079 * sample both in width and height, so the output would have about 4X fewer pixels. 0080 */ 0081 void run(uint8_t const *input, QImage *output_image, int sampling=1); 0082 0083 private: 0084 // Adjusts input_range for float and double types. 0085 void recalculateInputRange(const uint8_t *input); 0086 0087 // Inputs. 0088 int image_width; 0089 int image_height; 0090 int image_channels; 0091 int input_range; 0092 int dataType; 0093 0094 // Parameters. 0095 StretchParams params; 0096 };