Updated upstream Git repositories
[opendreambox.git] / meta-opendreambox / recipes-multimedia / zvbi / zvbi-0.2.33 / 0006-search-add-vbi_catch_page.patch
1 From 5c1a6dd50986d7734af4e3eb31d0795969bfcbea Mon Sep 17 00:00:00 2001
2 From: Andreas Oberritter <obi@opendreambox.org>
3 Date: Mon, 25 Jun 2012 11:29:45 +0200
4 Subject: [PATCH 6/6] search: add vbi_catch_page()
5
6 * patch by Roland Meier
7 ---
8  src/search.c |  204 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9  src/search.h |   10 +++
10  2 files changed, 214 insertions(+)
11
12 diff --git a/src/search.c b/src/search.c
13 index f9163eb..94d8190 100644
14 --- a/src/search.c
15 +++ b/src/search.c
16 @@ -72,6 +72,210 @@ struct vbi_search {
17  #define FIRST_ROW 1
18  #define LAST_ROW 24
19  
20 +vbi_search_status
21 +vbi_catch_page(vbi_decoder *vbi,
22 +                       vbi_pgno pgno,
23 +                       vbi_subno subno,
24 +                       int *r,
25 +                       int *c,
26 +                       vbi_page *pg,
27 +                       int dir)
28 +{
29 +       cache_page *cp;
30 +       int tmp_page, allowwrap = 1; /* allow first wrap around */
31 +       int firstlineinc;
32 +       int inc;
33 +
34 +       if (vbi->ca == NULL
35 +               || vbi->cn == NULL
36 +               || pg == NULL
37 +               || 0 == vbi->cn->n_cached_pages
38 +               )
39 +       {
40 +               return VBI_SEARCH_ERROR;
41 +       }
42 +
43 +       if (!(cp = _vbi_cache_get_page (vbi->ca, vbi->cn, pgno, subno, -1)))
44 +       {
45 +               return VBI_SEARCH_ERROR;
46 +       }
47 +       subno = cp->subno;
48 +
49 +       if (cp->function != PAGE_FUNCTION_LOP
50 +               || !vbi_format_vt_page(vbi, pg, cp, vbi->vt.max_level, 25, 1)
51 +               )
52 +       {
53 +               cache_page_unref(cp);
54 +               return VBI_SEARCH_ERROR; /* formatting error, abort */
55 +       }
56 +
57 +       switch (dir)
58 +       {
59 +               case DIR_RIGHT:
60 +                       firstlineinc = 0;
61 +                       inc = 1;
62 +                       break;
63 +               case DIR_LEFT:
64 +                       firstlineinc = 0;
65 +                       inc = -1;
66 +                       break;
67 +               case DIR_DOWN:
68 +                       firstlineinc = 1;
69 +                       inc = 1;
70 +                       break;
71 +               case DIR_UP:
72 +                       firstlineinc = -1;
73 +                       inc = -1;
74 +                       break;
75 +               default:
76 +                       cache_page_unref(cp);
77 +                       return VBI_SEARCH_ERROR;
78 +       }
79 +
80 +       for(;;)
81 +       {
82 +               vbi_char *p;
83 +
84 +               if (firstlineinc > 0)
85 +               {
86 +                       (*r)++;
87 +                       *c = 0;
88 +                       firstlineinc = 0;
89 +               }
90 +               else if (firstlineinc < 0)
91 +               {
92 +                       (*r)--;
93 +                       *c = 37;
94 +                       firstlineinc = 0;
95 +               }
96 +               else
97 +                       *c += inc;
98 +
99 +               if (*c > 37)
100 +               {
101 +                       (*r)++;
102 +                       *c = 0;
103 +               }
104 +               else if (*c < 0)
105 +               {
106 +                       (*r)--;
107 +                       *c = 37;
108 +               }
109 +
110 +               if (*r > 23)
111 +               {
112 +                       if (allowwrap)
113 +                       {
114 +                               allowwrap = 0;
115 +                               *r = 1;
116 +                               *c = 0;
117 +                       }
118 +                       else
119 +                       {
120 +                               cache_page_unref(cp);
121 +                               return VBI_SEARCH_ERROR; /* no PageNumber found */
122 +                       }
123 +               }
124 +               else if (*r < 1)
125 +               {
126 +                       if (allowwrap)
127 +                       {
128 +                               allowwrap = 0;
129 +                               *r = 23;
130 +                               *c = 37;
131 +                       }
132 +                       else
133 +                       {
134 +                               cache_page_unref(cp);
135 +                               return VBI_SEARCH_ERROR; /* no PageNumber found */
136 +                       }
137 +               }
138 +
139 +               p = &pg->text[*r * pg->columns + *c];
140 +
141 +               if (!p->conceal &&                                              /* not concealed */
142 +                       (p->foreground != p->background) && /* not hidden */
143 +                       (p->unicode >= '1' && p->unicode <= '8') && /* valid first digit */
144 +                       (*c == 0 || /* non-numeric char before */
145 +                        (*c >= 1 && ((p-1)->size == VBI_NORMAL_SIZE || (p-1)->size == VBI_DOUBLE_HEIGHT) &&
146 +                         ((p-1)->unicode < '0' || (p-1)->unicode > '9')) ||
147 +                        (*c >= 2 && ((p-2)->size == VBI_DOUBLE_WIDTH || (p-2)->size == VBI_DOUBLE_SIZE) &&
148 +                         ((p-2)->unicode < '0' || (p-2)->unicode > '9'))))
149 +               {
150 +                       switch (p->size)
151 +                       {
152 +                               case VBI_NORMAL_SIZE:
153 +                               case VBI_DOUBLE_HEIGHT:
154 +                                       if ((p->size == VBI_NORMAL_SIZE && (p+1)->size == VBI_NORMAL_SIZE && (p+2)->size == VBI_NORMAL_SIZE ||
155 +                                                p->size == VBI_DOUBLE_HEIGHT && (p+1)->size == VBI_DOUBLE_HEIGHT && (p+2)->size == VBI_DOUBLE_HEIGHT) && /* all 3 same size */
156 +                                               (p+1)->unicode >= '0' && (p+1)->unicode <= '9' && /* valid page number */
157 +                                               (p+2)->unicode >= '0' && (p+2)->unicode <= '9' &&
158 +                                               (*c == 37 || (p+3)->unicode < '0' || (p+3)->unicode > '9'))     /* non-numeric char behind */
159 +                                       {
160 +                                               int bg = (p->background == VBI_YELLOW) ? (32 + VBI_BLACK) : (32 + VBI_YELLOW);
161 +                                               int fg = (p->background == VBI_YELLOW) ? (32 + VBI_YELLOW) : (32 + VBI_BLACK);
162 +
163 +                                               tmp_page = ((p->unicode - '0')<<8) | (((p+1)->unicode - '0')<<4) | ((p+2)->unicode - '0');
164 +
165 +                                               p->foreground = (p+1)->foreground = (p+2)->foreground = fg;
166 +                                               p->background = (p+1)->background = (p+2)->background = bg;
167 +                                               if (p->size == VBI_DOUBLE_HEIGHT)
168 +                                               {
169 +                                                       (p+pg->columns)->foreground = (p+pg->columns+1)->foreground = (p+pg->columns+2)->foreground = fg;
170 +                                                       (p+pg->columns)->background = (p+pg->columns+1)->background = (p+pg->columns+2)->background = bg;
171 +                                               }
172 +
173 +                                               pg->nav_index[0] = p->unicode;
174 +                                               pg->nav_index[1] = (p+1)->unicode;
175 +                                               pg->nav_index[2] = (p+2)->unicode;
176 +
177 +                                               cache_page_unref(cp);
178 +                                               return VBI_SEARCH_SUCCESS;
179 +                                       }
180 +                                       break;
181 +                               case VBI_DOUBLE_WIDTH:
182 +                               case VBI_DOUBLE_SIZE:
183 +                                       if (*c <= 34 &&
184 +                                               (p->size == VBI_DOUBLE_WIDTH && (p+2)->size == VBI_DOUBLE_WIDTH && (p+4)->size == VBI_DOUBLE_WIDTH ||
185 +                                                p->size == VBI_DOUBLE_SIZE && (p+2)->size == VBI_DOUBLE_SIZE && (p+4)->size == VBI_DOUBLE_SIZE) && /* all 3 same size */
186 +                                               (p+2)->unicode >= '0' && (p+2)->unicode <= '9' && /* valid page number */
187 +                                               (p+4)->unicode >= '0' && (p+4)->unicode <= '9' &&
188 +                                               (*c == 34 || (p+6)->unicode < '0' || (p+6)->unicode > '9'))     /* non-numeric char behind */
189 +                                       {
190 +                                               int bg = (p->background == VBI_YELLOW) ? (32 + VBI_BLACK) : (32 + VBI_YELLOW);
191 +                                               int fg = (p->background == VBI_YELLOW) ? (32 + VBI_YELLOW) : (32 + VBI_BLACK);
192 +
193 +                                               tmp_page = ((p->unicode - '0')<<8) | (((p+2)->unicode - '0')<<4) | ((p+4)->unicode - '0');
194 +
195 +                                               p->foreground = (p+1)->foreground = (p+2)->foreground =
196 +                                                       (p+3)->foreground = (p+4)->foreground = (p+5)->foreground = fg;
197 +                                               p->background = (p+1)->background = (p+2)->background =
198 +                                                       (p+3)->background = (p+4)->background = (p+5)->background = bg;
199 +                                               if (p->size == VBI_DOUBLE_SIZE)
200 +                                               {
201 +                                                       (p+pg->columns)->foreground = (p+pg->columns+1)->foreground =
202 +                                                               (p+pg->columns+2)->foreground = (p+pg->columns+3)->foreground =
203 +                                                               (p+pg->columns+4)->foreground = (p+pg->columns+5)->foreground = fg;
204 +                                                       (p+pg->columns)->background = (p+pg->columns+1)->background =
205 +                                                               (p+pg->columns+2)->background = (p+pg->columns+3)->background =
206 +                                                               (p+pg->columns+4)->background = (p+pg->columns+5)->background = bg;
207 +                                               }
208 +
209 +                                               pg->nav_index[0] = p->unicode;
210 +                                               pg->nav_index[1] = (p+2)->unicode;
211 +                                               pg->nav_index[2] = (p+4)->unicode;
212 +
213 +                                               cache_page_unref(cp);
214 +                                               return VBI_SEARCH_SUCCESS;
215 +                                       }
216 +                                       break;
217 +                               default:
218 +                                       break;
219 +                       }
220 +               }
221 +       }
222 +}
223 +
224  static void
225  highlight(struct vbi_search *s, cache_page *vtp,
226           ucs2_t *first, long ms, long me)
227 diff --git a/src/search.h b/src/search.h
228 index be904d6..20a4e4d 100644
229 --- a/src/search.h
230 +++ b/src/search.h
231 @@ -34,6 +34,14 @@ typedef struct vbi_decoder vbi_decoder;
232  
233  /* Public */
234  
235 +typedef enum
236 +{
237 +       DIR_LEFT,
238 +       DIR_RIGHT,
239 +       DIR_UP,
240 +       DIR_DOWN
241 +};
242 +
243  /**
244   * @ingroup Search
245   * @brief Return codes of the vbi_search_next() function.
246 @@ -83,6 +91,8 @@ extern vbi_search *   vbi_search_new(vbi_decoder *vbi,
247                                        int (* progress)(vbi_page *pg));
248  extern void            vbi_search_delete(vbi_search *search);
249  extern vbi_search_status vbi_search_next(vbi_search *search, vbi_page **pg, int dir);
250 +extern vbi_search_status vbi_catch_page(vbi_decoder *vbi, vbi_pgno pgno, vbi_subno subno, int *r, int *c, vbi_page *pg, int dir);
251 +
252  /** @} */
253  
254  /* Private */
255 -- 
256 1.7.9.5
257