1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
/* http://delahaye.emmanuel.free.fr/clib/ */
#include "ed/inc/bits.h"
#include <string.h>
#include <stdio.h>
static void print (unsigned char const *px, size_t n)
{
int i;
for (i = 0; i < 4; i++)
{
printf ("Pixel %d (%02X):\n", i, (unsigned) px[i]);
printf ("\t%d\n", mGET (px[i], BIT (0)));
printf ("\t%d\n", mGET (px[i], BIT (1)));
printf ("\t%d\n", mGET (px[i], BIT (2)));
printf ("\t%d\n", mGET (px[i], BIT (3)));
printf ("\t%d\n", mGET (px[i], BIT (4)));
printf ("\t%d\n", mGET (px[i], BIT (5)));
printf ("\t%d\n", mGET (px[i], BIT (6)));
printf ("\t%d\n", mGET (px[i], BIT (7)));
}
}
int main (void)
{
unsigned char px[4];
/* On met différentes valeurs dans chaque pixel, en le castant en char */
px[0] = 'h';
px[1] = 'e';
px[2] = 'l';
px[3] = 'l';
print (px, 4);
{
/* On met dans un tableau char */
char ch_px[4];
memcpy (ch_px, px, 4); //strncpy(ch_px, (char*)(void*)(px), 4)
puts ("==================================");
puts ("==================================");
/* affiche hell */
printf ("Chaine de char: %c%c%c%c\n", ch_px[0], ch_px[1], ch_px[2],
ch_px[3]);
/* On remet ça dans un tableau de Pixels */
{
unsigned char px_2[4];
memcpy (px_2, ch_px, 4); //strncpy((char*)(void*)(px_2), ch_px, 4)
puts ("==================================");
puts ("==================================");
print (px, 4);
}
}
return 0;
} |