Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h"
35 : #include "cnst.h"
36 : #include "prot_fx.h"
37 : #include "stat_enc.h"
38 : #include "wmc_auto.h"
39 : #include "ivas_rom_com.h"
40 : #include "ivas_prot_fx.h"
41 :
42 : /*---------------------------------------------------------------------*
43 : * Local function prototypes
44 : *---------------------------------------------------------------------*/
45 :
46 : static Word16 adapt_GR_sg_fx( const Word16 *in, const Word16 len, const Word16 no_symb, Word16 *nbits, Word16 *in_enc, const Word16 *map0, const Word16 no_GR_ord );
47 :
48 :
49 : /*---------------------------------------------------------------------*
50 : * calculate_diff_fx()
51 : *
52 : * calculate difference wrt previous frame and maps it to positive integer
53 : *---------------------------------------------------------------------*/
54 :
55 50669 : static void calculate_diff_fx(
56 : const Word16 *in, /* i : current frame values */
57 : const Word16 *prev, /* i : previous frmae values */
58 : Word16 *in_diff, /* o : difference values */
59 : const Word16 len /* i : vector length */
60 : )
61 : {
62 : Word16 i, tmp;
63 :
64 423438 : FOR( i = 0; i < len; i++ )
65 : {
66 372769 : tmp = sub( in[i], prev[i] );
67 372769 : IF( tmp > 0 )
68 : {
69 83141 : in_diff[i] = sub( imult1616( 2, tmp ), 1 );
70 83141 : move16();
71 : }
72 : ELSE
73 : {
74 289628 : IF( tmp < 0 )
75 : {
76 60011 : in_diff[i] = imult1616( -2, tmp );
77 60011 : move16();
78 : }
79 : ELSE
80 : {
81 229617 : in_diff[i] = 0;
82 229617 : move16();
83 : }
84 : }
85 : }
86 :
87 50669 : return;
88 : }
89 :
90 :
91 : /*---------------------------------------------------------------------*
92 : * calculate_bit_diff_fx()
93 : *
94 : * estimates the GR number of bits for encoding differential values
95 : * selects between GR order 0 or 1
96 : *---------------------------------------------------------------------*/
97 :
98 : /*! r: number of bits */
99 50669 : static Word16 calculate_bit_diff_fx(
100 : Word16 *in_diff, /* i : values to be encoded */
101 : Word16 len, /* i : number of params */
102 : Word16 *flag_diff /* o : selected GR order */
103 : )
104 : {
105 : Word16 i, nb, nb1;
106 :
107 50669 : nb = 0;
108 50669 : move16();
109 50669 : nb1 = 0;
110 50669 : move16();
111 423438 : FOR( i = 0; i < len; i++ )
112 : {
113 372769 : nb = add( nb, in_diff[i] );
114 372769 : nb1 = add( nb1, shr( in_diff[i], 1 ) );
115 : }
116 50669 : nb = add( nb, len );
117 50669 : nb1 = add( nb1, imult1616( 2, len ) );
118 :
119 50669 : IF( LT_16( nb1, nb ) )
120 : {
121 5451 : nb = add( nb1, 1 );
122 5451 : *flag_diff = 1; /* GR order for differential coding */
123 5451 : move16();
124 : }
125 : ELSE
126 : {
127 45218 : nb = add( nb, 1 );
128 45218 : *flag_diff = 0;
129 45218 : move16();
130 : }
131 :
132 50669 : return nb;
133 : }
134 :
135 :
136 : /*---------------------------------------------------------------------*
137 : * adapt_GR_ief_fx()
138 : *
139 : * adaptive GR coding considering also the differential case
140 : *---------------------------------------------------------------------*/
141 :
142 : /*! r: used GR order */
143 45146 : Word16 adapt_GR_ief_fx(
144 : const Word16 *in, /* i : vector to encode */
145 : Word16 *in_diff, /* o : encoded symbols in case of differential encoding */
146 : const Word16 *prev, /* i : previous frame data */
147 : const Word16 len, /* i : input vector length */
148 : const Word16 no_symb, /* i : number of symbols */
149 : Word16 *nbits, /* o : number of used bits */
150 : Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */
151 : const Word16 *map0, /* i : mapping array */
152 : const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */
153 : Word16 *nbits_diff, /* o : number bits in diff encoding */
154 : const Word16 side_gain_counter, /* i : number of frames since last abs coding */
155 : Word16 *side_gain_bitdiff_lp, /* i/o: LP-filtered bit difference between abs/diff Q(q_side_gain_bitdiff_lp) */
156 : Word16 *q_side_gain_bitdiff_lp, /* i/o: Q of LP-filtered bit difference between abs/diff */
157 : const Word16 try_diff /* i : diff coding allowed 1/0 */
158 : )
159 : {
160 : Word16 nb_diff, flag, flag_diff;
161 : Word16 bitdiff;
162 : Word32 L_tmp, L_tmp1;
163 : Word16 exp_diff;
164 :
165 45146 : flag = adapt_GR_sg_fx( in, len, no_symb, nbits, in_enc, map0, no_GR_ord );
166 :
167 45146 : IF( try_diff ) /* inter-frame prediction allowed */
168 : {
169 10515 : calculate_diff_fx( in, prev, in_diff, len );
170 10515 : nb_diff = calculate_bit_diff_fx( in_diff, len, &flag_diff );
171 10515 : *nbits_diff = nb_diff;
172 10515 : move16();
173 :
174 10515 : bitdiff = sub( s_min( imult1616( 5, len ), *nbits ), add( nb_diff, 1 ) );
175 10515 : L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_LP_FAC_Q31, bitdiff ); // (Q31, Q0) -> Q16
176 10515 : L_tmp1 = Mpy_32_16_1( L_sub( ONE_IN_Q31, STEREO_DFT_BITDIFF_LP_FAC_Q31 ), *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16
177 10515 : *side_gain_bitdiff_lp = extract_h( BASOP_Util_Add_Mant32Exp( L_tmp, Q31 - Q16, L_tmp1, sub( Q31, add( *q_side_gain_bitdiff_lp, Q16 ) ), &exp_diff ) );
178 10515 : *q_side_gain_bitdiff_lp = sub( Q15, exp_diff );
179 10515 : move16();
180 :
181 10515 : L_tmp = Mpy_32_16_1( STEREO_DFT_BITDIFF_ABS_SELECT_Q31, *side_gain_bitdiff_lp ); // (Q31, *q_side_gain_bitdiff_lp) -> *q_side_gain_bitdiff_lp + Q16
182 10515 : L_tmp1 = Mpy_32_16_1( STEREO_DFT_FEC_THRESHOLD_PLUS_1_INV_Q31, side_gain_counter ); // (Q31, Q0) -> Q16
183 10515 : L_tmp = Mpy_32_32( L_tmp, L_tmp1 ); // (*q_side_gain_bitdiff_lp + Q16, Q16) -> *q_side_gain_bitdiff_lp + Q1
184 10515 : IF( GT_64( W_shl( W_deposit32_l( L_deposit_l( bitdiff ) ), add( *q_side_gain_bitdiff_lp, Q1 ) ), W_deposit32_l( L_tmp ) ) )
185 : {
186 8903 : flag = add( no_GR_ord, flag_diff );
187 8903 : *nbits = add( nb_diff, 1 );
188 8903 : move16();
189 : }
190 : }
191 : ELSE
192 : {
193 34631 : *nbits_diff = 100;
194 34631 : move16();
195 34631 : flag_diff = -1;
196 34631 : move16();
197 : }
198 :
199 45146 : return flag;
200 : }
201 :
202 :
203 : /*---------------------------------------------------------------------*
204 : * adapt_GR_rpg1_ief_fx()
205 : *
206 : * use adaptive GR for RPG's considering also the differential case
207 : *---------------------------------------------------------------------*/
208 :
209 : /*! r: used GR order */
210 42102 : Word16 adapt_GR_rpg1_ief_fx(
211 : const Word16 *in, /* i : res pred gains input vector */
212 : Word16 *in_diff, /* o : encoded symbols in case of differential encoding */
213 : const Word16 *prev, /* i : previous frame data */
214 : const Word16 len, /* i : input vector length */
215 : const Word16 no_symb, /* i : number of symbols */
216 : Word16 *nbits, /* o : number of used bits */
217 : Word16 *in_enc, /* o : symbold actually encoded after adapt_GR */
218 : const Word16 *maps, /* i : mapping array */
219 : Word16 *nbits_diff, /* o : estimated no of bits for differential encoding */
220 : const Word16 no_GR_ord, /* i : number of GR order to try 2: 0,1; 3:0,1,2 */
221 : const Word16 try_diff /* i : diff coding allowed 1/0 */
222 : )
223 : {
224 : const Word16 *map0;
225 : Word16 s, i, GR_ord, flag_diff, nb_diff;
226 :
227 42102 : map0 = &maps[8 * NO_SYMB_GR_PRED_G];
228 :
229 42102 : IF( in[0] == 0 )
230 : {
231 2401 : s = 0;
232 2401 : move16();
233 18657 : FOR( i = 0; i < len; i++ )
234 : {
235 16256 : s = add( s, in[i] );
236 : }
237 :
238 2401 : IF( s == 0 )
239 : {
240 : /* encode only the first zero with GR1 */
241 1082 : *nbits = add( shr( map0[0], 1 ), 2 );
242 1082 : move16();
243 1082 : in_enc[0] = map0[0];
244 1082 : move16();
245 : }
246 : ELSE
247 : {
248 1319 : *nbits = 1000; /* large number such that the plain coding will be selected */
249 1319 : move16();
250 : }
251 2401 : GR_ord = 1;
252 2401 : move16();
253 : }
254 : ELSE
255 : {
256 39701 : GR_ord = adapt_GR_sg_fx( in, len, no_symb, nbits, in_enc, maps, no_GR_ord );
257 : }
258 :
259 42102 : IF( try_diff )
260 : {
261 40154 : calculate_diff_fx( in, prev, in_diff, len );
262 40154 : nb_diff = calculate_bit_diff_fx( in_diff, len, &flag_diff );
263 40154 : *nbits_diff = nb_diff;
264 40154 : move16();
265 :
266 40154 : IF( LT_16( add( nb_diff, 1 ), *nbits ) ) /* there is one more bit to signal differential coding */
267 : {
268 31019 : GR_ord = add( no_GR_ord, flag_diff );
269 :
270 31019 : *nbits = add( nb_diff, 1 );
271 31019 : move16();
272 : }
273 : }
274 : ELSE
275 : {
276 1948 : *nbits_diff = 100;
277 1948 : move16();
278 : }
279 :
280 42102 : return GR_ord;
281 : }
282 :
283 :
284 : /*---------------------------------------------------------------------*
285 : * adapt_GR_sg_fx()
286 : *
287 : * adaptive GR coding
288 : *---------------------------------------------------------------------*/
289 :
290 : /*! r: GR order */
291 84847 : static Word16 adapt_GR_sg_fx(
292 : const Word16 *in, /* i : data to be encoded */
293 : const Word16 len, /* i : number of params to be encoded */
294 : const Word16 no_symb, /* i : max number of symbols */
295 : Word16 *nbits, /* o : estimated number of bits */
296 : Word16 *in_enc, /* o : mapped symbols */
297 : const Word16 *map0, /* i : mapping */
298 : const Word16 no_GR_ord /* i : number of GR orders to be tested (2 or 3)*/
299 : )
300 : {
301 : const Word16 *map;
302 : Word16 nbits0, nbits1, nbits2, symb, map_symb, i, nb0, nb1, nb2;
303 :
304 84847 : IF( EQ_16( no_symb, NO_SYMB_GR_SIDE_G ) )
305 : {
306 45146 : map = &map0[imult1616( 15, no_symb )];
307 : }
308 : ELSE
309 : {
310 39701 : map = &( map0[imult1616( 8, no_symb )] );
311 : }
312 :
313 84847 : set_s( in_enc, 0, len );
314 :
315 84847 : nbits1 = 0;
316 84847 : move16();
317 84847 : nbits0 = 0;
318 84847 : move16();
319 84847 : nbits2 = 0;
320 84847 : move16();
321 :
322 786099 : FOR( i = 0; i < len; i++ )
323 : {
324 701252 : symb = in[i];
325 701252 : move16();
326 701252 : map_symb = map[symb];
327 701252 : move16();
328 :
329 701252 : IF( i == 0 )
330 : {
331 : /* GR order is 1 for first band*/
332 84847 : nb0 = add( shr( map_symb, 1 ), 1 );
333 84847 : nb2 = sub( nb0, 2 );
334 : }
335 : ELSE
336 : {
337 616405 : nb0 = map_symb;
338 616405 : move16();
339 616405 : nb2 = shr( map_symb, 2 );
340 : }
341 701252 : nb1 = shr( map_symb, 1 );
342 :
343 701252 : in_enc[i] = map_symb;
344 701252 : move16();
345 701252 : nbits0 = add( nbits0, nb0 );
346 701252 : nbits1 = add( nbits1, nb1 );
347 701252 : nbits2 = add( nbits2, nb2 );
348 :
349 : /* update counts */
350 701252 : map = &( map0[imult1616( symb, no_symb )] );
351 : }
352 :
353 84847 : IF( EQ_16( no_GR_ord, 2 ) )
354 : {
355 39701 : nbits0 = add( nbits0, add( len, 1 ) );
356 39701 : nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) );
357 39701 : IF( LE_16( nbits0, nbits1 ) )
358 : {
359 21435 : *nbits = nbits0;
360 21435 : move16();
361 21435 : return 0;
362 : }
363 : ELSE
364 : {
365 18266 : *nbits = nbits1;
366 18266 : move16();
367 18266 : return 1;
368 : }
369 : }
370 : ELSE
371 : {
372 45146 : IF( EQ_16( no_GR_ord, 3 ) )
373 : {
374 45146 : nbits0 = add( nbits0, add( len, 2 ) );
375 45146 : nbits1 = add( nbits1, add( imult1616( 2, len ), 1 ) );
376 45146 : nbits2 = add( nbits2, add( imult1616( 3, len ), 2 ) );
377 :
378 45146 : test();
379 45146 : IF( LE_16( nbits1, nbits2 ) && LE_16( nbits1, nbits0 ) )
380 : {
381 28108 : *nbits = nbits1;
382 28108 : move16();
383 28108 : return 1;
384 : }
385 :
386 17038 : test();
387 17038 : IF( LE_16( nbits0, nbits2 ) && LE_16( nbits0, nbits1 ) )
388 : {
389 11866 : *nbits = nbits0;
390 11866 : move16();
391 11866 : return 0;
392 : }
393 :
394 5172 : test();
395 5172 : IF( LE_16( nbits2, nbits0 ) && LE_16( nbits2, nbits1 ) )
396 : {
397 5172 : *nbits = nbits2;
398 5172 : move16();
399 5172 : return 2;
400 : }
401 : }
402 : ELSE
403 : {
404 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "Wrong number of GR orders!" );
405 : }
406 : }
407 :
408 0 : return -1;
409 : }
410 :
411 :
412 : /*---------------------------------------------------------------------*
413 : * write_GR0_fx()
414 : *
415 : * write data with GR order 0
416 : *---------------------------------------------------------------------*/
417 :
418 : /*! r: number of bits written */
419 62221 : Word16 write_GR0_fx(
420 : BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
421 : const Word16 ind, /* i : bitstream index */
422 : const Word16 *in, /* i : data to be encoded */
423 : const Word16 len /* i : input data length */
424 : )
425 : {
426 : Word16 nb, i, n, val;
427 62221 : nb = 0;
428 62221 : move16();
429 :
430 473795 : FOR( i = 0; i < len; i++ )
431 : {
432 411574 : n = add( in[i], 1 );
433 :
434 411574 : IF( LT_16( n, 16 ) )
435 : {
436 411573 : val = sub( shl( 1, in[i] ), 1 );
437 411573 : val = shl( val, 1 );
438 411573 : push_indice( hBstr, ind, val, n );
439 : }
440 : ELSE
441 : {
442 1 : push_indice( hBstr, ind, 16383, 14 );
443 1 : push_indice( hBstr, ind, sub( shl( 1, sub( n, 15 ) ), 1 ), sub( n, 15 ) );
444 1 : push_indice( hBstr, ind, 0, 1 );
445 : }
446 411574 : nb = add( nb, n );
447 : }
448 :
449 62221 : return nb;
450 : }
451 :
452 :
453 : /*---------------------------------------------------------------------*
454 : * write_GR1_fx()
455 : *
456 : * write data with GR order 1
457 : *---------------------------------------------------------------------*/
458 :
459 : /*! r: number of bits written */
460 68707 : Word16 write_GR1_fx(
461 : BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
462 : const Word16 ind, /* i : bitstream index */
463 : const Word16 *in, /* i : data to be encoded */
464 : const Word16 len /* i : input data length */
465 : )
466 : {
467 : Word16 nb, i, n, val;
468 68707 : nb = 0;
469 68707 : move16();
470 :
471 328289 : FOR( i = 0; i < len; i++ )
472 : {
473 259582 : n = shr( in[i], 1 );
474 259582 : IF( LT_16( n, 14 ) )
475 : {
476 259422 : val = sub( shl( 1, n ), 1 );
477 259422 : val = add( shl( val, 2 ), s_and( in[i], 1 ) );
478 259422 : push_indice( hBstr, ind, val, add( n, 2 ) );
479 : }
480 : ELSE
481 : {
482 160 : push_indice( hBstr, ind, 16383, 14 );
483 160 : IF( GT_16( n, 14 ) )
484 : {
485 1 : push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */
486 : }
487 160 : push_indice( hBstr, ind, 0, 1 );
488 160 : push_indice( hBstr, ind, s_and( in[i], 1 ), 1 );
489 : }
490 259582 : nb = add( nb, add( n, 2 ) );
491 : }
492 :
493 68707 : return nb;
494 : }
495 :
496 :
497 : /*---------------------------------------------------------------------*
498 : * write_GR2_fx()
499 : *
500 : * write data with GR order 2
501 : *---------------------------------------------------------------------*/
502 :
503 : /*! r: number of bits written */
504 2814 : static Word16 write_GR2_fx(
505 : BSTR_ENC_HANDLE hBstr, /* i/o: bitstream handle */
506 : const Word16 ind, /* i : bitstream index */
507 : const Word16 *in, /* i : data to be encoded */
508 : const Word16 len /* i : input data length */
509 : )
510 : {
511 : Word16 nb, i, n;
512 2814 : nb = 0;
513 2814 : move16();
514 :
515 26061 : FOR( i = 0; i < len; i++ )
516 : {
517 23247 : n = shr( in[i], 2 );
518 23247 : IF( LT_16( n, 14 ) )
519 : {
520 23247 : IF( n > 0 )
521 : {
522 13097 : push_indice( hBstr, ind, sub( shl( 1, n ), 1 ), n ); /* 1 n times */
523 : }
524 23247 : push_indice( hBstr, ind, 0, 1 );
525 23247 : push_indice( hBstr, ind, s_and( in[i], 3 ), 2 );
526 : }
527 : ELSE
528 : {
529 0 : push_indice( hBstr, ind, 16383, 14 );
530 0 : IF( GT_16( n, 14 ) )
531 : {
532 0 : push_indice( hBstr, ind, sub( shl( 1, sub( n, 14 ) ), 1 ), sub( n, 14 ) ); /* 1 n times */
533 : }
534 0 : push_indice( hBstr, ind, 0, 1 );
535 0 : push_indice( hBstr, ind, s_and( in[i], 3 ), 2 );
536 : }
537 23247 : nb = add( nb, add( n, 3 ) );
538 : }
539 :
540 2814 : return nb;
541 : }
542 :
543 :
544 : /*---------------------------------------------------------------------*
545 : * write_bitstream_GR_fx()
546 : *
547 : * generic GR encoder for GR order 0 or 1
548 : *---------------------------------------------------------------------*/
549 :
550 : /*! r: number of bits written */
551 39199 : Word16 write_bitstream_GR_fx(
552 : BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
553 : const Word16 ind, /* i : bitstream index */
554 : const Word16 *in, /* i : input vector */
555 : const Word16 len, /* i : input vector length */
556 : const Word16 GR_ord /* i : GR order */
557 : )
558 : {
559 : Word16 nb;
560 39199 : nb = 0;
561 39199 : move16();
562 :
563 39199 : push_indice( hBstr, ind, GR_ord, 1 );
564 39199 : nb = add( nb, 1 );
565 :
566 39199 : IF( GR_ord == 0 )
567 : {
568 38504 : nb = add( nb, write_GR0_fx( hBstr, ind, in, len ) );
569 : }
570 : ELSE
571 : {
572 695 : nb = add( nb, write_GR1_fx( hBstr, ind, in, len ) );
573 : }
574 :
575 39199 : return nb;
576 : }
577 :
578 :
579 : /*---------------------------------------------------------------------*
580 : * write_bitstream_adapt_GR_fx()
581 : *
582 : * write encoded data using adaptive GR
583 : *---------------------------------------------------------------------*/
584 :
585 : /*! r: number of bits written */
586 42595 : Word16 write_bitstream_adapt_GR_fx(
587 : BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */
588 : const Word16 ind, /* i : bitstream index */
589 : const Word16 *in, /* i : values to be written in bitstream */
590 : const Word16 len, /* i : values vector length */
591 : const Word16 GR_ord, /* i : GR order to be used */
592 : const Word16 no_GR_ord /* i : speech/music 0/1 */
593 : )
594 : {
595 : Word16 nb;
596 :
597 42595 : nb = 0;
598 42595 : move16();
599 : /* first component first */
600 42595 : nb = add( nb, write_GR1_fx( hBstr, ind, in, 1 ) );
601 :
602 : /* write the GR order */
603 42595 : IF( EQ_16( no_GR_ord, 2 ) )
604 : {
605 7434 : push_indice( hBstr, ind, GR_ord, 1 );
606 7434 : nb = add( nb, 1 );
607 : }
608 : ELSE
609 : {
610 35161 : IF( EQ_16( GR_ord, 1 ) )
611 : {
612 23259 : push_indice( hBstr, ind, 0, 1 ); /* GR order = 1*/
613 23259 : nb = add( nb, 1 );
614 : }
615 : ELSE
616 : {
617 11902 : push_indice( hBstr, ind, 1, 1 );
618 11902 : push_indice( hBstr, ind, shr( GR_ord, 1 ), 1 ); /* '10' for GR ord = 0; '11' for GR ord 2 */
619 11902 : nb = add( nb, 2 );
620 : }
621 : }
622 :
623 42595 : IF( GR_ord == 0 )
624 : {
625 15339 : nb = add( nb, write_GR0_fx( hBstr, ind, &in[1], sub( len, 1 ) ) );
626 : }
627 : ELSE
628 : {
629 27256 : IF( EQ_16( GR_ord, 1 ) )
630 : {
631 24442 : nb = add( nb, write_GR1_fx( hBstr, ind, &in[1], sub( len, 1 ) ) );
632 : }
633 : ELSE
634 : {
635 2814 : nb = add( nb, write_GR2_fx( hBstr, ind, &in[1], sub( len, 1 ) ) );
636 : }
637 : }
638 :
639 42595 : return nb;
640 : }
|