Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1469:0046b4e1b35f
Various fixes in bmp encoding.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 10 May 2018 22:30:02 +0300 |
parents | 32203356c652 |
children | a988baa5b21f |
comparison
equal
deleted
inserted
replaced
1468:d14d1101616f | 1469:0046b4e1b35f |
---|---|
1348 | 1348 |
1349 int dmC64EncodeGenericBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) | 1349 int dmC64EncodeGenericBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) |
1350 { | 1350 { |
1351 int res = DMERR_OK; | 1351 int res = DMERR_OK; |
1352 | 1352 |
1353 if (buf == NULL || img == NULL || fmt == NULL) | 1353 if (img == NULL || fmt == NULL) |
1354 return DMERR_NULLPTR; | 1354 return DMERR_NULLPTR; |
1355 | 1355 |
1356 // Allocate the output buffer | 1356 // Allocate the output buffer |
1357 if ((res = dmGrowBufAlloc(buf, fmt->size, BUF_SIZE_GROW)) != DMERR_OK) | 1357 if ((res = dmGrowBufAlloc(buf, fmt->size, BUF_SIZE_GROW)) != DMERR_OK) |
1358 { | 1358 { |
1359 return dmError(res, | 1359 return dmError(res, |
1360 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", | 1360 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", |
1361 fmt->size); | 1361 fmt->size); |
1362 goto err; | 1362 goto err; |
1363 } | 1363 } |
1364 buf->len = fmt->size; | |
1364 | 1365 |
1365 // Perform encoding | 1366 // Perform encoding |
1366 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) | 1367 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
1367 { | 1368 { |
1368 const DMC64EncDecOp *op = &fmt->encdecOps[i]; | 1369 const DMC64EncDecOp *op = &fmt->encdecOps[i]; |
1723 | 1724 |
1724 if (res != DMERR_OK) | 1725 if (res != DMERR_OK) |
1725 goto err; | 1726 goto err; |
1726 | 1727 |
1727 // Add the loading address | 1728 // Add the loading address |
1728 if ((res = dmGrowBufGrow(buf, 2)) != DMERR_OK) | 1729 if (!dmGrowBufGrow(buf, 2)) |
1730 { | |
1731 res = DMERR_MALLOC; | |
1729 goto err; | 1732 goto err; |
1733 } | |
1730 | 1734 |
1731 memmove(buf->data + 2, buf->data, buf->len); | 1735 memmove(buf->data + 2, buf->data, buf->len); |
1732 | 1736 |
1733 buf->data[0] = DM_GET_ADDR_LO(fmt->addr); | 1737 buf->data[0] = DM_GET_ADDR_LO(fmt->addr); |
1734 buf->data[1] = DM_GET_ADDR_HI(fmt->addr); | 1738 buf->data[1] = DM_GET_ADDR_HI(fmt->addr); |
1735 | 1739 |
1736 buf->len += 2; | 1740 return DMERR_OK; |
1737 | 1741 |
1738 err: | 1742 err: |
1739 dmGrowBufFree(buf); | 1743 dmGrowBufFree(buf); |
1740 return res; | 1744 return res; |
1741 } | 1745 } |