ClanLib  2.3.7
pixel_buffer.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Harry Storbacka
28 ** Mark Page
29 */
30 
33 
34 #pragma once
35 
36 #include "../api_display.h"
37 #include "../../Core/System/sharedptr.h"
38 #include "pixel_format.h"
39 #include "../../Core/Math/rect.h"
40 #include "texture_format.h"
41 #include "buffer_usage.h"
42 
43 class CL_Size;
44 class CL_Rect;
45 class CL_PixelFormat;
46 class CL_Palette;
47 class CL_Color;
48 class CL_Colorf;
49 class CL_PixelBuffer;
50 class CL_PixelBuffer_Impl;
51 class CL_ResourceManager;
53 class CL_IODevice;
54 class CL_GraphicContext;
56 
61 {
64 
67 };
68 
73 {
76 
77 public:
80 
88  CL_PixelBuffer(int width, int height, CL_TextureFormat sized_format, const void *data = 0, bool only_reference_data = false);
89 
99  CL_PixelBuffer(CL_GraphicContext &gc, int width, int height, CL_PixelBufferDirection direction = cl_data_to_gpu, CL_TextureFormat sized_format = cl_rgba8, const void *data = 0, CL_BufferUsage usage = cl_usage_stream_draw);
100 
108 
116  CL_PixelBuffer(int width, int height, CL_TextureFormat sized_format, const CL_Palette &palette, const void *data = 0);
117 
121  CL_PixelBuffer(const CL_StringRef &fullname);
122 
127  CL_PixelBuffer(const CL_StringRef &filename, const CL_VirtualDirectory &dir);
128 
133  CL_PixelBuffer(CL_IODevice &file, const CL_String &image_type);
134 
135  virtual ~CL_PixelBuffer();
136 
140 
141 public:
143  bool is_null() const { return !impl; }
144 
146  void throw_if_null() const;
147 
149  CL_PixelBuffer copy() const;
150 
152  CL_PixelBuffer copy(const CL_Rect &rect) const;
153 
155  const CL_Palette *get_palette() const;
156 
158  int get_width() const;
159 
161  int get_height() const;
162 
164  CL_Size get_size() const;
165 
167  unsigned int get_pitch() const;
168 
170  void *get_data();
171 
172  const void *get_data() const;
173 
175  unsigned char *get_data_uint8() { return reinterpret_cast<unsigned char*>(get_data()); }
176  const unsigned char *get_data_uint8() const { return reinterpret_cast<const unsigned char*>(get_data()); }
177 
179  unsigned short *get_data_uint16() { return reinterpret_cast<unsigned short*>(get_data()); }
180  const unsigned short *get_data_uint16() const { return reinterpret_cast<const unsigned short*>(get_data()); }
181 
183  unsigned int *get_data_uint32() { return reinterpret_cast<unsigned int*>(get_data()); }
184  const unsigned int *get_data_uint32() const { return reinterpret_cast<const unsigned int*>(get_data()); }
185 
187  void *get_line(int line) { unsigned char *d = get_data_uint8(); return d + line * get_pitch(); }
188  const void *get_line(int line) const { const unsigned char *d = get_data_uint8(); return d + line * get_pitch(); }
189 
191  unsigned char *get_line_uint8(int line) { return reinterpret_cast<unsigned char*>(get_line(line)); }
192  const unsigned char *get_line_uint8(int line) const { return reinterpret_cast<const unsigned char*>(get_line(line)); }
193 
195  unsigned short *get_line_uint16(int line) { return reinterpret_cast<unsigned short*>(get_line(line)); }
196  const unsigned short *get_line_uint16(int line) const { return reinterpret_cast<const unsigned short*>(get_line(line)); }
197 
199  unsigned int *get_line_uint32(int line) { return reinterpret_cast<unsigned int*>(get_data()); }
200  const unsigned int *get_line_uint32(int line) const { return reinterpret_cast<const unsigned int*>(get_line(line)); }
201 
203  bool has_colorkey() const;
204 
206  unsigned int get_colorkey() const;
207 
211  int get_bytes_per_pixel() const;
212 
214  unsigned int get_red_mask() const;
215 
217  unsigned int get_green_mask() const;
218 
220  unsigned int get_blue_mask() const;
221 
223  unsigned int get_alpha_mask() const;
224 
226  CL_TextureFormat get_format() const;
227 
231  CL_PixelBufferProvider *get_provider() const;
232 
234  CL_Colorf get_pixel(int x, int y);
235 
239 
240 public:
241 
243  void lock(CL_BufferAccess access);
244 
246  void unlock();
247 
249  void upload_data(const CL_Rect &dest_rect, const void *data);
250 
252  operator bool () const;
253 
258  void convert(CL_PixelBuffer &target) const;
259 
266  void convert(CL_PixelBuffer &target, const CL_Rect &dest_rect, const CL_Rect &src_rect = CL_Rect()) const;
267 
269  CL_PixelBuffer to_format(CL_TextureFormat sized_format) const;
270 
277  void set_colorkey(bool enabled, unsigned int colorkey);
278 
280  void flip_vertical();
281 
285  void premultiply_alpha();
286 
290 
291 private:
292  CL_SharedPtr<CL_PixelBuffer_Impl> impl;
293  friend class CL_PixelBuffer_Impl;
295 };
296