File: SampleImage.hpp

package info (click to toggle)
hdrmerge 0.5%2Bgit20200117-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 33,872 kB
  • sloc: cpp: 5,026; sh: 175; makefile: 5
file content (68 lines) | stat: -rw-r--r-- 2,307 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
/*
 *  HDRMerge - HDR exposure merging software.
 *  Copyright 2012 Javier Celaya
 *  jcelaya@gmail.com
 *
 *  This file is part of HDRMerge.
 *
 *  HDRMerge 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  HDRMerge is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with HDRMerge. If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <cstdlib>
#include <QImage>
#include "../src/RawParameters.hpp"
#include "../src/Array2D.hpp"
#include "../src/Log.hpp"

namespace hdrmerge {

class SampleImage : public Array2D<uint16_t> {
public:
    RawParameters params;
    SampleImage() : Array2D<uint16_t>() {}
    SampleImage(const std::string & f) : Array2D<uint16_t>() {
        QImage image;
        if (!image.load(f.c_str())) {
            Log::msg(Log::DEBUG, "Imposible to load sample image ", f);
            return;
        }
        Log::msg(Log::DEBUG, "Loaded sample image ", f, " with format ", image.format());
        resize(image.width(), image.height());
        const uchar * data = image.constBits();
        int min = 255, max = 0;
        for (size_t i = 0; i < width * height; ++i) {
            (*this)[i] = data[i];
            if (min > data[i]) min = data[i];
            if (max < data[i]) max = data[i];
        }
        Log::msg(Log::DEBUG, "Data in range ", min, " - ", max);
        params.width = params.rawWidth = width;
        params.height = height;
        params.max = 255;
        params.FC.setPattern(0x4b4b4b4b, (uint8_t (*)(int, int))0);
    }

    void save(const std::string & f) {
        QImage image(width, height, QImage::Format_RGB32);
        QRgb * data = reinterpret_cast<QRgb *>(image.bits());
        for (size_t i = 0; i < width * height; ++i) {
            int v = (*this)[i];
            data[i] = qRgb(v, v, v);
        }
        image.save(f.c_str());
    }
};

} // namespace hdrmerge