1 #if !defined(_BTK_PIXELS_HPP_) 2 #define _BTK_PIXELS_HPP_ 7 #include <SDL2/SDL_pixels.h> 8 #include <SDL2/SDL_surface.h> 21 Color(Uint8 r,Uint8 g,Uint8 b,Uint8 a = 255){
27 Color(
const SDL_Color &c):
Color(c.r,c.g,c.b,c.a){}
34 PixBuf(SDL_Surface *s =
nullptr):surf(s){};
35 PixBuf(
int w,
int h,Uint32 format);
37 PixBuf(std::string_view file);
52 void save_png(
RWops &,
int quality);
53 void save_jpg(
RWops &,
int quality);
54 void save_bmp(
RWops &);
56 void save_png(std::string_view fname,
int quality);
57 void save_jpg(std::string_view fname,
int quality);
58 void save_bmp(std::string_view fname);
60 PixBuf &operator =(SDL_Surface *);
63 bool empty()
const noexcept{
64 return surf ==
nullptr;
67 Size size()
const noexcept{
68 return {surf->w,surf->h};
70 int w()
const noexcept{
73 int h()
const noexcept{
76 int refcount()
const noexcept{
77 return surf->refcount;
79 int pitch()
const noexcept{
83 size_t pixels_size()
const noexcept{
87 bool must_lock()
const noexcept{
88 return SDL_MUSTLOCK(surf);
91 template<
class T =
void>
92 T *pixels()
const noexcept{
93 return static_cast<T*
>(surf->pixels);
95 SDL_Surface *
get()
const noexcept{
98 SDL_Surface *operator ->()
const noexcept{
103 void unlock()
const noexcept;
105 void set_rle(
bool val =
true);
112 PixBuf convert(Uint32 fmt)
const;
114 static PixBuf FromFile(std::string_view file);
115 static PixBuf FromFile(FILE *f);
116 static PixBuf FromMem(
const void *mem,
size_t size);
118 static PixBuf FromXPMArray(
const char *
const*);
130 operator Uint32()
const noexcept{
144 PixFmt(pixfmt.fmt->format){};
152 Uint32 map_rgb (Uint8 r,Uint8 g,Uint8 b)
const;
153 Uint32 map_rgba(Uint8 r,Uint8 g,Uint8 b,Uint8 a)
const;
155 Uint32 map_rgb(
Color color)
const{
162 Uint32 map_rgba(
Color color)
const{
171 std::string_view name()
const;
172 SDL_PixelFormat *operator ->()
const noexcept{
175 operator Uint32()
const noexcept{
179 SDL_PixelFormat *fmt;
204 Texture(BtkTexture *t =
nullptr):texture(t){};
217 auto inf = information();
218 return {inf.w,inf.h};
227 bool empty()
const noexcept{
228 return texture ==
nullptr;
231 Texture &operator =(BtkTexture*);
234 BtkTexture *
get()
const noexcept{
245 void update(
const Rect *r,
void *pixels,
int pitch);
253 void lock(
const Rect *rect,
void **pixels,
int *pitch);
255 void lock(
const Rect &rect,
void **pixels,
int *pitch){
256 lock(&rect,pixels,pitch);
258 void lock(
void **pixels,
int *pitch){
259 lock(
nullptr,pixels,pitch);
261 void update(
const Rect &r,
void *pixels,
int pitch){
262 update(&r,pixels,pitch);
264 void update(
void *pixels,
int pitch){
265 update(
nullptr,pixels,pitch);
280 friend struct Renderer;
288 Gif():pimpl(
nullptr){};
316 texture.lock(rect,&pixels,&pitch);
321 texture.lock(rect,&pixels,&pitch);
323 LockGuard(
const LockGuard &) =
delete;
336 #endif // _BTK_PIXELS_HPP_ Definition: pixels.hpp:191
a SDL_Rect with methods
Definition: rect.hpp:10
This header include many useful containers.
Definition: async.hpp:7
TextureAccess
TextureAccess(same def in SDL_render.h)
Definition: pixels.hpp:185
Texture's information.
Definition: pixels.hpp:197
Definition: pixels.hpp:32
Color structure.
Definition: pixels.hpp:19
Size size() const
Get the size(w and h)
Definition: pixels.hpp:216
Generic LockGuard.
Definition: pixels.hpp:300
Gif Decoding class.
Definition: pixels.hpp:286
Pixels format detail.
Definition: pixels.hpp:139
Size of a Widget or Window.
Definition: rect.hpp:104