📄 compressed_local.h
字号:
~kd_tile_comp(); public: // Data kd_codestream *codestream; kd_tile *tile; int cnum; kdu_coords sub_sampling; kdu_dims dims; kdu_dims region; int dwt_levels, apparent_dwt_levels; bool reversible; int kernel_id; // One of Ckernels_W5X3 or Ckernels_W9X7. int recommended_extra_bits; kdu_coords blk; // Nominal code-block dimensions. int modes; // Block coder modes. Flags defined in scope `cod_params' kdu_coords grid_min; // These fields are used by the packet sequencer kdu_coords grid_inc; // for spatially oriented progressions. They are kd_resolution *resolutions; // Contains 1+`dwt_levels' entries. }; /* Notes: `recommended_extra_bits' may be added to the sample bit-depth (precision) for this component to determine an appropriate number of bits for internal representations associated with the data processing path. In the reversible path, the value is set to the maximum bit-depth expansion factor, as reported in Table 17.4 of the book by Taubman and Marcellin, adding an extra 1 bit if the RCT has been used -- note that it is not desirable for luminance and chrominance components to have different numeric representations, since that would significantly complicate the colour transform procedure. In the irreversible path, the value is set to 7, which means that 16-bit representations are judged sufficient for 9 bit imagery or less. Of course, the impact of selecting a reduced representation precision is only reduced accuracy in the irreversible processing path. *//*****************************************************************************//* kd_resolution *//*****************************************************************************/struct kd_resolution { // State structure for the "kdu_resolution" interface public: // Member functions kd_resolution() { // We will be relying on all fields starting out as 0. memset(this,0,sizeof(*this)); } ~kd_resolution(); public: // Data kd_codestream *codestream; kd_tile_comp *tile_comp; int res_level; // Runs from 0 (LL band) to `num_dwt_levels' int dwt_level; // Runs from `num_dwt_levels' (res level 0 and 1) to 1 bool propagate_roi; kdu_dims dims; kdu_dims region; kdu_dims precinct_partition; // Holds the coding origin and dimensions. kdu_dims precinct_indices; // Holds the range of valid precinct indices. kd_precinct **precinct_refs; // All pointers initially NULL. kdu_coords current_sequencer_pos; // Used by `kd_packet_sequencer'. int min_band, max_band; kd_subband *bands; }; /* Notes: The `current_sequencer_pos' coordinates are used to sequence spatially oriented packet progressions. They maintain the indices (starting from [0,0], rather than `precinct_indices.pos') of the precinct which is currently being sequenced. The `bands' array may be de-referenced with indices in the range 0 through `max_band', even though the actual band indices may not be smaller than `min_band'. This is a convenience measure. *//*****************************************************************************//* kd_subband *//*****************************************************************************/struct kd_subband { // State structure for the "kdu_subband" interface public: // Member functions kd_subband() { // We will be relying on all fields starting out as 0. memset(this,0,sizeof(*this)); } public: // Data kd_codestream *codestream; kd_resolution *resolution; int which_band; // one of LL_BAND, HL_BAND, LH_BAND or HH_BAND. kdu_coords band_idx; // Each coordinate is 0 for low-pass, 1 for high-pass. kdu_dims dims; kdu_dims region; int epsilon; // Ranging parameter. int K_max; // Maximum magnitude bit-planes, not including ROI upshift. int K_max_prime; // Maximum magnitude bit-planes, including ROI upshift. float delta; // Step size, normalized for image data range of -0.5 to 0.5 float G_b; // Subband energy gain factor. float W_b; // Subband amplitude weight; needs squaring to get energy weight float roi_weight; // Extra amplitude weight for ROI foreground blocks. kdu_dims block_partition; // Holds the coding origin and dimensions. kdu_dims block_indices; // Holds the range of valid block indices. kdu_dims region_indices; // Same as `block_indices', but restricted to // blocks which overlap the region of interest. kdu_coords blocks_per_precinct; // precinct size / block size kdu_coords log2_blocks_per_precinct; // log2 of precinct size/block size }; /* Notes: It may come as a surprise to notice that this object has no direct connection to code-blocks. To access a code-block, the object first determines the precinct to which it belongs, creating that precinct if necessary; this, in turn, creates its precinct-bands and the associated code-blocks. In this way, no memory whatsoever need be dedicated to code-blocks which lie in unaccessed precincts. *//*****************************************************************************//* kd_header_in *//*****************************************************************************/class kd_header_in { /* Manages the reading of packet header bytes from the code-stream, along with bit stuffing and unpacking. */ public: // Member functions kd_header_in(kd_input *source) { this->source = source; bits_left=0; byte=0; } int get_bit() // throws its own "this" pointer if the source is exhausted. { if (bits_left==0) { bits_left = (byte==0xFF)?7:8; if (!source->get(byte)) throw this; } bits_left--; return (byte >> bits_left) & 1; } kdu_uint32 get_bits(int num_bits) // thorws(kd_header_in *) { kdu_uint32 result = 0; while (num_bits > 0) { if (bits_left==0) { bits_left = (byte==0xFF)?7:8; if (!source->get(byte)) throw this; } int xfer_bits = (num_bits<bits_left)?num_bits:bits_left; bits_left -= xfer_bits; num_bits -= xfer_bits; result <<= xfer_bits; result |= ((byte >> bits_left) & ~(0xFF << xfer_bits)); } return result; } void finish() { // Call this when the header is all read, to consume any stuffing byte if ((bits_left == 0) && (byte == 0xFF)) { bits_left = 7; if (!source->get(byte)) throw this; } } private: // Data kd_input *source; // Provides the input mechanism. kdu_byte byte; int bits_left; };/*****************************************************************************//* kd_header_out *//*****************************************************************************/class kd_header_out { /* Manages the simulated and real output of packet header bytes. */ public: // Member functions kd_header_out(kdu_output *out=NULL) // Null for simulating header { byte = 0; bits_left = 8; completed_bytes = 0; this->out = out; } void put_bit(int bit) { // Output a header bit assert(bit == (bit & 1)); if (bits_left == 0) { if (out != NULL) out->put(byte); completed_bytes++; bits_left = (byte==0xFF)?7:8; byte = 0; } byte += byte + bit; bits_left--; } void put_bits(kdu_int32 val, int num_bits) { // Output the least significant `num_bits' of `val' while (num_bits > 0) put_bit((val >> (--num_bits)) & 1); } int finish() { // Returns the total number of bytes consumed by the packet header. if (bits_left < 8) { byte <<= bits_left; if (out != NULL) out->put(byte); completed_bytes++; if (byte == 0xFF) { // Need the stuffing byte. if (out != NULL) out->put((kdu_byte) 0); completed_bytes++; } } return completed_bytes; } private: // Data kdu_byte byte; int bits_left; int completed_bytes; kdu_output *out; };/*****************************************************************************//* kd_block *//*****************************************************************************/class kd_block { /* For a very small size (only 24 bytes on 32-bit machines), this class defines a lot of member functions!. */ // -------------------------------------------------------------------------- public: // Lifecycle member functions void cleanup(kd_precinct_band *pband); // Must call this before destroying // -------------------------------------------------------------------------- public: // Packet manipulation member functions int parse_packet_header(kd_header_in &head, kd_buf_server *buf_server, int layer_idx); // Throws (kdu_uint16 code) /* Parses bits in the packet header corresponding to the current block for the current layer (this must be the next layer for which information has not yet been parsed). The function returns the number of new body bytes contributed by the code-block in this layer and also stores this value internally to be used in subsequent calls to the `read_body_bytes' member function. The `kd_header_in' object may throw an exception if the packet data terminates unexpectedly. Moreover, to assist in locating and possibly recovering from errors, the present function may throw a 16-bit unsigned integer exception code, which is either the value of an illegal marker code encountered in the packet header, or one of the special exception codes, KDU_EXCEPTION_PRECISION or KDU_EXCEPTION_ILLEGAL_LAYER. */ void read_body_bytes(kd_input *source, kd_buf_server *buf_server); /* This function should be called after parsing the header of a packet. It reads the code-bytes contributed by the code-block to this packet. */ void retrieve_data(kdu_block *block, int max_layers); /* Retrieves compressed code-bytes, number of coding passes and codeword segment lengths from the current code-block and stores them in the `block' object. All fields which are common for compression and decompression have already been filled out by the caller. The byte buffer is allocated so as to be large enough to allow a 2 byte marker code to be appended to the compressed data, if desired -- see declaration of "kdu_subband::open_block". The `max_layers' field identifies the maximum nu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -