Changeset View
Changeset View
Standalone View
Standalone View
kstars/fitsviewer/stretch.h
- This file was added.
1 | /* Stretch | ||||
---|---|---|---|---|---|
2 | | ||||
3 | This application is free software; you can redistribute it and/or | ||||
4 | modify it under the terms of the GNU General Public | ||||
5 | License as published by the Free Software Foundation; either | ||||
6 | version 2 of the License, or (at your option) any later version. | ||||
7 | */ | ||||
8 | | ||||
9 | #pragma once | ||||
10 | | ||||
11 | #include <memory> | ||||
12 | #include <QImage> | ||||
13 | | ||||
14 | struct StretchParams1Channel | ||||
15 | { | ||||
16 | // Stretch algorithm parameters | ||||
17 | float shadows;; | ||||
18 | float highlights; | ||||
19 | float midtones; | ||||
20 | // The extension parameters are not yet used. | ||||
21 | float shadows_expansion; | ||||
22 | float highlights_expansion; | ||||
23 | | ||||
24 | // The default parameters result in no stretch at all. | ||||
25 | StretchParams1Channel() | ||||
26 | { | ||||
27 | shadows = 0.0; | ||||
28 | highlights = 1.0; | ||||
29 | midtones = 0.5; | ||||
30 | shadows_expansion = 0.0; | ||||
31 | highlights_expansion = 1.0; | ||||
32 | } | ||||
33 | }; | ||||
34 | | ||||
35 | struct StretchParams | ||||
36 | { | ||||
37 | StretchParams1Channel grey_red, green, blue; | ||||
38 | }; | ||||
39 | | ||||
40 | class Stretch | ||||
41 | { | ||||
42 | public: | ||||
43 | /** | ||||
44 | * @brief Stretch Constructor for Stretch class | ||||
45 | * @param image_buffer pointer to the image memory | ||||
46 | * @param width the image width | ||||
47 | * @param height the image height | ||||
48 | * @param channels should be 1 or 3 | ||||
49 | * @note The image should either be 1-channel or 3-channel | ||||
50 | * The image buffer is not copied, so it should not be deleted while the object is in use | ||||
51 | */ | ||||
52 | explicit Stretch(int width, int height, int channels, int data_type); | ||||
53 | ~Stretch() {} | ||||
54 | | ||||
55 | /** | ||||
56 | * @brief setParams Sets the stretch parameters. | ||||
57 | * @param param The desired parameter values. | ||||
58 | * @note This set method used for both 1-channel and 3-channel images. | ||||
59 | * In 1-channel images, the _g and _b parameters are ignored. | ||||
60 | * The parameter scale is 0-1 for all data types. | ||||
61 | */ | ||||
62 | void setParams(StretchParams input_params) { params = input_params; } | ||||
63 | | ||||
64 | /** | ||||
65 | * @brief getParams Returns the stretch parameters (computed by computeParameters()). | ||||
66 | */ | ||||
67 | StretchParams getParams() { return params; } | ||||
68 | | ||||
69 | /** | ||||
70 | * @brief computeParams Automatically generates and sets stretch parameters from the image. | ||||
71 | */ | ||||
72 | StretchParams computeParams(uint8_t *input); | ||||
73 | | ||||
74 | /** | ||||
75 | * @brief run run the stretch algorithm according to the params given | ||||
76 | * placing the output in output_image. | ||||
77 | */ | ||||
78 | void run(uint8_t *input, QImage *output_image); | ||||
79 | | ||||
80 | private: | ||||
81 | // Inputs. | ||||
82 | int image_width; | ||||
83 | int image_height; | ||||
84 | int image_channels; | ||||
85 | int input_range; | ||||
86 | int dataType; | ||||
87 | | ||||
88 | // Parameters. | ||||
89 | StretchParams params; | ||||
90 | }; |