a3a92abf1ca043aaaaaa79381afa316abaa00ace
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

1) #include <stdarg.h>
2) #include <stdio.h>
3) #include <stdlib.h>
4) 
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

5) #include <etherpix/etherpix.h>
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

6) 
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

7) #ifdef WINDOWS
8) #include <winsock.h>
9) #endif
10) 
Stefan Schuermans v1.0.5

Stefan Schuermans authored 13 years ago

11) /* just an example for some data */
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

12) typedef struct userdata_s {
13)   int i;
14)   float f;
15)   char c;
16) } userdata_t;
17) 
18) /* callback function called during display creation,
19)    the p_ctx parameter is the userdata supplied in the call
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

20)    to etp_display_create() */
21) void msg(void *p_ctx, etp_msg_type_t type, const char *fmt, ...)
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

22) {
23)   userdata_t *p_userdata = (userdata_t *)p_ctx;
24)   va_list va;
25) 
26)   printf("msg (%d %f %c): ",
27)          p_userdata->i, p_userdata->f,
28)          p_userdata->c); /* make use of the userdata */
29) 
30)   /* type tells if the message is an error, a warning or an information */
31)   switch (type) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

32)     case etp_msg_type_err:
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

33)       printf("ERROR: ");
34)       break;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

35)     case etp_msg_type_warn:
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

36)       printf("WARNING: ");
37)       break;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

38)     case etp_msg_type_info:
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

39)       printf("INFORMATION: ");
40)       break;
41)   }
42) 
43)   /* fmt is a printf-style format string,
44)      the arguments are passed exactly as for printf */
45)   va_start(va, fmt);
46)   vprintf(fmt, va);
47)   va_end(va);
48) }
49) 
50) int main(int argc, char *argv[])
51) {
52)   const char *config;
Stefan Schuermans v1.0.5

Stefan Schuermans authored 13 years ago

53)   userdata_t userdata = { 42, 42.0, '!' }; /* just an example */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

54)   etp_display_t *p_display;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

55)   unsigned int width, height, i, x, y;
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

56)   etp_u8_t *p_image;
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

57) 
58)   if (argc < 2) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

59)     printf("usage: %s <config.etp>\n", argv[0]);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

60)     return -1;
61)   }
62)   config = argv[1];
63) 
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

64) #ifdef WINDOWS
65)   {
66)     WSADATA data;
67)     WSAStartup(MAKEWORD(1,1), &data);
68)   }
69) #endif
70) 
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

71)   /* create a display, take the configuration from a file,
72)      deliver messages to the callback function msg(),
73)      the last parameter is passed as first parameter to msg()
74)      and can be used to supply some user defined data */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

75)   p_display = etp_display_create(config, msg, (void *)&userdata);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

76)   if (!p_display) {
77)     printf("could not create display\n");
78)     return -1;
79)   }
80) 
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

81)   etp_display_get_size(p_display, &width, &height);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

82)   printf("width:  %5u\nheight: %5u\n", width, height);
83) 
84)   /* create an image with a nice fade:
85)      black to red from left to right,
86)      black to green from top to bottom */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

87)   p_image = (etp_u8_t *)malloc(height * width * 3);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

88)   if (!p_image) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

89)     etp_display_free(p_display);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

90)     printf("out of memory\n");
91)     return -1;
92)   }
93)   i = 0;
94)   for (y = 0; y < height; ++y) {
95)     for (x = 0; x < width; ++x) {
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

96)       p_image[i++] = (etp_u8_t)(255.0*x/(width-1)+0.5); /* red */
97)       p_image[i++] = (etp_u8_t)(255.0*y/(height-1)+0.5); /* green */
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

98)       p_image[i++] = 0; /* no blue */
99)     }
100)   }
101) 
102)   /* output image */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

103)   etp_display_data_fmt(p_display, p_image,
Stefan Schuermans support BGR input in additi...

Stefan Schuermans authored 7 years ago

104)                        3, /* consecutive pixels are 3 bytes apart */
105)                        width*3, /* consecutive lines are width*3 bytes apart */
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

106)                        0, 0, width, height, etp_pixfmt_rgb24);
107)   etp_display_send(p_display);
Stefan Schuermans v1.0.0

Stefan Schuermans authored 13 years ago

108) 
109)   free(p_image);
Stefan Schuermans rename "FlexiPix" to "Ether...

Stefan Schuermans authored 7 years ago

110)   etp_display_free(p_display);
Stefan Schuermans v1.0.6

Stefan Schuermans authored 13 years ago

111) 
112) #ifdef WINDOWS
113)   WSACleanup();
114) #endif
115)