| 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
| 3 | * Copyright (c) 2015-2016, Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
| 8 | * |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer |
| 10 | * in the documentation and/or other materials provided with the distribution. |
| 11 | * |
| 12 | * 3. Neither the name of the copyright holder(s) nor the names of any contributors may be used to endorse or promote products derived |
| 13 | * from this software without specific prior written permission. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 17 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 19 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 20 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * LZVN low-level decoder (v2) |
| 25 | * Functions in the low-level API should switch to these at some point. |
| 26 | * Apr 2014 |
| 27 | */ |
| 28 | |
| 29 | #ifndef LZVN_DECODE_BASE_H |
| 30 | #define LZVN_DECODE_BASE_H |
| 31 | |
| 32 | #include "lzfse_internal.h" |
| 33 | |
| 34 | /*! @abstract Base decoder state. */ |
| 35 | typedef struct { |
| 36 | /* Decoder I/O */ |
| 37 | |
| 38 | /* Next byte to read in source buffer */ |
| 39 | const unsigned char *src; |
| 40 | /* Next byte after source buffer */ |
| 41 | const unsigned char *src_end; |
| 42 | |
| 43 | /* Next byte to write in destination buffer (by decoder) */ |
| 44 | unsigned char *dst; |
| 45 | /* Valid range for destination buffer is [dst_begin, dst_end - 1] */ |
| 46 | unsigned char *dst_begin; |
| 47 | unsigned char *dst_end; |
| 48 | /* Next byte to read in destination buffer (modified by caller) */ |
| 49 | unsigned char *dst_current; |
| 50 | |
| 51 | /* Decoder state */ |
| 52 | |
| 53 | /* |
| 54 | * Partially expanded match, or 0,0,0. |
| 55 | * In that case, src points to the next literal to copy, or the next |
| 56 | * op-code if L==0. |
| 57 | */ |
| 58 | size_t L, M, D; |
| 59 | |
| 60 | /* Distance for last emitted match, or 0 */ |
| 61 | lzvn_offset d_prev; |
| 62 | |
| 63 | /* Did we decode end-of-stream? */ |
| 64 | int end_of_stream; |
| 65 | |
| 66 | } lzvn_decoder_state; |
| 67 | |
| 68 | /*! @abstract Decode source to destination. |
| 69 | * Updates \p state (src,dst,d_prev). |
| 70 | */ |
| 71 | void lzvn_decode(lzvn_decoder_state *state); |
| 72 | |
| 73 | #endif /* LZVN_DECODE_BASE_H */ |