Mercurial > hg > dmlib
comparison 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 |
comparison
equal
deleted
inserted
replaced
2203:b259312ddb59 | 2204:cbac4912992c |
---|---|
1 /* | |
2 * Common utility functions for gfxconv and 64vw | |
3 * Programmed and designed by Matti 'ccr' Hamalainen | |
4 * (C) Copyright 2019 Tecnic Software productions (TNSP) | |
5 * | |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
8 #include "lib64util.h" | |
9 | |
10 | |
11 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng) | |
12 { | |
13 static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" }; | |
14 static const char *fmtModesLong[] = { "*", "HiRes", "MultiColor", "Extended Color Mode" }; | |
15 const char *fmtStr; | |
16 size_t nfmt = type & D64_FMT_MODE_MASK; | |
17 | |
18 if (nfmt < sizeof(fmtModesShort) / sizeof(fmtModesShort[0])) | |
19 fmtStr = lng ? fmtModesLong[nfmt] : fmtModesShort[nfmt]; | |
20 else | |
21 fmtStr = lng ? "ERROR" : "ERR"; | |
22 | |
23 snprintf(buf, len, | |
24 "%s %s%s%s", | |
25 fmtStr, | |
26 (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "", | |
27 (type & D64_FMT_FLI) ? "FLI " : "", | |
28 (type & D64_FMT_CHAR) ? "CHAR" : "" | |
29 ); | |
30 | |
31 return buf; | |
32 } | |
33 | |
34 | |
35 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent) | |
36 { | |
37 char typeStr[64]; | |
38 | |
39 if (fmt != NULL) | |
40 { | |
41 fprintf(fh, | |
42 "%sFormat : %s [%s]\n", | |
43 indent, fmt->name, fmt->fext); | |
44 } | |
45 | |
46 if (img != NULL) | |
47 { | |
48 dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE); | |
49 | |
50 fprintf(fh, | |
51 "%sType : %s\n" | |
52 "%sInternal blocks : %d\n", | |
53 indent, typeStr, | |
54 indent, img->nblocks); | |
55 | |
56 if (img->fmt->type & D64_FMT_ILACE) | |
57 { | |
58 char *tmps; | |
59 switch (img->laceType) | |
60 { | |
61 case D64_ILACE_COLOR: tmps = "color"; break; | |
62 case D64_ILACE_RES: tmps = "resolution"; break; | |
63 default: tmps = "ERROR"; break; | |
64 } | |
65 fprintf(fh, | |
66 "%sInterlace type : %s\n", | |
67 indent, tmps); | |
68 } | |
69 | |
70 fprintf(fh, | |
71 "%sWidth x Height : %d x %d\n" | |
72 "%sCHwidth x CHheight : %d x %d\n" | |
73 "%sd020 / border : %d ($%02x)\n" | |
74 "%sd021 / background : %d ($%02x)\n", | |
75 indent, img->fmt->width, img->fmt->height, | |
76 indent, img->fmt->chWidth, img->fmt->chHeight, | |
77 indent, img->d020, img->d020, | |
78 indent, img->bgcolor, img->bgcolor); | |
79 } | |
80 else | |
81 if (fmt != NULL) | |
82 { | |
83 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); | |
84 fprintf(fh, | |
85 "%sType : %s\n" | |
86 "%sWidth x Height : %d x %d\n" | |
87 "%sCHwidth x CHheight : %d x %d\n", | |
88 indent, typeStr, | |
89 indent, fmt->format->width, fmt->format->height, | |
90 indent, fmt->format->chWidth, fmt->format->chHeight); | |
91 } | |
92 } | |
93 | |
94 | |
95 void argShowC64PaletteHelp() | |
96 { | |
97 fprintf(stdout, "\nAvailable C64 palettes:\n"); | |
98 for (int n = 0; n < ndmC64DefaultPalettes; n++) | |
99 { | |
100 DMC64Palette *pal = &dmC64DefaultPalettes[n]; | |
101 fprintf(stdout, | |
102 "%-10s | %s\n", | |
103 pal->name, pal->desc); | |
104 } | |
105 fprintf(stdout, "\n"); | |
106 } |