view tools/lib64util.c @ 2204:cbac4912992c

Add new module "lib64util", and move some functions there from lib64gfx that do not strictly belong.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 14 Jun 2019 03:24:24 +0300
parents
children 90ec1ec89c56
line wrap: on
line source

/*
 * Common utility functions for gfxconv and 64vw
 * Programmed and designed by Matti 'ccr' Hamalainen
 * (C) Copyright 2019 Tecnic Software productions (TNSP)
 *
 * Please read file 'COPYING' for information on license and distribution.
 */
#include "lib64util.h"


char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng)
{
    static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" };
    static const char *fmtModesLong[] = { "*", "HiRes", "MultiColor", "Extended Color Mode" };
    const char *fmtStr;
    size_t nfmt = type & D64_FMT_MODE_MASK;

    if (nfmt < sizeof(fmtModesShort) / sizeof(fmtModesShort[0]))
        fmtStr = lng ? fmtModesLong[nfmt] : fmtModesShort[nfmt];
    else
        fmtStr = lng ? "ERROR" : "ERR";

    snprintf(buf, len,
        "%s %s%s%s",
        fmtStr,
        (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "",
        (type & D64_FMT_FLI)   ? "FLI " : "",
        (type & D64_FMT_CHAR)  ? "CHAR" : ""
        );

    return buf;
}


void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent)
{
    char typeStr[64];

    if (fmt != NULL)
    {
        fprintf(fh,
            "%sFormat              : %s [%s]\n",
            indent, fmt->name, fmt->fext);
    }

    if (img != NULL)
    {
        dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE);

        fprintf(fh,
            "%sType                : %s\n"
            "%sInternal blocks     : %d\n",
            indent, typeStr,
            indent, img->nblocks);

        if (img->fmt->type & D64_FMT_ILACE)
        {
            char *tmps;
            switch (img->laceType)
            {
                case D64_ILACE_COLOR: tmps = "color"; break;
                case D64_ILACE_RES: tmps = "resolution"; break;
                default: tmps = "ERROR"; break;
            }
            fprintf(fh,
                "%sInterlace type      : %s\n",
                indent, tmps);
        }

        fprintf(fh,
            "%sWidth x Height      : %d x %d\n"
            "%sCHwidth x CHheight  : %d x %d\n"
            "%sd020 / border       : %d ($%02x)\n"
            "%sd021 / background   : %d ($%02x)\n",
            indent, img->fmt->width, img->fmt->height,
            indent, img->fmt->chWidth, img->fmt->chHeight,
            indent, img->d020, img->d020,
            indent, img->bgcolor, img->bgcolor);
    }
    else
    if (fmt != NULL)
    {
        dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE);
        fprintf(fh,
            "%sType                : %s\n"
            "%sWidth x Height      : %d x %d\n"
            "%sCHwidth x CHheight  : %d x %d\n",
            indent, typeStr,
            indent, fmt->format->width, fmt->format->height,
            indent, fmt->format->chWidth, fmt->format->chHeight);
    }
}


void argShowC64PaletteHelp()
{
    fprintf(stdout, "\nAvailable C64 palettes:\n");
    for (int n = 0; n < ndmC64DefaultPalettes; n++)
    {
        DMC64Palette *pal = &dmC64DefaultPalettes[n];
        fprintf(stdout,
            "%-10s | %s\n",
            pal->name, pal->desc);
    }
    fprintf(stdout, "\n");
}