aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-06-02 21:00:47 +0200
committerMattias Andrée <maandree@kth.se>2017-06-02 21:08:58 +0200
commitb518ce8977c0b97dd2236fc8cbc7dad1dd70511b (patch)
treed788650ee5106c539b4251570a525850ae3422a4 /src/stream.c
parentUpdate todo (diff)
downloadblind-b518ce8977c0b97dd2236fc8cbc7dad1dd70511b.tar.gz
blind-b518ce8977c0b97dd2236fc8cbc7dad1dd70511b.tar.bz2
blind-b518ce8977c0b97dd2236fc8cbc7dad1dd70511b.tar.xz
Add blind-disperse, blind-split-rows, and blind-split-cols
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c51
1 files changed, 49 insertions, 2 deletions
diff --git a/src/stream.c b/src/stream.c
index 1f361a4..6c9dc72 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -270,8 +270,7 @@ enread_segment(int status, struct stream *stream, void *buf, size_t n)
size_t
ensend_frames(int status, struct stream *stream, int outfd, size_t frames, const char *outfname)
{
- size_t h, w, p, n;
- size_t ret = 0;
+ size_t h, w, p, n, ret;
for (ret = 0; ret < frames; ret++) {
for (p = stream->pixel_size; p; p--) {
@@ -295,6 +294,54 @@ done:
}
+size_t
+ensend_rows(int status, struct stream *stream, int outfd, size_t rows, const char *outfname)
+{
+ size_t w, p, n, ret;
+
+ for (ret = 0; ret < rows; ret++) {
+ for (p = stream->pixel_size; p; p--) {
+ for (w = stream->width; w; w -= n, stream->ptr -= n) {
+ if (!stream->ptr && !enread_stream(status, stream, w))
+ goto done;
+ n = MIN(stream->ptr, w);
+ if (outfd >= 0)
+ enwriteall(status, outfd, stream->buf, n, outfname);
+ }
+ }
+ }
+
+ return ret;
+done:
+ if (p != stream->pixel_size || w != stream->width)
+ enprintf(status, "%s: incomplete row", stream->file);
+ return ret;
+}
+
+
+size_t
+ensend_pixels(int status, struct stream *stream, int outfd, size_t pixels, const char *outfname)
+{
+ size_t p, n, ret;
+
+ for (ret = 0; ret < pixels; ret++) {
+ for (p = stream->pixel_size; p; p -= n, stream->ptr -= n) {
+ if (!stream->ptr && !enread_stream(status, stream, p))
+ goto done;
+ n = MIN(stream->ptr, p);
+ if (outfd >= 0)
+ enwriteall(status, outfd, stream->buf, n, outfname);
+ }
+ }
+
+ return ret;
+done:
+ if (p != stream->pixel_size)
+ enprintf(status, "%s: incomplete pixel", stream->file);
+ return ret;
+}
+
+
int
ensend_stream(int status, struct stream *stream, int outfd, const char *outfname)
{