image reader

This commit is contained in:
tkarrass 2013-11-02 22:30:30 +01:00
parent 2c9b507078
commit 92a9d59337
5 changed files with 56 additions and 3 deletions

View File

@ -4,7 +4,7 @@ BIN=bin
SRC=src
LIBS=-lncurses
TARGET=$(BIN)/netsl
OBJECTS=$(BIN)/main.o $(BIN)/msg.o $(BIN)/net.o $(BIN)/display.o
OBJECTS=$(BIN)/main.o $(BIN)/msg.o $(BIN)/net.o $(BIN)/display.o $(BIN)/image.o
all: $(BIN) $(TARGET)

10
image Normal file
View File

@ -0,0 +1,10 @@
_,-%/%|
_,-' \//%\
_,-' \%/|%
/ / ) __,-- /%\
\__/_,-'%(% ; %)%
/ %\%, %\
/ '--%'
/

View File

@ -77,9 +77,9 @@ void prntscreen(const struct message *msg, const struct prog_info *pinfo) {
int left = right + cols;
// printf("loop\n");
for (int y=0; y<10; y++) { // y<msg->height; y++) {
for (int y=0; y<50; y++) { // y<msg->height; y++) {
for (int x=left-frame; x<cols; x++) {
mvaddch(y, x, ('0' + x-(left-frame)));
mvaddch(y, x, ('0' + x-(left-frame)+y));
}
}

31
src/image.c Normal file
View File

@ -0,0 +1,31 @@
#include "image.h"
char *readImage(const char* filename, int *cols, int *rows) {
FILE *f = fopen(filename, "r");
*cols = 0;
*rows = 0;
char *linebuf = (char *)malloc(LINELEN);
char *ret = NULL;
if (!f) {
while (fgets(linebuf, LINELEN, f)) {
int len = strlen(linebuf);
*cols = len>*cols?len:*cols;
(*rows)++;
}
cols--;
ret = (char *)malloc(*cols * *rows);
memset(ret, ' ', *cols * *rows);
fseek(f, 0, SEEK_SET);
for (int r=0; r<*rows; r++) {
fgets(&ret[r * *cols], *cols, f);
}
fclose(f);
}
free(linebuf);
return ret;
}

12
src/image.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __IMAGE
#define __IMAGE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINELEN 20000
char *readImage(const char* filename, int *cols, int *rows);
#endif