GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_sdl_pixmap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2021 Cyril Hrubis <metan@ucw.cz>
4 */
5
10#ifndef BACKENDS_GP_SDL_PIXMAP_H
11#define BACKENDS_GP_SDL_PIXMAP_H
12
13#include <core/gp_pixel.h>
14#include <core/gp_pixmap.h>
15
43static inline int gp_pixmap_from_sdl_surface(gp_pixmap *pixmap,
44 const SDL_Surface *surf)
45{
46 /* sanity checks on the SDL surface */
47 if (surf->format->BytesPerPixel == 0) {
48 GP_WARN("Surface->BytesPerPixel == 0");
49 return 1;
50 }
51
52 if (surf->format->BytesPerPixel > 4) {
53 GP_WARN("Surface->BytesPerPixel > 4");
54 return 1;
55 }
56
57 enum gp_pixel_type pixeltype = gp_pixel_rgb_match(surf->format->Rmask,
58 surf->format->Gmask,
59 surf->format->Bmask,
60 surf->format->Ashift,
61 surf->format->BitsPerPixel);
62
63 if (pixeltype == GP_PIXEL_UNKNOWN)
64 return 1;
65
66 /* basic structure and size */
67 pixmap->pixels = surf->pixels;
68 pixmap->pixel_type = pixeltype;
69 pixmap->bytes_per_row = surf->pitch;
70 pixmap->w = surf->w;
71 pixmap->h = surf->h;
72 pixmap->gamma = NULL;
73
74 return 0;
75}
76
77#endif /* BACKENDS_GP_SDL_PIXMAP_H */
#define GP_WARN(...)
A debug WARN printf-like macro.
Definition gp_debug.h:104
gp_pixel_type
List of all pixel types.
A pixel description.
gp_pixel_type gp_pixel_rgb_match(gp_pixel rmask, gp_pixel gmask, gp_pixel bmask, gp_pixel amask, uint8_t bits_per_pixel)
Matches a RGB pixel type againts known pixel types.
A pixel buffer.
static int gp_pixmap_from_sdl_surface(gp_pixmap *pixmap, const SDL_Surface *surf)
A SDL surface to GFXprim pixmap conversion.
A pixmap buffer.
Definition gp_pixmap.h:33
uint32_t h
Pixmap height in pixels.
Definition gp_pixmap.h:46
uint8_t * pixels
A pointer to image pixels.
Definition gp_pixmap.h:35
enum gp_pixel_type pixel_type
A pixel format.
Definition gp_pixmap.h:63
uint32_t bytes_per_row
Number of bytes per row.
Definition gp_pixmap.h:42
gp_gamma * gamma
A pointer to a gamma correction table.
Definition gp_pixmap.h:70
uint32_t w
Pixmap width in pixels.
Definition gp_pixmap.h:44