comparison tools/lib64fmts.c @ 2149:810fc98d9003

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 02 Jun 2019 23:37:35 +0300
parents 009ee261704c
children b4fbb90937f7
comparison
equal deleted inserted replaced
2148:487157934904 2149:810fc98d9003
981 static int fmtDecodeCosmosDesignsHiresManagerPacked(DMC64Image *img, const DMGrowBuf *psrc, const DMC64ImageFormat *fmt) 981 static int fmtDecodeCosmosDesignsHiresManagerPacked(DMC64Image *img, const DMGrowBuf *psrc, const DMC64ImageFormat *fmt)
982 { 982 {
983 int res; 983 int res;
984 DMGrowBuf src, tmp; 984 DMGrowBuf src, tmp;
985 DMCompParams cfg; 985 DMCompParams cfg;
986 Uint8 data, count; 986 Uint8 data, count, *dstBuf;
987 const size_t dstSize = 0x7ff2 - 0x4000; 987 const size_t dstSize = 0x7ff2 - 0x4000;
988 size_t dstOffs; 988 size_t dstOffs;
989 Uint8 *dstBuf;
990 BOOL getByte = TRUE; 989 BOOL getByte = TRUE;
991 990
992 if ((dstBuf = dmMalloc0(dstSize)) == NULL) 991 // Setup the RLE config, only for input
993 {
994 return dmError(DMERR_MALLOC,
995 "Could not allocate memory for RLE decoding buffer.\n");
996 }
997
998 cfg.func = fmt->name; 992 cfg.func = fmt->name;
999 cfg.type = DM_COMP_RLE_MARKER; 993 cfg.type = DM_COMP_RLE_MARKER;
1000 cfg.flags = DM_RLE_BACKWARDS_INPUT; 994 cfg.flags = DM_RLE_BACKWARDS_INPUT;
1001 995
996 // Allocate output buffer
997 if ((dstBuf = dmMalloc0(dstSize)) == NULL)
998 {
999 return dmError(DMERR_MALLOC,
1000 "%s: Could not allocate memory for RLE decoding buffer.\n",
1001 cfg.func);
1002 }
1003
1004 // Setup input buffer
1002 dmGrowBufConstCopy(&src, psrc); 1005 dmGrowBufConstCopy(&src, psrc);
1003 dmSetupRLEBuffers(NULL, &src, &cfg); 1006 dmSetupRLEBuffers(NULL, &src, &cfg);
1004 dstOffs = dstSize; 1007 dstOffs = dstSize;
1005 1008
1006 while (dstOffs > 0 && src.offs > 0) 1009 while (dstOffs > 0 && src.offs > 0)
1036 { 1039 {
1037 int ncount = (int) data; 1040 int ncount = (int) data;
1038 for (int n = 0; n < ncount; n++) 1041 for (int n = 0; n < ncount; n++)
1039 { 1042 {
1040 if (!dmGrowBufGetU8(&src, &data)) 1043 if (!dmGrowBufGetU8(&src, &data))
1041 break; 1044 goto finish;
1042 1045
1043 if (dstOffs > 0) 1046 if (dstOffs > 0)
1044 dstBuf[--dstOffs] = data; 1047 dstBuf[--dstOffs] = data;
1045 else 1048 else
1046 break; 1049 goto finish;
1047 } 1050 }
1048 getByte = FALSE; 1051 getByte = FALSE;
1049 } 1052 }
1050 } 1053 }
1054
1055 finish:
1051 1056
1052 dmGrowBufConstCreateFrom(&tmp, dstBuf, 0x3fff); 1057 dmGrowBufConstCreateFrom(&tmp, dstBuf, 0x3fff);
1053 res = dmC64DecodeGenericBMP(img, &tmp, fmt); 1058 res = dmC64DecodeGenericBMP(img, &tmp, fmt);
1054 1059
1055 out: 1060 out: