comparison src/dmbstr.c @ 1091:988a3397839e

Move functions around for saner order.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 02 Mar 2015 20:30:25 +0200
parents 27d041472c8f
children e06abfde6c39
comparison
equal deleted inserted replaced
1090:e0fb6fa1c689 1091:988a3397839e
5 * (C) Copyright 2012 Tecnic Software productions (TNSP) 5 * (C) Copyright 2012 Tecnic Software productions (TNSP)
6 */ 6 */
7 #include "dmbstr.h" 7 #include "dmbstr.h"
8 8
9 9
10 static BOOL dmPutByteFILE(DMBitStreamContext *ctx, const Uint8 val)
11 {
12 return fputc(val, (FILE *) ctx->fp) == val;
13 }
14
15
16 void dmInitBitStreamContext(DMBitStreamContext *ctx) 10 void dmInitBitStreamContext(DMBitStreamContext *ctx)
17 { 11 {
18 ctx->outBuf = 0; 12 ctx->outBuf = 0;
19 ctx->outByteCount = 0; 13 ctx->outByteCount = 0;
20 ctx->outBitCount = 8; 14 ctx->outBitCount = 8;
21 }
22
23
24 int dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp)
25 {
26 if (ctx == NULL || fp == NULL)
27 return DMERR_NULLPTR;
28
29 ctx->putByte = dmPutByteFILE;
30 ctx->fp = (void *) fp;
31
32 dmInitBitStreamContext(ctx);
33
34 return DMERR_OK;
35 } 15 }
36 16
37 17
38 BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n) 18 BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n)
39 { 19 {
72 if (ctx->outBitCount != 8) 52 if (ctx->outBitCount != 8)
73 dmPutBits(ctx, 0, ctx->outBitCount); 53 dmPutBits(ctx, 0, ctx->outBitCount);
74 54
75 return 0; 55 return 0;
76 } 56 }
57
58
59 static BOOL dmPutByteFILE(DMBitStreamContext *ctx, const Uint8 val)
60 {
61 return fputc(val, (FILE *) ctx->fp) == val;
62 }
63
64
65 int dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp)
66 {
67 if (ctx == NULL || fp == NULL)
68 return DMERR_NULLPTR;
69
70 ctx->putByte = dmPutByteFILE;
71 ctx->fp = (void *) fp;
72
73 dmInitBitStreamContext(ctx);
74
75 return DMERR_OK;
76 }