]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/lzma/lzma_encoder.c
Renamed constants:
[icculus/xz.git] / src / liblzma / lzma / lzma_encoder.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       lzma_encoder.c
4 /// \brief      LZMA encoder
5 //
6 //  Copyright (C) 1999-2006 Igor Pavlov
7 //  Copyright (C) 2007 Lasse Collin
8 //
9 //  This library is free software; you can redistribute it and/or
10 //  modify it under the terms of the GNU Lesser General Public
11 //  License as published by the Free Software Foundation; either
12 //  version 2.1 of the License, or (at your option) any later version.
13 //
14 //  This library is distributed in the hope that it will be useful,
15 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 //  Lesser General Public License for more details.
18 //
19 ///////////////////////////////////////////////////////////////////////////////
20
21 #include "lzma_encoder_private.h"
22 #include "fastpos.h"
23
24
25 /////////////
26 // Literal //
27 /////////////
28
29 static inline void
30 literal_matched(lzma_range_encoder *rc, probability *subcoder,
31                 uint32_t match_byte, uint32_t symbol)
32 {
33         uint32_t offset = 0x100;
34         symbol += UINT32_C(1) << 8;
35
36         do {
37                 match_byte <<= 1;
38                 const uint32_t match_bit = match_byte & offset;
39                 const uint32_t subcoder_index
40                                 = offset + match_bit + (symbol >> 8);
41                 const uint32_t bit = (symbol >> 7) & 1;
42                 rc_bit(rc, &subcoder[subcoder_index], bit);
43
44                 symbol <<= 1;
45                 offset &= ~(match_byte ^ symbol);
46
47         } while (symbol < (UINT32_C(1) << 16));
48 }
49
50
51 static inline void
52 literal(lzma_coder *coder, lzma_mf *mf, uint32_t position)
53 {
54         // Locate the literal byte to be encoded and the subcoder.
55         const uint8_t cur_byte = mf->buffer[
56                         mf->read_pos - mf->read_ahead];
57         probability *subcoder = literal_subcoder(coder->literal,
58                         coder->literal_context_bits, coder->literal_pos_mask,
59                         position, mf->buffer[mf->read_pos - mf->read_ahead - 1]);
60
61         if (is_literal_state(coder->state)) {
62                 // Previous LZMA-symbol was a literal. Encode a normal
63                 // literal without a match byte.
64                 rc_bittree(&coder->rc, subcoder, 8, cur_byte);
65         } else {
66                 // Previous LZMA-symbol was a match. Use the last byte of
67                 // the match as a "match byte". That is, compare the bits
68                 // of the current literal and the match byte.
69                 const uint8_t match_byte = mf->buffer[
70                                 mf->read_pos - coder->reps[0] - 1
71                                 - mf->read_ahead];
72                 literal_matched(&coder->rc, subcoder, match_byte, cur_byte);
73         }
74
75         update_literal(coder->state);
76 }
77
78
79 //////////////////
80 // Match length //
81 //////////////////
82
83 static void
84 length_update_prices(lzma_length_encoder *lc, const uint32_t pos_state)
85 {
86         const uint32_t table_size = lc->table_size;
87         lc->counters[pos_state] = table_size;
88
89         const uint32_t a0 = rc_bit_0_price(lc->choice);
90         const uint32_t a1 = rc_bit_1_price(lc->choice);
91         const uint32_t b0 = a1 + rc_bit_0_price(lc->choice2);
92         const uint32_t b1 = a1 + rc_bit_1_price(lc->choice2);
93         uint32_t *const prices = lc->prices[pos_state];
94
95         uint32_t i;
96         for (i = 0; i < table_size && i < LEN_LOW_SYMBOLS; ++i)
97                 prices[i] = a0 + rc_bittree_price(lc->low[pos_state],
98                                 LEN_LOW_BITS, i);
99
100         for (; i < table_size && i < LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; ++i)
101                 prices[i] = b0 + rc_bittree_price(lc->mid[pos_state],
102                                 LEN_MID_BITS, i - LEN_LOW_SYMBOLS);
103
104         for (; i < table_size; ++i)
105                 prices[i] = b1 + rc_bittree_price(lc->high, LEN_HIGH_BITS,
106                                 i - LEN_LOW_SYMBOLS - LEN_MID_SYMBOLS);
107
108         return;
109 }
110
111
112 static inline void
113 length(lzma_range_encoder *rc, lzma_length_encoder *lc,
114                 const uint32_t pos_state, uint32_t len, const bool fast_mode)
115 {
116         assert(len <= MATCH_LEN_MAX);
117         len -= MATCH_LEN_MIN;
118
119         if (len < LEN_LOW_SYMBOLS) {
120                 rc_bit(rc, &lc->choice, 0);
121                 rc_bittree(rc, lc->low[pos_state], LEN_LOW_BITS, len);
122         } else {
123                 rc_bit(rc, &lc->choice, 1);
124                 len -= LEN_LOW_SYMBOLS;
125
126                 if (len < LEN_MID_SYMBOLS) {
127                         rc_bit(rc, &lc->choice2, 0);
128                         rc_bittree(rc, lc->mid[pos_state], LEN_MID_BITS, len);
129                 } else {
130                         rc_bit(rc, &lc->choice2, 1);
131                         len -= LEN_MID_SYMBOLS;
132                         rc_bittree(rc, lc->high, LEN_HIGH_BITS, len);
133                 }
134         }
135
136         // Only getoptimum uses the prices so don't update the table when
137         // in fast mode.
138         if (!fast_mode)
139                 if (--lc->counters[pos_state] == 0)
140                         length_update_prices(lc, pos_state);
141 }
142
143
144 ///////////
145 // Match //
146 ///////////
147
148 static inline void
149 match(lzma_coder *coder, const uint32_t pos_state,
150                 const uint32_t distance, const uint32_t len)
151 {
152         update_match(coder->state);
153
154         length(&coder->rc, &coder->match_len_encoder, pos_state, len,
155                         coder->fast_mode);
156
157         const uint32_t pos_slot = get_pos_slot(distance);
158         const uint32_t len_to_pos_state = get_len_to_pos_state(len);
159         rc_bittree(&coder->rc, coder->pos_slot[len_to_pos_state],
160                         POS_SLOT_BITS, pos_slot);
161
162         if (pos_slot >= START_POS_MODEL_INDEX) {
163                 const uint32_t footer_bits = (pos_slot >> 1) - 1;
164                 const uint32_t base = (2 | (pos_slot & 1)) << footer_bits;
165                 const uint32_t pos_reduced = distance - base;
166
167                 if (pos_slot < END_POS_MODEL_INDEX) {
168                         // Careful here: base - pos_slot - 1 can be -1, but
169                         // rc_bittree_reverse starts at probs[1], not probs[0].
170                         rc_bittree_reverse(&coder->rc,
171                                 coder->pos_special + base - pos_slot - 1,
172                                 footer_bits, pos_reduced);
173                 } else {
174                         rc_direct(&coder->rc, pos_reduced >> ALIGN_BITS,
175                                         footer_bits - ALIGN_BITS);
176                         rc_bittree_reverse(
177                                         &coder->rc, coder->pos_align,
178                                         ALIGN_BITS, pos_reduced & ALIGN_MASK);
179                         ++coder->align_price_count;
180                 }
181         }
182
183         coder->reps[3] = coder->reps[2];
184         coder->reps[2] = coder->reps[1];
185         coder->reps[1] = coder->reps[0];
186         coder->reps[0] = distance;
187         ++coder->match_price_count;
188 }
189
190
191 ////////////////////
192 // Repeated match //
193 ////////////////////
194
195 static inline void
196 rep_match(lzma_coder *coder, const uint32_t pos_state,
197                 const uint32_t rep, const uint32_t len)
198 {
199         if (rep == 0) {
200                 rc_bit(&coder->rc, &coder->is_rep0[coder->state], 0);
201                 rc_bit(&coder->rc,
202                                 &coder->is_rep0_long[coder->state][pos_state],
203                                 len != 1);
204         } else {
205                 const uint32_t distance = coder->reps[rep];
206                 rc_bit(&coder->rc, &coder->is_rep0[coder->state], 1);
207
208                 if (rep == 1) {
209                         rc_bit(&coder->rc, &coder->is_rep1[coder->state], 0);
210                 } else {
211                         rc_bit(&coder->rc, &coder->is_rep1[coder->state], 1);
212                         rc_bit(&coder->rc, &coder->is_rep2[coder->state],
213                                         rep - 2);
214
215                         if (rep == 3)
216                                 coder->reps[3] = coder->reps[2];
217
218                         coder->reps[2] = coder->reps[1];
219                 }
220
221                 coder->reps[1] = coder->reps[0];
222                 coder->reps[0] = distance;
223         }
224
225         if (len == 1) {
226                 update_short_rep(coder->state);
227         } else {
228                 length(&coder->rc, &coder->rep_len_encoder, pos_state, len,
229                                 coder->fast_mode);
230                 update_long_rep(coder->state);
231         }
232 }
233
234
235 //////////
236 // Main //
237 //////////
238
239 static void
240 encode_symbol(lzma_coder *coder, lzma_mf *mf,
241                 uint32_t back, uint32_t len, uint32_t position)
242 {
243         const uint32_t pos_state = position & coder->pos_mask;
244
245         if (back == UINT32_MAX) {
246                 // Literal i.e. eight-bit byte
247                 assert(len == 1);
248                 rc_bit(&coder->rc,
249                                 &coder->is_match[coder->state][pos_state], 0);
250                 literal(coder, mf, position);
251         } else {
252                 // Some type of match
253                 rc_bit(&coder->rc,
254                         &coder->is_match[coder->state][pos_state], 1);
255
256                 if (back < REP_DISTANCES) {
257                         // It's a repeated match i.e. the same distance
258                         // has been used earlier.
259                         rc_bit(&coder->rc, &coder->is_rep[coder->state], 1);
260                         rep_match(coder, pos_state, back, len);
261                 } else {
262                         // Normal match
263                         rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
264                         match(coder, pos_state, back - REP_DISTANCES, len);
265                 }
266         }
267
268         assert(mf->read_ahead >= len);
269         mf->read_ahead -= len;
270 }
271
272
273 static bool
274 encode_init(lzma_coder *coder, lzma_mf *mf)
275 {
276         if (mf->read_pos == mf->read_limit) {
277                 if (mf->action == LZMA_RUN)
278                         return false; // We cannot do anything.
279
280                 // We are finishing (we cannot get here when flushing).
281                 assert(mf->write_pos == mf->read_pos);
282                 assert(mf->action == LZMA_FINISH);
283         } else {
284                 // Do the actual initialization. The first LZMA symbol must
285                 // always be a literal.
286                 mf_skip(mf, 1);
287                 mf->read_ahead = 0;
288                 rc_bit(&coder->rc, &coder->is_match[0][0], 0);
289                 rc_bittree(&coder->rc, coder->literal[0], 8, mf->buffer[0]);
290         }
291
292         // Initialization is done (except if empty file).
293         coder->is_initialized = true;
294
295         return true;
296 }
297
298
299 static void
300 encode_eopm(lzma_coder *coder, uint32_t position)
301 {
302         const uint32_t pos_state = position & coder->pos_mask;
303         rc_bit(&coder->rc, &coder->is_match[coder->state][pos_state], 1);
304         rc_bit(&coder->rc, &coder->is_rep[coder->state], 0);
305         match(coder, pos_state, UINT32_MAX, MATCH_LEN_MIN);
306 }
307
308
309 /// Number of bytes that a single encoding loop in lzma_lzma_encode() can
310 /// consume from the dictionary. This limit comes from lzma_lzma_optimum()
311 /// and may need to be updated if that function is significantly modified.
312 #define LOOP_INPUT_MAX (OPTS + 1)
313
314
315 extern lzma_ret
316 lzma_lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
317                 uint8_t *restrict out, size_t *restrict out_pos,
318                 size_t out_size, uint32_t limit)
319 {
320         // Initialize the stream if no data has been encoded yet.
321         if (!coder->is_initialized && !encode_init(coder, mf))
322                 return LZMA_OK;
323
324         // Get the lowest bits of the uncompressed offset from the LZ layer.
325         uint32_t position = mf_position(mf);
326
327         while (true) {
328                 // Encode pending bits, if any. Calling this before encoding
329                 // the next symbol is needed only with plain LZMA, since
330                 // LZMA2 always provides big enough buffer to flush
331                 // everything out from the range encoder. For the same reason,
332                 // rc_encode() never returns true when this function is used
333                 // as part of LZMA2 encoder.
334                 if (rc_encode(&coder->rc, out, out_pos, out_size)) {
335                         assert(limit == UINT32_MAX);
336                         return LZMA_OK;
337                 }
338
339                 // With LZMA2 we need to take care that compressed size of
340                 // a chunk doesn't get too big.
341                 // TODO
342                 if (limit != UINT32_MAX
343                                 && (mf->read_pos - mf->read_ahead >= limit
344                                         || *out_pos + rc_pending(&coder->rc)
345                                                 >= (UINT32_C(1) << 16)
346                                                         - LOOP_INPUT_MAX))
347                         break;
348
349                 // Check that there is some input to process.
350                 if (mf->read_pos >= mf->read_limit) {
351                         if (mf->action == LZMA_RUN)
352                                 return LZMA_OK;
353
354                         if (mf->read_ahead == 0)
355                                 break;
356                 }
357
358                 // Get optimal match (repeat position and length).
359                 // Value ranges for pos:
360                 //   - [0, REP_DISTANCES): repeated match
361                 //   - [REP_DISTANCES, UINT32_MAX):
362                 //     match at (pos - REP_DISTANCES)
363                 //   - UINT32_MAX: not a match but a literal
364                 // Value ranges for len:
365                 //   - [MATCH_LEN_MIN, MATCH_LEN_MAX]
366                 uint32_t len;
367                 uint32_t back;
368
369                 if (coder->fast_mode)
370                         lzma_lzma_optimum_fast(coder, mf, &back, &len);
371                 else
372                         lzma_lzma_optimum_normal(
373                                         coder, mf, &back, &len, position);
374
375                 encode_symbol(coder, mf, back, len, position);
376
377                 position += len;
378         }
379
380         if (!coder->is_flushed) {
381                 coder->is_flushed = true;
382
383                 // We don't support encoding plain LZMA streams without EOPM,
384                 // and LZMA2 doesn't use EOPM at LZMA level.
385                 if (limit == UINT32_MAX)
386                         encode_eopm(coder, position);
387
388                 // Flush the remaining bytes from the range encoder.
389                 rc_flush(&coder->rc);
390
391                 // Copy the remaining bytes to the output buffer. If there
392                 // isn't enough output space, we will copy out the remaining
393                 // bytes on the next call to this function by using
394                 // the rc_encode() call in the encoding loop above.
395                 if (rc_encode(&coder->rc, out, out_pos, out_size)) {
396                         assert(limit == UINT32_MAX);
397                         return LZMA_OK;
398                 }
399         }
400
401         // Make it ready for the next LZMA2 chunk.
402         coder->is_flushed = false;
403
404         return LZMA_STREAM_END;
405 }
406
407
408 static lzma_ret
409 lzma_encode(lzma_coder *restrict coder, lzma_mf *restrict mf,
410                 uint8_t *restrict out, size_t *restrict out_pos,
411                 size_t out_size)
412 {
413         // Plain LZMA has no support for sync-flushing.
414         if (unlikely(mf->action == LZMA_SYNC_FLUSH))
415                 return LZMA_OPTIONS_ERROR;
416
417         return lzma_lzma_encode(coder, mf, out, out_pos, out_size, UINT32_MAX);
418 }
419
420
421 ////////////////////
422 // Initialization //
423 ////////////////////
424
425 static bool
426 set_lz_options(lzma_lz_options *lz_options, const lzma_options_lzma *options)
427 {
428         if (!is_lclppb_valid(options)
429                         || options->fast_bytes < LZMA_FAST_BYTES_MIN
430                         || options->fast_bytes > LZMA_FAST_BYTES_MAX)
431                 return true;
432
433         // FIXME validation
434
435         lz_options->before_size = OPTS;
436         lz_options->dictionary_size = options->dictionary_size;
437         lz_options->after_size = LOOP_INPUT_MAX;
438         lz_options->match_len_max = MATCH_LEN_MAX;
439         lz_options->find_len_max = options->fast_bytes;
440         lz_options->match_finder = options->match_finder;
441         lz_options->match_finder_cycles = options->match_finder_cycles;
442         lz_options->preset_dictionary = options->preset_dictionary;
443         lz_options->preset_dictionary_size = options->preset_dictionary_size;
444
445         return false;
446 }
447
448
449 static void
450 length_encoder_reset(lzma_length_encoder *lencoder,
451                 const uint32_t num_pos_states, const bool fast_mode)
452 {
453         bit_reset(lencoder->choice);
454         bit_reset(lencoder->choice2);
455
456         for (size_t pos_state = 0; pos_state < num_pos_states; ++pos_state) {
457                 bittree_reset(lencoder->low[pos_state], LEN_LOW_BITS);
458                 bittree_reset(lencoder->mid[pos_state], LEN_MID_BITS);
459         }
460
461         bittree_reset(lencoder->high, LEN_HIGH_BITS);
462
463         if (!fast_mode)
464                 for (size_t pos_state = 0; pos_state < num_pos_states;
465                                 ++pos_state)
466                         length_update_prices(lencoder, pos_state);
467
468         return;
469 }
470
471
472 extern void
473 lzma_lzma_encoder_reset(lzma_coder *coder, const lzma_options_lzma *options)
474 {
475         assert(!coder->is_flushed);
476
477         coder->pos_mask = (1U << options->pos_bits) - 1;
478         coder->literal_context_bits = options->literal_context_bits;
479         coder->literal_pos_mask = (1 << options->literal_pos_bits) - 1;
480
481
482         // Range coder
483         rc_reset(&coder->rc);
484
485         // State
486         coder->state = 0;
487         for (size_t i = 0; i < REP_DISTANCES; ++i)
488                 coder->reps[i] = 0;
489
490         literal_init(coder->literal, options->literal_context_bits,
491                         options->literal_pos_bits);
492
493         // Bit encoders
494         for (size_t i = 0; i < STATES; ++i) {
495                 for (size_t j = 0; j <= coder->pos_mask; ++j) {
496                         bit_reset(coder->is_match[i][j]);
497                         bit_reset(coder->is_rep0_long[i][j]);
498                 }
499
500                 bit_reset(coder->is_rep[i]);
501                 bit_reset(coder->is_rep0[i]);
502                 bit_reset(coder->is_rep1[i]);
503                 bit_reset(coder->is_rep2[i]);
504         }
505
506         for (size_t i = 0; i < FULL_DISTANCES - END_POS_MODEL_INDEX; ++i)
507                 bit_reset(coder->pos_special[i]);
508
509         // Bit tree encoders
510         for (size_t i = 0; i < LEN_TO_POS_STATES; ++i)
511                 bittree_reset(coder->pos_slot[i], POS_SLOT_BITS);
512
513         bittree_reset(coder->pos_align, ALIGN_BITS);
514
515         // Length encoders
516         length_encoder_reset(&coder->match_len_encoder,
517                         1U << options->pos_bits, coder->fast_mode);
518
519         length_encoder_reset(&coder->rep_len_encoder,
520                         1U << options->pos_bits, coder->fast_mode);
521
522         // FIXME: Too big or too small won't work when resetting in the middle of LZMA2.
523         coder->match_price_count = UINT32_MAX / 2;
524         coder->align_price_count = UINT32_MAX / 2;
525
526         coder->opts_end_index = 0;
527         coder->opts_current_index = 0;
528 }
529
530
531 extern lzma_ret
532 lzma_lzma_encoder_create(lzma_coder **coder_ptr, lzma_allocator *allocator,
533                 const lzma_options_lzma *options, lzma_lz_options *lz_options)
534 {
535         if (*coder_ptr == NULL) {
536                 *coder_ptr = lzma_alloc(sizeof(lzma_coder), allocator);
537                 if (*coder_ptr == NULL)
538                         return LZMA_MEM_ERROR;
539         }
540
541         lzma_coder *coder = *coder_ptr;
542
543         // Validate options that aren't validated elsewhere.
544         if (!is_lclppb_valid(options)
545                         || options->fast_bytes < LZMA_FAST_BYTES_MIN
546                         || options->fast_bytes > LZMA_FAST_BYTES_MAX)
547                 return LZMA_OPTIONS_ERROR;
548
549         // Set compression mode.
550         switch (options->mode) {
551                 case LZMA_MODE_FAST:
552                         coder->fast_mode = true;
553                         break;
554
555                 case LZMA_MODE_NORMAL: {
556                         coder->fast_mode = false;
557
558                         // Set dist_table_size.
559                         // Round the dictionary size up to next 2^n.
560                         uint32_t log_size = 0;
561                         while ((UINT32_C(1) << log_size)
562                                         < options->dictionary_size)
563                                 ++log_size;
564
565                         coder->dist_table_size = log_size * 2;
566
567                         // Length encoders' price table size
568                         coder->match_len_encoder.table_size
569                                 = options->fast_bytes + 1 - MATCH_LEN_MIN;
570                         coder->rep_len_encoder.table_size
571                                 = options->fast_bytes + 1 - MATCH_LEN_MIN;
572                         break;
573                 }
574
575                 default:
576                         return LZMA_OPTIONS_ERROR;
577         }
578
579         coder->is_initialized = false;
580         coder->is_flushed = false;
581
582         lzma_lzma_encoder_reset(coder, options);
583
584         // LZ encoder options FIXME validation
585         if (set_lz_options(lz_options, options))
586                 return LZMA_OPTIONS_ERROR;
587
588         return LZMA_OK;
589 }
590
591
592 static lzma_ret
593 lzma_encoder_init(lzma_lz_encoder *lz, lzma_allocator *allocator,
594                 const void *options, lzma_lz_options *lz_options)
595 {
596         lz->code = &lzma_encode;
597         return lzma_lzma_encoder_create(
598                         &lz->coder, allocator, options, lz_options);
599 }
600
601
602 extern lzma_ret
603 lzma_lzma_encoder_init(lzma_next_coder *next, lzma_allocator *allocator,
604                 const lzma_filter_info *filters)
605 {
606         // Initialization call chain:
607         //
608         //    lzma_lzma_encoder_init()
609         //      `-- lzma_lz_encoder_init()
610         //            `-- lzma_encoder_init()
611         //                  `-- lzma_encoder_init2()
612         //
613         // The above complexity is to let LZ encoder store the pointer to
614         // the LZMA encoder structure. Encoding call tree:
615         //
616         //    lz_encode()
617         //      |-- fill_window()
618         //      |     `-- Next coder in the chain, if any
619         //      `-- lzma_encode()
620         //            |-- lzma_dict_find()
621         //            `-- lzma_dict_skip()
622         //
623         // FIXME ^
624         //
625         return lzma_lz_encoder_init(
626                         next, allocator, filters, &lzma_encoder_init);
627 }
628
629
630 extern uint64_t
631 lzma_lzma_encoder_memusage(const void *options)
632 {
633         lzma_lz_options lz_options;
634         if (set_lz_options(&lz_options, options))
635                 return UINT64_MAX;
636
637         const uint64_t lz_memusage = lzma_lz_encoder_memusage(&lz_options);
638         if (lz_memusage == UINT64_MAX)
639                 return UINT64_MAX;
640
641         return (uint64_t)(sizeof(lzma_coder)) + lz_memusage;
642 }
643
644
645 extern bool
646 lzma_lzma_lclppb_encode(const lzma_options_lzma *options, uint8_t *byte)
647 {
648         if (options->literal_context_bits > LZMA_LITERAL_CONTEXT_BITS_MAX
649                         || options->literal_pos_bits
650                                 > LZMA_LITERAL_POS_BITS_MAX
651                         || options->pos_bits > LZMA_POS_BITS_MAX
652                         || options->literal_context_bits
653                                         + options->literal_pos_bits
654                                 > LZMA_LITERAL_BITS_MAX)
655                 return true;
656
657         *byte = (options->pos_bits * 5 + options->literal_pos_bits) * 9
658                         + options->literal_context_bits;
659         assert(*byte <= (4 * 5 + 4) * 9 + 8);
660
661         return false;
662 }
663
664
665 #ifdef HAVE_ENCODER_LZMA
666 extern lzma_ret
667 lzma_lzma_props_encode(const void *options, uint8_t *out)
668 {
669         const lzma_options_lzma *const opt = options;
670
671         if (lzma_lzma_lclppb_encode(opt, out))
672                 return LZMA_PROG_ERROR;
673
674         integer_write_32(out + 1, opt->dictionary_size);
675
676         return LZMA_OK;
677 }
678 #endif
679
680
681 extern LZMA_API lzma_bool
682 lzma_mode_is_available(lzma_mode mode)
683 {
684         return mode == LZMA_MODE_FAST || mode == LZMA_MODE_NORMAL;
685 }