aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-07-16 15:29:43 +0200
committerMattias Andrée <maandree@kth.se>2017-07-16 15:29:43 +0200
commitd05d162cb81664f292834fa5d48d623d2b6147a7 (patch)
tree9d4252fcdfa2210613188d5c965514cfab6a8ec2 /src/stream.c
parentUse #include instead of #define (diff)
downloadblind-d05d162cb81664f292834fa5d48d623d2b6147a7.tar.gz
blind-d05d162cb81664f292834fa5d48d623d2b6147a7.tar.bz2
blind-d05d162cb81664f292834fa5d48d623d2b6147a7.tar.xz
Misc code improvements
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/stream.c b/src/stream.c
index 7ce32e2..11dabd5 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -73,7 +73,7 @@ eninit_stream(int status, struct stream *stream)
memmove(stream->buf, stream->buf + 5, stream->ptr -= 5);
stream->headlen = n + 5;
- enset_pixel_size(status, stream);
+ enset_pixel_format(status, stream, NULL);
stream->xptr = 0;
@@ -93,8 +93,15 @@ enopen_stream(int status, struct stream *stream, const char *file)
int
-set_pixel_size(struct stream *stream)
+set_pixel_format(struct stream *stream, const char *pixfmt)
{
+ if (pixfmt) {
+ pixfmt = get_pixel_format(pixfmt, "xyza");
+ if (strlen(pixfmt) >= sizeof(stream->pixfmt))
+ return -1;
+ strcpy(stream->pixfmt, pixfmt);
+ }
+
if (!strcmp(stream->pixfmt, "xyza")) {
stream->n_chan = 4;
stream->chan_size = sizeof(double);
@@ -110,6 +117,7 @@ set_pixel_size(struct stream *stream)
} else {
return -1;
}
+
stream->pixel_size = stream->n_chan * stream->chan_size;
stream->row_size = stream->pixel_size * stream->width;
stream->col_size = stream->pixel_size * stream->height;
@@ -118,11 +126,15 @@ set_pixel_size(struct stream *stream)
}
void
-enset_pixel_size(int status, struct stream *stream)
+enset_pixel_format(int status, struct stream *stream, const char *pixfmt)
{
- if (set_pixel_size(stream))
- enprintf(status, "file %s uses unsupported pixel format: %s\n",
- stream->file, stream->pixfmt);
+ if (!set_pixel_format(stream, pixfmt)) {
+ if (pixfmt)
+ enprintf(status, "pixel format %s is not supported, try xyza\n", pixfmt);
+ else
+ enprintf(status, "%s: unsupported pixel format: %s\n",
+ stream->file, stream->pixfmt);
+ }
}