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

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

Issue 1258093002: FX Bool considered harmful, part 3 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 4 months 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_icc.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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void FPDFAPI_FlateEnd(void* context) 77 void FPDFAPI_FlateEnd(void* context)
78 { 78 {
79 inflateEnd((z_stream*)context); 79 inflateEnd((z_stream*)context);
80 ((z_stream*)context)->zfree(0, context); 80 ((z_stream*)context)->zfree(0, context);
81 } 81 }
82 } // extern "C" 82 } // extern "C"
83 83
84 class CLZWDecoder 84 class CLZWDecoder
85 { 85 {
86 public: 86 public:
87 int Decode(uint8_t* output, FX_DWORD& outlen, const uint8_t* input, FX_DWORD & size, FX_BOOL bEarlyChange); 87 int Decode(uint8_t* output, FX_DWORD& outlen, const uint8_t* input, FX_DWORD & size, bool bEarlyChange);
88 88
89 private: 89 private:
90 void AddCode(FX_DWORD prefix_code, uint8_t append_char); 90 void AddCode(FX_DWORD prefix_code, uint8_t append_char);
91 void DecodeString(FX_DWORD code); 91 void DecodeString(FX_DWORD code);
92 92
93 FX_DWORD m_InPos; 93 FX_DWORD m_InPos;
94 FX_DWORD m_OutPos; 94 FX_DWORD m_OutPos;
95 uint8_t* m_pOutput; 95 uint8_t* m_pOutput;
96 const uint8_t* m_pInput; 96 const uint8_t* m_pInput;
97 FX_BOOL» » m_Early; 97 bool» » m_Early;
98 FX_DWORD m_CodeArray[5021]; 98 FX_DWORD m_CodeArray[5021];
99 FX_DWORD m_nCodes; 99 FX_DWORD m_nCodes;
100 uint8_t m_DecodeStack[4000]; 100 uint8_t m_DecodeStack[4000];
101 FX_DWORD m_StackLen; 101 FX_DWORD m_StackLen;
102 int m_CodeLen; 102 int m_CodeLen;
103 }; 103 };
104 void CLZWDecoder::AddCode(FX_DWORD prefix_code, uint8_t append_char) 104 void CLZWDecoder::AddCode(FX_DWORD prefix_code, uint8_t append_char)
105 { 105 {
106 if (m_nCodes + m_Early == 4094) { 106 if (m_nCodes + m_Early == 4094) {
107 return; 107 return;
(...skipping 19 matching lines...) Expand all
127 return; 127 return;
128 } 128 }
129 m_DecodeStack[m_StackLen++] = (uint8_t)data; 129 m_DecodeStack[m_StackLen++] = (uint8_t)data;
130 code = data >> 16; 130 code = data >> 16;
131 } 131 }
132 if (m_StackLen >= sizeof(m_DecodeStack)) { 132 if (m_StackLen >= sizeof(m_DecodeStack)) {
133 return; 133 return;
134 } 134 }
135 m_DecodeStack[m_StackLen++] = (uint8_t)code; 135 m_DecodeStack[m_StackLen++] = (uint8_t)code;
136 } 136 }
137 int CLZWDecoder::Decode(uint8_t* dest_buf, FX_DWORD& dest_size, const uint8_t* s rc_buf, FX_DWORD& src_size, FX_BOOL bEarlyChange) 137 int CLZWDecoder::Decode(uint8_t* dest_buf, FX_DWORD& dest_size, const uint8_t* s rc_buf, FX_DWORD& src_size, bool bEarlyChange)
138 { 138 {
139 m_CodeLen = 9; 139 m_CodeLen = 9;
140 m_InPos = 0; 140 m_InPos = 0;
141 m_OutPos = 0; 141 m_OutPos = 0;
142 m_pInput = src_buf; 142 m_pInput = src_buf;
143 m_pOutput = dest_buf; 143 m_pOutput = dest_buf;
144 m_Early = bEarlyChange ? 1 : 0; 144 m_Early = bEarlyChange ? 1 : 0;
145 m_nCodes = 0; 145 m_nCodes = 0;
146 FX_DWORD old_code = (FX_DWORD) - 1; 146 FX_DWORD old_code = (FX_DWORD) - 1;
147 uint8_t last_char; 147 uint8_t last_char;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 int pb = FXSYS_abs(p - b); 231 int pb = FXSYS_abs(p - b);
232 int pc = FXSYS_abs(p - c); 232 int pc = FXSYS_abs(p - c);
233 if (pa <= pb && pa <= pc) { 233 if (pa <= pb && pa <= pc) {
234 return (uint8_t)a; 234 return (uint8_t)a;
235 } 235 }
236 if (pb <= pc) { 236 if (pb <= pc) {
237 return (uint8_t)b; 237 return (uint8_t)b;
238 } 238 }
239 return (uint8_t)c; 239 return (uint8_t)c;
240 } 240 }
241 static FX_BOOL PNG_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size, 241 static bool PNG_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size,
242 int predictor, int Colors, 242 int predictor, int Colors,
243 int BitsPerComponent, int Columns) 243 int BitsPerComponent, int Columns)
244 { 244 {
245 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 245 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
246 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 246 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
247 if (row_size <= 0) 247 if (row_size <= 0)
248 return FALSE; 248 return false;
249 const int row_count = (data_size + row_size - 1) / row_size; 249 const int row_count = (data_size + row_size - 1) / row_size;
250 const int last_row_size = data_size % row_size; 250 const int last_row_size = data_size % row_size;
251 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size + 1, row_count); 251 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size + 1, row_count);
252 int byte_cnt = 0; 252 int byte_cnt = 0;
253 uint8_t* pSrcData = data_buf; 253 uint8_t* pSrcData = data_buf;
254 uint8_t* pDestData = dest_buf; 254 uint8_t* pDestData = dest_buf;
255 for (int row = 0; row < row_count; row++) { 255 for (int row = 0; row < row_count; row++) {
256 if (predictor == 10) { 256 if (predictor == 10) {
257 pDestData[0] = 0; 257 pDestData[0] = 0;
258 int move_size = row_size; 258 int move_size = row_size;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 break; 321 break;
322 } 322 }
323 byte_cnt++; 323 byte_cnt++;
324 } 324 }
325 pDestData += (row_size + 1); 325 pDestData += (row_size + 1);
326 pSrcData += row_size; 326 pSrcData += row_size;
327 } 327 }
328 FX_Free(data_buf); 328 FX_Free(data_buf);
329 data_buf = dest_buf; 329 data_buf = dest_buf;
330 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0); 330 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0);
331 return TRUE; 331 return true;
332 } 332 }
333 static void PNG_PredictLine(uint8_t* pDestData, const uint8_t* pSrcData, const u int8_t* pLastLine, 333 static void PNG_PredictLine(uint8_t* pDestData, const uint8_t* pSrcData, const u int8_t* pLastLine,
334 int bpc, int nColors, int nPixels) 334 int bpc, int nColors, int nPixels)
335 { 335 {
336 int row_size = (nPixels * bpc * nColors + 7) / 8; 336 int row_size = (nPixels * bpc * nColors + 7) / 8;
337 int BytesPerPixel = (bpc * nColors + 7) / 8; 337 int BytesPerPixel = (bpc * nColors + 7) / 8;
338 uint8_t tag = pSrcData[0]; 338 uint8_t tag = pSrcData[0];
339 if (tag == 0) { 339 if (tag == 0) {
340 FXSYS_memmove(pDestData, pSrcData + 1, row_size); 340 FXSYS_memmove(pDestData, pSrcData + 1, row_size);
341 return; 341 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 386 }
387 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left); 387 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left);
388 break; 388 break;
389 } 389 }
390 default: 390 default:
391 pDestData[byte] = raw_byte; 391 pDestData[byte] = raw_byte;
392 break; 392 break;
393 } 393 }
394 } 394 }
395 } 395 }
396 static FX_BOOL PNG_Predictor(uint8_t*& data_buf, FX_DWORD& data_size, 396 static bool PNG_Predictor(uint8_t*& data_buf, FX_DWORD& data_size,
397 int Colors, int BitsPerComponent, int Columns) 397 int Colors, int BitsPerComponent, int Columns)
398 { 398 {
399 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 399 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
400 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 400 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
401 if (row_size <= 0) 401 if (row_size <= 0)
402 return FALSE; 402 return false;
403 const int row_count = (data_size + row_size) / (row_size + 1); 403 const int row_count = (data_size + row_size) / (row_size + 1);
404 const int last_row_size = data_size % (row_size + 1); 404 const int last_row_size = data_size % (row_size + 1);
405 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size, row_count); 405 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size, row_count);
406 int byte_cnt = 0; 406 int byte_cnt = 0;
407 uint8_t* pSrcData = data_buf; 407 uint8_t* pSrcData = data_buf;
408 uint8_t* pDestData = dest_buf; 408 uint8_t* pDestData = dest_buf;
409 for (int row = 0; row < row_count; row ++) { 409 for (int row = 0; row < row_count; row ++) {
410 uint8_t tag = pSrcData[0]; 410 uint8_t tag = pSrcData[0];
411 byte_cnt++; 411 byte_cnt++;
412 if (tag == 0) { 412 if (tag == 0) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 break; 472 break;
473 } 473 }
474 byte_cnt++; 474 byte_cnt++;
475 } 475 }
476 pSrcData += row_size + 1; 476 pSrcData += row_size + 1;
477 pDestData += row_size; 477 pDestData += row_size;
478 } 478 }
479 FX_Free(data_buf); 479 FX_Free(data_buf);
480 data_buf = dest_buf; 480 data_buf = dest_buf;
481 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0); 481 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0);
482 return TRUE; 482 return true;
483 } 483 }
484 static void TIFF_PredictorEncodeLine(uint8_t* dest_buf, int row_size, int BitsPe rComponent, int Colors, int Columns) 484 static void TIFF_PredictorEncodeLine(uint8_t* dest_buf, int row_size, int BitsPe rComponent, int Colors, int Columns)
485 { 485 {
486 int BytesPerPixel = BitsPerComponent * Colors / 8; 486 int BytesPerPixel = BitsPerComponent * Colors / 8;
487 if (BitsPerComponent < 8) { 487 if (BitsPerComponent < 8) {
488 uint8_t mask = 0x01; 488 uint8_t mask = 0x01;
489 if (BitsPerComponent == 2) { 489 if (BitsPerComponent == 2) {
490 mask = 0x03; 490 mask = 0x03;
491 } else if (BitsPerComponent == 4) { 491 } else if (BitsPerComponent == 4) {
492 mask = 0x0F; 492 mask = 0x0F;
(...skipping 18 matching lines...) Expand all
511 } 511 }
512 } else { 512 } else {
513 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) { 513 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) {
514 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1]; 514 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1];
515 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1]; 515 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1];
516 dest_buf[i] = pixel >> 8; 516 dest_buf[i] = pixel >> 8;
517 dest_buf[i + 1] = (uint8_t)pixel; 517 dest_buf[i + 1] = (uint8_t)pixel;
518 } 518 }
519 } 519 }
520 } 520 }
521 static FX_BOOL TIFF_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size, 521 static bool TIFF_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size,
522 int Colors, int BitsPerComponent, int Column s) 522 int Colors, int BitsPerComponent, int Column s)
523 { 523 {
524 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 524 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
525 if (row_size == 0) 525 if (row_size == 0)
526 return FALSE; 526 return false;
527 const int row_count = (data_size + row_size - 1) / row_size; 527 const int row_count = (data_size + row_size - 1) / row_size;
528 const int last_row_size = data_size % row_size; 528 const int last_row_size = data_size % row_size;
529 for (int row = 0; row < row_count; row++) { 529 for (int row = 0; row < row_count; row++) {
530 uint8_t* scan_line = data_buf + row * row_size; 530 uint8_t* scan_line = data_buf + row * row_size;
531 if ((row + 1) * row_size > (int)data_size) { 531 if ((row + 1) * row_size > (int)data_size) {
532 row_size = last_row_size; 532 row_size = last_row_size;
533 } 533 }
534 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns); 534 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns);
535 } 535 }
536 return TRUE; 536 return true;
537 } 537 }
538 static void TIFF_PredictLine(uint8_t* dest_buf, int row_size, int BitsPerCompone nt, int Colors, int Columns) 538 static void TIFF_PredictLine(uint8_t* dest_buf, int row_size, int BitsPerCompone nt, int Colors, int Columns)
539 { 539 {
540 if (BitsPerComponent == 1) { 540 if (BitsPerComponent == 1) {
541 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ; 541 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ;
542 int index_pre = 0; 542 int index_pre = 0;
543 int col_pre = 0; 543 int col_pre = 0;
544 for(int i = 1; i < row_bits; i ++) { 544 for(int i = 1; i < row_bits; i ++) {
545 int col = i % 8; 545 int col = i % 8;
546 int index = i / 8; 546 int index = i / 8;
(...skipping 14 matching lines...) Expand all
561 pixel += (dest_buf[i] << 8) | dest_buf[i + 1]; 561 pixel += (dest_buf[i] << 8) | dest_buf[i + 1];
562 dest_buf[i] = pixel >> 8; 562 dest_buf[i] = pixel >> 8;
563 dest_buf[i + 1] = (uint8_t)pixel; 563 dest_buf[i + 1] = (uint8_t)pixel;
564 } 564 }
565 } else { 565 } else {
566 for (int i = BytesPerPixel; i < row_size; i ++) { 566 for (int i = BytesPerPixel; i < row_size; i ++) {
567 dest_buf[i] += dest_buf[i - BytesPerPixel]; 567 dest_buf[i] += dest_buf[i - BytesPerPixel];
568 } 568 }
569 } 569 }
570 } 570 }
571 static FX_BOOL TIFF_Predictor(uint8_t*& data_buf, FX_DWORD& data_size, 571 static bool TIFF_Predictor(uint8_t*& data_buf, FX_DWORD& data_size,
572 int Colors, int BitsPerComponent, int Columns) 572 int Colors, int BitsPerComponent, int Columns)
573 { 573 {
574 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 574 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
575 if (row_size == 0) 575 if (row_size == 0)
576 return FALSE; 576 return false;
577 const int row_count = (data_size + row_size - 1) / row_size; 577 const int row_count = (data_size + row_size - 1) / row_size;
578 const int last_row_size = data_size % row_size; 578 const int last_row_size = data_size % row_size;
579 for (int row = 0; row < row_count; row ++) { 579 for (int row = 0; row < row_count; row ++) {
580 uint8_t* scan_line = data_buf + row * row_size; 580 uint8_t* scan_line = data_buf + row * row_size;
581 if ((row + 1) * row_size > (int)data_size) { 581 if ((row + 1) * row_size > (int)data_size) {
582 row_size = last_row_size; 582 row_size = last_row_size;
583 } 583 }
584 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ; 584 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ;
585 } 585 }
586 return TRUE; 586 return true;
587 } 587 }
588 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder 588 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder
589 { 589 {
590 public: 590 public:
591 CCodec_FlateScanlineDecoder(); 591 CCodec_FlateScanlineDecoder();
592 ~CCodec_FlateScanlineDecoder(); 592 ~CCodec_FlateScanlineDecoder();
593 void Create(const uint8_t* src_buf, FX_DWORD src_size, int width, int height , int nComps, int bpc, 593 void Create(const uint8_t* src_buf, FX_DWORD src_size, int width, int height , int nComps, int bpc,
594 int predictor, int Colors, int BitsPerComponent, int Columns); 594 int predictor, int Colors, int BitsPerComponent, int Columns);
595 virtual void Destroy() 595 virtual void Destroy()
596 { 596 {
597 delete this; 597 delete this;
598 } 598 }
599 virtual void v_DownScale(int dest_width, int dest_height) {} 599 virtual void v_DownScale(int dest_width, int dest_height) {}
600 virtual FX_BOOL» » v_Rewind(); 600 virtual bool» » v_Rewind();
601 virtual uint8_t* v_GetNextLine(); 601 virtual uint8_t* v_GetNextLine();
602 virtual FX_DWORD GetSrcOffset(); 602 virtual FX_DWORD GetSrcOffset();
603 void* m_pFlate; 603 void* m_pFlate;
604 const uint8_t* m_SrcBuf; 604 const uint8_t* m_SrcBuf;
605 FX_DWORD m_SrcSize; 605 FX_DWORD m_SrcSize;
606 uint8_t* m_pScanline; 606 uint8_t* m_pScanline;
607 uint8_t* m_pLastLine; 607 uint8_t* m_pLastLine;
608 uint8_t* m_pPredictBuffer; 608 uint8_t* m_pPredictBuffer;
609 uint8_t* m_pPredictRaw; 609 uint8_t* m_pPredictRaw;
610 int m_Predictor; 610 int m_Predictor;
(...skipping 28 matching lines...) Expand all
639 } 639 }
640 void CCodec_FlateScanlineDecoder::Create(const uint8_t* src_buf, FX_DWORD src_si ze, int width, int height, 640 void CCodec_FlateScanlineDecoder::Create(const uint8_t* src_buf, FX_DWORD src_si ze, int width, int height,
641 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns) 641 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns)
642 { 642 {
643 m_SrcBuf = src_buf; 643 m_SrcBuf = src_buf;
644 m_SrcSize = src_size; 644 m_SrcSize = src_size;
645 m_OutputWidth = m_OrigWidth = width; 645 m_OutputWidth = m_OrigWidth = width;
646 m_OutputHeight = m_OrigHeight = height; 646 m_OutputHeight = m_OrigHeight = height;
647 m_nComps = nComps; 647 m_nComps = nComps;
648 m_bpc = bpc; 648 m_bpc = bpc;
649 m_bColorTransformed = FALSE; 649 m_bColorTransformed = false;
650 m_Pitch = (width * nComps * bpc + 7) / 8; 650 m_Pitch = (width * nComps * bpc + 7) / 8;
651 m_pScanline = FX_Alloc(uint8_t, m_Pitch); 651 m_pScanline = FX_Alloc(uint8_t, m_Pitch);
652 m_Predictor = 0; 652 m_Predictor = 0;
653 if (predictor) { 653 if (predictor) {
654 if (predictor >= 10) { 654 if (predictor >= 10) {
655 m_Predictor = 2; 655 m_Predictor = 2;
656 } else if (predictor == 2) { 656 } else if (predictor == 2) {
657 m_Predictor = 1; 657 m_Predictor = 1;
658 } 658 }
659 if (m_Predictor) { 659 if (m_Predictor) {
660 if (BitsPerComponent * Colors * Columns == 0) { 660 if (BitsPerComponent * Colors * Columns == 0) {
661 BitsPerComponent = m_bpc; 661 BitsPerComponent = m_bpc;
662 Colors = m_nComps; 662 Colors = m_nComps;
663 Columns = m_OrigWidth; 663 Columns = m_OrigWidth;
664 } 664 }
665 m_Colors = Colors; 665 m_Colors = Colors;
666 m_BitsPerComponent = BitsPerComponent; 666 m_BitsPerComponent = BitsPerComponent;
667 m_Columns = Columns; 667 m_Columns = Columns;
668 m_PredictPitch = (m_BitsPerComponent * m_Colors * m_Columns + 7) / 8 ; 668 m_PredictPitch = (m_BitsPerComponent * m_Colors * m_Columns + 7) / 8 ;
669 m_pLastLine = FX_Alloc(uint8_t, m_PredictPitch); 669 m_pLastLine = FX_Alloc(uint8_t, m_PredictPitch);
670 m_pPredictRaw = FX_Alloc(uint8_t, m_PredictPitch + 1); 670 m_pPredictRaw = FX_Alloc(uint8_t, m_PredictPitch + 1);
671 m_pPredictBuffer = FX_Alloc(uint8_t, m_PredictPitch); 671 m_pPredictBuffer = FX_Alloc(uint8_t, m_PredictPitch);
672 } 672 }
673 } 673 }
674 } 674 }
675 FX_BOOL CCodec_FlateScanlineDecoder::v_Rewind() 675 bool CCodec_FlateScanlineDecoder::v_Rewind()
676 { 676 {
677 if (m_pFlate) { 677 if (m_pFlate) {
678 FPDFAPI_FlateEnd(m_pFlate); 678 FPDFAPI_FlateEnd(m_pFlate);
679 } 679 }
680 m_pFlate = FPDFAPI_FlateInit(my_alloc_func, my_free_func); 680 m_pFlate = FPDFAPI_FlateInit(my_alloc_func, my_free_func);
681 if (m_pFlate == NULL) { 681 if (m_pFlate == NULL) {
682 return FALSE; 682 return false;
683 } 683 }
684 FPDFAPI_FlateInput(m_pFlate, m_SrcBuf, m_SrcSize); 684 FPDFAPI_FlateInput(m_pFlate, m_SrcBuf, m_SrcSize);
685 m_LeftOver = 0; 685 m_LeftOver = 0;
686 return TRUE; 686 return true;
687 } 687 }
688 uint8_t* CCodec_FlateScanlineDecoder::v_GetNextLine() 688 uint8_t* CCodec_FlateScanlineDecoder::v_GetNextLine()
689 { 689 {
690 if (m_Predictor) { 690 if (m_Predictor) {
691 if (m_Pitch == m_PredictPitch) { 691 if (m_Pitch == m_PredictPitch) {
692 if (m_Predictor == 2) { 692 if (m_Predictor == 2) {
693 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1) ; 693 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1) ;
694 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine, m_BitsP erComponent, m_Colors, m_Columns); 694 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine, m_BitsP erComponent, m_Colors, m_Columns);
695 FXSYS_memcpy(m_pLastLine, m_pScanline, m_PredictPitch); 695 FXSYS_memcpy(m_pLastLine, m_pScanline, m_PredictPitch);
696 } else { 696 } else {
(...skipping 28 matching lines...) Expand all
725 } 725 }
726 return m_pScanline; 726 return m_pScanline;
727 } 727 }
728 FX_DWORD CCodec_FlateScanlineDecoder::GetSrcOffset() 728 FX_DWORD CCodec_FlateScanlineDecoder::GetSrcOffset()
729 { 729 {
730 return FPDFAPI_FlateGetTotalIn(m_pFlate); 730 return FPDFAPI_FlateGetTotalIn(m_pFlate);
731 } 731 }
732 static void FlateUncompress(const uint8_t* src_buf, FX_DWORD src_size, FX_DWORD orig_size, 732 static void FlateUncompress(const uint8_t* src_buf, FX_DWORD src_size, FX_DWORD orig_size,
733 uint8_t*& dest_buf, FX_DWORD& dest_size, FX_DWORD& o ffset) 733 uint8_t*& dest_buf, FX_DWORD& dest_size, FX_DWORD& o ffset)
734 { 734 {
735 const FX_BOOL useOldImpl = src_size < 10240; 735 const bool useOldImpl = src_size < 10240;
736 FX_DWORD guess_size = orig_size ? orig_size : src_size * 2; 736 FX_DWORD guess_size = orig_size ? orig_size : src_size * 2;
737 FX_DWORD alloc_step = orig_size ? 10240 : (src_size < 10240 ? 10240 : src_si ze); 737 FX_DWORD alloc_step = orig_size ? 10240 : (src_size < 10240 ? 10240 : src_si ze);
738 static const FX_DWORD kMaxInitialAllocSize = 10000000; 738 static const FX_DWORD kMaxInitialAllocSize = 10000000;
739 if (guess_size > kMaxInitialAllocSize) { 739 if (guess_size > kMaxInitialAllocSize) {
740 guess_size = kMaxInitialAllocSize; 740 guess_size = kMaxInitialAllocSize;
741 alloc_step = kMaxInitialAllocSize; 741 alloc_step = kMaxInitialAllocSize;
742 } 742 }
743 FX_DWORD buf_size = guess_size; 743 FX_DWORD buf_size = guess_size;
744 FX_DWORD last_buf_size = buf_size; 744 FX_DWORD last_buf_size = buf_size;
745 void* context = nullptr; 745 void* context = nullptr;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 dest_size = 0; 832 dest_size = 0;
833 return; 833 return;
834 } 834 }
835 ICodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder(const uint8_t* src_buf , FX_DWORD src_size, int width, int height, 835 ICodec_ScanlineDecoder* CCodec_FlateModule::CreateDecoder(const uint8_t* src_buf , FX_DWORD src_size, int width, int height,
836 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns) 836 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns)
837 { 837 {
838 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder; 838 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder;
839 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns); 839 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns);
840 return pDecoder; 840 return pDecoder;
841 } 841 }
842 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_b uf, FX_DWORD src_size, FX_BOOL bEarlyChange, 842 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(bool bLZW, const uint8_t* src_buf, FX_DWORD src_size, bool bEarlyChange,
843 int predictor, int Colors, int BitsPerComponent, int Columns, 843 int predictor, int Colors, int BitsPerComponent, int Columns,
844 FX_DWORD estimated_size, uint8_t*& dest_buf, FX_DWORD& dest_size) 844 FX_DWORD estimated_size, uint8_t*& dest_buf, FX_DWORD& dest_size)
845 { 845 {
846 dest_buf = NULL; 846 dest_buf = NULL;
847 FX_DWORD offset = 0; 847 FX_DWORD offset = 0;
848 int predictor_type = 0; 848 int predictor_type = 0;
849 if (predictor) { 849 if (predictor) {
850 if (predictor >= 10) { 850 if (predictor >= 10) {
851 predictor_type = 2; 851 predictor_type = 2;
852 } else if (predictor == 2) { 852 } else if (predictor == 2) {
(...skipping 16 matching lines...) Expand all
869 dest_buf = FX_Alloc( uint8_t, dest_size + 1); 869 dest_buf = FX_Alloc( uint8_t, dest_size + 1);
870 dest_buf[dest_size] = '\0'; 870 dest_buf[dest_size] = '\0';
871 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange); 871 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange);
872 } 872 }
873 } else { 873 } else {
874 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, offset); 874 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, offset);
875 } 875 }
876 if (predictor_type == 0) { 876 if (predictor_type == 0) {
877 return offset; 877 return offset;
878 } 878 }
879 FX_BOOL ret = TRUE; 879 bool ret = true;
880 if (predictor_type == 2) { 880 if (predictor_type == 2) {
881 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, 881 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
882 Columns); 882 Columns);
883 } else if (predictor_type == 1) { 883 } else if (predictor_type == 1) {
884 ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, 884 ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
885 Columns); 885 Columns);
886 } 886 }
887 return ret ? offset : -1; 887 return ret ? offset : -1;
888 } 888 }
889 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, 889 bool CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size,
890 int predictor, int Colors, int BitsPerCompone nt, int Columns, 890 int predictor, int Colors, int BitsPerCompone nt, int Columns,
891 uint8_t*& dest_buf, FX_DWORD& dest_size) 891 uint8_t*& dest_buf, FX_DWORD& dest_size)
892 { 892 {
893 if (predictor != 2 && predictor < 10) { 893 if (predictor != 2 && predictor < 10) {
894 return Encode(src_buf, src_size, dest_buf, dest_size); 894 return Encode(src_buf, src_size, dest_buf, dest_size);
895 } 895 }
896 uint8_t* pSrcBuf = NULL; 896 uint8_t* pSrcBuf = NULL;
897 pSrcBuf = FX_Alloc(uint8_t, src_size); 897 pSrcBuf = FX_Alloc(uint8_t, src_size);
898 FXSYS_memcpy(pSrcBuf, src_buf, src_size); 898 FXSYS_memcpy(pSrcBuf, src_buf, src_size);
899 FX_BOOL ret = TRUE; 899 bool ret = true;
900 if (predictor == 2) { 900 if (predictor == 2) {
901 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent, 901 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent,
902 Columns); 902 Columns);
903 } else if (predictor >= 10) { 903 } else if (predictor >= 10) {
904 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors, 904 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors,
905 BitsPerComponent, Columns); 905 BitsPerComponent, Columns);
906 } 906 }
907 if (ret) 907 if (ret)
908 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); 908 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size);
909 FX_Free(pSrcBuf); 909 FX_Free(pSrcBuf);
910 return ret; 910 return ret;
911 } 911 }
912 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, ui nt8_t*& dest_buf, FX_DWORD& dest_size) 912 bool CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, uint8 _t*& dest_buf, FX_DWORD& dest_size)
913 { 913 {
914 dest_size = src_size + src_size / 1000 + 12; 914 dest_size = src_size + src_size / 1000 + 12;
915 dest_buf = FX_Alloc( uint8_t, dest_size); 915 dest_buf = FX_Alloc( uint8_t, dest_size);
916 unsigned long temp_size = dest_size; 916 unsigned long temp_size = dest_size;
917 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); 917 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size);
918 dest_size = (FX_DWORD)temp_size; 918 dest_size = (FX_DWORD)temp_size;
919 return TRUE; 919 return true;
920 } 920 }
OLDNEW
« no previous file with comments | « core/src/fxcodec/codec/fx_codec_fax.cpp ('k') | core/src/fxcodec/codec/fx_codec_icc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698