Mercurial > hg > dmlib
comparison src/stb_image.c @ 966:c91befdb668b
Fixes and cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Feb 2015 05:23:25 +0200 |
parents | 70bcb294a437 |
children | e98bc627ad08 |
comparison
equal
deleted
inserted
replaced
965:df8d2ad98f7d | 966:c91befdb668b |
---|---|
3704 BOOL parseHeader) | 3704 BOOL parseHeader) |
3705 { | 3705 { |
3706 DMZLibContext ctx; | 3706 DMZLibContext ctx; |
3707 int ret; | 3707 int ret; |
3708 | 3708 |
3709 if ((*outBuf = dmMalloc(initialSize)) == NULL) | 3709 if ((ctx.zout = ctx.zoutStart = dmMalloc(initialSize)) == NULL) |
3710 return 0; | 3710 { |
3711 ret = dmError(DMERR_MALLOC, | |
3712 "Failed to allocate initial decompression buffer.\n"); | |
3713 goto err; | |
3714 } | |
3711 | 3715 |
3712 ctx.zbuffer = (Uint8 *) inBuf; | 3716 ctx.zbuffer = (Uint8 *) inBuf; |
3713 ctx.zbufferEnd = (Uint8 *) inBuf + inLen; | 3717 ctx.zbufferEnd = (Uint8 *) inBuf + inLen; |
3714 ctx.zout = *outBuf; | 3718 ctx.zoutEnd = ctx.zoutStart + initialSize; |
3715 ctx.zoutStart = *outBuf; | |
3716 ctx.zoutEnd = *outBuf + initialSize; | |
3717 ctx.expandable = TRUE; | 3719 ctx.expandable = TRUE; |
3718 | 3720 |
3719 if (parseHeader && (ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) | 3721 if (parseHeader && (ret = dmZLibParseHeader(&ctx, TRUE)) != DMERR_OK) |
3720 { | 3722 goto err; |
3721 return dmError(ret, | |
3722 "Failed to parse zlib header data.\n"); | |
3723 } | |
3724 | 3723 |
3725 if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) | 3724 if ((ret = dmZLibDecode(&ctx)) != DMERR_OK) |
3726 { | 3725 goto err; |
3727 dmFree(*outBuf); | |
3728 return ret; | |
3729 } | |
3730 | 3726 |
3727 *outBuf = ctx.zoutStart; | |
3731 *outLen = ctx.zout - ctx.zoutStart; | 3728 *outLen = ctx.zout - ctx.zoutStart; |
3732 return DMERR_OK; | 3729 return DMERR_OK; |
3730 | |
3731 err: | |
3732 dmFree(*outBuf); | |
3733 *outBuf = NULL; | |
3734 return ret; | |
3733 } | 3735 } |
3734 | 3736 |
3735 | 3737 |
3736 | 3738 |
3737 #define STBI__PNG_TYPE(a,b,c,d) (((a) << 24) + ((b) << 16) + ((c) << 8) + (d)) | 3739 #define STBI__PNG_TYPE(a,b,c,d) (((a) << 24) + ((b) << 16) + ((c) << 8) + (d)) |
3851 z->idata, ioff, | 3853 z->idata, ioff, |
3852 &z->expanded, &raw_len, | 3854 &z->expanded, &raw_len, |
3853 raw_len, !is_iphone) != DMERR_OK) | 3855 raw_len, !is_iphone) != DMERR_OK) |
3854 return 0; | 3856 return 0; |
3855 | 3857 |
3856 if (z->expanded == NULL) return 0; // zlib should set error | |
3857 STBI_FREE(z->idata); z->idata = NULL; | 3858 STBI_FREE(z->idata); z->idata = NULL; |
3859 | |
3858 if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) | 3860 if ((req_comp == s->img_n+1 && req_comp != 3 && !pal_img_n) || has_trans) |
3859 s->img_out_n = s->img_n+1; | 3861 s->img_out_n = s->img_n+1; |
3860 else | 3862 else |
3861 s->img_out_n = s->img_n; | 3863 s->img_out_n = s->img_n; |
3862 if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, depth, color, interlace)) return 0; | 3864 if (!stbi__create_png_image(z, z->expanded, raw_len, s->img_out_n, depth, color, interlace)) return 0; |