/* * PixelFlut client scaffold using Imlib2 * Install: * debian/ubuntu: apt install libimlib2 * arch: pacman -S imlib2 * fedora: dnf install imlib2 * Compile: `gcc -o pc file.c -Wall -Wextra -lImlib2` * Usage: ./pc * hostip: IP address of the server * port: port of the server (should be 1337) * file_path: path to the image file * x, y: coordinates of the image on the server * repeat: how many times to send the image (0 for infinite) * (c) 2023-2025 Péter Bohner * License: MIT */ #include #include #include #include #include #include #include #include #include uint32_t *get_pixelbuf(char *file_path, int *width, int *height) { Imlib_Image image = imlib_load_image(file_path); if (!image) { printf("Error: cannot load image\n"); exit(1); } imlib_context_set_image(image); *width = imlib_image_get_width(); *height = imlib_image_get_height(); uint32_t *argbbuf = imlib_image_get_data_for_reading_only(); if (!argbbuf) { printf("Error: cannot get image data\n"); exit(1); } return argbbuf; } int connect_to_server(char *host, int port) { // TODO: connect to server, return fd (void)host; (void)port; return 0; } void flood(int fd, uint32_t const *argbbuf, int w, int h, int x, int y) { // TODO: send pixels to server // The (w * h) image should appear at (x, y) on the server // argbbuf contains the loaded image in ARGB format (layed out // row-by-row). For example, pixel (x=0, y=1) is at argbbuf[width]. // If it were pure green, argbbuf[width] would be 0x__00ff00, // If it were violet, argbbuf[width] would be 0x__ff00ff, // where __ is the alpha channel, which can be ignored. (void)fd; (void)argbbuf; (void)w; (void)h; (void)x; (void)y; } int main(int argc, char *argv[]) { if (argc != 7) { printf("Usage: %s " "\n", argv[0]); return 1; } char *host = argv[1]; int port = atoi(argv[2]); char *file_path = argv[3]; int x = atoi(argv[4]); int y = atoi(argv[5]); int repeat = atoi(argv[6]); int width, height; uint32_t *argbbuf = get_pixelbuf(file_path, &width, &height); int fd = connect_to_server(host, port); if (fd < 0) { return 1; } for (int i = 0; i < repeat || repeat == 0; i++) { flood(fd, argbbuf, width, height, x, y); } return 0; }