Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 1482:df6dacb48970
Rename some struct members, and sanitize handling of DMC64Image allocation more.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 03:29:55 +0300 |
parents | d883b4c1cf48 |
children | 1e7f7489d3e0 |
line wrap: on
line diff
--- a/tools/lib64gfx.c Fri May 11 02:49:28 2018 +0300 +++ b/tools/lib64gfx.c Fri May 11 03:29:55 2018 +0300 @@ -84,10 +84,14 @@ // Initialize image information img->width = fmt->width; img->height = fmt->height; - img->ch_width = fmt->ch_width; - img->ch_height = fmt->ch_height; + img->chWidth = fmt->chWidth; + img->chHeight = fmt->chHeight; img->nbanks = dmC64ImageGetNumBanks(fmt); + img->screenSize = img->chWidth * img->chHeight; + img->bitmapSize = img->screenSize * 8; + img->charmemSize = C64_MAX_CHARS * C64_CHR_SIZE; + // Allocate banks if ((img->color = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || (img->bitmap = dmCalloc(img->nbanks, sizeof(Uint8 *))) == NULL || @@ -97,16 +101,16 @@ for (int i = 0; i < img->nbanks; i++) { - if ((img->color[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL) + if ((img->color[i] = dmMalloc0(img->screenSize)) == NULL) goto err; - if ((img->bitmap[i] = dmMalloc0(img->ch_width * img->ch_height * 8)) == NULL) + if ((img->bitmap[i] = dmMalloc0(img->bitmapSize)) == NULL) goto err; - if ((img->screen[i] = dmMalloc0(img->ch_width * img->ch_height)) == NULL) + if ((img->screen[i] = dmMalloc0(img->screenSize)) == NULL) goto err; - if ((img->charmem[i] = dmMalloc0(C64_MAX_CHARS * C64_CHR_SIZE)) == NULL) + if ((img->charmem[i] = dmMalloc0(img->charmemSize)) == NULL) goto err; } @@ -1220,12 +1224,12 @@ { case DT_SCREEN_RAM: case DT_COLOR_RAM: - *size = fmt->ch_height * fmt->ch_width; + *size = fmt->chHeight * fmt->chWidth; check = TRUE; break; case DT_BITMAP: - *size = fmt->ch_height * fmt->ch_width * 8; + *size = fmt->chHeight * fmt->chWidth * 8; check = TRUE; break; @@ -1273,8 +1277,8 @@ img->type = fmt->type; img->width = fmt->width; img->height = fmt->height; - img->ch_width = fmt->ch_width; - img->ch_height = fmt->ch_height; + img->chWidth = fmt->chWidth; + img->chHeight = fmt->chHeight; img->nbanks = dmC64ImageGetNumBanks(fmt); // Perform decoding @@ -1381,7 +1385,7 @@ case D64_CHCFG_LINEAR: { for (int bank = 0; bank < img->nbanks; bank++) - for (int offs = 0; offs < fmt->ch_height * fmt->ch_width; offs++) + for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++) img->screen[bank][offs] = offs & 0xff; } break; @@ -1395,14 +1399,14 @@ break; case DT_DEC_FUNCTION: - if (op->decfunction == NULL) + if (op->decFunction == NULL) { return dmError(DMERR_INTERNAL, "Decode op is a function, but function ptr is NULL: " "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", i, op->offs, op->offs, op->bank, size, size, len, len); } - if (!op->decfunction(img, op, buf, len)) + if (!op->decFunction(img, op, buf, len)) { return dmError(DMERR_INTERNAL, "Decode op custom function failed: op #%d, " @@ -1527,7 +1531,7 @@ break; case DT_ENC_FUNCTION: - if (op->encfunction == NULL) + if (op->encFunction == NULL) { res = dmError(DMERR_INTERNAL, "Encode op is a function, but function ptr is NULL: " @@ -1536,7 +1540,7 @@ goto err; } /* - if (!op->encfunction(op, buf, len)) + if (!op->encFunction(op, buf, len)) { res = dmError(DMERR_INTERNAL, "Encode op custom function failed: op #%d, " @@ -1592,7 +1596,7 @@ { Uint8 *d = dp; const int y = yc / 8, yb = yc & 7; - const int scroffsy = y * src->ch_width; + const int scroffsy = y * src->chWidth; int xc; if (src->type & D64_FMT_CHAR) @@ -1645,7 +1649,7 @@ else { // Perform generic BITMAP conversion - const int bmoffsy = y * src->ch_width * 8 + yb; + const int bmoffsy = y * src->chWidth * 8 + yb; if ((src->type & D64_FMT_MC) == D64_FMT_HIRES) // Hi-res bitmap