changeset 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 d14d1101616f
files tools/lib64gfx.c tools/lib64gfx.h
diffstat 2 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tools/lib64gfx.c	Thu May 10 21:46:50 2018 +0300
+++ b/tools/lib64gfx.c	Thu May 10 21:47:48 2018 +0300
@@ -1674,3 +1674,68 @@
     else
         return dmC64DecodeGenericBMP(*img, buf + loadOffs, len - loadOffs, *fmt);
 }
+
+
+// Convert a generic bitmap image to DMC64Image
+int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt)
+{
+    if (dst == NULL || src == NULL || fmt == NULL)
+        return DMERR_NULLPTR;
+
+    return DMERR_OK;
+}
+
+
+int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt)
+{
+    int res;
+    DMC64Image *dst;
+
+    if (pdst == NULL || src == NULL)
+        return DMERR_NULLPTR;
+
+    // Allocate the basic C64 bitmap image structure
+    if ((*pdst = dst = dmC64ImageAlloc(fmt)) == NULL)
+        return DMERR_MALLOC;
+
+    // Convert
+    if (fmt->convertTo != NULL)
+        res = fmt->convertTo(dst, src, fmt);
+    else
+        res = dmC64ConvertGenericImage2BMP(dst, src, fmt);
+
+    return res;
+}
+
+
+int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
+{
+    int res;
+
+    if (img == NULL)
+        return DMERR_NULLPTR;
+
+    // Attempt to encode the image to a buffer
+    if (fmt->encode != NULL)
+        res = fmt->encode(buf, img, fmt);
+    else
+        res = dmC64EncodeGenericBMP(buf, img, fmt);
+
+    if (res != DMERR_OK)
+        goto err;
+
+    // Add the loading address
+    if ((res = dmGrowBufGrow(buf, 2)) != DMERR_OK)
+        goto err;
+
+    memmove(buf->data + 2, buf->data, buf->len);
+
+    buf->data[0] = DM_GET_ADDR_LO(fmt->addr);
+    buf->data[1] = DM_GET_ADDR_HI(fmt->addr);
+
+    buf->len += 2;
+
+err:
+    dmGrowBufFree(buf);
+    return res;
+}
--- a/tools/lib64gfx.h	Thu May 10 21:46:50 2018 +0300
+++ b/tools/lib64gfx.h	Thu May 10 21:47:48 2018 +0300
@@ -204,10 +204,13 @@
 int       dmC64EncodeGenericBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
 
 int       dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt);
+int       dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt);
 
 int       dmC64DecodeBMP(DMC64Image **img, const Uint8 *buf, const size_t len, const size_t probeOffs, const size_t loadOffs, const DMC64ImageFormat **fmt, const DMC64ImageFormat *forced);
+int       dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
 
 int       dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt);
+int       dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt);
 
 
 #ifdef __cplusplus