2 * Image canonicalisation function for use by callers feeding
3 * images into structure.c's routines.
6 * This is part of ypp-sc-tools, a set of third-party tools for assisting
7 * players of Yohoho Puzzle Pirates.
9 * Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
25 * are used without permission. This program is not endorsed or
26 * sponsored by Three Rings.
36 typedef struct { char blue2[256]; } CanonColourInfoBlues;
37 typedef struct { CanonColourInfoBlues *green2[256]; } CanonColourInfoGreens;
38 typedef struct { CanonColourInfoGreens *red2[256]; } CanonColourInfoReds;
39 extern CanonColourInfoReds canoncolourinfo_tree;
41 CanonImage *alloc_canon_image(int w, int h);
43 static inline char canon_lookup_colour(unsigned char r,
46 CanonColourInfoGreens *greens= canoncolourinfo_tree.red2[r];
47 if (!greens) return '?';
48 CanonColourInfoBlues *blues= greens->green2[g];
49 if (!blues) return '?';
50 return blues->blue2[b];
53 #define CANONICALISE_IMAGE(im,w,h,rgb_save, COMPUTE_RGB) do{ \
54 /* compute_rgb should be a number of statements, or \
55 * a block, which assigns to \
57 * given the values of \
59 * all of which are anamorphic. Result is stored in im. \
60 * The COMPUTE_RGB is executed exactly once for \
61 * each pixel in reading order. \
63 (im)= alloc_canon_image((w), (h)); \
64 (rgb_save)= alloc_rgb_image((w), (h)); \
67 for (y=0; y<(h); y++) { \
68 for (x=0; x<(w); x++) { \
71 CANONIMG_ALSO_STORERGB((rgb_save)); \
72 (im)->d[y*(w) + x]= canon_lookup_colour(rgb, rgb>>8, rgb>>16); \
75 fprintf(debug, "%4d ",y); \
76 fwrite(im->d + y*(w), 1,(w), debug); \
84 #define CANONIMG_ALSO_STORERGB(ri) \
86 Rgb *rip= RI_PIXEL32((ri),x,y); \
91 #endif /*STRUCTURE_H*/