1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3  *            image.h
4  *
5  *  Sat Mar 16 15:05:08 CET 2013
6  *  Copyright 2013 Bent Bisballe Nyeng
7  *  deva@aasimon.org
8  ****************************************************************************/
9 
10 /*
11  *  This file is part of DrumGizmo.
12  *
13  *  DrumGizmo is free software; you can redistribute it and/or modify
14  *  it under the terms of the GNU Lesser General Public License as published by
15  *  the Free Software Foundation; either version 3 of the License, or
16  *  (at your option) any later version.
17  *
18  *  DrumGizmo is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU Lesser General Public License for more details.
22  *
23  *  You should have received a copy of the GNU Lesser General Public License
24  *  along with DrumGizmo; if not, write to the Free Software
25  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
26  */
27 #pragma once
28 
29 #include <string>
30 #include <vector>
31 
32 #include "drawable.h"
33 #include "colour.h"
34 #include "resource.h"
35 
36 namespace GUI {
37 
38 class Image
39 	: public Drawable
40 {
41 public:
42 	Image(const char* data, size_t size);
43 	Image(const std::string& filename);
44 	Image(Image&& other);
45 	virtual ~Image();
46 
47 	Image& operator=(Image&& other);
48 
49 	size_t width() const override;
50 	size_t height() const override;
51 
52 	const Colour& getPixel(size_t x, size_t y) const override;
53 	const std::uint8_t* line(std::size_t y,
54 	                         std::size_t x_offset = 0) const override;
55 
56 	bool hasAlpha() const override;
57 
58 	bool isValid() const;
59 
60 protected:
61 	void setError();
62 	bool valid{false};
63 
64 	void load(const char* data, size_t size);
65 
66 	std::size_t _width{0};
67 	std::size_t _height{0};
68 	std::vector<Colour> image_data;
69 	std::vector<std::uint8_t> image_data_raw;
70 	Colour out_of_range{0.0f, 0.0f, 0.0f, 0.0f};
71 	std::string filename;
72 	bool has_alpha{false};
73 };
74 
75 } // GUI::
76