annotate tools/lib64util.c @ 2265:48b48251610a

Refactor how the image "mode/type" is handled. It is still not perfect for our purposes, but better now.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 17 Jun 2019 02:03:35 +0300
parents e25fa516b53a
children 87533af8db64
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Common utility functions for gfxconv and 64vw
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2019 Tecnic Software productions (TNSP)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "lib64util.h"
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
9 #include "dmfile.h"
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 {
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 static const char *fmtModesShort[] = { "*", "HiR", "MC", "ECM" };
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 static const char *fmtModesLong[] = { "*", "HiRes", "MultiColor", "Extended Color Mode" };
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 const char *fmtStr;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 size_t nfmt = type & D64_FMT_MODE_MASK;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 if (nfmt < sizeof(fmtModesShort) / sizeof(fmtModesShort[0]))
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 fmtStr = lng ? fmtModesLong[nfmt] : fmtModesShort[nfmt];
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 else
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 fmtStr = lng ? "ERROR" : "ERR";
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 snprintf(buf, len,
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 "%s %s%s%s",
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 fmtStr,
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "",
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 (type & D64_FMT_FLI) ? "FLI " : "",
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 (type & D64_FMT_CHAR) ? "CHAR" : ""
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 );
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 return buf;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
36 static void dmC64ImageDumpLine(FILE *fh, const char *indent, const char *field, const char *fmt, ...)
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
37 {
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
38 va_list ap;
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
39
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
40 fputs(indent, fh);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
41 fprintf(fh, "%-20s: ", field);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
42 va_start(ap, fmt);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
43 vfprintf(fh, fmt, ap);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
44 va_end(ap);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
45 fputs("\n", fh);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
46 }
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
47
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
48
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 char typeStr[64];
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 if (fmt != NULL)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 {
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
55 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
56 "Format", "%s [%s]",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
57 fmt->name, fmt->fext);
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 if (img != NULL)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 {
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
62 dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->extraInfo[D64_EI_MODE], TRUE);
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
64 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
65 "Type", "%s", typeStr);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
66
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
67 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
68 "Internal blocks", "%d", img->nblocks);
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
70 if (img->extraInfo[D64_EI_MODE] & D64_FMT_ILACE)
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 {
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 char *tmps;
2238
5db6e0b63b35 Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents: 2210
diff changeset
73 switch (img->extraInfo[D64_EI_ILACE_TYPE])
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 {
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 case D64_ILACE_COLOR: tmps = "color"; break;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 case D64_ILACE_RES: tmps = "resolution"; break;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 default: tmps = "ERROR"; break;
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 }
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
79 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
80 "Interlace type", "%s", tmps);
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
83 if (img->extraInfo[D64_EI_MODE] & D64_FMT_FLI)
2238
5db6e0b63b35 Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents: 2210
diff changeset
84 {
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
85 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
86 "FLI type", "%d",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
87 img->extraInfo[D64_EI_FLI_TYPE]);
2238
5db6e0b63b35 Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents: 2210
diff changeset
88 }
5db6e0b63b35 Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents: 2210
diff changeset
89
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
90 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
91 "Width x Height", "%d x %d pixels",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
92 img->fmt->width, img->fmt->height);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
93
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
94 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
95 "CHwidth x CHheight", "%d x %d",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
96 img->fmt->chWidth, img->fmt->chHeight);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
97
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
98 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
99 "d020 / border", "%d ($%02x)",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
100 img->d020, img->d020);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
101
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
102 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
103 "d021 / background", "%d ($%02x)",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
104 img->bgcolor, img->bgcolor);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
105
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
106 if (img->extraInfo[D64_EI_MODE] & D64_FMT_CHAR)
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
107 {
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
108 if ((img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == (D64_FMT_MC | D64_FMT_ECM))
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
109 {
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
110 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
111 "d022", "%d ($%02x)",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
112 img->d022, img->d022);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
113 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
114 "d023", "%d ($%02x)",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
115 img->d023, img->d023);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
116 }
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
117
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
118 if ((img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_ECM)
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
119 {
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
120 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
121 "d024", "%d ($%02x)",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
122 img->d024, img->d024);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
123 }
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
124 }
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 else
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 if (fmt != NULL)
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 {
2265
48b48251610a Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents: 2264
diff changeset
129 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->mode, TRUE);
2264
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
130
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
131 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
132 "Type", "%s", typeStr);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
133
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
134 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
135 "Width x Height", "%d x %d pixels",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
136 fmt->format->width, fmt->format->height);
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
137
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
138 dmC64ImageDumpLine(fh, indent,
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
139 "CHwidth x CHheight", "%d x %d",
e25fa516b53a Add helper function dmC64ImageDumpLine() for printing information out in
Matti Hamalainen <ccr@tnsp.org>
parents: 2263
diff changeset
140 fmt->format->chWidth, fmt->format->chHeight);
2204
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 }
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
cbac4912992c Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
145 void argShowC64Formats(FILE *fh, const BOOL rw)
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
146 {
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
147 fprintf(fh,
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
148 "Available C64 bitmap formats (-f <frmt>):\n"
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
149 " frmt %s| Type | Description\n"
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
150 "------%s+-----------------+-------------------------------------\n",
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
151 rw ? "| RW " : "",
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
152 rw ? "+----" : ""
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
153 );
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
154
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
155 for (int i = 0; i < ndmC64ImageFormats; i++)
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
156 {
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
157 const DMC64ImageFormat *fmt = dmC64ImageFormatsSorted[i];
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
158 char buf[64];
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
159
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
160 fprintf(fh, "%-6s",
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
161 fmt->fext);
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
162
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
163 if (rw)
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
164 {
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
165 fprintf(fh, "| %c%c ",
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
166 (fmt->flags & DM_FMT_RD) ? 'R' : ' ',
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
167 (fmt->flags & DM_FMT_WR) ? 'W' : ' '
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
168 );
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
169 }
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
170
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
171 fprintf(fh,
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
172 "| %-15s | %s%s\n",
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
173 dmC64GetImageTypeString(buf, sizeof(buf), fmt->format->mode, FALSE),
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
174 fmt->name,
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
175 fmt->flags & DM_FMT_BROKEN ? " [BROKEN]" : "");
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
176 }
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
177
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
178 fprintf(fh, "%d formats supported.\n", ndmC64ImageFormats);
2242
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
179 }
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
180
65a2c2e99c81 Move listing of C64 formats function to argShowC64Formats in lib64util.
Matti Hamalainen <ccr@tnsp.org>
parents: 2240
diff changeset
181
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
182 void argShowC64PaletteHelp(FILE *fh)
2244
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
183 {
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
184 fprintf(fh,
2245
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
185 "\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
186 "Available C64 palettes (-p <name>):\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
187 "-----------------------------------\n");
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
188
2244
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
189 for (int n = 0; n < ndmC64DefaultPalettes; n++)
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
190 {
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
191 DMC64Palette *pal = &dmC64DefaultPalettes[n];
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
192 fprintf(fh,
2244
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
193 "%-10s | %s\n",
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
194 pal->name, pal->desc);
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
195 }
2245
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
196
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
197 fprintf(fh,
2245
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
198 "\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
199 "Instead one of the internal palettes, you can\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
200 "also specify an external palette file.\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
201 "Supported palette file formats are:\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
202 "-----------------------------------\n"
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
203 );
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
204
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
205 for (int n = 0; n < ndmPaletteFormatList; n++)
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
206 {
2247
bb7255792dd6 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 2245
diff changeset
207 const DMPaletteFormat *fmt = &dmPaletteFormatList[n];
2245
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
208 if (fmt->flags & DM_FMT_RD)
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
209 {
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
210 fprintf(fh,
2245
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
211 "%-6s | %s\n",
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
212 fmt->fext, fmt->name);
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
213 }
95f669692b01 Mention support for external palette files in palette help, and also
Matti Hamalainen <ccr@tnsp.org>
parents: 2244
diff changeset
214 }
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
215 fprintf(fh, "\n");
2244
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
216 }
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
217
b26e37e7cbe6 Move function to better place in the file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2242
diff changeset
218
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
219 BOOL argHandleC64PaletteOption(char *optArg, DMC64Palette **ppal, char **palFile)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
220 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
221 if (strcasecmp(optArg, "help") == 0 ||
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
222 strcasecmp(optArg, "list") == 0)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
223 {
2240
e2c6af0c9431 Add FILE argument to argShowC64PaletteHelp().
Matti Hamalainen <ccr@tnsp.org>
parents: 2238
diff changeset
224 argShowC64PaletteHelp(stdout);
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
225 return FALSE;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
226 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
227
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
228 for (int n = 0; n < ndmC64DefaultPalettes; n++)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
229 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
230 DMC64Palette *pal = &dmC64DefaultPalettes[n];
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
231 if (strcasecmp(pal->name, optArg) == 0)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
232 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
233 *ppal = pal;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
234 return TRUE;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
235 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
236 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
237
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
238 *palFile = optArg;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
239 return TRUE;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
240 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
241
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
242
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
243 int dmHandleExternalPalette(const char *filename, DMPalette **ppal)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
244 {
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
245 DMResource *fh = NULL;
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
246 const DMImageFormat *ifmt = NULL;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
247 const DMPaletteFormat *pfmt = NULL;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
248 DMImage *inImage = NULL;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
249 Uint8 *dataBuf = NULL;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
250 size_t dataSize;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
251 int index, res;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
252
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
253 dmMsg(1, "Probing file '%s' for palette data.\n", filename);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
254
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
255 if ((res = dmReadDataFile(NULL, filename, &dataBuf, &dataSize)) != DMERR_OK)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
256 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
257 dmErrorMsg("No such palette '%s', and no such file found (%s).\n",
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
258 filename, dmErrorStr(res));
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
259 goto done;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
260 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
261
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
262 if ((res = dmf_open_memio(NULL, filename, dataBuf, dataSize, &fh)) != DMERR_OK)
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
263 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
264 dmErrorMsg("Could not create MemIO handle for input.\n");
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
265 goto done;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
266 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
267
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
268 if (dmImageProbeGeneric(dataBuf, dataSize, &ifmt, &index) > 0 &&
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
269 ifmt->read != NULL)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
270 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
271 dmMsg(1, "Probed image format %s (%s)\n",
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
272 ifmt->name, ifmt->fext);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
273
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
274 res = ifmt->read(fh, &inImage);
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
275 if (res != DMERR_OK)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
276 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
277 dmErrorMsg("Could not read image file: %s\n",
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
278 dmErrorStr(res));
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
279 goto done;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
280 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
281
2210
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
282 if (inImage->pal != NULL)
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
283 res = dmPaletteCopy(ppal, inImage->pal);
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
284 else
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
285 {
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
286 dmErrorMsg("Image file does not have a palette.\n");
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
287 res = DMERR_NULLPTR;
fa5e74384d87 Check for non-existing palette when reading palette from image file.
Matti Hamalainen <ccr@tnsp.org>
parents: 2208
diff changeset
288 }
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
289 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
290 else
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
291 if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 &&
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
292 pfmt->read != NULL)
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
293 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
294 dmMsg(1, "Probed palette format %s (%s)\n",
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
295 pfmt->name, pfmt->fext);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
296
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
297 res = pfmt->read(fh, ppal);
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
298 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
299 else
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
300 {
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
301 res = DMERR_NOT_SUPPORTED;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
302 dmErrorMsg("Not an internal palette or recognized palette file '%s'.\n",
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
303 filename);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
304 }
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
305
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
306 done:
2263
891acec47aa0 Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 2247
diff changeset
307 dmf_close(fh);
2208
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
308 dmImageFree(inImage);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
309 dmFree(dataBuf);
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
310
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
311 return res;
90ec1ec89c56 Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents: 2204
diff changeset
312 }