Mercurial > hg > dmlib
comparison tools/gfxconv.c @ 909:be5d276f8a6c
Some work on error handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 23 Feb 2015 22:51:51 +0200 |
parents | bc6c338295e5 |
children | 43a71b097f17 |
comparison
equal
deleted
inserted
replaced
908:03bda6477ad4 | 909:be5d276f8a6c |
---|---|
1245 } | 1245 } |
1246 | 1246 |
1247 | 1247 |
1248 int dmWriteSpritesAndChars(const char *filename, DMImage *image, int outFormat, BOOL multicolor) | 1248 int dmWriteSpritesAndChars(const char *filename, DMImage *image, int outFormat, BOOL multicolor) |
1249 { | 1249 { |
1250 int ret = DMERR_OK; | |
1250 int outBlockW, outBlockH, bx, by; | 1251 int outBlockW, outBlockH, bx, by; |
1251 FILE *outFile = NULL; | 1252 FILE *outFile = NULL; |
1252 Uint8 *buf = NULL; | 1253 Uint8 *buf = NULL; |
1253 size_t outBufSize; | 1254 size_t outBufSize; |
1254 char *outType; | 1255 char *outType; |
1268 outBlockH = image->height / C64_SPR_HEIGHT; | 1269 outBlockH = image->height / C64_SPR_HEIGHT; |
1269 outType = "sprite"; | 1270 outType = "sprite"; |
1270 break; | 1271 break; |
1271 | 1272 |
1272 default: | 1273 default: |
1274 ret = DMERR_INVALID_ARGS; | |
1273 dmError("Invalid output format %d, internal error.\n", outFormat); | 1275 dmError("Invalid output format %d, internal error.\n", outFormat); |
1274 goto error; | 1276 goto error; |
1275 } | 1277 } |
1276 | 1278 |
1277 if (outBlockW <= 0 || outBlockH <= 0) | 1279 if (outBlockW < 1 || outBlockH < 1) |
1278 { | 1280 { |
1281 ret = DMERR_INVALID_ARGS; | |
1279 dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n", | 1282 dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n", |
1280 outBlockW, outBlockH); | 1283 outBlockW, outBlockH); |
1281 goto error; | 1284 goto error; |
1282 } | 1285 } |
1283 | 1286 |
1284 if ((outFile = fopen(filename, "wb")) == NULL) | 1287 if ((outFile = fopen(filename, "wb")) == NULL) |
1285 { | 1288 { |
1286 int err = dmGetErrno(); | 1289 ret = dmGetErrno(); |
1287 dmError("Could not open '%s' for writing, %d: %s.\n", | 1290 dmError("Could not open '%s' for writing, %d: %s.\n", |
1288 filename, err, dmErrorStr(err)); | 1291 filename, ret, dmErrorStr(ret)); |
1289 goto error; | 1292 goto error; |
1290 } | 1293 } |
1291 | 1294 |
1292 if ((buf = dmMalloc(outBufSize)) == NULL) | 1295 if ((buf = dmMalloc(outBufSize)) == NULL) |
1293 { | 1296 { |
1306 { | 1309 { |
1307 case FFMT_CHAR: | 1310 case FFMT_CHAR: |
1308 if (!dmConvertImage2Char(buf, image, | 1311 if (!dmConvertImage2Char(buf, image, |
1309 bx * C64_CHR_WIDTH_PX, by * C64_CHR_HEIGHT, | 1312 bx * C64_CHR_WIDTH_PX, by * C64_CHR_HEIGHT, |
1310 multicolor)) | 1313 multicolor)) |
1314 { | |
1315 ret = DMERR_DATA_ERROR; | |
1311 goto error; | 1316 goto error; |
1317 } | |
1312 break; | 1318 break; |
1313 | 1319 |
1314 case FFMT_SPRITE: | 1320 case FFMT_SPRITE: |
1315 if (!dmConvertImage2Sprite(buf, image, | 1321 if (!dmConvertImage2Sprite(buf, image, |
1316 bx * C64_SPR_WIDTH_PX, by * C64_SPR_HEIGHT, | 1322 bx * C64_SPR_WIDTH_PX, by * C64_SPR_HEIGHT, |
1317 multicolor)) | 1323 multicolor)) |
1324 { | |
1325 ret = DMERR_DATA_ERROR; | |
1318 goto error; | 1326 goto error; |
1327 } | |
1319 } | 1328 } |
1320 | 1329 |
1321 if (!dm_fwrite_str(outFile, buf, outBufSize)) | 1330 if (!dm_fwrite_str(outFile, buf, outBufSize)) |
1322 { | 1331 { |
1323 int err = dmGetErrno(); | 1332 ret = dmGetErrno(); |
1324 dmError("Error writing data block %d,%d to '%s', %d: %s\n", | 1333 dmError("Error writing data block %d,%d to '%s', %d: %s\n", |
1325 bx, by, filename, err, dmErrorStr(err)); | 1334 bx, by, filename, ret, dmErrorStr(ret)); |
1326 goto error; | 1335 goto error; |
1327 } | 1336 } |
1328 } | 1337 } |
1329 | 1338 |
1330 fclose(outFile); | 1339 fclose(outFile); |