-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
170 lines (131 loc) · 3.87 KB
/
main.c
File metadata and controls
170 lines (131 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <stdio.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#define LOAD_PROC "file-tgpcdx-load"
#define PLUG_IN_AUTHOR "Thomas Clark"
#define PLUG_IN_BINARY "file-tgpcdx"
#define PLUG_IN_COPYRIGHT "Copyright (C) 2025 Thomas Clark"
#define PLUG_IN_ROLE "gimp-file-tgpcdx"
#define PLUG_IN_VERSION "1.0.0"
static void query (void);
static void run (const char *name,
int n_params,
const GimpParam *param,
int *n_return_vals,
GimpParam **return_vals);
static int load_image (const char *filename, GError **error);
static int read_prelude (unsigned char *buffer, FILE *file);
const GimpPlugInInfo PLUG_IN_INFO = { NULL, NULL, query, run };
static GimpParamDef load_args[] = {
{ GIMP_PDB_INT32, "run_mode", "Interactive, non-interactive" },
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
{ GIMP_PDB_STRING, "raw_filename", "The name entered" }
};
static GimpParamDef load_return_vals[] = {
{ GIMP_PDB_IMAGE, "image", "Output image" }
};
MAIN ()
static void
query (void)
{
gimp_install_procedure (LOAD_PROC,
"Loads files in the TGPCDX file format",
"Loads files in the TGPCDX file format",
PLUG_IN_AUTHOR,
PLUG_IN_COPYRIGHT,
PLUG_IN_VERSION,
"TGPCDX image",
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (load_args),
G_N_ELEMENTS (load_return_vals),
load_args,
load_return_vals);
gimp_register_load_handler (LOAD_PROC, "tgpcdx", NULL);
}
static void
run (const char *name,
int n_params,
const GimpParam *param,
int *n_return_vals,
GimpParam **return_vals)
{
static GimpParam values[2];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GError *error = NULL;
run_mode = param[0].data.d_int32;
*n_return_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
if (strcmp (name, LOAD_PROC) == 0)
{
const int IMAGE_ID = load_image (param[1].data.d_string, &error);
if (IMAGE_ID != -1)
{
*n_return_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = IMAGE_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
values[0].data.d_status = status;
}
static int
load_image (const char *filename, GError **error)
{
gimp_progress_init_printf ("Opening '%s'", filename);
// TODO: Read tgpcdx file.
FILE *file = fopen (filename, "rb");
if (file == NULL)
{
g_set_error (error, 0, 0, "Failed to open the file '%s'", filename);
return -1;
}
int i, c;
for (i = 0; (c = fgetc (file)) != EOF; i++)
{
printf ("%02x", c);
if (i % 16 == 15)
{
putchar ('\n');
}
else if (i % 2 == 1)
{
putchar (' ');
}
}
if (i % 16 != 0)
{
putchar ('\n');
}
// TODO: Convert tgpcdx to dds.
// TODO: Write dds file.
// TODO: Run file dds load procedure.
// TODO: Handle return values.
return -1;
}
static int
read_prelude (unsigned char *buffer, FILE *file)
{
const unsigned char prelude[8] = { 0x53, 0x45, 0x52, 0x5a,
0x00, 0x00, 0x01, 0x00 };
for (int i = 0; i < sizeof (prelude); i++)
{
const unsigned char c = fgetc (file);
if (c != prelude[i])
{
return -1;
}
buffer[i] = c;
}
return 0;
}