Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: core/src/fxcodec/codec/fx_codec_flate.cpp

Issue 1473143003: Merge to M47: Change |CCodec_ScanlineDecoder::m_Pitch| to FX_DWORD (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@2526
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_fax.cpp ('k') | core/src/fxcodec/codec/fx_codec_jpeg.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../../../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../../../third_party/zlib_v128/zlib.h" 8 #include "../../../../third_party/zlib_v128/zlib.h"
9 #include "../../../include/fxcodec/fx_codec.h" 9 #include "../../../include/fxcodec/fx_codec.h"
10 #include "../../../include/fxcodec/fx_codec_flate.h" 10 #include "../../../include/fxcodec/fx_codec_flate.h"
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 if ((row + 1) * row_size > (int)data_size) { 551 if ((row + 1) * row_size > (int)data_size) {
552 row_size = last_row_size; 552 row_size = last_row_size;
553 } 553 }
554 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, 554 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors,
555 Columns); 555 Columns);
556 } 556 }
557 return TRUE; 557 return TRUE;
558 } 558 }
559 559
560 void TIFF_PredictLine(uint8_t* dest_buf, 560 void TIFF_PredictLine(uint8_t* dest_buf,
561 int row_size, 561 FX_DWORD row_size,
562 int BitsPerComponent, 562 int BitsPerComponent,
563 int Colors, 563 int Colors,
564 int Columns) { 564 int Columns) {
565 if (BitsPerComponent == 1) { 565 if (BitsPerComponent == 1) {
566 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8); 566 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8);
567 int index_pre = 0; 567 int index_pre = 0;
568 int col_pre = 0; 568 int col_pre = 0;
569 for (int i = 1; i < row_bits; i++) { 569 for (int i = 1; i < row_bits; i++) {
570 int col = i % 8; 570 int col = i % 8;
571 int index = i / 8; 571 int index = i / 8;
572 if (((dest_buf[index] >> (7 - col)) & 1) ^ 572 if (((dest_buf[index] >> (7 - col)) & 1) ^
573 ((dest_buf[index_pre] >> (7 - col_pre)) & 1)) { 573 ((dest_buf[index_pre] >> (7 - col_pre)) & 1)) {
574 dest_buf[index] |= 1 << (7 - col); 574 dest_buf[index] |= 1 << (7 - col);
575 } else { 575 } else {
576 dest_buf[index] &= ~(1 << (7 - col)); 576 dest_buf[index] &= ~(1 << (7 - col));
577 } 577 }
578 index_pre = index; 578 index_pre = index;
579 col_pre = col; 579 col_pre = col;
580 } 580 }
581 return; 581 return;
582 } 582 }
583 int BytesPerPixel = BitsPerComponent * Colors / 8; 583 int BytesPerPixel = BitsPerComponent * Colors / 8;
584 if (BitsPerComponent == 16) { 584 if (BitsPerComponent == 16) {
585 for (int i = BytesPerPixel; i < row_size; i += 2) { 585 for (FX_DWORD i = BytesPerPixel; i < row_size; i += 2) {
586 FX_WORD pixel = 586 FX_WORD pixel =
587 (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerPixel + 1]; 587 (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerPixel + 1];
588 pixel += (dest_buf[i] << 8) | dest_buf[i + 1]; 588 pixel += (dest_buf[i] << 8) | dest_buf[i + 1];
589 dest_buf[i] = pixel >> 8; 589 dest_buf[i] = pixel >> 8;
590 dest_buf[i + 1] = (uint8_t)pixel; 590 dest_buf[i + 1] = (uint8_t)pixel;
591 } 591 }
592 } else { 592 } else {
593 for (int i = BytesPerPixel; i < row_size; i++) { 593 for (FX_DWORD i = BytesPerPixel; i < row_size; i++) {
594 dest_buf[i] += dest_buf[i - BytesPerPixel]; 594 dest_buf[i] += dest_buf[i - BytesPerPixel];
595 } 595 }
596 } 596 }
597 } 597 }
598 598
599 FX_BOOL TIFF_Predictor(uint8_t*& data_buf, 599 FX_BOOL TIFF_Predictor(uint8_t*& data_buf,
600 FX_DWORD& data_size, 600 FX_DWORD& data_size,
601 int Colors, 601 int Colors,
602 int BitsPerComponent, 602 int BitsPerComponent,
603 int Columns) { 603 int Columns) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 FX_DWORD GetSrcOffset() override; 754 FX_DWORD GetSrcOffset() override;
755 755
756 void* m_pFlate; 756 void* m_pFlate;
757 const uint8_t* m_SrcBuf; 757 const uint8_t* m_SrcBuf;
758 FX_DWORD m_SrcSize; 758 FX_DWORD m_SrcSize;
759 uint8_t* m_pScanline; 759 uint8_t* m_pScanline;
760 uint8_t* m_pLastLine; 760 uint8_t* m_pLastLine;
761 uint8_t* m_pPredictBuffer; 761 uint8_t* m_pPredictBuffer;
762 uint8_t* m_pPredictRaw; 762 uint8_t* m_pPredictRaw;
763 int m_Predictor; 763 int m_Predictor;
764 int m_Colors, m_BitsPerComponent, m_Columns, m_PredictPitch, m_LeftOver; 764 int m_Colors;
765 int m_BitsPerComponent;
766 int m_Columns;
767 FX_DWORD m_PredictPitch;
768 size_t m_LeftOver;
765 }; 769 };
766 770
767 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() { 771 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() {
768 m_pFlate = NULL; 772 m_pFlate = NULL;
769 m_pScanline = NULL; 773 m_pScanline = NULL;
770 m_pLastLine = NULL; 774 m_pLastLine = NULL;
771 m_pPredictBuffer = NULL; 775 m_pPredictBuffer = NULL;
772 m_pPredictRaw = NULL; 776 m_pPredictRaw = NULL;
773 m_LeftOver = 0; 777 m_LeftOver = 0;
774 } 778 }
(...skipping 16 matching lines...) Expand all
791 int Colors, 795 int Colors,
792 int BitsPerComponent, 796 int BitsPerComponent,
793 int Columns) { 797 int Columns) {
794 m_SrcBuf = src_buf; 798 m_SrcBuf = src_buf;
795 m_SrcSize = src_size; 799 m_SrcSize = src_size;
796 m_OutputWidth = m_OrigWidth = width; 800 m_OutputWidth = m_OrigWidth = width;
797 m_OutputHeight = m_OrigHeight = height; 801 m_OutputHeight = m_OrigHeight = height;
798 m_nComps = nComps; 802 m_nComps = nComps;
799 m_bpc = bpc; 803 m_bpc = bpc;
800 m_bColorTransformed = FALSE; 804 m_bColorTransformed = FALSE;
801 m_Pitch = (width * nComps * bpc + 7) / 8; 805 m_Pitch = (static_cast<FX_DWORD>(width) * nComps * bpc + 7) / 8;
802 m_pScanline = FX_Alloc(uint8_t, m_Pitch); 806 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
803 m_Predictor = 0; 807 m_Predictor = 0;
804 if (predictor) { 808 if (predictor) {
805 if (predictor >= 10) { 809 if (predictor >= 10) {
806 m_Predictor = 2; 810 m_Predictor = 2;
807 } else if (predictor == 2) { 811 } else if (predictor == 2) {
808 m_Predictor = 1; 812 m_Predictor = 1;
809 } 813 }
810 if (m_Predictor) { 814 if (m_Predictor) {
811 if (BitsPerComponent * Colors * Columns == 0) { 815 if (BitsPerComponent * Colors * Columns == 0) {
812 BitsPerComponent = m_bpc; 816 BitsPerComponent = m_bpc;
813 Colors = m_nComps; 817 Colors = m_nComps;
814 Columns = m_OrigWidth; 818 Columns = m_OrigWidth;
815 } 819 }
816 m_Colors = Colors; 820 m_Colors = Colors;
817 m_BitsPerComponent = BitsPerComponent; 821 m_BitsPerComponent = BitsPerComponent;
818 m_Columns = Columns; 822 m_Columns = Columns;
819 m_PredictPitch = (m_BitsPerComponent * m_Colors * m_Columns + 7) / 8; 823 m_PredictPitch =
824 (static_cast<FX_DWORD>(m_BitsPerComponent) * m_Colors * m_Columns +
825 7) /
826 8;
820 m_pLastLine = FX_Alloc(uint8_t, m_PredictPitch); 827 m_pLastLine = FX_Alloc(uint8_t, m_PredictPitch);
821 m_pPredictRaw = FX_Alloc(uint8_t, m_PredictPitch + 1); 828 m_pPredictRaw = FX_Alloc(uint8_t, m_PredictPitch + 1);
822 m_pPredictBuffer = FX_Alloc(uint8_t, m_PredictPitch); 829 m_pPredictBuffer = FX_Alloc(uint8_t, m_PredictPitch);
823 } 830 }
824 } 831 }
825 } 832 }
826 FX_BOOL CCodec_FlateScanlineDecoder::v_Rewind() { 833 FX_BOOL CCodec_FlateScanlineDecoder::v_Rewind() {
827 if (m_pFlate) { 834 if (m_pFlate) {
828 FPDFAPI_FlateEnd(m_pFlate); 835 FPDFAPI_FlateEnd(m_pFlate);
829 } 836 }
(...skipping 12 matching lines...) Expand all
842 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1); 849 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1);
843 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine, 850 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine,
844 m_BitsPerComponent, m_Colors, m_Columns); 851 m_BitsPerComponent, m_Colors, m_Columns);
845 FXSYS_memcpy(m_pLastLine, m_pScanline, m_PredictPitch); 852 FXSYS_memcpy(m_pLastLine, m_pScanline, m_PredictPitch);
846 } else { 853 } else {
847 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch); 854 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch);
848 TIFF_PredictLine(m_pScanline, m_PredictPitch, m_bpc, m_nComps, 855 TIFF_PredictLine(m_pScanline, m_PredictPitch, m_bpc, m_nComps,
849 m_OutputWidth); 856 m_OutputWidth);
850 } 857 }
851 } else { 858 } else {
852 int bytes_to_go = m_Pitch; 859 size_t bytes_to_go = m_Pitch;
853 int read_leftover = m_LeftOver > bytes_to_go ? bytes_to_go : m_LeftOver; 860 size_t read_leftover =
861 m_LeftOver > bytes_to_go ? bytes_to_go : m_LeftOver;
854 if (read_leftover) { 862 if (read_leftover) {
855 FXSYS_memcpy(m_pScanline, 863 FXSYS_memcpy(m_pScanline,
856 m_pPredictBuffer + m_PredictPitch - m_LeftOver, 864 m_pPredictBuffer + m_PredictPitch - m_LeftOver,
857 read_leftover); 865 read_leftover);
858 m_LeftOver -= read_leftover; 866 m_LeftOver -= read_leftover;
859 bytes_to_go -= read_leftover; 867 bytes_to_go -= read_leftover;
860 } 868 }
861 while (bytes_to_go) { 869 while (bytes_to_go) {
862 if (m_Predictor == 2) { 870 if (m_Predictor == 2) {
863 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1); 871 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1);
864 PNG_PredictLine(m_pPredictBuffer, m_pPredictRaw, m_pLastLine, 872 PNG_PredictLine(m_pPredictBuffer, m_pPredictRaw, m_pLastLine,
865 m_BitsPerComponent, m_Colors, m_Columns); 873 m_BitsPerComponent, m_Colors, m_Columns);
866 FXSYS_memcpy(m_pLastLine, m_pPredictBuffer, m_PredictPitch); 874 FXSYS_memcpy(m_pLastLine, m_pPredictBuffer, m_PredictPitch);
867 } else { 875 } else {
868 FPDFAPI_FlateOutput(m_pFlate, m_pPredictBuffer, m_PredictPitch); 876 FPDFAPI_FlateOutput(m_pFlate, m_pPredictBuffer, m_PredictPitch);
869 TIFF_PredictLine(m_pPredictBuffer, m_PredictPitch, m_BitsPerComponent, 877 TIFF_PredictLine(m_pPredictBuffer, m_PredictPitch, m_BitsPerComponent,
870 m_Colors, m_Columns); 878 m_Colors, m_Columns);
871 } 879 }
872 int read_bytes = 880 size_t read_bytes =
873 m_PredictPitch > bytes_to_go ? bytes_to_go : m_PredictPitch; 881 m_PredictPitch > bytes_to_go ? bytes_to_go : m_PredictPitch;
874 FXSYS_memcpy(m_pScanline + m_Pitch - bytes_to_go, m_pPredictBuffer, 882 FXSYS_memcpy(m_pScanline + m_Pitch - bytes_to_go, m_pPredictBuffer,
875 read_bytes); 883 read_bytes);
876 m_LeftOver += m_PredictPitch - read_bytes; 884 m_LeftOver += m_PredictPitch - read_bytes;
877 bytes_to_go -= read_bytes; 885 bytes_to_go -= read_bytes;
878 } 886 }
879 } 887 }
880 } else { 888 } else {
881 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch); 889 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch);
882 } 890 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 FX_DWORD src_size, 994 FX_DWORD src_size,
987 uint8_t*& dest_buf, 995 uint8_t*& dest_buf,
988 FX_DWORD& dest_size) { 996 FX_DWORD& dest_size) {
989 dest_size = src_size + src_size / 1000 + 12; 997 dest_size = src_size + src_size / 1000 + 12;
990 dest_buf = FX_Alloc(uint8_t, dest_size); 998 dest_buf = FX_Alloc(uint8_t, dest_size);
991 unsigned long temp_size = dest_size; 999 unsigned long temp_size = dest_size;
992 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); 1000 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size);
993 dest_size = (FX_DWORD)temp_size; 1001 dest_size = (FX_DWORD)temp_size;
994 return TRUE; 1002 return TRUE;
995 } 1003 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_fax.cpp ('k') | core/src/fxcodec/codec/fx_codec_jpeg.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698