Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1472:b9d3577d8290
Improve error handling and checking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 10 May 2018 23:08:09 +0300 |
parents | a988baa5b21f |
children | 7729fefe8e57 |
comparison
equal
deleted
inserted
replaced
1471:a988baa5b21f | 1472:b9d3577d8290 |
---|---|
1363 int res = DMERR_OK; | 1363 int res = DMERR_OK; |
1364 | 1364 |
1365 if (img == NULL || fmt == NULL) | 1365 if (img == NULL || fmt == NULL) |
1366 return DMERR_NULLPTR; | 1366 return DMERR_NULLPTR; |
1367 | 1367 |
1368 // Sanity check img vs format | |
1369 if (img->type != fmt->type || | |
1370 img->width != fmt->width || img->height != fmt->height) | |
1371 { | |
1372 res = dmError(DMERR_NOT_SUPPORTED, | |
1373 "Can't directly encode a differing C64 bitmap image format.\n"); | |
1374 goto err; | |
1375 } | |
1376 | |
1368 // Allocate the output buffer | 1377 // Allocate the output buffer |
1369 if ((res = dmGrowBufAlloc(buf, fmt->size, BUF_SIZE_GROW)) != DMERR_OK) | 1378 if ((res = dmGrowBufAlloc(buf, fmt->size, BUF_SIZE_GROW)) != DMERR_OK) |
1370 { | 1379 { |
1371 return dmError(res, | 1380 dmError(res, |
1372 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", | 1381 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", |
1373 fmt->size); | 1382 fmt->size); |
1374 goto err; | 1383 goto err; |
1375 } | 1384 } |
1376 buf->len = fmt->size; | 1385 buf->len = fmt->size; |
1723 | 1732 |
1724 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) | 1733 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) |
1725 { | 1734 { |
1726 int res; | 1735 int res; |
1727 | 1736 |
1728 if (img == NULL) | 1737 if (img == NULL || fmt == NULL) |
1729 return DMERR_NULLPTR; | 1738 return DMERR_NULLPTR; |
1730 | 1739 |
1731 // Attempt to encode the image to a buffer | 1740 // Attempt to encode the image to a buffer |
1741 if ((res = dmGrowBufInit(buf)) != DMERR_OK) | |
1742 return res; | |
1743 | |
1732 if (fmt->encode != NULL) | 1744 if (fmt->encode != NULL) |
1733 res = fmt->encode(buf, img, fmt); | 1745 res = fmt->encode(buf, img, fmt); |
1734 else | 1746 else |
1735 res = dmC64EncodeGenericBMP(buf, img, fmt); | 1747 res = dmC64EncodeGenericBMP(buf, img, fmt); |
1736 | 1748 |