chiark / gitweb /
1dcb8a2f5d78ee70f52aab1ac446467f72826dc1
[ypp-sc-tools.db-test.git] / pctb / convert.h
1 /*
2  * general header file for ypp-commodities
3  */
4 /*
5  *  This is part of ypp-sc-tools, a set of third-party tools for assisting
6  *  players of Yohoho Puzzle Pirates.
7  * 
8  *  Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
9  * 
10  *  This program is free software: you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation, either version 3 of the License, or
13  *  (at your option) any later version.
14  * 
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  * 
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  * 
23  *  Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
24  *  are used without permission.  This program is not endorsed or
25  *  sponsored by Three Rings.
26  */
27
28 #ifndef CONVERT_H
29 #define CONVERT_H
30
31 #include "common.h"
32 #include "ocr.h"
33
34 #include <pam.h>
35 #include <time.h>
36 #include <limits.h>
37
38 #include <sys/time.h>
39
40
41 /*----- from rgbimage.c -----*/
42
43 #define MAXIMGIDENT 100
44
45 typedef struct RgbImage {
46   int w, h;
47   unsigned char data[];
48   /* red   = data[ y*w*3 + x*3 + 0 ] = RI_PIXEL(ri,x,y)[0]
49    * green = data[ y*w*3 + x*3 + 1 ] = RI_PIXEL(ri,x,y)[1]
50    * blue  = data[ y*w*3 + x*3 + 2 ] = RI_PIXEL(ri,x,y)[2]
51    */
52 } RgbImage;
53
54 typedef unsigned long Rgb;
55
56 void identify_rgbimage(const RgbImage *base, Rect portion,
57                        char result[MAXIMGIDENT], const char *what);
58 RgbImage *alloc_rgb_image(int w, int h);
59 void fwrite_ppmraw(FILE *f, const RgbImage *ri);
60
61 #define RI_PIXEL(ri,x,y) ((ri)->data + ((y)*(ri)->w + (x)) * 3)
62
63 static inline Rgb ri_rgb(const RgbImage *ri, int x, int y) {
64   const unsigned char *rip= RI_PIXEL(ri,x,y);
65   return (rip[0] << 16) |
66          (rip[1] <<  8) |
67          (rip[2]      );
68 }
69
70 /*----- from structure.c -----*/
71
72 typedef struct PageStruct PageStruct;
73
74 void find_structure(const CanonImage *im,
75                     PageStruct **pagestruct_r, /* caller must free() */
76                     int *max_relevant_y_r,
77                     Point *commod_focus_point_r,
78                     Point *commod_page_point_r,
79                     Point *commod_focuslast_point_r);
80 void store_current_page(CanonImage *ci /*pointer saved*/,
81                         PageStruct *pagestruct, /*freed*/
82                         RgbImage *rgb /*freed*/);
83 void adjust_colours(CanonImage *ci, const RgbImage *rgb);
84
85 void select_page(int page);
86
87 Rect find_sunshine_widget(void);
88
89 void canon_colour_prepare(void);
90 void find_islandname(void);
91 void check_correct_commodities(void);
92 void read_screenshots(void);
93 void read_one_screenshot(void);
94 void analyse(FILE *tsv_output);
95
96 /*----- from convert.c -----*/
97
98 extern FILE *screenshot_file;
99 void fetch_with_rsync(const char *stem);
100 void fetch_with_rsync_gz(const char *stem);
101
102 void vwarning(const char *fmt, va_list) FMT(1,0);
103 void warning(const char *fmt, ...)      FMT(1,2);
104
105 void vprogress(const char *fmt, va_list) FMT(1,0);
106 void progress(const char *fmt, ...)      FMT(1,2);
107
108 void vprogress_log(const char *fmt, va_list) FMT(1,0);
109 void progress_log(const char *fmt, ...)      FMT(1,2);
110
111 void vprogress_spinner(const char *fmt, va_list) FMT(1,0);
112 void progress_spinner(const char *fmt, ...)      FMT(1,2);
113
114 enum flags {
115   ff_singlepage=          000002,
116   ff_testservers=         000004,
117
118   ff_charset_edit=        000010,
119   ff_charset_allowedit=   000020,
120   ff_charset_havelocal=   000040,
121   ffm_charset=            000070,
122   
123   ff_dict_fetch=          000100,
124   ff_dict_submit=         000200,
125   ff_dict_pirate=         000400,
126   ffs_dict=               000700,
127
128   ff_needisland=          001000,
129   ff_printisland=         002000,
130   ff_upload=              004000,
131   ffs_printisland=        003000,
132   ffs_upload=             005000,
133 };
134 extern enum flags o_flags;
135
136 enum mode {
137   mf_findwindow=      00001,
138   mf_screenshot=      00010,
139   mf_readscreenshot=  00020,
140   mf_analyse=         00100,
141   mfm_special=        07000,
142   
143   mode_findwindow=    00001,
144   mode_screenshot=    00011,
145   mode_analyse=       00120,
146   mode_showcharset=   01000,
147
148   mode_all=           00111,
149 };
150 extern enum mode o_mode;
151
152 extern const char *o_ocean, *o_pirate;
153 extern int o_quiet;
154
155 /*----- from pages.c -----*/
156
157 void screenshot_startup(void);
158 void set_yppclient_window(unsigned long wul);
159 void find_yppclient_window(void);
160 void take_screenshots(void);
161 void take_one_screenshot(void);
162
163 #define MAX_PAGES 1000
164
165 extern const CanonImage *page_images[MAX_PAGES];
166 extern const RgbImage *page0_rgbimage;
167 extern int npages;
168
169 extern const char *ocean, *pirate;
170 extern char *archipelago, *island;
171
172
173 #endif /*CONVERT_H*/