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.
37 unsigned long rgb; /* on screen */
38 char c; /* canonical */
41 extern const CanonColourInfo canoncolourinfos[];
43 CanonImage *alloc_canon_image(int w, int h);
45 #define CANONICALISE_IMAGE(im,w,h, COMPUTE_RGB) do{ \
46 /* compute_rgb should be a number of statements, or \
47 * a block, which assigns to \
48 * unsigned long rgb; \
49 * given the values of \
51 * all of which are anamorphic. Result is stored in im. \
52 * The COMPUTE_RGB is executed exactly once for \
53 * each pixel in reading order. \
55 (im)= alloc_canon_image((w), (h)); \
58 for (y=0; y<(h); y++) { \
59 for (x=0; x<(w); x++) { \
60 const CanonColourInfo *cci; \
63 for (cci=canoncolourinfos; cci->c; cci++) { \
64 if (cci->rgb == rgb) { \
65 (im)->d[y*(w) + x]= cci->c; \
71 fprintf(debug, "%4d ",y); \
72 fwrite(im->d + y*w, 1,w, debug); \
80 #endif /*STRUCTURE_H*/