Add deflateUsed() function to get the used bits in the last byte.

This returns the number of used bits in the last byte of a stream
that has just been compressed with deflate.
This commit is contained in:
Mark Adler 2024-07-01 19:24:01 -05:00
parent 534864bccd
commit e011d8c164
17 changed files with 239 additions and 178 deletions

View File

@ -1,7 +1,7 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
VERSION 1.3
EXPORTS
adler32 @1
@ -153,6 +153,9 @@ EXPORTS
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -1,7 +1,7 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
VERSION 1.3
EXPORTS
adler32 @1
@ -153,6 +153,9 @@ EXPORTS
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -1,7 +1,7 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
VERSION 1.3
EXPORTS
adler32 @1
@ -153,6 +153,9 @@ EXPORTS
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -1,7 +1,7 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
VERSION 1.3
EXPORTS
adler32 @1
@ -153,6 +153,9 @@ EXPORTS
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -1,158 +1,161 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
EXPORTS
adler32 @1
compress @2
crc32 @3
deflate @4
deflateCopy @5
deflateEnd @6
deflateInit2_ @7
deflateInit_ @8
deflateParams @9
deflateReset @10
deflateSetDictionary @11
gzclose @12
gzdopen @13
gzerror @14
gzflush @15
gzopen @16
gzread @17
gzwrite @18
inflate @19
inflateEnd @20
inflateInit2_ @21
inflateInit_ @22
inflateReset @23
inflateSetDictionary @24
inflateSync @25
uncompress @26
zlibVersion @27
gzprintf @28
gzputc @29
gzgetc @30
gzseek @31
gzrewind @32
gztell @33
gzeof @34
gzsetparams @35
zError @36
inflateSyncPoint @37
get_crc_table @38
compress2 @39
gzputs @40
gzgets @41
inflateCopy @42
inflateBackInit_ @43
inflateBack @44
inflateBackEnd @45
compressBound @46
deflateBound @47
gzclearerr @48
gzungetc @49
zlibCompileFlags @50
deflatePrime @51
deflatePending @52
unzOpen @61
unzClose @62
unzGetGlobalInfo @63
unzGetCurrentFileInfo @64
unzGoToFirstFile @65
unzGoToNextFile @66
unzOpenCurrentFile @67
unzReadCurrentFile @68
unzOpenCurrentFile3 @69
unztell @70
unzeof @71
unzCloseCurrentFile @72
unzGetGlobalComment @73
unzStringFileNameCompare @74
unzLocateFile @75
unzGetLocalExtrafield @76
unzOpen2 @77
unzOpenCurrentFile2 @78
unzOpenCurrentFilePassword @79
zipOpen @80
zipOpenNewFileInZip @81
zipWriteInFileInZip @82
zipCloseFileInZip @83
zipClose @84
zipOpenNewFileInZip2 @86
zipCloseFileInZipRaw @87
zipOpen2 @88
zipOpenNewFileInZip3 @89
unzGetFilePos @100
unzGoToFilePos @101
fill_win32_filefunc @110
; zlibwapi v1.2.4 added:
fill_win32_filefunc64 @111
fill_win32_filefunc64A @112
fill_win32_filefunc64W @113
unzOpen64 @120
unzOpen2_64 @121
unzGetGlobalInfo64 @122
unzGetCurrentFileInfo64 @124
unzGetCurrentFileZStreamPos64 @125
unztell64 @126
unzGetFilePos64 @127
unzGoToFilePos64 @128
zipOpen64 @130
zipOpen2_64 @131
zipOpenNewFileInZip64 @132
zipOpenNewFileInZip2_64 @133
zipOpenNewFileInZip3_64 @134
zipOpenNewFileInZip4_64 @135
zipCloseFileInZipRaw64 @136
; zlib1 v1.2.4 added:
adler32_combine @140
crc32_combine @142
deflateSetHeader @144
deflateTune @145
gzbuffer @146
gzclose_r @147
gzclose_w @148
gzdirect @149
gzoffset @150
inflateGetHeader @156
inflateMark @157
inflatePrime @158
inflateReset2 @159
inflateUndermine @160
; zlib1 v1.2.6 added:
gzgetc_ @161
inflateResetKeep @163
deflateResetKeep @164
; zlib1 v1.2.7 added:
gzopen_w @165
; zlib1 v1.2.8 added:
inflateGetDictionary @166
gzvprintf @167
; zlib1 v1.2.9 added:
inflateCodesUsed @168
inflateValidate @169
uncompress2 @170
gzfread @171
gzfwrite @172
deflateGetDictionary @173
adler32_z @174
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
EXPORTS
adler32 @1
compress @2
crc32 @3
deflate @4
deflateCopy @5
deflateEnd @6
deflateInit2_ @7
deflateInit_ @8
deflateParams @9
deflateReset @10
deflateSetDictionary @11
gzclose @12
gzdopen @13
gzerror @14
gzflush @15
gzopen @16
gzread @17
gzwrite @18
inflate @19
inflateEnd @20
inflateInit2_ @21
inflateInit_ @22
inflateReset @23
inflateSetDictionary @24
inflateSync @25
uncompress @26
zlibVersion @27
gzprintf @28
gzputc @29
gzgetc @30
gzseek @31
gzrewind @32
gztell @33
gzeof @34
gzsetparams @35
zError @36
inflateSyncPoint @37
get_crc_table @38
compress2 @39
gzputs @40
gzgets @41
inflateCopy @42
inflateBackInit_ @43
inflateBack @44
inflateBackEnd @45
compressBound @46
deflateBound @47
gzclearerr @48
gzungetc @49
zlibCompileFlags @50
deflatePrime @51
deflatePending @52
unzOpen @61
unzClose @62
unzGetGlobalInfo @63
unzGetCurrentFileInfo @64
unzGoToFirstFile @65
unzGoToNextFile @66
unzOpenCurrentFile @67
unzReadCurrentFile @68
unzOpenCurrentFile3 @69
unztell @70
unzeof @71
unzCloseCurrentFile @72
unzGetGlobalComment @73
unzStringFileNameCompare @74
unzLocateFile @75
unzGetLocalExtrafield @76
unzOpen2 @77
unzOpenCurrentFile2 @78
unzOpenCurrentFilePassword @79
zipOpen @80
zipOpenNewFileInZip @81
zipWriteInFileInZip @82
zipCloseFileInZip @83
zipClose @84
zipOpenNewFileInZip2 @86
zipCloseFileInZipRaw @87
zipOpen2 @88
zipOpenNewFileInZip3 @89
unzGetFilePos @100
unzGoToFilePos @101
fill_win32_filefunc @110
; zlibwapi v1.2.4 added:
fill_win32_filefunc64 @111
fill_win32_filefunc64A @112
fill_win32_filefunc64W @113
unzOpen64 @120
unzOpen2_64 @121
unzGetGlobalInfo64 @122
unzGetCurrentFileInfo64 @124
unzGetCurrentFileZStreamPos64 @125
unztell64 @126
unzGetFilePos64 @127
unzGoToFilePos64 @128
zipOpen64 @130
zipOpen2_64 @131
zipOpenNewFileInZip64 @132
zipOpenNewFileInZip2_64 @133
zipOpenNewFileInZip3_64 @134
zipOpenNewFileInZip4_64 @135
zipCloseFileInZipRaw64 @136
; zlib1 v1.2.4 added:
adler32_combine @140
crc32_combine @142
deflateSetHeader @144
deflateTune @145
gzbuffer @146
gzclose_r @147
gzclose_w @148
gzdirect @149
gzoffset @150
inflateGetHeader @156
inflateMark @157
inflatePrime @158
inflateReset2 @159
inflateUndermine @160
; zlib1 v1.2.6 added:
gzgetc_ @161
inflateResetKeep @163
deflateResetKeep @164
; zlib1 v1.2.7 added:
gzopen_w @165
; zlib1 v1.2.8 added:
inflateGetDictionary @166
gzvprintf @167
; zlib1 v1.2.9 added:
inflateCodesUsed @168
inflateValidate @169
uncompress2 @170
gzfread @171
gzfwrite @172
deflateGetDictionary @173
adler32_z @174
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -1,7 +1,7 @@
LIBRARY
; zlib data compression and ZIP file I/O library
VERSION 1.3
VERSION 1.3
EXPORTS
adler32 @1
@ -153,6 +153,9 @@ EXPORTS
crc32_z @175
; zlib1 v1.2.12 added:
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
crc32_combine_gen @176
crc32_combine_gen64 @177
crc32_combine_op @178
; zlib1 v1.3.2 added:
deflateUsed @179

View File

@ -719,6 +719,14 @@ int ZEXPORT deflatePending(z_streamp strm, unsigned *pending, int *bits) {
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflateUsed(z_streamp strm, int *bits) {
if (deflateStateCheck(strm)) return Z_STREAM_ERROR;
if (bits != Z_NULL)
*bits = strm->state->bi_used;
return Z_OK;
}
/* ========================================================================= */
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value) {
deflate_state *s;

View File

@ -271,6 +271,9 @@ typedef struct internal_state {
/* Number of valid bits in bi_buf. All bits above the last valid bit
* are always zero.
*/
int bi_used;
/* Last number of used bits when going to a byte boundary.
*/
ulg high_water;
/* High water mark offset in window for initialized bytes -- bytes above

View File

@ -124,4 +124,10 @@ STRPGMEXP PGMLVL(*CURRENT) SIGNATURE('ZLIB')
EXPORT SYMBOL("crc32_combine_gen")
EXPORT SYMBOL("crc32_combine_op")
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
/* Version 1.3.2 additional entry points. */
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
EXPORT SYMBOL("deflateUsed")
ENDPGMEXP

View File

@ -371,6 +371,10 @@
D pending 10U 0 Pending bytes
D bits 10I 0 Pending bits
*
D deflateUsed PR 10I 0 extproc('deflateUsed') Get used bits
D strm like(z_stream) Compression stream
D bits 10I 0 Used bits
*
D deflatePrime PR 10I 0 extproc('deflatePrime') Change level & strat
D strm like(z_stream) Compression stream
D bits 10I 0 value # of bits to insert

View File

@ -184,6 +184,7 @@ local void bi_windup(deflate_state *s) {
} else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf);
}
s->bi_used = ((s->bi_valid - 1) & 7) + 1;
s->bi_buf = 0;
s->bi_valid = 0;
#ifdef ZLIB_DEBUG
@ -466,6 +467,7 @@ void ZLIB_INTERNAL _tr_init(deflate_state *s) {
s->bi_buf = 0;
s->bi_valid = 0;
s->bi_used = 0;
#ifdef ZLIB_DEBUG
s->compressed_len = 0L;
s->bits_sent = 0L;

View File

@ -15,6 +15,7 @@ EXPORTS
deflateTune
deflateBound
deflatePending
deflateUsed
deflatePrime
deflateSetHeader
inflateSetDictionary

View File

@ -59,6 +59,7 @@
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO

View File

@ -61,6 +61,7 @@
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO

View File

@ -59,6 +59,7 @@
# define deflateSetDictionary z_deflateSetDictionary
# define deflateSetHeader z_deflateSetHeader
# define deflateTune z_deflateTune
# define deflateUsed z_deflateUsed
# define deflate_copyright z_deflate_copyright
# define get_crc_table z_get_crc_table
# ifndef Z_SOLO

12
zlib.h
View File

@ -791,6 +791,18 @@ ZEXTERN int ZEXPORT deflatePending(z_streamp strm,
stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflateUsed(z_streamp strm,
int *bits);
/*
deflateUsed() returns in *bits the most recent number of deflate bits used
in the last byte when flushing to a byte boundary. The result is in 1..8, or
0 if there has not yet been a flush. This helps determine the location of
the last bit of a deflate stream.
deflateUsed returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent.
*/
ZEXTERN int ZEXPORT deflatePrime(z_streamp strm,
int bits,
int value);

View File

@ -98,3 +98,7 @@ ZLIB_1.2.12 {
crc32_combine_gen64;
crc32_combine_op;
} ZLIB_1.2.9;
ZLIB_1.3.2 {
deflateUsed;
} ZLIB_1.2.12;