1 /* 2 Copyright (C) 2016-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: dk4strmco.ctr 12 */ 13 14 #ifndef DK4STRMCO_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define DK4STRMCO_H_INCLUDED 1 17 18 19 /** @file dk4strmco.h Compression streams. 20 21 A compression stream is an additional dk4_stream_t object on top of 22 an existring stream (referred to as downside stream). 23 24 Data written to the compression stream is compressed using one or multiple 25 algorithms: 26 27 - Run-length encoding as preprocessing. 28 - Flate compression or LZW compression. 29 - ASCII-Hex or ASCII-85 output encoding. 30 31 The results of the compression operations are passed to the downside stream. 32 33 Note: Closing the compression stream does not close the downside stream. 34 35 So you create a mixed stream (i.e. for PDF files) containing both plain 36 text and compressed chunks. To add a compressed chunk open a compression 37 stream on top of the existing output stream, pass data to the compression 38 stream, close the compression stream and continue writing to the output 39 stream. 40 41 */ 42 43 #ifndef DK4CONF_H_INCLUDED 44 #if DK4_BUILDING_DKTOOLS4 45 #include "dk4conf.h" 46 #else 47 #include <dktools-4/dk4conf.h> 48 #endif 49 #endif 50 51 #ifndef DK4ERROR_H_INCLUDED 52 #if DK4_BUILDING_DKTOOLS4 53 #include <libdk4base/dk4error.h> 54 #else 55 #include <dktools-4/dk4error.h> 56 #endif 57 #endif 58 59 #ifndef DK4STRM_H_INCLUDED 60 #if DK4_BUILDING_DKTOOLS4 61 #include <libdk4c/dk4strm.h> 62 #else 63 #include <dktools-4/dk4strm.h> 64 #endif 65 #endif 66 67 68 /** Preprocessing before compression. 69 */ 70 enum dk4_strmco_pp { 71 DK4_STRMCO_PP_NONE = 0 , /**< No preprocessing. */ 72 DK4_STRMCO_PP_RUNLENGTH /**< Use run-length before real compression. */ 73 }; 74 75 76 /** Compression method. 77 */ 78 enum dk4_strmco_co { 79 DK4_STRMCO_CO_NONE = 0 , /**< No compression. */ 80 DK4_STRMCO_CO_FLATE , /**< Use flate compression. */ 81 DK4_STRMCO_CO_LZW /**< Use LZW compression for PS level 2. */ 82 }; 83 84 85 /** Output encoding. 86 */ 87 enum dk4_strmco_oe { 88 DK4_STRMCO_OE_NONE = 0 , /**< No output encoding. */ 89 DK4_STRMCO_OE_HEX , /**< Hexadecimal encoding. */ 90 DK4_STRMCO_OE_ASCII85 /**< ASCII85 encoding. */ 91 }; 92 93 94 /** Flags for compression stream. 95 */ 96 enum { 97 DK4_STRMCO_FL_EOD_PP = 1 , /**< Write EOD marker at end of preproc. */ 98 DK4_STRMCO_FL_EOD_OE = 2 , /**< Write EOD marker at end of out enc. */ 99 DK4_STRMCO_FL_NL_OE = 4 , /**< Break output lines before 80. */ 100 DK4_STRMCO_FL_CR_NL = 8 , /**< Use CR/NL combination. */ 101 DK4_STRMCO_FL_UPPER_OE = 16 , /**< Upper case characters in hex digits. */ 102 }; 103 104 105 #ifdef __cplusplus 106 extern "C" { 107 #endif 108 109 /** Open a compressing stream on top of an existing stream. 110 Only write operations can be performed on the new stream, no 111 read operations. 112 @param strm Low-level destination stream, must be writable. 113 @param pp Preprocessing method. 114 @param co Compression method. 115 @param oe Output encoding. 116 @param fl Flags. 117 @param erp Error report, may be NULL. 118 @return Valid pointer to new stream on success, NULL on error. 119 120 Error codes: 121 - DK4_E_INVALID_ARGUMENTS<br> 122 if strm is NULL, 123 - DK4_E_MATH_OVERFLOW<br> 124 on numeric overflow when calculating the product of elsize and nelem, 125 - DK4_E_MEMORY_ALLOCATION_FAILED<br> 126 with mem.elsize and mem.nelem set if there is not enough memory 127 available. 128 */ 129 dk4_stream_t * 130 dk4strmco_open( 131 dk4_stream_t *strm, 132 enum dk4_strmco_pp pp, 133 enum dk4_strmco_co co, 134 enum dk4_strmco_oe oe, 135 int fl, 136 dk4_er_t *erp 137 ); 138 139 #ifdef __cplusplus 140 } 141 #endif 142 143 144 /* vim: set ai sw=4 ts=4 : */ 145 146 #endif 147