changeset 1309:5ad7d780a09b

Move bitstream reading functions to libgfx, as they were only used there.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 19 Aug 2017 15:27:43 +0300
parents 8f71ca1900ea
children dce4730372c7
files Makefile.gen src/dmbstr.c src/dmbstr.h tools/libgfx.c tools/libgfx.h
diffstat 5 files changed, 85 insertions(+), 118 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.gen	Sat Aug 19 15:21:41 2017 +0300
+++ b/Makefile.gen	Sat Aug 19 15:27:43 2017 +0300
@@ -305,7 +305,7 @@
 
 DMLIB_A=$(OBJPATH)dmlib.a
 DMLIB_OBJS += \
-	dmfile.o dmbstr.o dmlib.o dmcurves.o dmstring.o \
+	dmfile.o dmlib.o dmcurves.o dmstring.o \
 	dmargs.o dmvecmat.o dmperlin.o dmimage.o \
 	dmwav.o dmengine.o dmfft.o dmzlib.o
 
--- a/src/dmbstr.c	Sat Aug 19 15:21:41 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,76 +0,0 @@
-/*
- * DMLib
- * -- Simple bitstream I/O functions
- * Programmed and designed by Matti 'ccr' Hamalainen
- * (C) Copyright 2012 Tecnic Software productions (TNSP)
- */
-#include "dmbstr.h"
-
-
-void dmInitBitStreamContext(DMBitStreamContext *ctx)
-{
-    ctx->outBuf       = 0;
-    ctx->outByteCount = 0;
-    ctx->outBitCount  = 8;
-}
-
-
-BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n)
-{
-    int i;
-    unsigned int mask = 1 << (n - 1);
-
-    for (i = 0; i < n; i++)
-    {
-        ctx->outBuf <<= 1;
-
-        if (val & mask)
-          ctx->outBuf |= 1;
-
-        mask >>= 1;
-        ctx->outBitCount--;
-
-        if (ctx->outBitCount == 0)
-        {
-            if (!ctx->putByte(ctx, ctx->outBuf & 0xff))
-                return FALSE;
-
-            ctx->outBitCount = 8;
-            ctx->outByteCount++;
-        }
-    }
-
-    return TRUE;
-}
-
-
-int dmFlushBitStream(DMBitStreamContext *ctx)
-{
-  if (ctx == NULL)
-      return DMERR_NULLPTR;
-
-  if (ctx->outBitCount != 8)
-      dmPutBits(ctx, 0, ctx->outBitCount);
-
-  return 0;
-}
-
-
-static BOOL dmPutByteFILE(DMBitStreamContext *ctx, const Uint8 val)
-{
-    return fputc(val, (FILE *) ctx->fp) == val;
-}
-
-
-int dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp)
-{
-    if (ctx == NULL || fp == NULL)
-        return DMERR_NULLPTR;
-
-    ctx->putByte = dmPutByteFILE;
-    ctx->fp      = (void *) fp;
-
-    dmInitBitStreamContext(ctx);
-
-    return DMERR_OK;
-}
--- a/src/dmbstr.h	Sat Aug 19 15:21:41 2017 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-/*
- * DMLib
- * -- Simple bitstream I/O functions
- * Programmed and designed by Matti 'ccr' Hamalainen
- * (C) Copyright 2012 Tecnic Software productions (TNSP)
- */
-#ifndef DMBSTR_H
-#define DMBSTR_H
-
-#include "dmlib.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-typedef struct _DMBitStreamContext
-{
-    void *fp;
-
-    BOOL (*putByte)(struct _DMBitStreamContext *ctx, Uint8 val);
-
-    int outBuf, outBitCount, outByteCount;
-} DMBitStreamContext;
-
-
-void  dmInitBitStreamContext(DMBitStreamContext *ctx);
-int   dmFlushBitStream(DMBitStreamContext *ctx);
-
-BOOL  dmPutBits(DMBitStreamContext *ctx, const int val, const int n);
-
-
-int   dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp);
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif // DMBSTR_H
--- a/tools/libgfx.c	Sat Aug 19 15:21:41 2017 +0300
+++ b/tools/libgfx.c	Sat Aug 19 15:27:43 2017 +0300
@@ -7,7 +7,6 @@
  */
 #include "libgfx.h"
 #include "dmfile.h"
-#include "dmbstr.h"
 
 #ifdef DM_USE_LIBPNG
 #include <png.h>
@@ -17,6 +16,73 @@
 int dmGFXErrorMode = DM_ERRMODE_FAIL;
 
 
+void dmInitBitStreamContext(DMBitStreamContext *ctx)
+{
+    ctx->outBuf       = 0;
+    ctx->outByteCount = 0;
+    ctx->outBitCount  = 8;
+}
+
+
+BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n)
+{
+    int i;
+    unsigned int mask = 1 << (n - 1);
+
+    for (i = 0; i < n; i++)
+    {
+        ctx->outBuf <<= 1;
+
+        if (val & mask)
+          ctx->outBuf |= 1;
+
+        mask >>= 1;
+        ctx->outBitCount--;
+
+        if (ctx->outBitCount == 0)
+        {
+            if (!ctx->putByte(ctx, ctx->outBuf & 0xff))
+                return FALSE;
+
+            ctx->outBitCount = 8;
+            ctx->outByteCount++;
+        }
+    }
+
+    return TRUE;
+}
+
+
+int dmFlushBitStream(DMBitStreamContext *ctx)
+{
+  if (ctx == NULL)
+      return DMERR_NULLPTR;
+
+  if (ctx->outBitCount != 8)
+      dmPutBits(ctx, 0, ctx->outBitCount);
+
+  return 0;
+}
+
+
+static BOOL dmPutByteFILE(DMBitStreamContext *ctx, const Uint8 val)
+{
+    return fputc(val, (FILE *) ctx->handle) == val;
+}
+
+
+int dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp)
+{
+    if (ctx == NULL || fp == NULL)
+        return DMERR_NULLPTR;
+
+    ctx->putByte = dmPutByteFILE;
+    ctx->handle  = (void *) fp;
+
+    dmInitBitStreamContext(ctx);
+
+    return DMERR_OK;
+}
 
 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha)
 {
--- a/tools/libgfx.h	Sat Aug 19 15:21:41 2017 +0300
+++ b/tools/libgfx.h	Sat Aug 19 15:27:43 2017 +0300
@@ -124,6 +124,23 @@
 int dmReadPCXImage(const char *filename, DMImage **pimg);
 
 
+typedef struct _DMBitStreamContext
+{
+    void *handle;
+
+    BOOL (*putByte)(struct _DMBitStreamContext *ctx, Uint8 val);
+
+    int outBuf, outBitCount, outByteCount;
+} DMBitStreamContext;
+
+
+void  dmInitBitStreamContext(DMBitStreamContext *ctx);
+int   dmFlushBitStream(DMBitStreamContext *ctx);
+BOOL  dmPutBits(DMBitStreamContext *ctx, const int val, const int n);
+int   dmInitBitStreamFILE(DMBitStreamContext *ctx, FILE *fp);
+
+
+
 #ifdef __cplusplus
 }
 #endif