# HG changeset patch # User Matti Hamalainen # Date 1525978068 -10800 # Node ID 32203356c652f00544737fc3d48e8b2eaa5258fc # Parent bc75be0546fc9e0c0acbb5d11c4aeb04b0cc4c6b Add some new functions that are mostly just stubs and not working tho. diff -r bc75be0546fc -r 32203356c652 tools/lib64gfx.c --- 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; +} diff -r bc75be0546fc -r 32203356c652 tools/lib64gfx.h --- 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