OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../include/fxcodec/fx_codec.h" | 7 #include "../../../include/fxcodec/fx_codec.h" |
8 #include "codec_int.h" | 8 #include "codec_int.h" |
9 const uint8_t OneLeadPos[256] = { | 9 const uint8_t OneLeadPos[256] = { |
10 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, | 10 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 if (byte_pos == max_byte) { | 73 if (byte_pos == max_byte) { |
74 return max_pos; | 74 return max_pos; |
75 } | 75 } |
76 int pos = leading_pos[data_buf[byte_pos]] + byte_pos * 8; | 76 int pos = leading_pos[data_buf[byte_pos]] + byte_pos * 8; |
77 if (pos > max_pos) { | 77 if (pos > max_pos) { |
78 pos = max_pos; | 78 pos = max_pos; |
79 } | 79 } |
80 return pos; | 80 return pos; |
81 } | 81 } |
82 void _FaxG4FindB1B2(const uint8_t* ref_buf, int columns, int a0, FX_BOOL a0color
, int& b1, int& b2) | 82 void _FaxG4FindB1B2(const uint8_t* ref_buf, int columns, int a0, bool a0color, i
nt& b1, int& b2) |
83 { | 83 { |
84 if (a0color) { | 84 if (a0color) { |
85 a0color = 1; | 85 a0color = 1; |
86 } | 86 } |
87 uint8_t first_bit = (a0 < 0) ? 1 : ((ref_buf[a0 / 8] & (1 << (7 - a0 % 8)))
!= 0); | 87 uint8_t first_bit = (a0 < 0) ? 1 : ((ref_buf[a0 / 8] & (1 << (7 - a0 % 8)))
!= 0); |
88 b1 = _FindBit(ref_buf, columns, a0 + 1, !first_bit); | 88 b1 = _FindBit(ref_buf, columns, a0 + 1, !first_bit); |
89 if (b1 >= columns) { | 89 if (b1 >= columns) { |
90 b1 = b2 = columns; | 90 b1 = b2 = columns; |
91 return; | 91 return; |
92 } | 92 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 393 } |
394 bitpos ++; | 394 bitpos ++; |
395 int next_off = ins_off + ins * 3; | 395 int next_off = ins_off + ins * 3; |
396 for (; ins_off < next_off; ins_off += 3) { | 396 for (; ins_off < next_off; ins_off += 3) { |
397 if (ins_array[ins_off] == code) { | 397 if (ins_array[ins_off] == code) { |
398 return ins_array[ins_off + 1] + ins_array[ins_off + 2] * 256; | 398 return ins_array[ins_off + 1] + ins_array[ins_off + 2] * 256; |
399 } | 399 } |
400 } | 400 } |
401 } | 401 } |
402 } | 402 } |
403 FX_BOOL _FaxG4GetRow(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t*
dest_buf, const uint8_t* ref_buf, int columns) | 403 bool _FaxG4GetRow(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t* des
t_buf, const uint8_t* ref_buf, int columns) |
404 { | 404 { |
405 int a0 = -1, a0color = 1; | 405 int a0 = -1, a0color = 1; |
406 while (1) { | 406 while (1) { |
407 if (bitpos >= bitsize) { | 407 if (bitpos >= bitsize) { |
408 return FALSE; | 408 return false; |
409 } | 409 } |
410 int a1, a2, b1, b2; | 410 int a1, a2, b1, b2; |
411 _FaxG4FindB1B2(ref_buf, columns, a0, a0color, b1, b2); | 411 _FaxG4FindB1B2(ref_buf, columns, a0, a0color, b1, b2); |
412 FX_BOOL bit = NEXTBIT; | 412 bool bit = NEXTBIT; |
413 int v_delta = 0; | 413 int v_delta = 0; |
414 if (bit) { | 414 if (bit) { |
415 } else { | 415 } else { |
416 if (bitpos >= bitsize) { | 416 if (bitpos >= bitsize) { |
417 return FALSE; | 417 return false; |
418 } | 418 } |
419 FX_BOOL bit1 = NEXTBIT; | 419 bool bit1 = NEXTBIT; |
420 if (bitpos >= bitsize) { | 420 if (bitpos >= bitsize) { |
421 return FALSE; | 421 return false; |
422 } | 422 } |
423 FX_BOOL bit2 = NEXTBIT; | 423 bool bit2 = NEXTBIT; |
424 if (bit1 && bit2) { | 424 if (bit1 && bit2) { |
425 v_delta = 1; | 425 v_delta = 1; |
426 } else if (bit1) { | 426 } else if (bit1) { |
427 v_delta = -1; | 427 v_delta = -1; |
428 } else if (bit2) { | 428 } else if (bit2) { |
429 int run_len1 = 0; | 429 int run_len1 = 0; |
430 while (1) { | 430 while (1) { |
431 int run = _FaxGetRun(a0color ? FaxWhiteRunIns : FaxBlackRunI
ns, src_buf, bitpos, bitsize); | 431 int run = _FaxGetRun(a0color ? FaxWhiteRunIns : FaxBlackRunI
ns, src_buf, bitpos, bitsize); |
432 run_len1 += run; | 432 run_len1 += run; |
433 if (run < 64) { | 433 if (run < 64) { |
(...skipping 16 matching lines...) Expand all Loading... |
450 } | 450 } |
451 } | 451 } |
452 a2 = a1 + run_len2; | 452 a2 = a1 + run_len2; |
453 if (a0color) { | 453 if (a0color) { |
454 _FaxFillBits(dest_buf, columns, a1, a2); | 454 _FaxFillBits(dest_buf, columns, a1, a2); |
455 } | 455 } |
456 a0 = a2; | 456 a0 = a2; |
457 if (a0 < columns) { | 457 if (a0 < columns) { |
458 continue; | 458 continue; |
459 } | 459 } |
460 return TRUE; | 460 return true; |
461 } else { | 461 } else { |
462 if (bitpos >= bitsize) { | 462 if (bitpos >= bitsize) { |
463 return FALSE; | 463 return false; |
464 } | 464 } |
465 bit = NEXTBIT; | 465 bit = NEXTBIT; |
466 if (bit) { | 466 if (bit) { |
467 if (!a0color) { | 467 if (!a0color) { |
468 _FaxFillBits(dest_buf, columns, a0, b2); | 468 _FaxFillBits(dest_buf, columns, a0, b2); |
469 } | 469 } |
470 if (b2 >= columns) { | 470 if (b2 >= columns) { |
471 return TRUE; | 471 return true; |
472 } | 472 } |
473 a0 = b2; | 473 a0 = b2; |
474 continue; | 474 continue; |
475 } else { | 475 } else { |
476 if (bitpos >= bitsize) { | 476 if (bitpos >= bitsize) { |
477 return FALSE; | 477 return false; |
478 } | 478 } |
479 FX_BOOL bit1 = NEXTBIT; | 479 bool bit1 = NEXTBIT; |
480 if (bitpos >= bitsize) { | 480 if (bitpos >= bitsize) { |
481 return FALSE; | 481 return false; |
482 } | 482 } |
483 FX_BOOL bit2 = NEXTBIT; | 483 bool bit2 = NEXTBIT; |
484 if (bit1 && bit2) { | 484 if (bit1 && bit2) { |
485 v_delta = 2; | 485 v_delta = 2; |
486 } else if (bit1) { | 486 } else if (bit1) { |
487 v_delta = -2; | 487 v_delta = -2; |
488 } else if (bit2) { | 488 } else if (bit2) { |
489 if (bitpos >= bitsize) { | 489 if (bitpos >= bitsize) { |
490 return FALSE; | 490 return false; |
491 } | 491 } |
492 bit = NEXTBIT; | 492 bit = NEXTBIT; |
493 if (bit) { | 493 if (bit) { |
494 v_delta = 3; | 494 v_delta = 3; |
495 } else { | 495 } else { |
496 v_delta = -3; | 496 v_delta = -3; |
497 } | 497 } |
498 } else { | 498 } else { |
499 if (bitpos >= bitsize) { | 499 if (bitpos >= bitsize) { |
500 return FALSE; | 500 return false; |
501 } | 501 } |
502 bit = NEXTBIT; | 502 bit = NEXTBIT; |
503 if (bit) { | 503 if (bit) { |
504 bitpos += 3; | 504 bitpos += 3; |
505 continue; | 505 continue; |
506 } else { | 506 } else { |
507 bitpos += 5; | 507 bitpos += 5; |
508 return TRUE; | 508 return true; |
509 } | 509 } |
510 } | 510 } |
511 } | 511 } |
512 } | 512 } |
513 } | 513 } |
514 a1 = b1 + v_delta; | 514 a1 = b1 + v_delta; |
515 if (!a0color) { | 515 if (!a0color) { |
516 _FaxFillBits(dest_buf, columns, a0, a1); | 516 _FaxFillBits(dest_buf, columns, a0, a1); |
517 } | 517 } |
518 if (a1 >= columns) { | 518 if (a1 >= columns) { |
519 return TRUE; | 519 return true; |
520 } | 520 } |
521 a0 = a1; | 521 a0 = a1; |
522 a0color = !a0color; | 522 a0color = !a0color; |
523 } | 523 } |
524 } | 524 } |
525 FX_BOOL _FaxSkipEOL(const uint8_t* src_buf, int bitsize, int& bitpos) | 525 bool _FaxSkipEOL(const uint8_t* src_buf, int bitsize, int& bitpos) |
526 { | 526 { |
527 int startbit = bitpos; | 527 int startbit = bitpos; |
528 while (bitpos < bitsize) { | 528 while (bitpos < bitsize) { |
529 int bit = NEXTBIT; | 529 int bit = NEXTBIT; |
530 if (bit) { | 530 if (bit) { |
531 if (bitpos - startbit <= 11) { | 531 if (bitpos - startbit <= 11) { |
532 bitpos = startbit; | 532 bitpos = startbit; |
533 } | 533 } |
534 return TRUE; | 534 return true; |
535 } | 535 } |
536 } | 536 } |
537 return FALSE; | 537 return false; |
538 } | 538 } |
539 FX_BOOL _FaxGet1DLine(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t*
dest_buf, int columns) | 539 bool _FaxGet1DLine(const uint8_t* src_buf, int bitsize, int& bitpos, uint8_t* de
st_buf, int columns) |
540 { | 540 { |
541 int color = TRUE; | 541 int color = true; |
542 int startpos = 0; | 542 int startpos = 0; |
543 while (1) { | 543 while (1) { |
544 if (bitpos >= bitsize) { | 544 if (bitpos >= bitsize) { |
545 return FALSE; | 545 return false; |
546 } | 546 } |
547 int run_len = 0; | 547 int run_len = 0; |
548 while (1) { | 548 while (1) { |
549 int run = _FaxGetRun(color ? FaxWhiteRunIns : FaxBlackRunIns, src_bu
f, bitpos, bitsize); | 549 int run = _FaxGetRun(color ? FaxWhiteRunIns : FaxBlackRunIns, src_bu
f, bitpos, bitsize); |
550 if (run < 0) { | 550 if (run < 0) { |
551 while (bitpos < bitsize) { | 551 while (bitpos < bitsize) { |
552 int bit = NEXTBIT; | 552 int bit = NEXTBIT; |
553 if (bit) { | 553 if (bit) { |
554 return TRUE; | 554 return true; |
555 } | 555 } |
556 } | 556 } |
557 return FALSE; | 557 return false; |
558 } | 558 } |
559 run_len += run; | 559 run_len += run; |
560 if (run < 64) { | 560 if (run < 64) { |
561 break; | 561 break; |
562 } | 562 } |
563 } | 563 } |
564 if (!color) { | 564 if (!color) { |
565 _FaxFillBits(dest_buf, columns, startpos, startpos + run_len); | 565 _FaxFillBits(dest_buf, columns, startpos, startpos + run_len); |
566 } | 566 } |
567 startpos += run_len; | 567 startpos += run_len; |
568 if (startpos >= columns) { | 568 if (startpos >= columns) { |
569 break; | 569 break; |
570 } | 570 } |
571 color = !color; | 571 color = !color; |
572 } | 572 } |
573 return TRUE; | 573 return true; |
574 } | 574 } |
575 class CCodec_FaxDecoder : public CCodec_ScanlineDecoder | 575 class CCodec_FaxDecoder : public CCodec_ScanlineDecoder |
576 { | 576 { |
577 public: | 577 public: |
578 CCodec_FaxDecoder(); | 578 CCodec_FaxDecoder(); |
579 virtual ~CCodec_FaxDecoder(); | 579 virtual ~CCodec_FaxDecoder(); |
580 FX_BOOL» » » » Create(const uint8_t* src_buf, FX_DWORD
src_size, int width, int height, | 580 bool» » » » Create(const uint8_t* src_buf, FX_DWORD
src_size, int width, int height, |
581 int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlig
n, FX_BOOL BlackIs1, int Columns, int Rows); | 581 int K, bool EndOfLine, bool EncodedByteAlign, boo
l BlackIs1, int Columns, int Rows); |
582 virtual void v_DownScale(int dest_width, int dest_height) {} | 582 virtual void v_DownScale(int dest_width, int dest_height) {} |
583 virtual FX_BOOL» » v_Rewind(); | 583 virtual bool» » v_Rewind(); |
584 virtual uint8_t* v_GetNextLine(); | 584 virtual uint8_t* v_GetNextLine(); |
585 virtual FX_DWORD GetSrcOffset(); | 585 virtual FX_DWORD GetSrcOffset(); |
586 int m_Encoding, m_bEndOfLine, m_bByteAlign, m_bBlack; | 586 int m_Encoding, m_bEndOfLine, m_bByteAlign, m_bBlack; |
587 int bitpos; | 587 int bitpos; |
588 const uint8_t* m_pSrcBuf; | 588 const uint8_t* m_pSrcBuf; |
589 FX_DWORD m_SrcSize; | 589 FX_DWORD m_SrcSize; |
590 uint8_t* m_pScanlineBuf; | 590 uint8_t* m_pScanlineBuf; |
591 uint8_t* m_pRefBuf; | 591 uint8_t* m_pRefBuf; |
592 }; | 592 }; |
593 CCodec_FaxDecoder::CCodec_FaxDecoder() | 593 CCodec_FaxDecoder::CCodec_FaxDecoder() |
594 { | 594 { |
595 m_pScanlineBuf = NULL; | 595 m_pScanlineBuf = NULL; |
596 m_pRefBuf = NULL; | 596 m_pRefBuf = NULL; |
597 } | 597 } |
598 CCodec_FaxDecoder::~CCodec_FaxDecoder() | 598 CCodec_FaxDecoder::~CCodec_FaxDecoder() |
599 { | 599 { |
600 if (m_pScanlineBuf) { | 600 if (m_pScanlineBuf) { |
601 FX_Free(m_pScanlineBuf); | 601 FX_Free(m_pScanlineBuf); |
602 } | 602 } |
603 if (m_pRefBuf) { | 603 if (m_pRefBuf) { |
604 FX_Free(m_pRefBuf); | 604 FX_Free(m_pRefBuf); |
605 } | 605 } |
606 } | 606 } |
607 FX_BOOL CCodec_FaxDecoder::Create(const uint8_t* src_buf, FX_DWORD src_size, int
width, int height, | 607 bool CCodec_FaxDecoder::Create(const uint8_t* src_buf, FX_DWORD src_size, int wi
dth, int height, |
608 int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteA
lign, FX_BOOL BlackIs1, int Columns, int Rows) | 608 int K, bool EndOfLine, bool EncodedByteAlign,
bool BlackIs1, int Columns, int Rows) |
609 { | 609 { |
610 m_Encoding = K; | 610 m_Encoding = K; |
611 m_bEndOfLine = EndOfLine; | 611 m_bEndOfLine = EndOfLine; |
612 m_bByteAlign = EncodedByteAlign; | 612 m_bByteAlign = EncodedByteAlign; |
613 m_bBlack = BlackIs1; | 613 m_bBlack = BlackIs1; |
614 m_OrigWidth = Columns; | 614 m_OrigWidth = Columns; |
615 m_OrigHeight = Rows; | 615 m_OrigHeight = Rows; |
616 if (m_OrigWidth == 0) { | 616 if (m_OrigWidth == 0) { |
617 m_OrigWidth = width; | 617 m_OrigWidth = width; |
618 } | 618 } |
619 if (m_OrigHeight == 0) { | 619 if (m_OrigHeight == 0) { |
620 m_OrigHeight = height; | 620 m_OrigHeight = height; |
621 } | 621 } |
622 m_Pitch = (m_OrigWidth + 31) / 32 * 4; | 622 m_Pitch = (m_OrigWidth + 31) / 32 * 4; |
623 m_OutputWidth = m_OrigWidth; | 623 m_OutputWidth = m_OrigWidth; |
624 m_OutputHeight = m_OrigHeight; | 624 m_OutputHeight = m_OrigHeight; |
625 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); | 625 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); |
626 m_pRefBuf = FX_Alloc(uint8_t, m_Pitch); | 626 m_pRefBuf = FX_Alloc(uint8_t, m_Pitch); |
627 m_pSrcBuf = src_buf; | 627 m_pSrcBuf = src_buf; |
628 m_SrcSize = src_size; | 628 m_SrcSize = src_size; |
629 m_nComps = 1; | 629 m_nComps = 1; |
630 m_bpc = 1; | 630 m_bpc = 1; |
631 m_bColorTransformed = FALSE; | 631 m_bColorTransformed = false; |
632 return TRUE; | 632 return true; |
633 } | 633 } |
634 FX_BOOL CCodec_FaxDecoder::v_Rewind() | 634 bool CCodec_FaxDecoder::v_Rewind() |
635 { | 635 { |
636 FXSYS_memset(m_pRefBuf, 0xff, m_Pitch); | 636 FXSYS_memset(m_pRefBuf, 0xff, m_Pitch); |
637 bitpos = 0; | 637 bitpos = 0; |
638 return TRUE; | 638 return true; |
639 } | 639 } |
640 uint8_t* CCodec_FaxDecoder::v_GetNextLine() | 640 uint8_t* CCodec_FaxDecoder::v_GetNextLine() |
641 { | 641 { |
642 int bitsize = m_SrcSize * 8; | 642 int bitsize = m_SrcSize * 8; |
643 _FaxSkipEOL(m_pSrcBuf, bitsize, bitpos); | 643 _FaxSkipEOL(m_pSrcBuf, bitsize, bitpos); |
644 if (bitpos >= bitsize) { | 644 if (bitpos >= bitsize) { |
645 return NULL; | 645 return NULL; |
646 } | 646 } |
647 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); | 647 FXSYS_memset(m_pScanlineBuf, 0xff, m_Pitch); |
648 if (m_Encoding < 0) { | 648 if (m_Encoding < 0) { |
649 _FaxG4GetRow(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf, m_Or
igWidth); | 649 _FaxG4GetRow(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf, m_Or
igWidth); |
650 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); | 650 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); |
651 } else if (m_Encoding == 0) { | 651 } else if (m_Encoding == 0) { |
652 _FaxGet1DLine(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_OrigWidth); | 652 _FaxGet1DLine(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_OrigWidth); |
653 } else { | 653 } else { |
654 FX_BOOL bNext1D = m_pSrcBuf[bitpos / 8] & (1 << (7 - bitpos % 8)); | 654 bool bNext1D = m_pSrcBuf[bitpos / 8] & (1 << (7 - bitpos % 8)); |
655 bitpos ++; | 655 bitpos ++; |
656 if (bNext1D) { | 656 if (bNext1D) { |
657 _FaxGet1DLine(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_OrigWidt
h); | 657 _FaxGet1DLine(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_OrigWidt
h); |
658 } else { | 658 } else { |
659 _FaxG4GetRow(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf,
m_OrigWidth); | 659 _FaxG4GetRow(m_pSrcBuf, bitsize, bitpos, m_pScanlineBuf, m_pRefBuf,
m_OrigWidth); |
660 } | 660 } |
661 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); | 661 FXSYS_memcpy(m_pRefBuf, m_pScanlineBuf, m_Pitch); |
662 } | 662 } |
663 if (m_bEndOfLine) { | 663 if (m_bEndOfLine) { |
664 _FaxSkipEOL(m_pSrcBuf, bitsize, bitpos); | 664 _FaxSkipEOL(m_pSrcBuf, bitsize, bitpos); |
665 } | 665 } |
666 if (m_bByteAlign && bitpos < bitsize) { | 666 if (m_bByteAlign && bitpos < bitsize) { |
667 int bitpos0 = bitpos; | 667 int bitpos0 = bitpos; |
668 int bitpos1 = (bitpos + 7) / 8 * 8; | 668 int bitpos1 = (bitpos + 7) / 8 * 8; |
669 while (m_bByteAlign && bitpos0 < bitpos1) { | 669 while (m_bByteAlign && bitpos0 < bitpos1) { |
670 int bit = m_pSrcBuf[bitpos0 / 8] & (1 << (7 - bitpos0 % 8)); | 670 int bit = m_pSrcBuf[bitpos0 / 8] & (1 << (7 - bitpos0 % 8)); |
671 if (bit != 0) { | 671 if (bit != 0) { |
672 m_bByteAlign = FALSE; | 672 m_bByteAlign = false; |
673 } else { | 673 } else { |
674 bitpos0 ++; | 674 bitpos0 ++; |
675 } | 675 } |
676 } | 676 } |
677 if (m_bByteAlign) { | 677 if (m_bByteAlign) { |
678 bitpos = bitpos1; | 678 bitpos = bitpos1; |
679 } | 679 } |
680 } | 680 } |
681 if (m_bBlack) { | 681 if (m_bBlack) { |
682 for (int i = 0; i < m_Pitch; i ++) { | 682 for (int i = 0; i < m_Pitch; i ++) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 }; | 839 }; |
840 static void _AddBitStream(uint8_t* dest_buf, int& dest_bitpos, int data, int bit
len) | 840 static void _AddBitStream(uint8_t* dest_buf, int& dest_bitpos, int data, int bit
len) |
841 { | 841 { |
842 for (int i = bitlen - 1; i >= 0; i --) { | 842 for (int i = bitlen - 1; i >= 0; i --) { |
843 if (data & (1 << i)) { | 843 if (data & (1 << i)) { |
844 dest_buf[dest_bitpos / 8] |= 1 << (7 - dest_bitpos % 8); | 844 dest_buf[dest_bitpos / 8] |= 1 << (7 - dest_bitpos % 8); |
845 } | 845 } |
846 dest_bitpos ++; | 846 dest_bitpos ++; |
847 } | 847 } |
848 } | 848 } |
849 static void _FaxEncodeRun(uint8_t* dest_buf, int& dest_bitpos, int run, FX_BOOL
bWhite) | 849 static void _FaxEncodeRun(uint8_t* dest_buf, int& dest_bitpos, int run, bool bWh
ite) |
850 { | 850 { |
851 while (run >= 2560) { | 851 while (run >= 2560) { |
852 _AddBitStream(dest_buf, dest_bitpos, 0x1f, 12); | 852 _AddBitStream(dest_buf, dest_bitpos, 0x1f, 12); |
853 run -= 2560; | 853 run -= 2560; |
854 } | 854 } |
855 if (run >= 64) { | 855 if (run >= 64) { |
856 int markup = run - run % 64; | 856 int markup = run - run % 64; |
857 const uint8_t* p = bWhite ? WhiteRunMarkup : BlackRunMarkup; | 857 const uint8_t* p = bWhite ? WhiteRunMarkup : BlackRunMarkup; |
858 p += (markup / 64 - 1) * 2; | 858 p += (markup / 64 - 1) * 2; |
859 _AddBitStream(dest_buf, dest_bitpos, *p, p[1]); | 859 _AddBitStream(dest_buf, dest_bitpos, *p, p[1]); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 dest_bitpos %= 8; | 965 dest_bitpos %= 8; |
966 FXSYS_memcpy(m_pRefLine, scan_line, m_Pitch); | 966 FXSYS_memcpy(m_pRefLine, scan_line, m_Pitch); |
967 } | 967 } |
968 if (dest_bitpos) { | 968 if (dest_bitpos) { |
969 m_DestBuf.AppendByte(last_byte); | 969 m_DestBuf.AppendByte(last_byte); |
970 } | 970 } |
971 dest_buf = m_DestBuf.GetBuffer(); | 971 dest_buf = m_DestBuf.GetBuffer(); |
972 dest_size = m_DestBuf.GetSize(); | 972 dest_size = m_DestBuf.GetSize(); |
973 m_DestBuf.DetachBuffer(); | 973 m_DestBuf.DetachBuffer(); |
974 } | 974 } |
975 FX_BOOL»CCodec_FaxModule::Encode(const uint8_t* src_buf, int width, int height,
int pitch, uint8_t*& dest_buf, FX_DWORD& dest_size) | 975 bool» CCodec_FaxModule::Encode(const uint8_t* src_buf, int width, int height,
int pitch, uint8_t*& dest_buf, FX_DWORD& dest_size) |
976 { | 976 { |
977 CCodec_FaxEncoder encoder(src_buf, width, height, pitch); | 977 CCodec_FaxEncoder encoder(src_buf, width, height, pitch); |
978 encoder.Encode(dest_buf, dest_size); | 978 encoder.Encode(dest_buf, dest_size); |
979 return TRUE; | 979 return true; |
980 } | 980 } |
981 ICodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size, int width, int height, | 981 ICodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(const uint8_t* src_buf,
FX_DWORD src_size, int width, int height, |
982 int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, in
t Columns, int Rows) | 982 int K, bool EndOfLine, bool EncodedByteAlign, bool BlackIs1, int Columns
, int Rows) |
983 { | 983 { |
984 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; | 984 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; |
985 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, EncodedByte
Align, BlackIs1, Columns, Rows); | 985 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, EncodedByte
Align, BlackIs1, Columns, Rows); |
986 return pDecoder; | 986 return pDecoder; |
987 } | 987 } |
OLD | NEW |