Mercurial > hg > dmlib
changeset 1121:043b5942fdb6
Rename some dmzlib functions and add context init/close functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2015 04:37:58 +0200 |
parents | c1583a2278ec |
children | 320dcfd1bd75 |
files | src/dmres.c src/dmzlib.c src/dmzlib.h src/stb_image.c tests/testdmzlib.c |
diffstat | 5 files changed, 44 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmres.c Wed Mar 04 03:53:22 2015 +0200 +++ b/src/dmres.c Wed Mar 04 04:37:58 2015 +0200 @@ -410,9 +410,10 @@ } // Initialize decompression structures + if ((ret = dmZLibInitInflate(&ctx)) != DMERR_OK) + goto out; ctx.inBuffer = ctx.inBufferStart = inBuf; ctx.inBufferEnd = inBuf + node->length; - ctx.outBuffer = ctx.outBufferStart = handle->rawData; ctx.outBufferEnd = handle->rawData + node->size; ctx.expandable = FALSE; @@ -421,13 +422,14 @@ if ((ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) goto out; - if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) + if ((ret = dmZLibInflate(&ctx)) != DMERR_OK) goto out; handle->rawData = ctx.outBufferStart; handle->rawSize = ctx.outBuffer - ctx.outBufferStart; out: + dmZLibCloseInflate(&ctx); dmFree(inBuf); return ret; }
--- a/src/dmzlib.c Wed Mar 04 03:53:22 2015 +0200 +++ b/src/dmzlib.c Wed Mar 04 04:37:58 2015 +0200 @@ -548,7 +548,26 @@ } -int dmZLibDecode(DMZLibContext * ctx) +int dmZLibInitInflate(DMZLibContext *ctx) +{ + if (ctx == NULL) + return DMERR_NULLPTR; + + memset(ctx, 0, sizeof(DMZLibContext)); + return DMERR_OK; +} + + +void dmZLibCloseInflate(DMZLibContext *ctx) +{ + if (ctx != NULL) + { + memset(ctx, 0, sizeof(DMZLibContext)); + } +} + + +int dmZLibInflate(DMZLibContext * ctx) { int final, type, ret;
--- a/src/dmzlib.h Wed Mar 04 03:53:22 2015 +0200 +++ b/src/dmzlib.h Wed Mar 04 04:37:58 2015 +0200 @@ -53,8 +53,11 @@ int dmZLibInit(); void dmZLibClose(); + +int dmZLibInitInflate(DMZLibContext *ctx); +void dmZLibCloseInflate(DMZLibContext *ctx); int dmZLibParseHeader(DMZLibContext * ctx, BOOL checkPNG); -int dmZLibDecode(DMZLibContext * ctx); +int dmZLibInflate(DMZLibContext * ctx); #ifdef __cplusplus
--- a/src/stb_image.c Wed Mar 04 03:53:22 2015 +0200 +++ b/src/stb_image.c Wed Mar 04 04:37:58 2015 +0200 @@ -3713,6 +3713,10 @@ goto err; } + // Initialize decompression structures + if ((ret = dmZLibInitInflate(&ctx)) != DMERR_OK) + goto err; + ctx.inBuffer = ctx.inBufferStart = inBuf; ctx.inBufferEnd = inBuf + inLen; ctx.outBufferEnd = ctx.outBufferStart + initialSize; @@ -3721,14 +3725,17 @@ if (parseHeader && (ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) goto err; - if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) + if ((ret = dmZLibInflate(&ctx)) != DMERR_OK) goto err; *outBuf = ctx.outBufferStart; *outLen = ctx.outBuffer - ctx.outBufferStart; + + dmZLibCloseInflate(&ctx); return DMERR_OK; err: + dmZLibCloseInflate(&ctx); dmFree(*outBuf); *outBuf = NULL; return ret;
--- a/tests/testdmzlib.c Wed Mar 04 03:53:22 2015 +0200 +++ b/tests/testdmzlib.c Wed Mar 04 04:37:58 2015 +0200 @@ -129,6 +129,9 @@ } // Initialize decompression structures + if ((ret = dmZLibInitInflate(&ctx)) != DMERR_OK) + goto out; + ctx.inBuffer = ctx.inBufferStart = inBuffer; ctx.inBufferEnd = inBuffer + *inSize; @@ -143,7 +146,7 @@ goto out; } - if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) + if ((ret = dmZLibInflate(&ctx)) != DMERR_OK) { dmErrorMsg("Error in ZLIB decompress: %d, %s\n", ret, dmErrorStr(ret)); goto out; @@ -159,7 +162,7 @@ } out: - + dmZLibCloseInflate(&ctx); dmFree(inBuffer); dmFree(outBuffer); return ret; @@ -275,6 +278,8 @@ argHandleOpt, argHandleFile, OPTH_BAILOUT)) exit(1); + dmZLibInit(); + // Input and output files if (optInFilename == NULL) inFile = stdin; @@ -321,5 +326,6 @@ if (inFile != NULL) fclose(inFile); + dmZLibClose(); return 0; }