Mercurial > hg > dmlib
comparison lib64gfx.c @ 536:18fc2890ba4b
Take loading address into account while encoding, so start other data from offset +2.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 22 Nov 2012 22:16:06 +0200 |
parents | ab8d9696225c |
children | 32d9e67da189 |
comparison
equal
deleted
inserted
replaced
535:ab8d9696225c | 536:18fc2890ba4b |
---|---|
633 | 633 |
634 // Perform encoding | 634 // Perform encoding |
635 for (i = 0; i < fmt->nencdecOps; i++) | 635 for (i = 0; i < fmt->nencdecOps; i++) |
636 { | 636 { |
637 const DMC64EncDecOp *op = &fmt->encdecOps[i]; | 637 const DMC64EncDecOp *op = &fmt->encdecOps[i]; |
638 Uint8 *dst = buf + op->offs; | 638 Uint8 *dst = 2 + buf + op->offs; |
639 size_t size; | 639 size_t size; |
640 | 640 |
641 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) | 641 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) |
642 goto error; | 642 goto error; |
643 | 643 |
644 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; | 644 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; |
645 | 645 |
646 if (op->offs + size > allocated) | 646 if (2 + op->offs + size > allocated) |
647 { | 647 { |
648 if ((buf = dmRealloc(buf, allocated)) == NULL) | 648 if ((buf = dmRealloc(buf, allocated)) == NULL) |
649 { | 649 { |
650 size_t diff = allocated - (op->offs + size), | 650 size_t diff = allocated - (op->offs + size + 2), |
651 grow = (diff / (BUF_SIZE_GROW - 1)) * BUF_SIZE_GROW; | 651 grow = (diff / (BUF_SIZE_GROW - 1)) * BUF_SIZE_GROW; |
652 allocated = allocated + grow; | 652 allocated = allocated + grow; |
653 dmError("Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", | 653 dmError("Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", |
654 allocated); | 654 allocated); |
655 res = DMERR_MALLOC; | 655 res = DMERR_MALLOC; |
656 goto error; | 656 goto error; |
657 } | 657 } |
658 } | 658 } |
659 | 659 |
660 if (fmt->size == 0 && op->offs + size > *plen) | 660 if (fmt->size == 0 && op->offs + size + 2 > *plen) |
661 *plen = op->offs + size; | 661 *plen = op->offs + size + 2; |
662 | 662 |
663 switch (op->type) | 663 switch (op->type) |
664 { | 664 { |
665 case DT_COLOR_RAM: memcpy(dst, img->color[op->bank], size); break; | 665 case DT_COLOR_RAM: memcpy(dst, img->color[op->bank], size); break; |
666 case DT_BITMAP: memcpy(dst, img->bitmap[op->bank], size); break; | 666 case DT_BITMAP: memcpy(dst, img->bitmap[op->bank], size); break; |