File: stretch.h

package info (click to toggle)
stellarsolver 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,112 kB
  • sloc: ansic: 31,587; cpp: 15,103; python: 186; sh: 74; pascal: 67; perl: 9; makefile: 2
file content (102 lines) | stat: -rw-r--r-- 3,278 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*  Stretch

    This application is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.
*/

#pragma once

//Qt Includes
#include <QImage>

//System Includes
#include <memory>

struct StretchParams1Channel
{
  // Stretch algorithm parameters
  float shadows;;
  float highlights;
  float midtones;
  // The extension parameters are not yet used.
  float shadows_expansion;
  float highlights_expansion;
          
  // The default parameters result in no stretch at all.
  StretchParams1Channel()
  {
    shadows = 0.0;
    highlights = 1.0;
    midtones = 0.5;
    shadows_expansion = 0.0;
    highlights_expansion = 1.0;
  }
};

struct StretchParams
{
  StretchParams1Channel grey_red, green, blue;
};

class Stretch
{
    public:
        /**
         * @brief Stretch Constructor for Stretch class
         * @param image_buffer pointer to the image memory
         * @param width the image width
         * @param height the image height
         * @param channels should be 1 or 3
         * @note The image should either be 1-channel or 3-channel
         * The image buffer is not copied, so it should not be deleted while the object is in use
         */
        explicit Stretch(int width, int height, int channels, int data_type);
        ~Stretch() {}

        /**
         * @brief setParams Sets the stretch parameters. 
         * @param param The desired parameter values.
         * @note This set method used for both 1-channel and 3-channel images.
         * In 1-channel images, the _g and _b parameters are ignored.
         * The parameter scale is 0-1 for all data types.
         */
        void setParams(StretchParams input_params) { params = input_params; }

        /**
         * @brief getParams Returns the stretch parameters (computed by computeParameters()).
         */
        StretchParams getParams() { return params; }

        /**
         * @brief computeParams Automatically generates and sets stretch parameters from the image.
         */
        StretchParams computeParams(uint8_t *input);

        /**
         * @brief run run the stretch algorithm according to the params given
         * placing the output in output_image.
         * @param input the raw data buffer.
         * @param output_image a QImage pointer that should be the same size as the input if
         * sampling is 1 otherwise, the proper size if the input is downsampled by sampling.
         * @param sampling The sampling parameter. Applies to both width and height.
         * Sampling is applied to the output (that is, with sampling=2, we compute every other output
         * sample both in width and height, so the output would have about 4X fewer pixels.
         */
        void run(uint8_t *input, QImage *output_image, int sampling=1);

 private:
        // Adjusts input_range for float and double types.
        void recalculateInputRange(uint8_t *input);

        // Inputs.
        int image_width;
        int image_height;
        int image_channels;
        int input_range;
        int dataType;
  
        // Parameters.
        StretchParams params;
};