comparison tools/lib64gfx.c @ 1467:32203356c652

Add some new functions that are mostly just stubs and not working tho.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 10 May 2018 21:47:48 +0300
parents bc75be0546fc
children 0046b4e1b35f
comparison
equal deleted inserted replaced
1466:bc75be0546fc 1467:32203356c652
1672 if ((*fmt)->decode != NULL) 1672 if ((*fmt)->decode != NULL)
1673 return (*fmt)->decode(*img, buf + loadOffs, len - loadOffs, *fmt); 1673 return (*fmt)->decode(*img, buf + loadOffs, len - loadOffs, *fmt);
1674 else 1674 else
1675 return dmC64DecodeGenericBMP(*img, buf + loadOffs, len - loadOffs, *fmt); 1675 return dmC64DecodeGenericBMP(*img, buf + loadOffs, len - loadOffs, *fmt);
1676 } 1676 }
1677
1678
1679 // Convert a generic bitmap image to DMC64Image
1680 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt)
1681 {
1682 if (dst == NULL || src == NULL || fmt == NULL)
1683 return DMERR_NULLPTR;
1684
1685 return DMERR_OK;
1686 }
1687
1688
1689 int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt)
1690 {
1691 int res;
1692 DMC64Image *dst;
1693
1694 if (pdst == NULL || src == NULL)
1695 return DMERR_NULLPTR;
1696
1697 // Allocate the basic C64 bitmap image structure
1698 if ((*pdst = dst = dmC64ImageAlloc(fmt)) == NULL)
1699 return DMERR_MALLOC;
1700
1701 // Convert
1702 if (fmt->convertTo != NULL)
1703 res = fmt->convertTo(dst, src, fmt);
1704 else
1705 res = dmC64ConvertGenericImage2BMP(dst, src, fmt);
1706
1707 return res;
1708 }
1709
1710
1711 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
1712 {
1713 int res;
1714
1715 if (img == NULL)
1716 return DMERR_NULLPTR;
1717
1718 // Attempt to encode the image to a buffer
1719 if (fmt->encode != NULL)
1720 res = fmt->encode(buf, img, fmt);
1721 else
1722 res = dmC64EncodeGenericBMP(buf, img, fmt);
1723
1724 if (res != DMERR_OK)
1725 goto err;
1726
1727 // Add the loading address
1728 if ((res = dmGrowBufGrow(buf, 2)) != DMERR_OK)
1729 goto err;
1730
1731 memmove(buf->data + 2, buf->data, buf->len);
1732
1733 buf->data[0] = DM_GET_ADDR_LO(fmt->addr);
1734 buf->data[1] = DM_GET_ADDR_HI(fmt->addr);
1735
1736 buf->len += 2;
1737
1738 err:
1739 dmGrowBufFree(buf);
1740 return res;
1741 }