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 FX_BYTE 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, |
11 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | 11 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
12 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 12 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
13 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 13 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
14 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 14 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
15 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 15 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
16 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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 1, |
38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
40 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 40 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
41 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | 41 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
42 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, | 42 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
43 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, | 43 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, |
44 }; | 44 }; |
45 | 45 |
46 int _FindBit(const FX_BYTE* data_buf, int max_pos, int start_pos, int bit) | 46 int _FindBit(const uint8_t* data_buf, int max_pos, int start_pos, int bit) |
47 { | 47 { |
48 if (start_pos >= max_pos) { | 48 if (start_pos >= max_pos) { |
49 return max_pos; | 49 return max_pos; |
50 } | 50 } |
51 FX_LPCBYTE leading_pos = bit ? OneLeadPos : ZeroLeadPos; | 51 FX_LPCBYTE leading_pos = bit ? OneLeadPos : ZeroLeadPos; |
52 if (start_pos % 8) { | 52 if (start_pos % 8) { |
53 FX_BYTE data = data_buf[start_pos / 8]; | 53 uint8_t data = data_buf[start_pos / 8]; |
54 if (bit) { | 54 if (bit) { |
55 data &= 0xff >> (start_pos % 8); | 55 data &= 0xff >> (start_pos % 8); |
56 } else { | 56 } else { |
57 data |= 0xff << (8 - start_pos % 8); | 57 data |= 0xff << (8 - start_pos % 8); |
58 } | 58 } |
59 if (leading_pos[data] < 8) { | 59 if (leading_pos[data] < 8) { |
60 return start_pos / 8 * 8 + leading_pos[data]; | 60 return start_pos / 8 * 8 + leading_pos[data]; |
61 } | 61 } |
62 start_pos += 7; | 62 start_pos += 7; |
63 } | 63 } |
64 FX_BYTE skip = bit ? 0x00 : 0xff; | 64 uint8_t skip = bit ? 0x00 : 0xff; |
65 int byte_pos = start_pos / 8; | 65 int byte_pos = start_pos / 8; |
66 int max_byte = (max_pos + 7) / 8; | 66 int max_byte = (max_pos + 7) / 8; |
67 while (byte_pos < max_byte) { | 67 while (byte_pos < max_byte) { |
68 if (data_buf[byte_pos] != skip) { | 68 if (data_buf[byte_pos] != skip) { |
69 break; | 69 break; |
70 } | 70 } |
71 byte_pos ++; | 71 byte_pos ++; |
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 FX_BYTE* 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, FX_BOOL a0color
, int& b1, int& b2) |
83 { | 83 { |
84 if (a0color) { | 84 if (a0color) { |
85 a0color = 1; | 85 a0color = 1; |
86 } | 86 } |
87 FX_BYTE 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 } |
93 if (first_bit == !a0color) { | 93 if (first_bit == !a0color) { |
94 b1 = _FindBit(ref_buf, columns, b1 + 1, first_bit); | 94 b1 = _FindBit(ref_buf, columns, b1 + 1, first_bit); |
95 first_bit = !first_bit; | 95 first_bit = !first_bit; |
96 } | 96 } |
97 if (b1 >= columns) { | 97 if (b1 >= columns) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 for (i = 0; i <= (endpos - 1) % 8; i ++) { | 129 for (i = 0; i <= (endpos - 1) % 8; i ++) { |
130 dest_buf[last_byte] -= 1 << (7 - i); | 130 dest_buf[last_byte] -= 1 << (7 - i); |
131 } | 131 } |
132 if (last_byte > first_byte + 1) { | 132 if (last_byte > first_byte + 1) { |
133 FXSYS_memset32(dest_buf + first_byte + 1, 0, last_byte - first_byte - 1)
; | 133 FXSYS_memset32(dest_buf + first_byte + 1, 0, last_byte - first_byte - 1)
; |
134 } | 134 } |
135 } | 135 } |
136 #define NEXTBIT src_buf[bitpos/8] & (1 << (7-bitpos%8)); bitpos ++; | 136 #define NEXTBIT src_buf[bitpos/8] & (1 << (7-bitpos%8)); bitpos ++; |
137 #define ADDBIT(code, bit) code = code << 1; if (bit) code ++; | 137 #define ADDBIT(code, bit) code = code << 1; if (bit) code ++; |
138 #define GETBIT(bitpos) src_buf[bitpos/8] & (1 << (7-bitpos%8)) | 138 #define GETBIT(bitpos) src_buf[bitpos/8] & (1 << (7-bitpos%8)) |
139 static const FX_BYTE FaxBlackRunIns[] = { | 139 static const uint8_t FaxBlackRunIns[] = { |
140 0, | 140 0, |
141 2, | 141 2, |
142 0x02, 3, 0, | 142 0x02, 3, 0, |
143 0x03, 2, 0, | 143 0x03, 2, 0, |
144 2, | 144 2, |
145 0x02, 1, 0, | 145 0x02, 1, 0, |
146 0x03, 4, 0, | 146 0x03, 4, 0, |
147 2, | 147 2, |
148 0x02, 6, 0, | 148 0x02, 6, 0, |
149 0x03, 5, 0, | 149 0x03, 5, 0, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 0x6c, 512 % 256, 512 / 256, | 249 0x6c, 512 % 256, 512 / 256, |
250 0x6d, 576 % 256, 576 / 256, | 250 0x6d, 576 % 256, 576 / 256, |
251 0x72, 896 % 256, 896 / 256, | 251 0x72, 896 % 256, 896 / 256, |
252 0x73, 960 % 256, 960 / 256, | 252 0x73, 960 % 256, 960 / 256, |
253 0x74, 1024 % 256, 1024 / 256, | 253 0x74, 1024 % 256, 1024 / 256, |
254 0x75, 1088 % 256, 1088 / 256, | 254 0x75, 1088 % 256, 1088 / 256, |
255 0x76, 1152 % 256, 1152 / 256, | 255 0x76, 1152 % 256, 1152 / 256, |
256 0x77, 1216 % 256, 1216 / 256, | 256 0x77, 1216 % 256, 1216 / 256, |
257 0xff | 257 0xff |
258 }; | 258 }; |
259 static const FX_BYTE FaxWhiteRunIns[] = { | 259 static const uint8_t FaxWhiteRunIns[] = { |
260 0, | 260 0, |
261 0, | 261 0, |
262 0, | 262 0, |
263 6, | 263 6, |
264 0x07, 2, 0, | 264 0x07, 2, 0, |
265 0x08, 3, 0, | 265 0x08, 3, 0, |
266 0x0B, 4, 0, | 266 0x0B, 4, 0, |
267 0x0C, 5, 0, | 267 0x0C, 5, 0, |
268 0x0E, 6, 0, | 268 0x0E, 6, 0, |
269 0x0F, 7, 0, | 269 0x0F, 7, 0, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 0x14, 2112 % 256, 2112 / 256, | 368 0x14, 2112 % 256, 2112 / 256, |
369 0x15, 2176 % 256, 2176 / 256, | 369 0x15, 2176 % 256, 2176 / 256, |
370 0x16, 2240 % 256, 2240 / 256, | 370 0x16, 2240 % 256, 2240 / 256, |
371 0x17, 2304 % 256, 2304 / 256, | 371 0x17, 2304 % 256, 2304 / 256, |
372 0x1c, 2368 % 256, 2368 / 256, | 372 0x1c, 2368 % 256, 2368 / 256, |
373 0x1d, 2432 % 256, 2432 / 256, | 373 0x1d, 2432 % 256, 2432 / 256, |
374 0x1e, 2496 % 256, 2496 / 256, | 374 0x1e, 2496 % 256, 2496 / 256, |
375 0x1f, 2560 % 256, 2560 / 256, | 375 0x1f, 2560 % 256, 2560 / 256, |
376 0xff, | 376 0xff, |
377 }; | 377 }; |
378 int _FaxGetRun(FX_LPCBYTE ins_array, const FX_BYTE* src_buf, int& bitpos, int bi
tsize) | 378 int _FaxGetRun(FX_LPCBYTE ins_array, const uint8_t* src_buf, int& bitpos, int bi
tsize) |
379 { | 379 { |
380 FX_DWORD code = 0; | 380 FX_DWORD code = 0; |
381 int ins_off = 0; | 381 int ins_off = 0; |
382 while (1) { | 382 while (1) { |
383 FX_BYTE ins = ins_array[ins_off++]; | 383 uint8_t ins = ins_array[ins_off++]; |
384 if (ins == 0xff) { | 384 if (ins == 0xff) { |
385 return -1; | 385 return -1; |
386 } | 386 } |
387 if (bitpos >= bitsize) { | 387 if (bitpos >= bitsize) { |
388 return -1; | 388 return -1; |
389 } | 389 } |
390 code <<= 1; | 390 code <<= 1; |
391 if (src_buf[bitpos / 8] & (1 << (7 - bitpos % 8))) { | 391 if (src_buf[bitpos / 8] & (1 << (7 - bitpos % 8))) { |
392 code ++; | 392 code ++; |
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 FX_BYTE* src_buf, int bitsize, int& bitpos, FX_LPBYTE
dest_buf, const FX_BYTE* ref_buf, int columns) | 403 FX_BOOL _FaxG4GetRow(const uint8_t* src_buf, int bitsize, int& bitpos, FX_LPBYTE
dest_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 FX_BOOL bit = NEXTBIT; |
413 int v_delta = 0; | 413 int v_delta = 0; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 FX_BYTE* src_buf, int bitsize, int& bitpos) | 525 FX_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 FX_BYTE* src_buf, int bitsize, int& bitpos, FX_LPBYT
E dest_buf, int columns) | 539 FX_BOOL _FaxGet1DLine(const uint8_t* src_buf, int bitsize, int& bitpos, FX_LPBYT
E dest_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); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 m_OrigHeight = Rows; | 614 m_OrigHeight = Rows; |
615 if (m_OrigWidth == 0) { | 615 if (m_OrigWidth == 0) { |
616 m_OrigWidth = width; | 616 m_OrigWidth = width; |
617 } | 617 } |
618 if (m_OrigHeight == 0) { | 618 if (m_OrigHeight == 0) { |
619 m_OrigHeight = height; | 619 m_OrigHeight = height; |
620 } | 620 } |
621 m_Pitch = (m_OrigWidth + 31) / 32 * 4; | 621 m_Pitch = (m_OrigWidth + 31) / 32 * 4; |
622 m_OutputWidth = m_OrigWidth; | 622 m_OutputWidth = m_OrigWidth; |
623 m_OutputHeight = m_OrigHeight; | 623 m_OutputHeight = m_OrigHeight; |
624 m_pScanlineBuf = FX_Alloc(FX_BYTE, m_Pitch); | 624 m_pScanlineBuf = FX_Alloc(uint8_t, m_Pitch); |
625 m_pRefBuf = FX_Alloc(FX_BYTE, m_Pitch); | 625 m_pRefBuf = FX_Alloc(uint8_t, m_Pitch); |
626 m_pSrcBuf = src_buf; | 626 m_pSrcBuf = src_buf; |
627 m_SrcSize = src_size; | 627 m_SrcSize = src_size; |
628 m_nComps = 1; | 628 m_nComps = 1; |
629 m_bpc = 1; | 629 m_bpc = 1; |
630 m_bColorTransformed = FALSE; | 630 m_bColorTransformed = FALSE; |
631 return TRUE; | 631 return TRUE; |
632 } | 632 } |
633 FX_BOOL CCodec_FaxDecoder::v_Rewind() | 633 FX_BOOL CCodec_FaxDecoder::v_Rewind() |
634 { | 634 { |
635 FXSYS_memset8(m_pRefBuf, 0xff, m_Pitch); | 635 FXSYS_memset8(m_pRefBuf, 0xff, m_Pitch); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 ret = m_SrcSize; | 691 ret = m_SrcSize; |
692 } | 692 } |
693 return ret; | 693 return ret; |
694 } | 694 } |
695 extern "C" { | 695 extern "C" { |
696 void _FaxG4Decode(void*, FX_LPCBYTE src_buf, FX_DWORD src_size, int* pbitpos
, FX_LPBYTE dest_buf, int width, int height, int pitch) | 696 void _FaxG4Decode(void*, FX_LPCBYTE src_buf, FX_DWORD src_size, int* pbitpos
, FX_LPBYTE dest_buf, int width, int height, int pitch) |
697 { | 697 { |
698 if (pitch == 0) { | 698 if (pitch == 0) { |
699 pitch = (width + 7) / 8; | 699 pitch = (width + 7) / 8; |
700 } | 700 } |
701 FX_LPBYTE ref_buf = FX_Alloc(FX_BYTE, pitch); | 701 FX_LPBYTE ref_buf = FX_Alloc(uint8_t, pitch); |
702 FXSYS_memset8(ref_buf, 0xff, pitch); | 702 FXSYS_memset8(ref_buf, 0xff, pitch); |
703 int bitpos = *pbitpos; | 703 int bitpos = *pbitpos; |
704 for (int iRow = 0; iRow < height; iRow ++) { | 704 for (int iRow = 0; iRow < height; iRow ++) { |
705 FX_LPBYTE line_buf = dest_buf + iRow * pitch; | 705 FX_LPBYTE line_buf = dest_buf + iRow * pitch; |
706 FXSYS_memset8(line_buf, 0xff, pitch); | 706 FXSYS_memset8(line_buf, 0xff, pitch); |
707 _FaxG4GetRow(src_buf, src_size << 3, bitpos, line_buf, ref_buf, widt
h); | 707 _FaxG4GetRow(src_buf, src_size << 3, bitpos, line_buf, ref_buf, widt
h); |
708 FXSYS_memcpy32(ref_buf, line_buf, pitch); | 708 FXSYS_memcpy32(ref_buf, line_buf, pitch); |
709 } | 709 } |
710 FX_Free(ref_buf); | 710 FX_Free(ref_buf); |
711 *pbitpos = bitpos; | 711 *pbitpos = bitpos; |
712 } | 712 } |
713 }; | 713 }; |
714 static const FX_BYTE BlackRunTerminator[128] = { | 714 static const uint8_t BlackRunTerminator[128] = { |
715 0x37, 10, 0x02, 3, 0x03, 2, 0x02, 2, 0x03, 3, 0x03, 4, 0x02, 4, 0x03, 5, | 715 0x37, 10, 0x02, 3, 0x03, 2, 0x02, 2, 0x03, 3, 0x03, 4, 0x02, 4, 0x03, 5, |
716 0x05, 6, 0x04, 6, 0x04, 7, 0x05, 7, 0x07, 7, 0x04, 8, 0x07, 8, 0x18, 9, | 716 0x05, 6, 0x04, 6, 0x04, 7, 0x05, 7, 0x07, 7, 0x04, 8, 0x07, 8, 0x18, 9, |
717 0x17, 10, 0x18, 10, 0x08, 10, 0x67, 11, 0x68, 11, 0x6c, 11, 0x37, 11, 0x28,
11, | 717 0x17, 10, 0x18, 10, 0x08, 10, 0x67, 11, 0x68, 11, 0x6c, 11, 0x37, 11, 0x28,
11, |
718 0x17, 11, 0x18, 11, 0xca, 12, 0xcb, 12, 0xcc, 12, 0xcd, 12, 0x68, 12, 0x69,
12, | 718 0x17, 11, 0x18, 11, 0xca, 12, 0xcb, 12, 0xcc, 12, 0xcd, 12, 0x68, 12, 0x69,
12, |
719 0x6a, 12, 0x6b, 12, 0xd2, 12, 0xd3, 12, 0xd4, 12, 0xd5, 12, 0xd6, 12, 0xd7,
12, | 719 0x6a, 12, 0x6b, 12, 0xd2, 12, 0xd3, 12, 0xd4, 12, 0xd5, 12, 0xd6, 12, 0xd7,
12, |
720 0x6c, 12, 0x6d, 12, 0xda, 12, 0xdb, 12, 0x54, 12, 0x55, 12, 0x56, 12, 0x57,
12, | 720 0x6c, 12, 0x6d, 12, 0xda, 12, 0xdb, 12, 0x54, 12, 0x55, 12, 0x56, 12, 0x57,
12, |
721 0x64, 12, 0x65, 12, 0x52, 12, 0x53, 12, 0x24, 12, 0x37, 12, 0x38, 12, 0x27,
12, | 721 0x64, 12, 0x65, 12, 0x52, 12, 0x53, 12, 0x24, 12, 0x37, 12, 0x38, 12, 0x27,
12, |
722 0x28, 12, 0x58, 12, 0x59, 12, 0x2b, 12, 0x2c, 12, 0x5a, 12, 0x66, 12, 0x67,
12, | 722 0x28, 12, 0x58, 12, 0x59, 12, 0x2b, 12, 0x2c, 12, 0x5a, 12, 0x66, 12, 0x67,
12, |
723 }; | 723 }; |
724 static const FX_BYTE BlackRunMarkup[80] = { | 724 static const uint8_t BlackRunMarkup[80] = { |
725 0x0f, 10, 0xc8, 12, 0xc9, 12, 0x5b, 12, 0x33, 12, 0x34, 12, 0x35, 12, 0x6c,
13, | 725 0x0f, 10, 0xc8, 12, 0xc9, 12, 0x5b, 12, 0x33, 12, 0x34, 12, 0x35, 12, 0x6c,
13, |
726 0x6d, 13, 0x4a, 13, 0x4b, 13, 0x4c, 13, 0x4d, 13, 0x72, 13, 0x73, 13, 0x74,
13, | 726 0x6d, 13, 0x4a, 13, 0x4b, 13, 0x4c, 13, 0x4d, 13, 0x72, 13, 0x73, 13, 0x74,
13, |
727 0x75, 13, 0x76, 13, 0x77, 13, 0x52, 13, 0x53, 13, 0x54, 13, 0x55, 13, 0x5a,
13, | 727 0x75, 13, 0x76, 13, 0x77, 13, 0x52, 13, 0x53, 13, 0x54, 13, 0x55, 13, 0x5a,
13, |
728 0x5b, 13, 0x64, 13, 0x65, 13, 0x08, 11, 0x0c, 11, 0x0d, 11, 0x12, 12, 0x13,
12, | 728 0x5b, 13, 0x64, 13, 0x65, 13, 0x08, 11, 0x0c, 11, 0x0d, 11, 0x12, 12, 0x13,
12, |
729 0x14, 12, 0x15, 12, 0x16, 12, 0x17, 12, 0x1c, 12, 0x1d, 12, 0x1e, 12, 0x1f,
12, | 729 0x14, 12, 0x15, 12, 0x16, 12, 0x17, 12, 0x1c, 12, 0x1d, 12, 0x1e, 12, 0x1f,
12, |
730 }; | 730 }; |
731 static const FX_BYTE WhiteRunTerminator[128] = { | 731 static const uint8_t WhiteRunTerminator[128] = { |
732 0x35, 8, | 732 0x35, 8, |
733 0x07, 6, | 733 0x07, 6, |
734 0x07, 4, | 734 0x07, 4, |
735 0x08, 4, | 735 0x08, 4, |
736 0x0B, 4, | 736 0x0B, 4, |
737 0x0C, 4, | 737 0x0C, 4, |
738 0x0E, 4, | 738 0x0E, 4, |
739 0x0F, 4, | 739 0x0F, 4, |
740 0x13, 5, | 740 0x13, 5, |
741 0x14, 5, | 741 0x14, 5, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 0x58, 8, | 787 0x58, 8, |
788 0x59, 8, | 788 0x59, 8, |
789 0x5a, 8, | 789 0x5a, 8, |
790 0x5b, 8, | 790 0x5b, 8, |
791 0x4a, 8, | 791 0x4a, 8, |
792 0x4b, 8, | 792 0x4b, 8, |
793 0x32, 8, | 793 0x32, 8, |
794 0x33, 8, | 794 0x33, 8, |
795 0x34, 8, | 795 0x34, 8, |
796 }; | 796 }; |
797 static const FX_BYTE WhiteRunMarkup[80] = { | 797 static const uint8_t WhiteRunMarkup[80] = { |
798 0x1b, 5, | 798 0x1b, 5, |
799 0x12, 5, | 799 0x12, 5, |
800 0x17, 6, | 800 0x17, 6, |
801 0x37, 7, | 801 0x37, 7, |
802 0x36, 8, | 802 0x36, 8, |
803 0x37, 8, | 803 0x37, 8, |
804 0x64, 8, | 804 0x64, 8, |
805 0x65, 8, | 805 0x65, 8, |
806 0x68, 8, | 806 0x68, 8, |
807 0x67, 8, | 807 0x67, 8, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 FX_LPBYTE m_pRefLine, m_pLineBuf; | 928 FX_LPBYTE m_pRefLine, m_pLineBuf; |
929 int m_Cols, m_Rows, m_Pitch; | 929 int m_Cols, m_Rows, m_Pitch; |
930 FX_LPCBYTE m_pSrcBuf; | 930 FX_LPCBYTE m_pSrcBuf; |
931 }; | 931 }; |
932 CCodec_FaxEncoder::CCodec_FaxEncoder(FX_LPCBYTE src_buf, int width, int height,
int pitch) | 932 CCodec_FaxEncoder::CCodec_FaxEncoder(FX_LPCBYTE src_buf, int width, int height,
int pitch) |
933 { | 933 { |
934 m_pSrcBuf = src_buf; | 934 m_pSrcBuf = src_buf; |
935 m_Cols = width; | 935 m_Cols = width; |
936 m_Rows = height; | 936 m_Rows = height; |
937 m_Pitch = pitch; | 937 m_Pitch = pitch; |
938 m_pRefLine = FX_Alloc(FX_BYTE, m_Pitch); | 938 m_pRefLine = FX_Alloc(uint8_t, m_Pitch); |
939 FXSYS_memset8(m_pRefLine, 0xff, m_Pitch); | 939 FXSYS_memset8(m_pRefLine, 0xff, m_Pitch); |
940 m_pLineBuf = FX_Alloc2D(FX_BYTE, m_Pitch, 8); | 940 m_pLineBuf = FX_Alloc2D(uint8_t, m_Pitch, 8); |
941 m_DestBuf.EstimateSize(0, 10240); | 941 m_DestBuf.EstimateSize(0, 10240); |
942 } | 942 } |
943 CCodec_FaxEncoder::~CCodec_FaxEncoder() | 943 CCodec_FaxEncoder::~CCodec_FaxEncoder() |
944 { | 944 { |
945 if (m_pRefLine) { | 945 if (m_pRefLine) { |
946 FX_Free(m_pRefLine); | 946 FX_Free(m_pRefLine); |
947 } | 947 } |
948 if (m_pLineBuf) { | 948 if (m_pLineBuf) { |
949 FX_Free(m_pLineBuf); | 949 FX_Free(m_pLineBuf); |
950 } | 950 } |
951 } | 951 } |
952 void CCodec_FaxEncoder::Encode(FX_LPBYTE& dest_buf, FX_DWORD& dest_size) | 952 void CCodec_FaxEncoder::Encode(FX_LPBYTE& dest_buf, FX_DWORD& dest_size) |
953 { | 953 { |
954 int dest_bitpos = 0; | 954 int dest_bitpos = 0; |
955 FX_BYTE last_byte = 0; | 955 uint8_t last_byte = 0; |
956 for (int i = 0; i < m_Rows; i ++) { | 956 for (int i = 0; i < m_Rows; i ++) { |
957 FX_LPCBYTE scan_line = m_pSrcBuf + i * m_Pitch; | 957 FX_LPCBYTE scan_line = m_pSrcBuf + i * m_Pitch; |
958 FXSYS_memset32(m_pLineBuf, 0, m_Pitch * 8); | 958 FXSYS_memset32(m_pLineBuf, 0, m_Pitch * 8); |
959 m_pLineBuf[0] = last_byte; | 959 m_pLineBuf[0] = last_byte; |
960 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols)
; | 960 _FaxEncode2DLine(m_pLineBuf, dest_bitpos, scan_line, m_pRefLine, m_Cols)
; |
961 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); | 961 m_DestBuf.AppendBlock(m_pLineBuf, dest_bitpos / 8); |
962 last_byte = m_pLineBuf[dest_bitpos / 8]; | 962 last_byte = m_pLineBuf[dest_bitpos / 8]; |
963 dest_bitpos %= 8; | 963 dest_bitpos %= 8; |
964 FXSYS_memcpy32(m_pRefLine, scan_line, m_Pitch); | 964 FXSYS_memcpy32(m_pRefLine, scan_line, m_Pitch); |
965 } | 965 } |
(...skipping 10 matching lines...) Expand all Loading... |
976 encoder.Encode(dest_buf, dest_size); | 976 encoder.Encode(dest_buf, dest_size); |
977 return TRUE; | 977 return TRUE; |
978 } | 978 } |
979 ICodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(FX_LPCBYTE src_buf, FX_D
WORD src_size, int width, int height, | 979 ICodec_ScanlineDecoder* CCodec_FaxModule::CreateDecoder(FX_LPCBYTE src_buf, FX_D
WORD src_size, int width, int height, |
980 int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, in
t Columns, int Rows) | 980 int K, FX_BOOL EndOfLine, FX_BOOL EncodedByteAlign, FX_BOOL BlackIs1, in
t Columns, int Rows) |
981 { | 981 { |
982 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; | 982 CCodec_FaxDecoder* pDecoder = new CCodec_FaxDecoder; |
983 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, EncodedByte
Align, BlackIs1, Columns, Rows); | 983 pDecoder->Create(src_buf, src_size, width, height, K, EndOfLine, EncodedByte
Align, BlackIs1, Columns, Rows); |
984 return pDecoder; | 984 return pDecoder; |
985 } | 985 } |
OLD | NEW |