1 /* sane - Scanner Access Now Easy.
2 
3    Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
4 
5    This file is part of the SANE package.
6 
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <https://www.gnu.org/licenses/>.
19 */
20 
21 #ifndef BACKEND_GENESYS_IMAGE_H
22 #define BACKEND_GENESYS_IMAGE_H
23 
24 #include "image_pixel.h"
25 #include <vector>
26 
27 namespace genesys {
28 
29 class Image
30 {
31 public:
32     Image();
33     Image(std::size_t width, std::size_t height, PixelFormat format);
34 
get_width() const35     std::size_t get_width() const { return width_; }
get_height() const36     std::size_t get_height() const { return height_; }
get_format() const37     PixelFormat get_format() const { return format_; }
get_row_bytes() const38     std::size_t get_row_bytes() const { return row_bytes_; }
39 
40     std::uint8_t* get_row_ptr(std::size_t y);
41     const std::uint8_t* get_row_ptr(std::size_t y) const;
42 
43     Pixel get_pixel(std::size_t x, std::size_t y) const;
44     void set_pixel(std::size_t x, std::size_t y, const Pixel& pixel);
45 
46     RawPixel get_raw_pixel(std::size_t x, std::size_t y) const;
47     std::uint16_t get_raw_channel(std::size_t x, std::size_t y, unsigned channel) const;
48     void set_raw_pixel(std::size_t x, std::size_t y, const RawPixel& pixel);
49 
50     void resize(std::size_t width, std::size_t height, PixelFormat format);
51 private:
52     std::size_t width_ = 0;
53     std::size_t height_ = 0;
54     PixelFormat format_ = PixelFormat::UNKNOWN;
55     std::size_t row_bytes_ = 0;
56     std::vector<std::uint8_t> data_;
57 };
58 
59 void convert_pixel_row_format(const std::uint8_t* in_data, PixelFormat in_format,
60                               std::uint8_t* out_data, PixelFormat out_format, std::size_t count);
61 
62 void write_tiff_file(const std::string& filename, const void* data, int depth,
63                      int channels, int pixels_per_line, int lines);
64 
65 void write_tiff_file(const std::string& filename, const Image& image);
66 
67 } // namespace genesys
68 
69 #endif // ifndef BACKEND_GENESYS_IMAGE_H
70