box_content_decoder.h (1361B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #ifndef LIB_JXL_BOX_CONTENT_DECODER_H_ 7 #define LIB_JXL_BOX_CONTENT_DECODER_H_ 8 9 #include <brotli/decode.h> 10 #include <jxl/decode.h> 11 #include <stdint.h> 12 #include <stdlib.h> 13 14 namespace jxl { 15 16 /** Outputs the contents of a box in a streaming fashion, either directly, or 17 * optionally decoding with Brotli, in case of a brob box. The input must be 18 * the contents of a box, excluding the box header. 19 */ 20 class JxlBoxContentDecoder { 21 public: 22 JxlBoxContentDecoder(); 23 ~JxlBoxContentDecoder(); 24 25 void StartBox(bool brob_decode, bool box_until_eof, size_t contents_size); 26 27 // Outputs decoded bytes from the box, decoding with brotli if needed. 28 // box_pos is the position in the box content which next_in points to. 29 // Returns success, whether more input or output bytes are needed, or error. 30 JxlDecoderStatus Process(const uint8_t* next_in, size_t avail_in, 31 size_t box_pos, uint8_t** next_out, 32 size_t* avail_out); 33 34 private: 35 BrotliDecoderState* brotli_dec; 36 37 bool header_done_; 38 bool brob_decode_; 39 bool box_until_eof_; 40 size_t remaining_; 41 size_t pos_; 42 }; 43 44 } // namespace jxl 45 46 #endif // LIB_JXL_BOX_CONTENT_DECODER_H_