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

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

Issue 1171733003: Remove typdefs for pointer types in fx_system.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual fixes. Created 5 years, 6 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 "../../../include/fxcodec/fx_codec.h" 8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "../../fx_zlib.h" 9 #include "../../fx_zlib.h"
10 #include "codec_int.h" 10 #include "codec_int.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 ((z_stream*)context)->zfree(0, context); 72 ((z_stream*)context)->zfree(0, context);
73 } 73 }
74 void FPDFAPI_FlateCompress(unsigned char* dest_buf, unsigned long* dest_size , const unsigned char* src_buf, unsigned long src_size) 74 void FPDFAPI_FlateCompress(unsigned char* dest_buf, unsigned long* dest_size , const unsigned char* src_buf, unsigned long src_size)
75 { 75 {
76 compress(dest_buf, dest_size, src_buf, src_size); 76 compress(dest_buf, dest_size, src_buf, src_size);
77 } 77 }
78 } 78 }
79 class CLZWDecoder 79 class CLZWDecoder
80 { 80 {
81 public: 81 public:
82 FX_BOOL Decode(FX_LPBYTE output, FX_DWORD& outlen, const uint8_t* input, FX_ DWORD& size, FX_BOOL bEarlyChange); 82 FX_BOOL Decode(uint8_t* output, FX_DWORD& outlen, const uint8_t* input, FX_D WORD& size, FX_BOOL bEarlyChange);
83 private: 83 private:
84 FX_DWORD m_InPos; 84 FX_DWORD m_InPos;
85 FX_DWORD m_OutPos; 85 FX_DWORD m_OutPos;
86 FX_LPBYTE» m_pOutput; 86 uint8_t*» m_pOutput;
87 const uint8_t* m_pInput; 87 const uint8_t* m_pInput;
88 FX_BOOL m_Early; 88 FX_BOOL m_Early;
89 void AddCode(FX_DWORD prefix_code, uint8_t append_char); 89 void AddCode(FX_DWORD prefix_code, uint8_t append_char);
90 FX_DWORD m_CodeArray[5021]; 90 FX_DWORD m_CodeArray[5021];
91 FX_DWORD m_nCodes; 91 FX_DWORD m_nCodes;
92 uint8_t m_DecodeStack[4000]; 92 uint8_t m_DecodeStack[4000];
93 FX_DWORD m_StackLen; 93 FX_DWORD m_StackLen;
94 void DecodeString(FX_DWORD code); 94 void DecodeString(FX_DWORD code);
95 int m_CodeLen; 95 int m_CodeLen;
96 }; 96 };
(...skipping 23 matching lines...) Expand all
120 return; 120 return;
121 } 121 }
122 m_DecodeStack[m_StackLen++] = (uint8_t)data; 122 m_DecodeStack[m_StackLen++] = (uint8_t)data;
123 code = data >> 16; 123 code = data >> 16;
124 } 124 }
125 if (m_StackLen >= sizeof(m_DecodeStack)) { 125 if (m_StackLen >= sizeof(m_DecodeStack)) {
126 return; 126 return;
127 } 127 }
128 m_DecodeStack[m_StackLen++] = (uint8_t)code; 128 m_DecodeStack[m_StackLen++] = (uint8_t)code;
129 } 129 }
130 int CLZWDecoder::Decode(FX_LPBYTE dest_buf, FX_DWORD& dest_size, const uint8_t* src_buf, FX_DWORD& src_size, FX_BOOL bEarlyChange) 130 int CLZWDecoder::Decode(uint8_t* dest_buf, FX_DWORD& dest_size, const uint8_t* s rc_buf, FX_DWORD& src_size, FX_BOOL bEarlyChange)
131 { 131 {
132 m_CodeLen = 9; 132 m_CodeLen = 9;
133 m_InPos = 0; 133 m_InPos = 0;
134 m_OutPos = 0; 134 m_OutPos = 0;
135 m_pInput = src_buf; 135 m_pInput = src_buf;
136 m_pOutput = dest_buf; 136 m_pOutput = dest_buf;
137 m_Early = bEarlyChange ? 1 : 0; 137 m_Early = bEarlyChange ? 1 : 0;
138 m_nCodes = 0; 138 m_nCodes = 0;
139 FX_DWORD old_code = (FX_DWORD) - 1; 139 FX_DWORD old_code = (FX_DWORD) - 1;
140 uint8_t last_char; 140 uint8_t last_char;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 int pb = FXSYS_abs(p - b); 224 int pb = FXSYS_abs(p - b);
225 int pc = FXSYS_abs(p - c); 225 int pc = FXSYS_abs(p - c);
226 if (pa <= pb && pa <= pc) { 226 if (pa <= pb && pa <= pc) {
227 return (uint8_t)a; 227 return (uint8_t)a;
228 } 228 }
229 if (pb <= pc) { 229 if (pb <= pc) {
230 return (uint8_t)b; 230 return (uint8_t)b;
231 } 231 }
232 return (uint8_t)c; 232 return (uint8_t)c;
233 } 233 }
234 static FX_BOOL PNG_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size, 234 static FX_BOOL PNG_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size,
235 int predictor, int Colors, 235 int predictor, int Colors,
236 int BitsPerComponent, int Columns) 236 int BitsPerComponent, int Columns)
237 { 237 {
238 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 238 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
239 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 239 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
240 if (row_size <= 0) 240 if (row_size <= 0)
241 return FALSE; 241 return FALSE;
242 const int row_count = (data_size + row_size - 1) / row_size; 242 const int row_count = (data_size + row_size - 1) / row_size;
243 const int last_row_size = data_size % row_size; 243 const int last_row_size = data_size % row_size;
244 FX_LPBYTE dest_buf = FX_Alloc2D(uint8_t, row_size + 1, row_count); 244 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size + 1, row_count);
245 int byte_cnt = 0; 245 int byte_cnt = 0;
246 FX_LPBYTE pSrcData = data_buf; 246 uint8_t* pSrcData = data_buf;
247 FX_LPBYTE pDestData = dest_buf; 247 uint8_t* pDestData = dest_buf;
248 for (int row = 0; row < row_count; row++) { 248 for (int row = 0; row < row_count; row++) {
249 if (predictor == 10) { 249 if (predictor == 10) {
250 pDestData[0] = 0; 250 pDestData[0] = 0;
251 int move_size = row_size; 251 int move_size = row_size;
252 if (move_size * (row + 1) > (int)data_size) { 252 if (move_size * (row + 1) > (int)data_size) {
253 move_size = data_size - (move_size * row); 253 move_size = data_size - (move_size * row);
254 } 254 }
255 FXSYS_memmove32(pDestData + 1, pSrcData, move_size); 255 FXSYS_memmove32(pDestData + 1, pSrcData, move_size);
256 pDestData += (move_size + 1); 256 pDestData += (move_size + 1);
257 pSrcData += move_size; 257 pSrcData += move_size;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 byte_cnt++; 316 byte_cnt++;
317 } 317 }
318 pDestData += (row_size + 1); 318 pDestData += (row_size + 1);
319 pSrcData += row_size; 319 pSrcData += row_size;
320 } 320 }
321 FX_Free(data_buf); 321 FX_Free(data_buf);
322 data_buf = dest_buf; 322 data_buf = dest_buf;
323 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0); 323 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0);
324 return TRUE; 324 return TRUE;
325 } 325 }
326 static void PNG_PredictLine(FX_LPBYTE pDestData, FX_LPCBYTE pSrcData, FX_LPCBYTE pLastLine, 326 static void PNG_PredictLine(uint8_t* pDestData, const uint8_t* pSrcData, const u int8_t* pLastLine,
327 int bpc, int nColors, int nPixels) 327 int bpc, int nColors, int nPixels)
328 { 328 {
329 int row_size = (nPixels * bpc * nColors + 7) / 8; 329 int row_size = (nPixels * bpc * nColors + 7) / 8;
330 int BytesPerPixel = (bpc * nColors + 7) / 8; 330 int BytesPerPixel = (bpc * nColors + 7) / 8;
331 uint8_t tag = pSrcData[0]; 331 uint8_t tag = pSrcData[0];
332 if (tag == 0) { 332 if (tag == 0) {
333 FXSYS_memmove32(pDestData, pSrcData + 1, row_size); 333 FXSYS_memmove32(pDestData, pSrcData + 1, row_size);
334 return; 334 return;
335 } 335 }
336 for (int byte = 0; byte < row_size; byte ++) { 336 for (int byte = 0; byte < row_size; byte ++) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 } 379 }
380 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left); 380 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left);
381 break; 381 break;
382 } 382 }
383 default: 383 default:
384 pDestData[byte] = raw_byte; 384 pDestData[byte] = raw_byte;
385 break; 385 break;
386 } 386 }
387 } 387 }
388 } 388 }
389 static FX_BOOL PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size, 389 static FX_BOOL PNG_Predictor(uint8_t*& data_buf, FX_DWORD& data_size,
390 int Colors, int BitsPerComponent, int Columns) 390 int Colors, int BitsPerComponent, int Columns)
391 { 391 {
392 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 392 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
393 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 393 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
394 if (row_size <= 0) 394 if (row_size <= 0)
395 return FALSE; 395 return FALSE;
396 const int row_count = (data_size + row_size) / (row_size + 1); 396 const int row_count = (data_size + row_size) / (row_size + 1);
397 const int last_row_size = data_size % (row_size + 1); 397 const int last_row_size = data_size % (row_size + 1);
398 FX_LPBYTE dest_buf = FX_Alloc2D(uint8_t, row_size, row_count); 398 uint8_t* dest_buf = FX_Alloc2D(uint8_t, row_size, row_count);
399 int byte_cnt = 0; 399 int byte_cnt = 0;
400 FX_LPBYTE pSrcData = data_buf; 400 uint8_t* pSrcData = data_buf;
401 FX_LPBYTE pDestData = dest_buf; 401 uint8_t* pDestData = dest_buf;
402 for (int row = 0; row < row_count; row ++) { 402 for (int row = 0; row < row_count; row ++) {
403 uint8_t tag = pSrcData[0]; 403 uint8_t tag = pSrcData[0];
404 byte_cnt++; 404 byte_cnt++;
405 if (tag == 0) { 405 if (tag == 0) {
406 int move_size = row_size; 406 int move_size = row_size;
407 if ((row + 1) * (move_size + 1) > (int)data_size) { 407 if ((row + 1) * (move_size + 1) > (int)data_size) {
408 move_size = last_row_size - 1; 408 move_size = last_row_size - 1;
409 } 409 }
410 FXSYS_memmove32(pDestData, pSrcData + 1, move_size); 410 FXSYS_memmove32(pDestData, pSrcData + 1, move_size);
411 pSrcData += move_size + 1; 411 pSrcData += move_size + 1;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 byte_cnt++; 467 byte_cnt++;
468 } 468 }
469 pSrcData += row_size + 1; 469 pSrcData += row_size + 1;
470 pDestData += row_size; 470 pDestData += row_size;
471 } 471 }
472 FX_Free(data_buf); 472 FX_Free(data_buf);
473 data_buf = dest_buf; 473 data_buf = dest_buf;
474 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0); 474 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0);
475 return TRUE; 475 return TRUE;
476 } 476 }
477 static void TIFF_PredictorEncodeLine(FX_LPBYTE dest_buf, int row_size, int BitsP erComponent, int Colors, int Columns) 477 static void TIFF_PredictorEncodeLine(uint8_t* dest_buf, int row_size, int BitsPe rComponent, int Colors, int Columns)
478 { 478 {
479 int BytesPerPixel = BitsPerComponent * Colors / 8; 479 int BytesPerPixel = BitsPerComponent * Colors / 8;
480 if (BitsPerComponent < 8) { 480 if (BitsPerComponent < 8) {
481 uint8_t mask = 0x01; 481 uint8_t mask = 0x01;
482 if (BitsPerComponent == 2) { 482 if (BitsPerComponent == 2) {
483 mask = 0x03; 483 mask = 0x03;
484 } else if (BitsPerComponent == 4) { 484 } else if (BitsPerComponent == 4) {
485 mask = 0x0F; 485 mask = 0x0F;
486 } 486 }
487 int row_bits = Colors * BitsPerComponent * Columns; 487 int row_bits = Colors * BitsPerComponent * Columns;
(...skipping 16 matching lines...) Expand all
504 } 504 }
505 } else { 505 } else {
506 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) { 506 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) {
507 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1]; 507 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1];
508 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1]; 508 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1];
509 dest_buf[i] = pixel >> 8; 509 dest_buf[i] = pixel >> 8;
510 dest_buf[i + 1] = (uint8_t)pixel; 510 dest_buf[i + 1] = (uint8_t)pixel;
511 } 511 }
512 } 512 }
513 } 513 }
514 static FX_BOOL TIFF_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size, 514 static FX_BOOL TIFF_PredictorEncode(uint8_t*& data_buf, FX_DWORD& data_size,
515 int Colors, int BitsPerComponent, int Column s) 515 int Colors, int BitsPerComponent, int Column s)
516 { 516 {
517 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 517 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
518 if (row_size == 0) 518 if (row_size == 0)
519 return FALSE; 519 return FALSE;
520 const int row_count = (data_size + row_size - 1) / row_size; 520 const int row_count = (data_size + row_size - 1) / row_size;
521 const int last_row_size = data_size % row_size; 521 const int last_row_size = data_size % row_size;
522 for (int row = 0; row < row_count; row++) { 522 for (int row = 0; row < row_count; row++) {
523 FX_LPBYTE scan_line = data_buf + row * row_size; 523 uint8_t* scan_line = data_buf + row * row_size;
524 if ((row + 1) * row_size > (int)data_size) { 524 if ((row + 1) * row_size > (int)data_size) {
525 row_size = last_row_size; 525 row_size = last_row_size;
526 } 526 }
527 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns); 527 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns);
528 } 528 }
529 return TRUE; 529 return TRUE;
530 } 530 }
531 static void TIFF_PredictLine(FX_LPBYTE dest_buf, int row_size, int BitsPerCompon ent, int Colors, int Columns) 531 static void TIFF_PredictLine(uint8_t* dest_buf, int row_size, int BitsPerCompone nt, int Colors, int Columns)
532 { 532 {
533 if (BitsPerComponent == 1) { 533 if (BitsPerComponent == 1) {
534 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ; 534 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ;
535 int index_pre = 0; 535 int index_pre = 0;
536 int col_pre = 0; 536 int col_pre = 0;
537 for(int i = 1; i < row_bits; i ++) { 537 for(int i = 1; i < row_bits; i ++) {
538 int col = i % 8; 538 int col = i % 8;
539 int index = i / 8; 539 int index = i / 8;
540 if( ((dest_buf[index] >> (7 - col)) & 1) ^ ((dest_buf[index_pre] >> (7 - col_pre)) & 1) ) { 540 if( ((dest_buf[index] >> (7 - col)) & 1) ^ ((dest_buf[index_pre] >> (7 - col_pre)) & 1) ) {
541 dest_buf[index] |= 1 << (7 - col); 541 dest_buf[index] |= 1 << (7 - col);
(...skipping 12 matching lines...) Expand all
554 pixel += (dest_buf[i] << 8) | dest_buf[i + 1]; 554 pixel += (dest_buf[i] << 8) | dest_buf[i + 1];
555 dest_buf[i] = pixel >> 8; 555 dest_buf[i] = pixel >> 8;
556 dest_buf[i + 1] = (uint8_t)pixel; 556 dest_buf[i + 1] = (uint8_t)pixel;
557 } 557 }
558 } else { 558 } else {
559 for (int i = BytesPerPixel; i < row_size; i ++) { 559 for (int i = BytesPerPixel; i < row_size; i ++) {
560 dest_buf[i] += dest_buf[i - BytesPerPixel]; 560 dest_buf[i] += dest_buf[i - BytesPerPixel];
561 } 561 }
562 } 562 }
563 } 563 }
564 static FX_BOOL TIFF_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size, 564 static FX_BOOL TIFF_Predictor(uint8_t*& data_buf, FX_DWORD& data_size,
565 int Colors, int BitsPerComponent, int Columns) 565 int Colors, int BitsPerComponent, int Columns)
566 { 566 {
567 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 567 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
568 if (row_size == 0) 568 if (row_size == 0)
569 return FALSE; 569 return FALSE;
570 const int row_count = (data_size + row_size - 1) / row_size; 570 const int row_count = (data_size + row_size - 1) / row_size;
571 const int last_row_size = data_size % row_size; 571 const int last_row_size = data_size % row_size;
572 for (int row = 0; row < row_count; row ++) { 572 for (int row = 0; row < row_count; row ++) {
573 FX_LPBYTE scan_line = data_buf + row * row_size; 573 uint8_t* scan_line = data_buf + row * row_size;
574 if ((row + 1) * row_size > (int)data_size) { 574 if ((row + 1) * row_size > (int)data_size) {
575 row_size = last_row_size; 575 row_size = last_row_size;
576 } 576 }
577 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ; 577 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ;
578 } 578 }
579 return TRUE; 579 return TRUE;
580 } 580 }
581 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder 581 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder
582 { 582 {
583 public: 583 public:
584 CCodec_FlateScanlineDecoder(); 584 CCodec_FlateScanlineDecoder();
585 ~CCodec_FlateScanlineDecoder(); 585 ~CCodec_FlateScanlineDecoder();
586 void Create(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, in t nComps, int bpc, 586 void Create(const uint8_t* src_buf, FX_DWORD src_size, int width, int height , int nComps, int bpc,
587 int predictor, int Colors, int BitsPerComponent, int Columns); 587 int predictor, int Colors, int BitsPerComponent, int Columns);
588 virtual void Destroy() 588 virtual void Destroy()
589 { 589 {
590 delete this; 590 delete this;
591 } 591 }
592 virtual void v_DownScale(int dest_width, int dest_height) {} 592 virtual void v_DownScale(int dest_width, int dest_height) {}
593 virtual FX_BOOL v_Rewind(); 593 virtual FX_BOOL v_Rewind();
594 virtual FX_LPBYTE» v_GetNextLine(); 594 virtual uint8_t*» v_GetNextLine();
595 virtual FX_DWORD GetSrcOffset(); 595 virtual FX_DWORD GetSrcOffset();
596 void* m_pFlate; 596 void* m_pFlate;
597 FX_LPCBYTE» » » m_SrcBuf; 597 const uint8_t*» » » m_SrcBuf;
598 FX_DWORD m_SrcSize; 598 FX_DWORD m_SrcSize;
599 FX_LPBYTE» » » m_pScanline; 599 uint8_t*» » » m_pScanline;
600 FX_LPBYTE» » » m_pLastLine; 600 uint8_t*» » » m_pLastLine;
601 FX_LPBYTE» » » m_pPredictBuffer; 601 uint8_t*» » » m_pPredictBuffer;
602 FX_LPBYTE» » » m_pPredictRaw; 602 uint8_t*» » » m_pPredictRaw;
603 int m_Predictor; 603 int m_Predictor;
604 int m_Colors, m_BitsPerComponent, m_Columns, m_PredictPitch, m_LeftOver; 604 int m_Colors, m_BitsPerComponent, m_Columns, m_PredictPitch, m_LeftOver;
605 }; 605 };
606 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder() 606 CCodec_FlateScanlineDecoder::CCodec_FlateScanlineDecoder()
607 { 607 {
608 m_pFlate = NULL; 608 m_pFlate = NULL;
609 m_pScanline = NULL; 609 m_pScanline = NULL;
610 m_pLastLine = NULL; 610 m_pLastLine = NULL;
611 m_pPredictBuffer = NULL; 611 m_pPredictBuffer = NULL;
612 m_pPredictRaw = NULL; 612 m_pPredictRaw = NULL;
(...skipping 10 matching lines...) Expand all
623 if (m_pPredictBuffer) { 623 if (m_pPredictBuffer) {
624 FX_Free(m_pPredictBuffer); 624 FX_Free(m_pPredictBuffer);
625 } 625 }
626 if (m_pPredictRaw) { 626 if (m_pPredictRaw) {
627 FX_Free(m_pPredictRaw); 627 FX_Free(m_pPredictRaw);
628 } 628 }
629 if (m_pFlate) { 629 if (m_pFlate) {
630 FPDFAPI_FlateEnd(m_pFlate); 630 FPDFAPI_FlateEnd(m_pFlate);
631 } 631 }
632 } 632 }
633 void CCodec_FlateScanlineDecoder::Create(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, 633 void CCodec_FlateScanlineDecoder::Create(const uint8_t* src_buf, FX_DWORD src_si ze, int width, int height,
634 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns) 634 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns)
635 { 635 {
636 m_SrcBuf = src_buf; 636 m_SrcBuf = src_buf;
637 m_SrcSize = src_size; 637 m_SrcSize = src_size;
638 m_OutputWidth = m_OrigWidth = width; 638 m_OutputWidth = m_OrigWidth = width;
639 m_OutputHeight = m_OrigHeight = height; 639 m_OutputHeight = m_OrigHeight = height;
640 m_nComps = nComps; 640 m_nComps = nComps;
641 m_bpc = bpc; 641 m_bpc = bpc;
642 m_bColorTransformed = FALSE; 642 m_bColorTransformed = FALSE;
643 m_Pitch = (width * nComps * bpc + 7) / 8; 643 m_Pitch = (width * nComps * bpc + 7) / 8;
(...skipping 27 matching lines...) Expand all
671 FPDFAPI_FlateEnd(m_pFlate); 671 FPDFAPI_FlateEnd(m_pFlate);
672 } 672 }
673 m_pFlate = FPDFAPI_FlateInit(my_alloc_func, my_free_func); 673 m_pFlate = FPDFAPI_FlateInit(my_alloc_func, my_free_func);
674 if (m_pFlate == NULL) { 674 if (m_pFlate == NULL) {
675 return FALSE; 675 return FALSE;
676 } 676 }
677 FPDFAPI_FlateInput(m_pFlate, m_SrcBuf, m_SrcSize); 677 FPDFAPI_FlateInput(m_pFlate, m_SrcBuf, m_SrcSize);
678 m_LeftOver = 0; 678 m_LeftOver = 0;
679 return TRUE; 679 return TRUE;
680 } 680 }
681 FX_LPBYTE CCodec_FlateScanlineDecoder::v_GetNextLine() 681 uint8_t* CCodec_FlateScanlineDecoder::v_GetNextLine()
682 { 682 {
683 if (m_Predictor) { 683 if (m_Predictor) {
684 if (m_Pitch == m_PredictPitch) { 684 if (m_Pitch == m_PredictPitch) {
685 if (m_Predictor == 2) { 685 if (m_Predictor == 2) {
686 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1) ; 686 FPDFAPI_FlateOutput(m_pFlate, m_pPredictRaw, m_PredictPitch + 1) ;
687 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine, m_BitsP erComponent, m_Colors, m_Columns); 687 PNG_PredictLine(m_pScanline, m_pPredictRaw, m_pLastLine, m_BitsP erComponent, m_Colors, m_Columns);
688 FXSYS_memcpy32(m_pLastLine, m_pScanline, m_PredictPitch); 688 FXSYS_memcpy32(m_pLastLine, m_pScanline, m_PredictPitch);
689 } else { 689 } else {
690 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch); 690 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch);
691 TIFF_PredictLine(m_pScanline, m_PredictPitch, m_bpc, m_nComps, m _OutputWidth); 691 TIFF_PredictLine(m_pScanline, m_PredictPitch, m_bpc, m_nComps, m _OutputWidth);
(...skipping 23 matching lines...) Expand all
715 } 715 }
716 } else { 716 } else {
717 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch); 717 FPDFAPI_FlateOutput(m_pFlate, m_pScanline, m_Pitch);
718 } 718 }
719 return m_pScanline; 719 return m_pScanline;
720 } 720 }
721 FX_DWORD CCodec_FlateScanlineDecoder::GetSrcOffset() 721 FX_DWORD CCodec_FlateScanlineDecoder::GetSrcOffset()
722 { 722 {
723 return FPDFAPI_FlateGetTotalIn(m_pFlate); 723 return FPDFAPI_FlateGetTotalIn(m_pFlate);
724 } 724 }
725 static void FlateUncompress(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_DWORD orig _size, 725 static void FlateUncompress(const uint8_t* src_buf, FX_DWORD src_size, FX_DWORD orig_size,
726 FX_LPBYTE& dest_buf, FX_DWORD& dest_size, FX_DWORD& offset) 726 uint8_t*& dest_buf, FX_DWORD& dest_size, FX_DWORD& o ffset)
727 { 727 {
728 const FX_BOOL useOldImpl = src_size < 10240; 728 const FX_BOOL useOldImpl = src_size < 10240;
729 FX_DWORD guess_size = orig_size ? orig_size : src_size * 2; 729 FX_DWORD guess_size = orig_size ? orig_size : src_size * 2;
730 FX_DWORD alloc_step = orig_size ? 10240 : (src_size < 10240 ? 10240 : src_si ze); 730 FX_DWORD alloc_step = orig_size ? 10240 : (src_size < 10240 ? 10240 : src_si ze);
731 static const FX_DWORD kMaxInitialAllocSize = 10000000; 731 static const FX_DWORD kMaxInitialAllocSize = 10000000;
732 if (guess_size > kMaxInitialAllocSize) { 732 if (guess_size > kMaxInitialAllocSize) {
733 guess_size = kMaxInitialAllocSize; 733 guess_size = kMaxInitialAllocSize;
734 alloc_step = kMaxInitialAllocSize; 734 alloc_step = kMaxInitialAllocSize;
735 } 735 }
736 FX_DWORD buf_size = guess_size; 736 FX_DWORD buf_size = guess_size;
737 FX_DWORD last_buf_size = buf_size; 737 FX_DWORD last_buf_size = buf_size;
738 void* context = nullptr; 738 void* context = nullptr;
739 739
740 FX_LPBYTE guess_buf = FX_Alloc(uint8_t, guess_size + 1); 740 uint8_t* guess_buf = FX_Alloc(uint8_t, guess_size + 1);
741 FX_LPBYTE cur_buf = guess_buf; 741 uint8_t* cur_buf = guess_buf;
742 guess_buf[guess_size] = '\0'; 742 guess_buf[guess_size] = '\0';
743 context = FPDFAPI_FlateInit(my_alloc_func, my_free_func); 743 context = FPDFAPI_FlateInit(my_alloc_func, my_free_func);
744 if (!context) 744 if (!context)
745 goto fail; 745 goto fail;
746 FPDFAPI_FlateInput(context, src_buf, src_size); 746 FPDFAPI_FlateInput(context, src_buf, src_size);
747 if (useOldImpl) { 747 if (useOldImpl) {
748 while (1) { 748 while (1) {
749 int32_t ret = FPDFAPI_FlateOutput(context, cur_buf, buf_size); 749 int32_t ret = FPDFAPI_FlateOutput(context, cur_buf, buf_size);
750 if (ret != Z_OK) 750 if (ret != Z_OK)
751 break; 751 break;
(...skipping 17 matching lines...) Expand all
769 offset = FPDFAPI_FlateGetTotalIn(context); 769 offset = FPDFAPI_FlateGetTotalIn(context);
770 if (guess_size / 2 > dest_size) { 770 if (guess_size / 2 > dest_size) {
771 guess_buf = FX_Realloc(uint8_t, guess_buf, dest_size + 1); 771 guess_buf = FX_Realloc(uint8_t, guess_buf, dest_size + 1);
772 if (!guess_buf) 772 if (!guess_buf)
773 goto fail; 773 goto fail;
774 guess_size = dest_size; 774 guess_size = dest_size;
775 guess_buf[guess_size] = '\0'; 775 guess_buf[guess_size] = '\0';
776 } 776 }
777 dest_buf = guess_buf; 777 dest_buf = guess_buf;
778 } else { 778 } else {
779 CFX_ArrayTemplate<FX_LPBYTE> result_tmp_bufs; 779 CFX_ArrayTemplate<uint8_t*> result_tmp_bufs;
780 while (1) { 780 while (1) {
781 int32_t ret = FPDFAPI_FlateOutput(context, cur_buf, buf_size); 781 int32_t ret = FPDFAPI_FlateOutput(context, cur_buf, buf_size);
782 int32_t avail_buf_size = FPDFAPI_FlateGetAvailOut(context); 782 int32_t avail_buf_size = FPDFAPI_FlateGetAvailOut(context);
783 if (ret != Z_OK) { 783 if (ret != Z_OK) {
784 last_buf_size = buf_size - avail_buf_size; 784 last_buf_size = buf_size - avail_buf_size;
785 result_tmp_bufs.Add(cur_buf); 785 result_tmp_bufs.Add(cur_buf);
786 break; 786 break;
787 } 787 }
788 if (avail_buf_size != 0) { 788 if (avail_buf_size != 0) {
789 last_buf_size = buf_size - avail_buf_size; 789 last_buf_size = buf_size - avail_buf_size;
790 result_tmp_bufs.Add(cur_buf); 790 result_tmp_bufs.Add(cur_buf);
791 break; 791 break;
792 } 792 }
793 793
794 // |avail_buf_size| == 0 case. 794 // |avail_buf_size| == 0 case.
795 result_tmp_bufs.Add(cur_buf); 795 result_tmp_bufs.Add(cur_buf);
796 cur_buf = FX_Alloc(uint8_t, buf_size + 1); 796 cur_buf = FX_Alloc(uint8_t, buf_size + 1);
797 cur_buf[buf_size] = '\0'; 797 cur_buf[buf_size] = '\0';
798 } 798 }
799 dest_size = FPDFAPI_FlateGetTotalOut(context); 799 dest_size = FPDFAPI_FlateGetTotalOut(context);
800 offset = FPDFAPI_FlateGetTotalIn(context); 800 offset = FPDFAPI_FlateGetTotalIn(context);
801 if (result_tmp_bufs.GetSize() == 1) { 801 if (result_tmp_bufs.GetSize() == 1) {
802 dest_buf = result_tmp_bufs[0]; 802 dest_buf = result_tmp_bufs[0];
803 } else { 803 } else {
804 FX_LPBYTE result_buf = FX_Alloc(uint8_t, dest_size); 804 uint8_t* result_buf = FX_Alloc(uint8_t, dest_size);
805 FX_DWORD result_pos = 0; 805 FX_DWORD result_pos = 0;
806 for (int32_t i = 0; i < result_tmp_bufs.GetSize(); i++) { 806 for (int32_t i = 0; i < result_tmp_bufs.GetSize(); i++) {
807 FX_LPBYTE tmp_buf = result_tmp_bufs[i]; 807 uint8_t* tmp_buf = result_tmp_bufs[i];
808 FX_DWORD tmp_buf_size = buf_size; 808 FX_DWORD tmp_buf_size = buf_size;
809 if (i == result_tmp_bufs.GetSize() - 1) { 809 if (i == result_tmp_bufs.GetSize() - 1) {
810 tmp_buf_size = last_buf_size; 810 tmp_buf_size = last_buf_size;
811 } 811 }
812 FXSYS_memcpy32(result_buf + result_pos, tmp_buf, tmp_buf_size); 812 FXSYS_memcpy32(result_buf + result_pos, tmp_buf, tmp_buf_size);
813 result_pos += tmp_buf_size; 813 result_pos += tmp_buf_size;
814 FX_Free(result_tmp_bufs[i]); 814 FX_Free(result_tmp_bufs[i]);
815 } 815 }
816 dest_buf = result_buf; 816 dest_buf = result_buf;
817 } 817 }
818 } 818 }
819 FPDFAPI_FlateEnd(context); 819 FPDFAPI_FlateEnd(context);
820 return; 820 return;
821 821
822 fail: 822 fail:
823 FX_Free(guess_buf); 823 FX_Free(guess_buf);
824 dest_buf = nullptr; 824 dest_buf = nullptr;
825 dest_size = 0; 825 dest_size = 0;
826 return; 826 return;
827 } 827 }
828 ICodec_ScanlineDecoder*»CCodec_FlateModule::CreateDecoder(FX_LPCBYTE src_buf, FX _DWORD src_size, int width, int height, 828 ICodec_ScanlineDecoder*»CCodec_FlateModule::CreateDecoder(const uint8_t* src_buf , FX_DWORD src_size, int width, int height,
829 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns) 829 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns)
830 { 830 {
831 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder; 831 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder;
832 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns); 832 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns);
833 return pDecoder; 833 return pDecoder;
834 } 834 }
835 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_b uf, FX_DWORD src_size, FX_BOOL bEarlyChange, 835 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const uint8_t* src_b uf, FX_DWORD src_size, FX_BOOL bEarlyChange,
836 int predictor, int Colors, int BitsPerComponent, int Columns, 836 int predictor, int Colors, int BitsPerComponent, int Columns,
837 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 837 FX_DWORD estimated_size, uint8_t*& dest_buf, FX_DWORD& dest_size)
838 { 838 {
839 dest_buf = NULL; 839 dest_buf = NULL;
840 FX_DWORD offset = 0; 840 FX_DWORD offset = 0;
841 int predictor_type = 0; 841 int predictor_type = 0;
842 if (predictor) { 842 if (predictor) {
843 if (predictor >= 10) { 843 if (predictor >= 10) {
844 predictor_type = 2; 844 predictor_type = 2;
845 } else if (predictor == 2) { 845 } else if (predictor == 2) {
846 predictor_type = 1; 846 predictor_type = 1;
847 } 847 }
(...skipping 26 matching lines...) Expand all
874 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, 874 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
875 Columns); 875 Columns);
876 } else if (predictor_type == 1) { 876 } else if (predictor_type == 1) {
877 ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, 877 ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
878 Columns); 878 Columns);
879 } 879 }
880 return ret ? offset : -1; 880 return ret ? offset : -1;
881 } 881 }
882 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, 882 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size,
883 int predictor, int Colors, int BitsPerCompone nt, int Columns, 883 int predictor, int Colors, int BitsPerCompone nt, int Columns,
884 FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 884 uint8_t*& dest_buf, FX_DWORD& dest_size)
885 { 885 {
886 if (predictor != 2 && predictor < 10) { 886 if (predictor != 2 && predictor < 10) {
887 return Encode(src_buf, src_size, dest_buf, dest_size); 887 return Encode(src_buf, src_size, dest_buf, dest_size);
888 } 888 }
889 FX_LPBYTE pSrcBuf = NULL; 889 uint8_t* pSrcBuf = NULL;
890 pSrcBuf = FX_Alloc(uint8_t, src_size); 890 pSrcBuf = FX_Alloc(uint8_t, src_size);
891 FXSYS_memcpy32(pSrcBuf, src_buf, src_size); 891 FXSYS_memcpy32(pSrcBuf, src_buf, src_size);
892 FX_BOOL ret = TRUE; 892 FX_BOOL ret = TRUE;
893 if (predictor == 2) { 893 if (predictor == 2) {
894 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent, 894 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent,
895 Columns); 895 Columns);
896 } else if (predictor >= 10) { 896 } else if (predictor >= 10) {
897 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors, 897 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors,
898 BitsPerComponent, Columns); 898 BitsPerComponent, Columns);
899 } 899 }
900 if (ret) 900 if (ret)
901 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); 901 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size);
902 FX_Free(pSrcBuf); 902 FX_Free(pSrcBuf);
903 return ret; 903 return ret;
904 } 904 }
905 FX_BOOL CCodec_FlateModule::Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPB YTE& dest_buf, FX_DWORD& dest_size) 905 FX_BOOL CCodec_FlateModule::Encode(const uint8_t* src_buf, FX_DWORD src_size, ui nt8_t*& dest_buf, FX_DWORD& dest_size)
906 { 906 {
907 dest_size = src_size + src_size / 1000 + 12; 907 dest_size = src_size + src_size / 1000 + 12;
908 dest_buf = FX_Alloc( uint8_t, dest_size); 908 dest_buf = FX_Alloc( uint8_t, dest_size);
909 unsigned long temp_size = dest_size; 909 unsigned long temp_size = dest_size;
910 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); 910 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size);
911 dest_size = (FX_DWORD)temp_size; 911 dest_size = (FX_DWORD)temp_size;
912 return TRUE; 912 return TRUE;
913 } 913 }
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