2 * upkg: tool for manipulating Unreal Tournament packages.
3 * Copyright © 2011 Nick Bowler
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 G_DEFINE_DYNAMIC_TYPE(EnginePalette, engine_palette, U_TYPE_OBJECT);
27 static int deserialize(UObject *uo)
29 EnginePalette *p = ENGINE_PALETTE(uo);
30 struct upkg_file *f = uo->pkg_file;
31 unsigned char buf[16];
35 U_OBJECT_CLASS(engine_palette_parent_class)->deserialize(uo);
37 buflen = upkg_export_read(f, buf, sizeof buf);
38 rc = upkg_decode_index(&entries, buf, buflen);
39 if (rc == 0 || entries < 0)
42 upkg_export_seek(f, rc, SEEK_SET);
45 p->rgba = malloc(entries * sizeof p->rgba[0]);
49 rc = upkg_export_read(f, p->rgba, entries * sizeof p->rgba[0]);
50 if (rc != entries * sizeof p->rgba[0]) {
58 void palette_register(GTypeModule *m)
60 engine_palette_register_type(m);
63 static void engine_palette_init(EnginePalette *p)
68 static void engine_palette_class_init(EnginePaletteClass *class)
70 UObjectClass *uo = U_OBJECT_CLASS(class);
72 uo->deserialize = deserialize;
75 static void engine_palette_class_finalize(EnginePaletteClass *class)