summaryrefslogtreecommitdiff
path: root/src/pixel.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2017-12-28 21:52:04 +0100
committerOlivier Gayot <duskcoder@gmail.com>2017-12-28 21:52:04 +0100
commit3282ab0cd838ab7e070021cd2a537d78e60d263a (patch)
treea05ead754b3dd1ac8bf2dc9549c77d5ab135d238 /src/pixel.c
Imported sources files into the Git
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'src/pixel.c')
-rw-r--r--src/pixel.c69
1 files changed, 69 insertions, 0 deletions
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 <gayot_o@epitech.net>
+**
+** 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;
+ }
+}