summaryrefslogtreecommitdiff
path: root/src/pixel.c
diff options
context:
space:
mode:
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;
+ }
+}