Debian Codegraph @

cuneiform_src/Kern/lns32/src/sbambuk.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 //# define DEBUG_SBAMBUK
59
60 #include <fcntl.h>
61
62 #ifndef __SBAMBUK_H
63 # include "sbambuk.h"
64 #endif
65 #ifndef __BLCKWHTE_H
66 # include "blckwhte.h"
67 #endif
68
69
70 #include "hliner.h"
71
72 #include "smooth.h"
73 static int _smooth_height=0;
74
75 static uchar bytebit0[8] = {
76 0x7F, 0xBF, 0xDF, 0xEF,
77 0xF7, 0xFB, 0xFD, 0xFE
78 };
79
80
81
82 /* VERTICAL FILTRATION+SEGMENT EXTRACTION PART...*******************/
83 // static uint16_t cur_row_ = 0;
84
85 // static TBlackSeg far * v_segments_;
86 // static TBlackSeg far * cur_seg_;
87
88 // static BHandle new_segment_ = NULLBHandle;
89 // static TSegBambuk far * vsb_ = NULL;
90
91 #ifndef NDEBUG_SBAMBUK
92 static int started_ = 0;
93 #endif
94
95 static int width_dword_ = 0;
96 static int width_byte_ = 0;
97
98 #ifdef __TGREADER_H
99 THVSegBambuk::THVSegBambuk( TigerReader & reader )
100 {
101 errCode = ER_NONE;
102 assert( reader.isOk() );
103
104
105 /* set frame */
106 // left = reader.wAddX;
107 left = 0;
108 right = left + reader.wImageWidth -1;
109 // bottom = reader.wAddY;
110 bottom = 0;
111 top = bottom + reader.wImageHeight-1;
112
113 xres = reader.wResolutionX;
114 yres = reader.wResolutionY;
115
116 width_dword_ = (width() + 31)/32 ;
117 width_byte_ = (width() + 7)/8;
118
119 TFltBuf filter( width_dword_ );
120 if (filter.isOk())
121 {
122 if (vBambuk.createBambuk( MAX_V_SEGMENTS_COUNT, width() )){
123 TBlackSeg zero_seg = { 0x3333, 0x2222, NULLBHandle, NULLBHandle };
124 vBambuk.cleanMembers( &zero_seg, 0 );
125 if(hBambuk.createBambuk( MAX_H_SEGMENTS_COUNT, height() )){
126 hBambuk.cleanMembers( &zero_seg, 0 );
127
128 makeIt( &reader, &filter );
129 assert( errCode == ER_NONE );
130 }
131 else { errCode = BERROR( ER_NOMEMORY ); };
132 }
133 else { errCode = BERROR( ER_NOMEMORY ); };
134 filter.destroy();
135 };
136 /******
137 if (errCode == ER_NONE)
138 if (!hBambuk.shrinkBambuk( hBambuk.segCount ))
139 { errCode = BERROR( ER_NOMEMORY ); };
140
141 if (errCode == ER_NONE)
142 if (!vBambuk.shrinkBambuk( vBambuk.segCount ))
143 { errCode = BERROR( ER_NOMEMORY ); };
144 ******/
145
146 }
147
148 Bool THVSegBambuk::makeIt( TigerReader * reader,
149 TFltBuf* filter )
150 {
151 assert( this );
152 assert( reader );
153 assert( reader->isOk() );
154 assert( filter );
155 assert( filter->isOk() );
156
157 uchar* new_line = NULL;
158 int cur_row = 0;
159 // int width_byte = reader->lineWidthByte(); assert(width_byte > 0);
160
161 hBambuk.hInitProcess( left, right, 16 );
162
163 if (height() < 17) {
164 for (cur_row = bottom; cur_row <= top; cur_row++) {
165 new_line = (uchar*)(reader->getLine());
166 if (new_line == NULL)
167 {
168 errCode = ER_CANTREAD;
169 return WRONG();
170 };
171
172 if (!hBambuk.hUpdate( new_line ))
173 {
174 errCode = ER_NOMEMORY;
175 return WRONG();
176 };
177 };
178 return TRUE;
179 };
180
181 // vsb_ = &( vBambuk );
182 // v_segments_ = &((*vsb_)[0]);
183 assert( hBambuk.memberTotalCount() == 0 );
184 assert( vBambuk.memberTotalCount() == 0 );
185
186 /* process first 16 lines - extract horisontal and fill buffer*/
187 for (cur_row = bottom; cur_row < bottom + 16; cur_row++)
188 {
189 new_line = (uchar*)(reader->getLine());
190 if (new_line == NULL)
191 {
192 errCode = ER_CANTREAD;
193 return WRONG();
194 };
195 HLiner_AddImageLine(new_line);
196 if (!hBambuk.hUpdate( new_line )) { errCode = ER_NOMEMORY;
197 return WRONG();
198 };
199 filter->addLine( new_line );
200 };
201
202 /* now prepear filter to work */
203 filter->preBuffer();
204
205 // upper bound for h segments
206 #ifndef NDEBUG_SBAMBUK
207 started_ = 0;
208 #endif
209 new_line = (uchar*)(reader->getLine());
210 if (new_line == NULL)
211 {
212 errCode = ER_CANTREAD;
213 return WRONG();
214 };
215 HLiner_AddImageLine(new_line);
216
217 if (!hBambuk.hUpdate( new_line )) { errCode = ER_NOMEMORY;
218 return WRONG();
219 };
220
221 /*
222 if (!vBambuk.vUpdateFirst( (int32_t*)new_line,
223 (int32_t*)(filter->cur16),
224 16
225 )
226 ) {
227 errCode = ER_NOMEMORY;
228 return WRONG();
229 };
230 */
231 int32_t white_line[1024]; memset(white_line, 0xff, sizeof(white_line));
232 if (!vBambuk.vUpdate( (int32_t*)new_line,
233 (int32_t*)(filter->cur16),
234 white_line,
235 16
236 )
237 ) {
238 errCode = ER_NOMEMORY;
239 return WRONG();
240 };
241
242 filter->updateByLine( new_line );
243
244 #ifdef SMOOTH98
245 smooth_start(width_dword_);
246 _smooth_height = smooth_get_height();
247 #endif
248 /* main loop */
249 for (cur_row = bottom + 17; cur_row <= top ; cur_row++)
250 {
251 new_line = (uchar*)(reader->getLine());
252 if (new_line == NULL)
253 {
254 errCode = ER_CANTREAD;
255 return WRONG();
256 };
257 HLiner_AddImageLine(new_line);
258
259 if (!hBambuk.hUpdate( new_line ))
260 {
261 errCode = ER_NOMEMORY;
262 return WRONG();
263 };
264 #ifdef SMOOTH98
265 new_line = (uchar*)smooth_update((int32_t*)new_line);
266 #endif
267 if (!vBambuk.vUpdate( (int32_t*)new_line,
268 (int32_t*)filter->cur16,
269 (int32_t*)filter->last16,
270 cur_row
271 )
272 ){ errCode = ER_NOMEMORY;
273 return WRONG();
274 }
275 filter->updateByLine( new_line );
276 };
277
278 #ifdef SMOOTH98
279 smooth_finish();
280 #endif
281 if (!vBambuk.vUpdate( white_line,
282 (int32_t*)filter->cur16,
283 (int32_t*)filter->last16,
284 cur_row
285 )
286 ){ errCode = ER_NOMEMORY;
287 return WRONG();
288 }
289
290 /*
291 if (!vBambuk.vUpdateLast( (int32_t*)(filter->cur16),
292 (int32_t*)(filter->last16),
293 top+1
294 )
295 ){ errCode = ER_NOMEMORY;
296 return WRONG(); // close vertical segments touching down bound
297 };
298 */
299 #ifndef NDEBUG_SBAMBUK
300 assert( started_ == 0 );
301 #endif
302 return TRUE;
303 }
304
305 #endif // __TGREADER_H
306
307 /**********************************************************************/
308 Bool TSegBambuk::vUpdate( int32_t* new_line,
309 int32_t* cur16,
310 int32_t* prev16,
311 int cur_row
312 )
313 { assert( new_line != NULL );
314 assert( cur16 != NULL );
315 assert( prev16 != NULL );
316 BHandle seg_handle;
317
318 int j, col;
319
320 int nbytes = width_byte_-1;
321
322 uchar* cur_byte = (uchar*)cur16;
323 uchar* prev_byte = (uchar*)prev16;
324 uchar* new_byte = (uchar*)new_line;
325
326 for ( int i = 0; i < nbytes; i++ )
327 {
328 /* 1. process started segments */
329 uchar was_born = (*prev_byte) & ~(*cur_byte);
330 if (was_born)
331 {
332 col = i << 3; // i*8;
333 do {
334 segCount++;
335 if ( (seg_handle = addMember( col+
336 (j = FIRST_BIT_IN_BYTE( was_born ))
337 )
338 ) == NULLBHandle
339 )
340 return WRONG();
341 THE[ seg_handle ].left = cur_row - 16;
342 #ifndef NDEBUG_SBAMBUK
343 started_++;
344 THE[ seg_handle ].right = 0;
345 #endif
346 } while ( was_born &= bytebit0[j]);
347 }
348
349 /* 2. process ended segments */
350 uchar has_died = ~(*cur_byte) & (*new_byte);
351 if (has_died)
352 {
353 col = i << 3; // i*8
354 do {
355 seg_handle = lastEntryMember( col+
356 (j = FIRST_BIT_IN_BYTE( has_died ))
357 );
358 #ifndef NDEBUG_SBAMBUK
359 assert( started_ > 0 );
360 started_--;
361 assert( seg_handle != NULLBHandle );
362 assert(THE[ seg_handle ].right == 0);
363 #endif
364 #ifdef SMOOTH98
365 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
366 #else
367 THE[ seg_handle ].right = cur_row-1;
368 #endif
369 } while ( has_died &= bytebit0[j]);
370 };
371
372 new_byte++;
373 cur_byte++;
374 prev_byte++;
375 }; // for
376 return TRUE;
377 } // vUpdate()
378
379 Bool TSegBambuk::vUpdateFirst( int32_t* new_line,
380 int32_t* cur16,
381 int cur_row
382 )
383 { assert( new_line != NULL );
384 assert( cur16 != NULL );
385 BHandle seg_handle;
386
387 int32_t was_born_dword;
388 int32_t has_died_dword;
389 uchar was_born, has_died;
390 int j, col;
391
392 for ( int i = 0; i < width_dword_ - 1; i++ ){
393 /* process started segments */
394 if ( ( was_born_dword = (~(*cur16)) ) != 0){ // 1(W) at prev; 0(B) at cur;
395 #ifdef BIG_ENDIAN
396 was_born_dword = SWAPLONG(was_born_dword);
397 #endif
398 if ( (was_born = (uchar)was_born_dword ) != 0){ // first byte
399 col = i << 5; // i*32
400 do {
401 segCount++;
402 if ( (seg_handle = addMember( col+
403 (j = FIRST_BIT_IN_BYTE( was_born ))
404 )
405 ) == NULLBHandle
406 ) return WRONG();
407 THE[ seg_handle ].left = cur_row - 16;
408 #ifndef NDEBUG_SBAMBUK
409 started_++;
410 THE[ seg_handle ].right = 0;
411 #endif
412 } while ( was_born &= bytebit0[j]);
413 };
414 if ( (was_born = (uchar)(was_born_dword >> 8) ) != 0){ // second byte
415 col = (i << 5) + 8; // i*32 + 8
416 do {
417 segCount++;
418 if ( (seg_handle = addMember( col+
419 (j = FIRST_BIT_IN_BYTE( was_born ))
420 )
421 ) == NULLBHandle
422 ) return WRONG();
423 THE[ seg_handle ].left = cur_row - 16;
424 #ifndef NDEBUG_SBAMBUK
425 started_++;
426 THE[ seg_handle ].right = 0;
427 #endif
428 } while ( was_born &= bytebit0[j]);
429 };
430 if ( (was_born = (uchar)(was_born_dword >> 16) ) != 0){ // third byte
431 col = (i << 5) + 16; // i*32 + 8
432 do {
433 segCount++;
434 if ( (seg_handle = addMember( col+
435 (j = FIRST_BIT_IN_BYTE( was_born ))
436 )
437 ) == NULLBHandle
438 ) return WRONG();
439 THE[ seg_handle ].left = cur_row - 16;
440 #ifndef NDEBUG_SBAMBUK
441 started_++;
442 THE[ seg_handle ].right = 0;
443 #endif
444 } while ( was_born &= bytebit0[j]);
445 };
446 if ( (was_born = (uchar)(was_born_dword >> 24) ) != 0){ // forth byte
447 col = (i << 5) + 24; // i*32 + 24
448 do {
449 segCount++;
450 if ( (seg_handle = addMember( col+
451 (j = FIRST_BIT_IN_BYTE( was_born ))
452 )
453 ) == NULLBHandle
454 ) return WRONG();
455 THE[ seg_handle ].left = cur_row - 16;
456 #ifndef NDEBUG_SBAMBUK
457 started_++;
458 THE[ seg_handle ].right = 0;
459 #endif
460 } while ( was_born &= bytebit0[j]);
461 };
462 };
463
464 /* process ended segments */
465 if ( (has_died_dword = (~(*cur16) & (*new_line)) ) != 0 ){ // 0(B) at cur; 1(W) at new_line;
466 #ifdef BIG_ENDIAN
467 has_died_dword= SWAPLONG(has_died_dword);
468 #endif
469 if ((has_died = (uchar)has_died_dword ) != 0){ // first byte
470 col = i << 5; // i*32
471 do {
472 seg_handle = lastEntryMember( col+
473 (j = FIRST_BIT_IN_BYTE( has_died ))
474 );
475 #ifndef NDEBUG_SBAMBUK
476 assert( started_ > 0 );
477 started_--;
478 assert( seg_handle != NULLBHandle );
479 assert(THE[ seg_handle ].right == 0);
480 #endif
481 #ifdef SMOOTH98
482 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
483 #else
484 THE[ seg_handle ].right = cur_row-1;
485 #endif
486 } while ( has_died &= bytebit0[j]);
487 };
488 if ((has_died = (uchar)(has_died_dword>>8) ) != 0){ // second byte
489 col = (i << 5) + 8; // i*32
490 do {
491 seg_handle = lastEntryMember( col+
492 (j = FIRST_BIT_IN_BYTE( has_died ))
493 );
494 #ifndef NDEBUG_SBAMBUK
495 assert( started_ > 0 );
496 started_--;
497 assert( seg_handle != NULLBHandle );
498 assert(THE[ seg_handle ].right == 0);
499 #endif
500 #ifdef SMOOTH98
501 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
502 #else
503 THE[ seg_handle ].right = cur_row-1;
504 #endif
505 } while ( has_died &= bytebit0[j]);
506 };
507 if ( (has_died = (uchar)(has_died_dword>>16) ) != 0){ // third byte
508 col = (i << 5) + 16; // i*32
509 do {
510 seg_handle = lastEntryMember( col+
511 (j = FIRST_BIT_IN_BYTE( has_died ))
512 );
513 #ifndef NDEBUG_SBAMBUK
514 assert( started_ > 0 );
515 started_--;
516 assert( seg_handle != NULLBHandle );
517 assert(THE[ seg_handle ].right == 0);
518 #endif
519 #ifdef SMOOTH98
520 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
521 #else
522 THE[ seg_handle ].right = cur_row-1;
523 #endif
524 } while ( has_died &= bytebit0[j]);
525 };
526 if ( (has_died = (uchar)(has_died_dword>>24) ) != 0){ // forth byte
527 col = (i << 5) + 24; // i*32
528 do {
529 seg_handle = lastEntryMember( col+
530 (j = FIRST_BIT_IN_BYTE( has_died ))
531 );
532 #ifndef NDEBUG_SBAMBUK
533 assert( started_ > 0 );
534 started_--;
535 assert( seg_handle != NULLBHandle );
536 assert(THE[ seg_handle ].right == 0);
537 #endif
538 #ifdef SMOOTH98
539 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
540 #else
541 THE[ seg_handle ].right = cur_row-1;
542 #endif
543 } while ( has_died &= bytebit0[j]);
544 };
545 };
546 /**************************/
547 new_line++;
548 cur16++;
549 }; // for
550 return TRUE;
551 } // vUpdateFirst()
552
553 Bool TSegBambuk::vUpdateLast( int32_t* cur16,
554 int32_t* last16,
555 int cur_row
556 )
557 {
558 assert( cur16 != NULL );
559 assert( last16 != NULL );
560 BHandle seg_handle;
561
562 int32_t was_born_dword;
563 int32_t has_died_dword;
564 uchar was_born, has_died;
565 int j, col;
566
567 for ( int i = 0; i < width_dword_ - 1; i++ ){
568 /* process started segments */
569 if ( (was_born_dword = ((*last16) & ~(*cur16)) ) != 0 ){ // 1(W) at prev; 0(B) at cur;
570 #ifdef BIG_ENDIAN
571 was_born_dword = SWAPLONG(was_born_dword);
572 #endif
573 if ((was_born = (uchar)was_born_dword) != 0){ // first byte
574 col = i << 5; // i*32
575 do {
576 segCount++;
577 if ( (seg_handle = addMember( col+
578 (j = FIRST_BIT_IN_BYTE( was_born ))
579 )
580 ) == NULLBHandle
581 ) return WRONG();
582 THE[ seg_handle ].left = cur_row - 16;
583 #ifndef NDEBUG_SBAMBUK
584 started_++;
585 THE[ seg_handle ].right = 0;
586 #endif
587 } while ( was_born &= bytebit0[j]);
588 };
589 if ((was_born = (uchar)(was_born_dword >> 8)) != 0){ // second byte
590 col = (i << 5) + 8; // i*32 + 8
591 do {
592 segCount++;
593 if ( (seg_handle = addMember( col+
594 (j = FIRST_BIT_IN_BYTE( was_born ))
595 )
596 ) == NULLBHandle
597 ) return WRONG();
598 THE[ seg_handle ].left = cur_row - 16;
599 #ifndef NDEBUG_SBAMBUK
600 started_++;
601 THE[ seg_handle ].right = 0;
602 #endif
603 } while ( was_born &= bytebit0[j]);
604 };
605 if ( (was_born = (uchar)(was_born_dword >> 16) ) != 0){ // third byte
606 col = (i << 5) + 16; // i*32 + 8
607 do {
608 segCount++;
609 if ( (seg_handle = addMember( col+
610 (j = FIRST_BIT_IN_BYTE( was_born ))
611 )
612 ) == NULLBHandle
613 ) return WRONG();
614 THE[ seg_handle ].left = cur_row - 16;
615 #ifndef NDEBUG_SBAMBUK
616 started_++;
617 THE[ seg_handle ].right = 0;
618 #endif
619 } while ( was_born &= bytebit0[j]);
620 };
621 if ( (was_born = (uchar)(was_born_dword >> 24)) != 0){ // forth byte
622 col = (i << 5) + 24; // i*32 + 24
623 do {
624 segCount++;
625 if ( (seg_handle = addMember( col+
626 (j = FIRST_BIT_IN_BYTE( was_born ))
627 )
628 ) == NULLBHandle
629 ) return WRONG();
630 THE[ seg_handle ].left = cur_row - 16;
631 #ifndef NDEBUG_SBAMBUK
632 started_++;
633 THE[ seg_handle ].right = 0;
634 #endif
635 } while ( was_born &= bytebit0[j]);
636 };
637 };
638
639 /* process ended segments */
640 if ( ( has_died_dword = ~(*cur16) ) != 0){ // 0(B) at cur; 1(W) at new_line;
641 #ifdef BIG_ENDIAN
642 has_died_dword= SWAPLONG(has_died_dword);
643 #endif
644 if ( (has_died = (uchar)has_died_dword ) != 0){ // first byte
645 col = i << 5; // i*32
646 do {
647 seg_handle = lastEntryMember( col+
648 (j = FIRST_BIT_IN_BYTE( has_died ))
649 );
650 #ifndef NDEBUG_SBAMBUK
651 assert( started_ > 0 );
652 started_--;
653 assert( seg_handle != NULLBHandle );
654 assert(THE[ seg_handle ].right == 0);
655 #endif
656 #ifdef SMOOTH98
657 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
658 #else
659 THE[ seg_handle ].right = cur_row-1;
660 #endif
661 } while ( has_died &= bytebit0[j]);
662 };
663 if ( ( has_died = (uchar)(has_died_dword>>8) ) != 0){ // second byte
664 col = (i << 5) + 8; // i*32
665 do {
666 seg_handle = lastEntryMember( col+
667 (j = FIRST_BIT_IN_BYTE( has_died ))
668 );
669 #ifndef NDEBUG_SBAMBUK
670 assert( started_ > 0 );
671 started_--;
672 assert( seg_handle != NULLBHandle );
673 assert(THE[ seg_handle ].right == 0);
674 #endif
675 #ifdef SMOOTH98
676 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
677 #else
678 THE[ seg_handle ].right = cur_row-1;
679 #endif
680 } while ( has_died &= bytebit0[j]);
681 };
682 if ( ( has_died = (uchar)(has_died_dword>>16) ) != 0){ // third byte
683 col = (i << 5) + 16; // i*32
684 do {
685 seg_handle = lastEntryMember( col+
686 (j = FIRST_BIT_IN_BYTE( has_died ))
687 );
688 #ifndef NDEBUG_SBAMBUK
689 assert( started_ > 0 );
690 started_--;
691 assert( seg_handle != NULLBHandle );
692 assert(THE[ seg_handle ].right == 0);
693 #endif
694 #ifdef SMOOTH98
695 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
696 #else
697 THE[ seg_handle ].right = cur_row-1;
698 #endif
699 } while ( has_died &= bytebit0[j]);
700 };
701 if ( ( has_died = (uchar)(has_died_dword>>24) ) != 0){ // forth byte
702 col = (i << 5) + 24; // i*32
703 do {
704 seg_handle = lastEntryMember( col+
705 (j = FIRST_BIT_IN_BYTE( has_died ))
706 );
707 #ifndef NDEBUG_SBAMBUK
708 assert( started_ > 0 );
709 started_--;
710 assert( seg_handle != NULLBHandle );
711 assert(THE[ seg_handle ].right == 0);
712 #endif
713 #ifdef SMOOTH98
714 THE[ seg_handle ].right = cur_row - _smooth_height - 1;
715 #else
716 THE[ seg_handle ].right = cur_row-1;
717 #endif
718 } while ( has_died &= bytebit0[j]);
719 };
720 };
721 /**************************/
722 last16++;
723 cur16++;
724 }; // for
725 return TRUE;
726 } // vUpdateLast()