diff options
-rw-r--r-- | xdelta3/xdelta3-second.h | 45 | ||||
-rw-r--r-- | xdelta3/xdelta3.c | 139 |
2 files changed, 100 insertions, 84 deletions
diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h index a1fe120..f4dc908 100644 --- a/xdelta3/xdelta3-second.h +++ b/xdelta3/xdelta3-second.h | |||
@@ -19,50 +19,6 @@ | |||
19 | #ifndef _XDELTA3_SECOND_H_ | 19 | #ifndef _XDELTA3_SECOND_H_ |
20 | #define _XDELTA3_SECOND_H_ | 20 | #define _XDELTA3_SECOND_H_ |
21 | 21 | ||
22 | /************************************************************** | ||
23 | Secondary compression | ||
24 | **************************************************************/ | ||
25 | |||
26 | #define xd3_sec_data(s) ((s)->sec_stream_d) | ||
27 | #define xd3_sec_inst(s) ((s)->sec_stream_i) | ||
28 | #define xd3_sec_addr(s) ((s)->sec_stream_a) | ||
29 | |||
30 | struct _xd3_sec_type | ||
31 | { | ||
32 | int id; | ||
33 | const char *name; | ||
34 | xd3_secondary_flags flags; | ||
35 | |||
36 | /* xd3_sec_stream is opaque to the generic code */ | ||
37 | xd3_sec_stream* (*alloc) (xd3_stream *stream); | ||
38 | void (*destroy) (xd3_stream *stream, | ||
39 | xd3_sec_stream *sec); | ||
40 | void (*init) (xd3_sec_stream *sec); | ||
41 | int (*decode) (xd3_stream *stream, | ||
42 | xd3_sec_stream *sec_stream, | ||
43 | const uint8_t **input, | ||
44 | const uint8_t *input_end, | ||
45 | uint8_t **output, | ||
46 | const uint8_t *output_end); | ||
47 | #if XD3_ENCODER | ||
48 | int (*encode) (xd3_stream *stream, | ||
49 | xd3_sec_stream *sec_stream, | ||
50 | xd3_output *input, | ||
51 | xd3_output *output, | ||
52 | xd3_sec_cfg *cfg); | ||
53 | #endif | ||
54 | }; | ||
55 | |||
56 | #define BIT_STATE_ENCODE_INIT { 0, 1 } | ||
57 | #define BIT_STATE_DECODE_INIT { 0, 0x100 } | ||
58 | |||
59 | typedef struct _bit_state bit_state; | ||
60 | struct _bit_state | ||
61 | { | ||
62 | usize_t cur_byte; | ||
63 | usize_t cur_mask; | ||
64 | }; | ||
65 | |||
66 | static inline void xd3_bit_state_encode_init (bit_state *bits) | 22 | static inline void xd3_bit_state_encode_init (bit_state *bits) |
67 | { | 23 | { |
68 | bits->cur_byte = 0; | 24 | bits->cur_byte = 0; |
@@ -204,7 +160,6 @@ xd3_decode_secondary (xd3_stream *stream, | |||
204 | } | 160 | } |
205 | 161 | ||
206 | #if XD3_ENCODER | 162 | #if XD3_ENCODER |
207 | /* OPT: Should these be inline? */ | ||
208 | static inline int xd3_encode_bit (xd3_stream *stream, | 163 | static inline int xd3_encode_bit (xd3_stream *stream, |
209 | xd3_output **output, | 164 | xd3_output **output, |
210 | bit_state *bits, | 165 | bit_state *bits, |
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 1e92c25..e843e1f 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -647,30 +647,69 @@ const char* xd3_strerror (int ret) | |||
647 | 647 | ||
648 | /***********************************************************************/ | 648 | /***********************************************************************/ |
649 | 649 | ||
650 | #define xd3_sec_data(s) ((s)->sec_stream_d) | ||
651 | #define xd3_sec_inst(s) ((s)->sec_stream_i) | ||
652 | #define xd3_sec_addr(s) ((s)->sec_stream_a) | ||
653 | |||
654 | struct _xd3_sec_type | ||
655 | { | ||
656 | int id; | ||
657 | const char *name; | ||
658 | xd3_secondary_flags flags; | ||
659 | |||
660 | /* xd3_sec_stream is opaque to the generic code */ | ||
661 | xd3_sec_stream* (*alloc) (xd3_stream *stream); | ||
662 | void (*destroy) (xd3_stream *stream, | ||
663 | xd3_sec_stream *sec); | ||
664 | void (*init) (xd3_sec_stream *sec); | ||
665 | int (*decode) (xd3_stream *stream, | ||
666 | xd3_sec_stream *sec_stream, | ||
667 | const uint8_t **input, | ||
668 | const uint8_t *input_end, | ||
669 | uint8_t **output, | ||
670 | const uint8_t *output_end); | ||
671 | #if XD3_ENCODER | ||
672 | int (*encode) (xd3_stream *stream, | ||
673 | xd3_sec_stream *sec_stream, | ||
674 | xd3_output *input, | ||
675 | xd3_output *output, | ||
676 | xd3_sec_cfg *cfg); | ||
677 | #endif | ||
678 | }; | ||
679 | |||
680 | #define BIT_STATE_ENCODE_INIT { 0, 1 } | ||
681 | #define BIT_STATE_DECODE_INIT { 0, 0x100 } | ||
682 | |||
683 | typedef struct _bit_state bit_state; | ||
684 | struct _bit_state | ||
685 | { | ||
686 | usize_t cur_byte; | ||
687 | usize_t cur_mask; | ||
688 | }; | ||
689 | |||
650 | #if SECONDARY_ANY == 0 | 690 | #if SECONDARY_ANY == 0 |
651 | #define IF_SEC(x) | 691 | #define IF_SEC(x) |
652 | #define IF_NSEC(x) x | 692 | #define IF_NSEC(x) x |
653 | #else /* yuck */ | 693 | #else /* yuck */ |
654 | #define IF_SEC(x) x | 694 | #define IF_SEC(x) x |
655 | #define IF_NSEC(x) | 695 | #define IF_NSEC(x) |
656 | #include "xdelta3-second.h" | 696 | static int |
697 | xd3_decode_secondary (xd3_stream *stream, | ||
698 | xd3_desect *sect, | ||
699 | xd3_sec_stream **sec_streamp); | ||
700 | #if XD3_ENCODER | ||
701 | static int | ||
702 | xd3_encode_secondary (xd3_stream *stream, | ||
703 | xd3_output **head, | ||
704 | xd3_output **tail, | ||
705 | xd3_sec_stream **sec_streamp, | ||
706 | xd3_sec_cfg *cfg, | ||
707 | int *did_it); | ||
708 | #endif | ||
657 | #endif /* SECONDARY_ANY */ | 709 | #endif /* SECONDARY_ANY */ |
658 | 710 | ||
659 | #if SECONDARY_FGK | 711 | #if SECONDARY_FGK |
660 | #include "xdelta3-fgk.h" | 712 | static const xd3_sec_type fgk_sec_type; |
661 | |||
662 | static const xd3_sec_type fgk_sec_type = | ||
663 | { | ||
664 | VCD_FGK_ID, | ||
665 | "FGK Adaptive Huffman", | ||
666 | SEC_NOFLAGS, | ||
667 | (xd3_sec_stream* (*)()) fgk_alloc, | ||
668 | (void (*)()) fgk_destroy, | ||
669 | (void (*)()) fgk_init, | ||
670 | (int (*)()) xd3_decode_fgk, | ||
671 | IF_ENCODER((int (*)()) xd3_encode_fgk) | ||
672 | }; | ||
673 | |||
674 | #define IF_FGK(x) x | 713 | #define IF_FGK(x) x |
675 | #define FGK_CASE(s) \ | 714 | #define FGK_CASE(s) \ |
676 | s->sec_type = & fgk_sec_type; \ | 715 | s->sec_type = & fgk_sec_type; \ |
@@ -683,20 +722,7 @@ static const xd3_sec_type fgk_sec_type = | |||
683 | #endif | 722 | #endif |
684 | 723 | ||
685 | #if SECONDARY_DJW | 724 | #if SECONDARY_DJW |
686 | #include "xdelta3-djw.h" | 725 | static const xd3_sec_type djw_sec_type; |
687 | |||
688 | static const xd3_sec_type djw_sec_type = | ||
689 | { | ||
690 | VCD_DJW_ID, | ||
691 | "Static Huffman", | ||
692 | SEC_COUNT_FREQS, | ||
693 | (xd3_sec_stream* (*)()) djw_alloc, | ||
694 | (void (*)()) djw_destroy, | ||
695 | (void (*)()) djw_init, | ||
696 | (int (*)()) xd3_decode_huff, | ||
697 | IF_ENCODER((int (*)()) xd3_encode_huff) | ||
698 | }; | ||
699 | |||
700 | #define IF_DJW(x) x | 726 | #define IF_DJW(x) x |
701 | #define DJW_CASE(s) \ | 727 | #define DJW_CASE(s) \ |
702 | s->sec_type = & djw_sec_type; \ | 728 | s->sec_type = & djw_sec_type; \ |
@@ -715,6 +741,41 @@ static const xd3_sec_type djw_sec_type = | |||
715 | #include "xdelta3.c" | 741 | #include "xdelta3.c" |
716 | #undef __XDELTA3_C_INLINE_PASS__ | 742 | #undef __XDELTA3_C_INLINE_PASS__ |
717 | 743 | ||
744 | /* Secondary compression */ | ||
745 | #if SECONDARY_ANY | ||
746 | #include "xdelta3-second.h" | ||
747 | #endif | ||
748 | |||
749 | #if SECONDARY_FGK | ||
750 | #include "xdelta3-fgk.h" | ||
751 | static const xd3_sec_type fgk_sec_type = | ||
752 | { | ||
753 | VCD_FGK_ID, | ||
754 | "FGK Adaptive Huffman", | ||
755 | SEC_NOFLAGS, | ||
756 | (xd3_sec_stream* (*)()) fgk_alloc, | ||
757 | (void (*)()) fgk_destroy, | ||
758 | (void (*)()) fgk_init, | ||
759 | (int (*)()) xd3_decode_fgk, | ||
760 | IF_ENCODER((int (*)()) xd3_encode_fgk) | ||
761 | }; | ||
762 | #endif | ||
763 | |||
764 | #if SECONDARY_DJW | ||
765 | #include "xdelta3-djw.h" | ||
766 | static const xd3_sec_type djw_sec_type = | ||
767 | { | ||
768 | VCD_DJW_ID, | ||
769 | "Static Huffman", | ||
770 | SEC_COUNT_FREQS, | ||
771 | (xd3_sec_stream* (*)()) djw_alloc, | ||
772 | (void (*)()) djw_destroy, | ||
773 | (void (*)()) djw_init, | ||
774 | (int (*)()) xd3_decode_huff, | ||
775 | IF_ENCODER((int (*)()) xd3_encode_huff) | ||
776 | }; | ||
777 | #endif | ||
778 | |||
718 | /* Process template passes - this includes xdelta3.c several times. */ | 779 | /* Process template passes - this includes xdelta3.c several times. */ |
719 | #define __XDELTA3_C_TEMPLATE_PASS__ | 780 | #define __XDELTA3_C_TEMPLATE_PASS__ |
720 | #include "xdelta3-cfgs.h" | 781 | #include "xdelta3-cfgs.h" |
@@ -1743,7 +1804,7 @@ xd3_comprun (const uint8_t *seg, int slook, uint8_t *run_cp) | |||
1743 | Basic encoder/decoder functions | 1804 | Basic encoder/decoder functions |
1744 | ***********************************************************************/ | 1805 | ***********************************************************************/ |
1745 | 1806 | ||
1746 | static int | 1807 | static inline int |
1747 | xd3_decode_byte (xd3_stream *stream, uint *val) | 1808 | xd3_decode_byte (xd3_stream *stream, uint *val) |
1748 | { | 1809 | { |
1749 | if (stream->avail_in == 0) | 1810 | if (stream->avail_in == 0) |
@@ -1758,7 +1819,7 @@ xd3_decode_byte (xd3_stream *stream, uint *val) | |||
1758 | return 0; | 1819 | return 0; |
1759 | } | 1820 | } |
1760 | 1821 | ||
1761 | static int | 1822 | static inline int |
1762 | xd3_decode_bytes (xd3_stream *stream, uint8_t *buf, usize_t *pos, usize_t size) | 1823 | xd3_decode_bytes (xd3_stream *stream, uint8_t *buf, usize_t *pos, usize_t size) |
1763 | { | 1824 | { |
1764 | usize_t want; | 1825 | usize_t want; |
@@ -1788,7 +1849,7 @@ xd3_decode_bytes (xd3_stream *stream, uint8_t *buf, usize_t *pos, usize_t size) | |||
1788 | } | 1849 | } |
1789 | 1850 | ||
1790 | #if XD3_ENCODER | 1851 | #if XD3_ENCODER |
1791 | static int | 1852 | static inline int |
1792 | xd3_emit_byte (xd3_stream *stream, | 1853 | xd3_emit_byte (xd3_stream *stream, |
1793 | xd3_output **outputp, | 1854 | xd3_output **outputp, |
1794 | uint8_t code) | 1855 | uint8_t code) |
@@ -1812,7 +1873,7 @@ xd3_emit_byte (xd3_stream *stream, | |||
1812 | return 0; | 1873 | return 0; |
1813 | } | 1874 | } |
1814 | 1875 | ||
1815 | static int | 1876 | static inline int |
1816 | xd3_emit_bytes (xd3_stream *stream, | 1877 | xd3_emit_bytes (xd3_stream *stream, |
1817 | xd3_output **outputp, | 1878 | xd3_output **outputp, |
1818 | const uint8_t *base, | 1879 | const uint8_t *base, |
@@ -1935,7 +1996,7 @@ xd3_emit_bytes (xd3_stream *stream, | |||
1935 | #define IF_SIZEOF64(x) if (num < (1ULL << (7 * (x)))) return (x); | 1996 | #define IF_SIZEOF64(x) if (num < (1ULL << (7 * (x)))) return (x); |
1936 | 1997 | ||
1937 | #if USE_UINT32 | 1998 | #if USE_UINT32 |
1938 | static uint | 1999 | static inline uint |
1939 | xd3_sizeof_uint32_t (uint32_t num) | 2000 | xd3_sizeof_uint32_t (uint32_t num) |
1940 | { | 2001 | { |
1941 | IF_SIZEOF32(1); | 2002 | IF_SIZEOF32(1); |
@@ -1945,29 +2006,29 @@ xd3_sizeof_uint32_t (uint32_t num) | |||
1945 | return 5; | 2006 | return 5; |
1946 | } | 2007 | } |
1947 | 2008 | ||
1948 | static int | 2009 | static inline int |
1949 | xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val) | 2010 | xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val) |
1950 | { DECODE_INTEGER_TYPE (stream->dec_32part, UINT32_OFLOW_MASK); } | 2011 | { DECODE_INTEGER_TYPE (stream->dec_32part, UINT32_OFLOW_MASK); } |
1951 | 2012 | ||
1952 | static int | 2013 | static inline int |
1953 | xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp, | 2014 | xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp, |
1954 | const uint8_t *max, uint32_t *valp) | 2015 | const uint8_t *max, uint32_t *valp) |
1955 | { READ_INTEGER_TYPE (uint32_t, UINT32_OFLOW_MASK); } | 2016 | { READ_INTEGER_TYPE (uint32_t, UINT32_OFLOW_MASK); } |
1956 | 2017 | ||
1957 | #if XD3_ENCODER | 2018 | #if XD3_ENCODER |
1958 | static int | 2019 | static inline int |
1959 | xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num) | 2020 | xd3_emit_uint32_t (xd3_stream *stream, xd3_output **output, uint32_t num) |
1960 | { EMIT_INTEGER_TYPE (); } | 2021 | { EMIT_INTEGER_TYPE (); } |
1961 | #endif | 2022 | #endif |
1962 | #endif | 2023 | #endif |
1963 | 2024 | ||
1964 | #if USE_UINT64 | 2025 | #if USE_UINT64 |
1965 | static int | 2026 | static inline int |
1966 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) | 2027 | xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val) |
1967 | { DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); } | 2028 | { DECODE_INTEGER_TYPE (stream->dec_64part, UINT64_OFLOW_MASK); } |
1968 | 2029 | ||
1969 | #if XD3_ENCODER | 2030 | #if XD3_ENCODER |
1970 | static int | 2031 | static inline int |
1971 | xd3_emit_uint64_t (xd3_stream *stream, xd3_output **output, uint64_t num) | 2032 | xd3_emit_uint64_t (xd3_stream *stream, xd3_output **output, uint64_t num) |
1972 | { EMIT_INTEGER_TYPE (); } | 2033 | { EMIT_INTEGER_TYPE (); } |
1973 | #endif | 2034 | #endif |