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 <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "core/fxcodec/codec/codec_int.h" | 11 #include "core/fxcodec/codec/codec_int.h" |
11 #include "core/fxcodec/fx_codec.h" | 12 #include "core/fxcodec/fx_codec.h" |
| 13 #include "third_party/base/ptr_util.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 const uint8_t OneLeadPos[256] = { | 17 const uint8_t OneLeadPos[256] = { |
16 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, | 18 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, |
17 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 19 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
18 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, | 20 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, |
19 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 21 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
20 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 22 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
21 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | 23 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 int bitpos = *pbitpos; | 575 int bitpos = *pbitpos; |
574 for (int iRow = 0; iRow < height; iRow++) { | 576 for (int iRow = 0; iRow < height; iRow++) { |
575 uint8_t* line_buf = dest_buf + iRow * pitch; | 577 uint8_t* line_buf = dest_buf + iRow * pitch; |
576 FXSYS_memset(line_buf, 0xff, pitch); | 578 FXSYS_memset(line_buf, 0xff, pitch); |
577 FaxG4GetRow(src_buf, src_size << 3, &bitpos, line_buf, ref_buf, width); | 579 FaxG4GetRow(src_buf, src_size << 3, &bitpos, line_buf, ref_buf, width); |
578 FXSYS_memcpy(ref_buf.data(), line_buf, pitch); | 580 FXSYS_memcpy(ref_buf.data(), line_buf, pitch); |
579 } | 581 } |
580 *pbitpos = bitpos; | 582 *pbitpos = bitpos; |
581 } | 583 } |
582 | 584 |
583 CCodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(const uint8_t* src_buf, | 585 std::unique_ptr<CCodec_ScanlineDecoder> CCodec_FaxModule::CreateDecoder( |
584 uint32_t src_size, | 586 const uint8_t* src_buf, |
585 int width, | 587 uint32_t src_size, |
586 int height, | 588 int width, |
587 int K, | 589 int height, |
588 bool EndOfLine, | 590 int K, |
589 bool EncodedByteAlign, | 591 bool EndOfLine, |
590 bool BlackIs1, | 592 bool EncodedByteAlign, |
591 int Columns, | 593 bool BlackIs1, |
592 int Rows) { | 594 int Columns, |
| 595 int Rows) { |
593 int actual_width = Columns ? Columns : width; | 596 int actual_width = Columns ? Columns : width; |
594 int actual_height = Rows ? Rows : height; | 597 int actual_height = Rows ? Rows : height; |
595 | 598 |
596 // Reject invalid values. | 599 // Reject invalid values. |
597 if (actual_width <= 0 || actual_height <= 0) | 600 if (actual_width <= 0 || actual_height <= 0) |
598 return nullptr; | 601 return nullptr; |
599 | 602 |
600 // Reject unreasonable large input. | 603 // Reject unreasonable large input. |
601 if (actual_width > kMaxImageDimension || actual_height > kMaxImageDimension) | 604 if (actual_width > kMaxImageDimension || actual_height > kMaxImageDimension) |
602 return nullptr; | 605 return nullptr; |
603 | 606 |
604 uint32_t pitch = (static_cast<uint32_t>(actual_width) + 31) / 32 * 4; | 607 uint32_t pitch = (static_cast<uint32_t>(actual_width) + 31) / 32 * 4; |
605 return new CCodec_FaxDecoder(src_buf, src_size, actual_width, actual_height, | 608 return pdfium::MakeUnique<CCodec_FaxDecoder>( |
606 pitch, K, EndOfLine, EncodedByteAlign, BlackIs1); | 609 src_buf, src_size, actual_width, actual_height, pitch, K, EndOfLine, |
| 610 EncodedByteAlign, BlackIs1); |
607 } | 611 } |
OLD | NEW |