Debian Codegraph @

cuneiform_src/Kern/lns32/src/tgreader.cpp

raw
1 /*
2 Copyright (c) 1993-2008, Cognitive Technologies
3 All rights reserved.
4
5 Разрешается повторное распространение и использование как в виде исходного кода,
6 так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
7
8 * При повторном распространении исходного кода должны оставаться указанное
9 выше уведомление об авторском праве, этот список условий и последующий
10 отказ от гарантий.
11 * При повторном распространении двоичного кода в документации и/или в
12 других материалах, поставляемых при распространении, должны сохраняться
13 указанная выше информация об авторском праве, этот список условий и
14 последующий отказ от гарантий.
15 * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16 быть использованы в качестве средства поддержки и/или продвижения
17 продуктов, основанных на этом ПО, без предварительного письменного
18 разрешения.
19
20 ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21 ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22 ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23 ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24 МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25 НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26 ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27 НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28 СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29 ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30 НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31 ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
33 Redistribution and use in source and binary forms, with or without modification,
34 are permitted provided that the following conditions are met:
35
36 * Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
41 * Neither the name of the Cognitive Technologies nor the names of its
42 contributors may be used to endorse or promote products derived from this
43 software without specific prior written permission.
44
45 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57 #include "lnslang.h"
58 #include "lns.h"
59
60 #include "tgreader.h"
61 #include "sweeper.h"
62 #include "memops.h"
63
64 void ExtrLinesInitLNS(void);
65
66 static TImageOpen __f_op = NULL;
67 static TImageRead __f_rd = NULL;
68 static TImageClose __f_cl = NULL;
69
70
71 #include "fillgap3.h"
72 #include "shortseg.h"
73
74 static Bool HBorder=TRUE;
75 static Bool VBorder=TRUE;
76
77 //********************************************
78
79 void InitLNS( TImageOpen f_op,
80 TImageRead f_rd,
81 TImageClose f_cl
82 )
83 { __f_op = f_op;
84 __f_rd = f_rd;
85 __f_cl = f_cl;
86 InitSweeperCallbacks(f_op,f_rd,f_cl);
87 ExtrLinesInitLNS();
88 }
89
90 #define Tiger_Callback_ImageOpen (*__f_op)
91 #define Tiger_Callback_ImageRead (*__f_rd)
92 #define Tiger_Callback_ImageClose (*__f_cl)
93
94 #define BUF_LEN 0x7FFF
95 static int lines_counter=0;
96
97 extern LnsSetupStr lnsSetup;
98
99 TigerReader::TigerReader(void)
100 { lines_counter=0;
101 wImageByteWidth=0;
102 errCode = Tiger_Callback_ImageOpen( (Tiger_ImageInfo*)this) ?
103 ER_NONE :
104 ER_CANTOPEN;
105 if (!isOk())
106 { assert(0); return;
107 };
108
109 VBorder = !(lnsSetup.nOptions & LSS_NOVBORDER_FILTER);
110 if (VBorder) // flag not set - look ini
111 {
112 VBorder = LnsGetProfileInt( "CleanVerticalBorder", 1 ); // sweep, by default
113 }
114
115 HBorder = !(lnsSetup.nOptions & LSS_NOHBORDER_FILTER);
116 if (HBorder) // flag not set - look ini
117 {
118 HBorder = LnsGetProfileInt( "CleanHorisontalBorder", 1 ); // sweep, by default
119 }
120
121 lines_count = 0;
122 dword_len = BUF_LEN / 4;
123 line_buf = (uchar*)malloc( BUF_LEN ); // 24 apr 96, VP. Bug: BUF_LEN <== (dword_len*4)
124 if (line_buf == NULL)
125 { assert(0); errCode = ER_NOMEMORY;
126 dword_len=0;
127 return;
128 };
129 if ( (wAddX % 8) != 0 )
130 { assert(0);
131 }
132
133 FillGap3_Init(wImageByteWidth);
134 }
135
136 TigerReader::~TigerReader(void)
137 {
138
139 FillGap3_Done();
140
141 Tiger_Callback_ImageClose();
142 if (line_buf != NULL)
143 free( (void*)line_buf );
144 }
145
146 void* TigerReader::getLine(void)
147 {
148 //#ifdef LNS_DEBUG
149 // lines_counter++;
150 // printf("\n[%d]\t", lines_counter);
151 //#endif
152 if (lines_count == 0) // there is no lines in buf...
153 { int32_t res = Tiger_Callback_ImageRead( (uchar*)line_buf, (BUF_LEN/wImageByteWidth)*wImageByteWidth ); // 03-09-94 01:45pm
154 lines_count = res / wImageByteWidth;
155 if (lines_count == 0)
156 { assert(0);
157 return NULL;
158 };
159 cur_line = line_buf;
160 if (bFotoMetrics == 0x00) // white is zero
161 {
162 #ifdef NO_ASM
163 register int32_t* cur_dword = (int32_t*)line_buf;
164 int ww16 = dword_len >> 4;
165 while (ww16--)
166 {
167 cur_dword[ 0] = ~(cur_dword[ 0]);
168 cur_dword[ 1] = ~(cur_dword[ 1]);
169 cur_dword[ 2] = ~(cur_dword[ 2]);
170 cur_dword[ 3] = ~(cur_dword[ 3]);
171
172 cur_dword[ 4] = ~(cur_dword[ 4]);
173 cur_dword[ 5] = ~(cur_dword[ 5]);
174 cur_dword[ 6] = ~(cur_dword[ 6]);
175 cur_dword[ 7] = ~(cur_dword[ 7]);
176
177 cur_dword[ 8] = ~(cur_dword[ 8]);
178 cur_dword[ 9] = ~(cur_dword[ 9]);
179 cur_dword[10] = ~(cur_dword[10]);
180 cur_dword[11] = ~(cur_dword[11]);
181
182 cur_dword[12] = ~(cur_dword[12]);
183 cur_dword[13] = ~(cur_dword[13]);
184 cur_dword[14] = ~(cur_dword[14]);
185 cur_dword[15] = ~(cur_dword[15]);
186 cur_dword +=16;
187 }
188
189 int ww__ = dword_len & 15;
190 while (ww__--)
191 *cur_dword++ = ~(*cur_dword);
192
193 #else
194 InvertSelf(line_buf, dword_len);
195 #endif
196 };
197
198 };
199 lines_count --;
200 void* res_line = (void*)( cur_line );
201 cur_line += wImageByteWidth;
202
203 ///////////////////////////////////////////////////////
204 if (HBorder) //*******Rom
205 { // kill hor border
206 int32_t num_short_segm = 0;
207 uchar* pp = (uchar*)res_line;
208 int wi16 = wImageByteWidth >> 4;
209 int wi = wImageByteWidth & 15;
210 while (wi16--)
211 {
212 num_short_segm += tabNumShortSegm[*pp++];
213 num_short_segm += tabNumShortSegm[*pp++];
214 num_short_segm += tabNumShortSegm[*pp++];
215 num_short_segm += tabNumShortSegm[*pp++];
216
217 num_short_segm += tabNumShortSegm[*pp++];
218 num_short_segm += tabNumShortSegm[*pp++];
219 num_short_segm += tabNumShortSegm[*pp++];
220 num_short_segm += tabNumShortSegm[*pp++];
221
222 num_short_segm += tabNumShortSegm[*pp++];
223 num_short_segm += tabNumShortSegm[*pp++];
224 num_short_segm += tabNumShortSegm[*pp++];
225 num_short_segm += tabNumShortSegm[*pp++];
226
227 num_short_segm += tabNumShortSegm[*pp++];
228 num_short_segm += tabNumShortSegm[*pp++];
229 num_short_segm += tabNumShortSegm[*pp++];
230 num_short_segm += tabNumShortSegm[*pp++];
231 };
232
233 while (wi--)
234 num_short_segm += tabNumShortSegm[*pp++];
235
236 if (num_short_segm > wImageByteWidth) // line seems to be noise
237 memset(res_line, 0xff, wImageByteWidth);
238 }
239
240 ///////////////////////////////////////////////////////
241 if (VBorder) //*******Rom
242 { // kill left border - kill all for first white segm
243 int max_border_width = wImageByteWidth >> 4; // 1/16 of page
244 uchar* pp = (uchar*)res_line;
245 while (max_border_width--)
246 {
247 if (*pp == 0xff) // full white segm
248 break;
249 *pp++ = 0xff;
250 }
251 }
252
253 ///////////////////////////////////////////////////////
254 if (VBorder) //*******Rom
255 { // kill right border - kill all for first white segm
256 int max_border_width = wImageByteWidth >> 4; // 1/16 of page
257 uchar* pp = (uchar*)res_line;
258 pp += wImageByteWidth - 1; // set to last byte
259 while (max_border_width--)
260 {
261 if (*pp == 0xff) // full white segm
262 break;
263 *pp-- = 0xff;
264 }
265 }
266
267
268
269 if (wAddX)
270 {
271 uchar* pp = (uchar*)res_line;
272 int32_t skipbytes = wAddX >> 3;
273 pp += skipbytes;
274 res_line = pp;
275 }
276
277
278 return res_line;
279 }
280