| 496 | |
| 497 | |
| 498 | def create_bytes(buffer: BitBuffer, rs_blocks: list[RSBlock]): |
| 499 | offset = 0 |
| 500 | |
| 501 | maxDcCount = 0 |
| 502 | maxEcCount = 0 |
| 503 | |
| 504 | dcdata: list[list[int]] = [] |
| 505 | ecdata: list[list[int]] = [] |
| 506 | |
| 507 | for rs_block in rs_blocks: |
| 508 | dcCount = rs_block.data_count |
| 509 | ecCount = rs_block.total_count - dcCount |
| 510 | |
| 511 | maxDcCount = max(maxDcCount, dcCount) |
| 512 | maxEcCount = max(maxEcCount, ecCount) |
| 513 | |
| 514 | current_dc = [0xFF & buffer.buffer[i + offset] for i in range(dcCount)] |
| 515 | offset += dcCount |
| 516 | |
| 517 | # Get error correction polynomial. |
| 518 | if ecCount in LUT.rsPoly_LUT: |
| 519 | rsPoly = base.Polynomial(LUT.rsPoly_LUT[ecCount], 0) |
| 520 | else: |
| 521 | rsPoly = base.Polynomial([1], 0) |
| 522 | for i in range(ecCount): |
| 523 | rsPoly = rsPoly * base.Polynomial([1, base.gexp(i)], 0) |
| 524 | |
| 525 | rawPoly = base.Polynomial(current_dc, len(rsPoly) - 1) |
| 526 | |
| 527 | modPoly = rawPoly % rsPoly |
| 528 | current_ec = [] |
| 529 | mod_offset = len(modPoly) - ecCount |
| 530 | for i in range(ecCount): |
| 531 | modIndex = i + mod_offset |
| 532 | current_ec.append(modPoly[modIndex] if (modIndex >= 0) else 0) |
| 533 | |
| 534 | dcdata.append(current_dc) |
| 535 | ecdata.append(current_ec) |
| 536 | |
| 537 | data = [] |
| 538 | for i in range(maxDcCount): |
| 539 | for dc in dcdata: |
| 540 | if i < len(dc): |
| 541 | data.append(dc[i]) |
| 542 | for i in range(maxEcCount): |
| 543 | for ec in ecdata: |
| 544 | if i < len(ec): |
| 545 | data.append(ec[i]) |
| 546 | |
| 547 | return data |
| 548 | |
| 549 | |
| 550 | def create_data(version, error_correction, data_list): |