diff --git a/src/display.c b/src/display.c index 938a6c9..6f2dce3 100644 --- a/src/display.c +++ b/src/display.c @@ -89,12 +89,18 @@ void prntscreen(const struct message *msg, const struct prog_info *pinfo) { int right = pinfo->client_offset; int left = right + cols; +// for (int y=0; yheight; y++) { for (int x=left-frame; x=w?' ':img[y*w+p]); diff --git a/src/image.c b/src/image.c index 6c37a44..233cc7b 100644 --- a/src/image.c +++ b/src/image.c @@ -20,22 +20,32 @@ char *readImage(const char* filename, int *cols, int *rows) { if (f) { while (fgets(linebuf, LINELEN, f)) { int len = strlen(linebuf); - *cols = MAX(len, *cols); + *cols = len>*cols?len:*cols; (*rows)++; } - cols--; - ret = (char *)malloc(*cols * *rows); + (*cols)--; + ret = (char *)malloc(*cols * *rows + 1); memset(ret, ' ', *cols * *rows); fseek(f, 0, SEEK_SET); for (int r=0; r<*rows; r++) { - fgets(&ret[r * *cols], *cols, f); + fgets(&ret[r * *cols], LINELEN, f); } fclose(f); } free(linebuf); + printf("image size: %d x %d\n", *cols, *rows); + + for (int y=0; y < *rows; y++) { + for (int x=0; x < *cols; x++) { + //mvaddch(y,x,img[y * *cols +x]); + printf("%c", ret[y * *cols +x]); + } + printf("\n"); + } + return ret; }