comparison tools/lib64gfx.c @ 1447:de5f7e31a8bf

Rename labels.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 05:15:25 +0300
parents 57e97e58cbf3
children 50402c225ef4
comparison
equal deleted inserted replaced
1446:948b32bd67ef 1447:de5f7e31a8bf
1276 if ((buf = dmMalloc(allocated)) == NULL) 1276 if ((buf = dmMalloc(allocated)) == NULL)
1277 { 1277 {
1278 return dmError(DMERR_MALLOC, 1278 return dmError(DMERR_MALLOC,
1279 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", 1279 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n",
1280 allocated); 1280 allocated);
1281 goto error; 1281 goto err;
1282 } 1282 }
1283 1283
1284 // Perform encoding 1284 // Perform encoding
1285 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) 1285 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
1286 { 1286 {
1292 if (op->type == DT_LAST) 1292 if (op->type == DT_LAST)
1293 break; 1293 break;
1294 1294
1295 // Check operation validity 1295 // Check operation validity
1296 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK) 1296 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
1297 goto error; 1297 goto err;
1298 1298
1299 // Check size 1299 // Check size
1300 if (!dmC64GetOpSize(op, fmt, &size)) 1300 if (!dmC64GetOpSize(op, fmt, &size))
1301 { 1301 {
1302 res = dmError(DMERR_INVALID_DATA, 1302 res = dmError(DMERR_INVALID_DATA,
1303 "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), " 1303 "Decode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
1304 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n", 1304 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
1305 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size); 1305 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
1306 goto error; 1306 goto err;
1307 } 1307 }
1308 1308
1309 // Do we need to reallocate some more space? 1309 // Do we need to reallocate some more space?
1310 chksize = op->offs + size + 2; 1310 chksize = op->offs + size + 2;
1311 if (chksize > allocated) 1311 if (chksize > allocated)
1318 if ((buf = dmRealloc(buf, allocated)) == NULL) 1318 if ((buf = dmRealloc(buf, allocated)) == NULL)
1319 { 1319 {
1320 res = dmError(DMERR_MALLOC, 1320 res = dmError(DMERR_MALLOC,
1321 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", 1321 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",
1322 allocated); 1322 allocated);
1323 goto error; 1323 goto err;
1324 } 1324 }
1325 } 1325 }
1326 1326
1327 if (fmt->size == 0 && chksize > *plen) 1327 if (fmt->size == 0 && chksize > *plen)
1328 *plen = chksize; 1328 *plen = chksize;
1339 { 1339 {
1340 res = dmError(DMERR_NULLPTR, 1340 res = dmError(DMERR_NULLPTR,
1341 "DT_EXTRA_DATA block is NULL in ", 1341 "DT_EXTRA_DATA block is NULL in ",
1342 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 1342 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1343 i, op->offs, op->offs, op->bank, size, size, *plen, *plen); 1343 i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
1344 goto error; 1344 goto err;
1345 } 1345 }
1346 if (size > img->extraDataSizes[op->bank]) 1346 if (size > img->extraDataSizes[op->bank])
1347 { 1347 {
1348 res = dmError(DMERR_INTERNAL, 1348 res = dmError(DMERR_INTERNAL,
1349 "DT_EXTRA_DATA size mismatch %d <> %d in ", 1349 "DT_EXTRA_DATA size mismatch %d <> %d in ",
1350 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 1350 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1351 op->size, img->extraDataSizes[op->bank], i, op->offs, op->offs, op->bank, size, size, *plen, *plen); 1351 op->size, img->extraDataSizes[op->bank], i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
1352 goto error; 1352 goto err;
1353 } 1353 }
1354 memcpy(dst, img->extraData[op->bank], size); 1354 memcpy(dst, img->extraData[op->bank], size);
1355 break; 1355 break;
1356 1356
1357 case DT_COLOR_REG: 1357 case DT_COLOR_REG:
1366 default: 1366 default:
1367 res = dmError(DMERR_INTERNAL, 1367 res = dmError(DMERR_INTERNAL,
1368 "Unhandled DT_COLOR_REG mode %d in ", 1368 "Unhandled DT_COLOR_REG mode %d in ",
1369 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 1369 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1370 op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen); 1370 op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
1371 goto error; 1371 goto err;
1372 } 1372 }
1373 break; 1373 break;
1374 1374
1375 case DT_ENC_FUNCTION: 1375 case DT_ENC_FUNCTION:
1376 if (op->encfunction == NULL) 1376 if (op->encfunction == NULL)
1377 { 1377 {
1378 res = dmError(DMERR_INTERNAL, 1378 res = dmError(DMERR_INTERNAL,
1379 "Encode op is a function, but function ptr is NULL: " 1379 "Encode op is a function, but function ptr is NULL: "
1380 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", 1380 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1381 i, op->offs, op->offs, op->bank, size, size, *plen, *plen); 1381 i, op->offs, op->offs, op->bank, size, size, *plen, *plen);
1382 goto error; 1382 goto err;
1383 } 1383 }
1384 /* 1384 /*
1385 if (!op->encfunction(op, buf, len)) 1385 if (!op->encfunction(op, buf, len))
1386 { 1386 {
1387 res = dmError(DMERR_INTERNAL, 1387 res = dmError(DMERR_INTERNAL,
1396 } 1396 }
1397 1397
1398 buf[0] = DM_GET_ADDR_LO(fmt->addr); 1398 buf[0] = DM_GET_ADDR_LO(fmt->addr);
1399 buf[1] = DM_GET_ADDR_HI(fmt->addr); 1399 buf[1] = DM_GET_ADDR_HI(fmt->addr);
1400 1400
1401 err:
1401 *pbuf = buf; 1402 *pbuf = buf;
1402 return DMERR_OK;
1403
1404 error:
1405 dmFree(buf);
1406 *pbuf = NULL;
1407 *plen = 0;
1408 return res; 1403 return res;
1409 } 1404 }
1410 1405
1411 1406
1412 // Convert a generic "C64" format bitmap in DMC64Image struct to 1407 // Convert a generic "C64" format bitmap in DMC64Image struct to