From 3282ab0cd838ab7e070021cd2a537d78e60d263a Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 28 Dec 2017 21:52:04 +0100 Subject: Imported sources files into the Git Signed-off-by: Olivier Gayot --- src/pixel.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/pixel.c (limited to 'src/pixel.c') diff --git a/src/pixel.c b/src/pixel.c new file mode 100644 index 0000000..abe756e --- /dev/null +++ b/src/pixel.c @@ -0,0 +1,69 @@ +/* +** pixel.c for in /home/gayot_o/prog/lib/sdl-digit +** +** Made by olivier gayot +** Login +** +** Started on Mon Apr 23 08:13:46 2012 olivier gayot +** Last update Mon Apr 23 08:13:46 2012 olivier gayot +*/ + +#include "sdl_digit.h" + +void set_pixel_color(SDL_Surface *surf, + int x, int y, Uint32 color) { + char *address = surf->pixels; + union_ cast_; + + if (x >= surf->w || y >= surf->h || x < 0 || y < 0) + return; + address += surf->pitch * y; + address += x * surf->format->BytesPerPixel; + switch (surf->format->BitsPerPixel) { + case 32: + cast_.int_ = (Uint32 *)address; + *cast_.int_ = color; + break; + case 24: + cast_.int_ = (Uint32 *)address; + *cast_.int_ = color; + break; + case 16: + cast_.short_ = (Uint16 *)address; + *cast_.short_ = color; + break; + case 8: + cast_.char_ = (Uint8 *)address; + *cast_.char_ = color; + break; + default: + return; + break; + } +} + +Uint32 get_pixel_color(SDL_Surface *surf, int x, int y) { + char *address = surf->pixels; + + if (x >= surf->w || y >= surf->h || x < 0 || y < 0) + return 0; + address += surf->pitch * y; + address += x * surf->format->BytesPerPixel; + switch (surf->format->BitsPerPixel) { + case 32: + return ((Uint32)*((Uint32 *)address)); + break; + case 24: + return ((Uint32)*((Uint32 *)address)); + break; + case 16: + return ((Uint32)*((Uint16 *)address)); + break; + case 8: + return ((Uint32)*((Uint8 *)address)); + break; + default: + return ((Uint32)0); + break; + } +} -- cgit v1.2.3