Colobot
image.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 #include "graphics/core/color.h"
28 
29 #include "math/intpoint.h"
30 
31 #include <memory>
32 #include <string>
33 
34 
35 // Forward declaration without including headers to clutter the code
36 struct SDL_Surface;
37 
39 
41 struct ImageData
42 {
44  SDL_Surface* surface = nullptr;
45 };
46 
54 class CImage
55 {
56 public:
58  CImage();
60  CImage(Math::IntPoint size);
62  virtual ~CImage();
63 
64  CImage(const CImage &other) = delete;
65  void operator=(const CImage &other) = delete;
66 
68  void Free();
69 
71  bool IsEmpty() const;
72 
74  ImageData* GetData();
75 
77  Math::IntPoint GetSize() const;
78 
80  void Fill(Gfx::IntColor color);
81 
83  void SetPixel(Math::IntPoint pixel, Gfx::Color color);
84 
86  void SetPixelInt(Math::IntPoint pixel, Gfx::IntColor color);
87 
89  Gfx::Color GetPixel(Math::IntPoint pixel);
90 
92  Gfx::IntColor GetPixelInt(Math::IntPoint pixel);
93 
95  void PadToNearestPowerOfTwo();
96 
98  void ConvertToRGBA();
99 
101  bool Load(const std::string &fileName);
102 
104  bool SavePNG(const std::string &fileName);
105 
107  std::string GetError();
108 
110  void FlipVertically();
111 
113  void SetDataPixels(void *pixels);
114 
115 private:
117  void BlitToNewRGBASurface(int width, int height);
118 
120  std::string m_error;
122  std::unique_ptr<ImageData> m_data;
123 };
124 
Color with integer values.
Definition: color.h:101
SDL_Surface * surface
SDL surface with image data.
Definition: image.h:44
Color structs and related functions.
Image loaded from file.
Definition: image.h:54
Implementation-specific image data.
Definition: image.h:41
2D Point with integer coords
Definition: intpoint.h:41
RGBA color.
Definition: color.h:39
IntPoint struct.