⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compressed_local.h

📁 JPEG2000的C++实现代码
💻 H
📖 第 1 页 / 共 5 页
字号:
        if (transpose) dims.transpose();        if (hflip) dims.pos.x = -(dims.pos.x+dims.size.x-1);        if (vflip) dims.pos.y = -(dims.pos.y+dims.size.y-1);      }    void trim_compressed_data();      /* This function may be called periodically to trim away the storage         associated with compressed data bytes which will never be included         in the final compressed representation.  The function can do nothing         unless `kdu_codestream::set_max_bytes' has been called to establish         a target compressed length. */    void get_min_header_cost(int &fixed_cost, int &per_layer_cost);      /* Discovers the minimum total number of header bytes required by the         code-stream.  Specifically the minimum header cost for the first         k quality layers is equal to `fixed_cost' + `per_layer_cost'*k.         The fixed cost includes the main header, any tile headers and the         EOC marker.  The per-layer cost includes 1 byte for every         precinct, plus an additional 2 bytes per precinct if EPH markers         are used and an additional 6 bytes per precinct if SOP markers are         used.  To understand how this minimum header cost is useful for         rate allocation, see the description of "kdu_codestream::flush". */    int simulate_output(int &header_bytes,                        int layer_idx, kdu_uint16 slope_threshold,                        bool finalize_layer, bool last_layer,                        int max_bytes=INT_MAX, int *sloppy_bytes=NULL);      /* This function may be called only once all precincts of all         tile-component resolutions have been completed.  Its purpose is         to simulate the process of generating final code-stream output for         a single quality layer, so as to determine the number of bytes         occupied by that layer, given a particular distortion-length slope         threshold.  A slope threshold of 0 yields the largest possible         output size and 0xFFFF yielding the smallest possible output size         (all code-block bytes discarded).            The number of bytes returned includes the extra cost of tile and         packet headers.  The number of such header bytes is also separately         returned via the `header_bytes' argument.  Although not strictly         correct, the function currently incorporates the cost of additional         tile-part headers into the layer 0 size.  This can lead to slightly         conservative rate control when working with multiple tile-parts.         The cost of tile-part headers, however, should not usually be         substantial.            The `finalize_layer' argument should be true if this is the last         call to this function with the current layer index.  This causes the         packet header state information to be saved to a place from which         it will be restored in each simulation attempt for the next layer.         Also, it is mandatory to finalize the layers during simulation         before actually generating packet data.            The `last_layer' argument should be true if this is the final         layer for which any information will be generated.  If any tile         contains more layers, their contribution will be included at this         point as empty packets (i.e., the empty packet bit is set to 0).         Any such empty packet is never assigned an SOP marker.            The `max_bytes' argument may be used to supply an upper bound on         the total number of bytes which are allowed to be generated here.         This allows the simulation process to stop as soon as this limit         is exceeded.  In this case, the returned byte count may not be a         true reflection of the full cost of generating the layer, but it         is guaranteed to exceed the `max_bytes' limit.            When the function is called with `finalize_layer' true, the         `max_bytes' limit must not, under any circumstances be exceeded.         The assumption is that the caller has already done the work of         figuring out a slope threshold which will satisfy the relevant         rate constraint -- if not, `max_bytes' can be set to INT_MAX (the         default).            A non-NULL `sloppy_bytes' argument may be supplied only when         finalizing the last layer.  In this case, the caller must be certain         that a slope threshold of `slope_threshold'+1 can satisfy the         limit imposed by `max_bytes'.  The function first runs the low         level packet-oriented simulation tools with this value of         `slope_threshold'+1 and then runs them again (this time finalizing)         with `slope_threshold'.  On the second run, any additional coding         passes which would be contributed due to the reduced threshold are         trimmed away from the relevant code-blocks (they cannot be recovered         later on) until the number of additional bytes is less than the value         of *`sloppy_bytes'.  The *`sloppy_bytes' is progressively decremented,         so that upon return the caller may determine the total number of         available bytes which could not be used up.  The caller should then         generate packet data using the supplied slope threshold.            This `sloppy_bytes' option slows down the rate control process and         is recommended primarily when you can expect quite a few code-block         passes to have the same length-distortion slope value.  This happens         during transcoding, where the only slope information available comes         from the indices of the quality layers to which the coding passes         originally contributed.  It may also happen if the block encoder         does not collect a rich set of length-distortion statistics, simply         estimating a rough prioritization instead. */    void pcrd_opt(int layer_bytes[], kdu_uint16 slope_thresholds[],                  int num_layers);      /* Runs the PCRD-opt algorithm to find the slope thresholds for each         quality layer.  Fills in the contents of the `slope_thresholds' array         and may overwrite the contents of the `layer_bytes' array.  On entry,         the `layer_bytes' entries have the same interpretation as that         described in connection with the "kdu_codestream::flush" function.         On exit, each entry in this array identifies the number of bytes         which the layer will occupy in the final code-stream. */    void generate_codestream(int max_layers, kdu_uint16 slope_thresholds[]);      /* Generates the final code-stream.  The "pcrd_opt" member function         should have been used to find the distortion-length slope thresholds         for the various quality layers.  In any event, some simulation must         have been performed (i.e., calls to "kd_tile::simulate_output")         so as to set up the packet size information required to determine         tile-part header sizes (these are required by the SOT marker         segments). */  public: // Data    kd_compressed_input *in; // NULL unless an input codestream object.    kd_marker *marker; // General marker reading service. NULL if `in' is NULL    kd_compressed_output *out; // NULL unless an output codestream object.    std::ostream *textualize_out; // NULL unless params to be textualized    siz_params *siz;    int num_components;    kdu_coords *sub_sampling; // Component sub-sampling factors.    float *crg_x, *crg_y; // Component registration offsets.    int *precision; // Original component bit-depths.    bool *is_signed; // Signed/unsigned nature of original components    kdu_dims canvas; // Holds the image origin and dimensions.    kdu_dims tile_partition; // Holds the tiling origin and dimensions.    kdu_coords num_tiles; // Number of tiles in each direction.    int first_apparent_component, num_apparent_components;    int discard_levels, max_apparent_layers;    int max_tile_layers; // Max layers in any tile opened so far.    bool transpose, vflip, hflip; // Geometric manipulation parameters    bool resilient; // If true, error resilience is maximized.    bool expect_ubiquitous_sops; // See declaration of "set_resilient" function    bool fussy; // If true, sensitivity to correctness is maximized.    bool persistent;    bool tiles_accessed; // Becomes false after first tile access    int num_open_tiles; // Number of tiles opened, but not yet closed.    kdu_dims region; // Current region of interest; often identical to `canvas'    kd_tile **tile_refs; // An array of pointers to `kd_tile' objects.    kd_tile *active_tile; // NULL unless we are in the middle of reading a tile    kd_buf_server *buf_server; // Serves resources to buffer compressed data    kdu_block *shared_block; // Resource checked by `kdu_subband::open_block'    kd_pp_markers *ppm_markers; // NULL unless PPM markers are used.    int num_tparts_used; // Number of tile-parts actually read or written.    kd_compressed_stats *stats; // NULL unless rate prediction is being used.    kdu_uint16 min_slope_threshold; // 0 until `set_min_slope_threshold' called    clock_t start_time; // Used by `report_cpu_time'.    int peak_var_structure_bytes; // Peak block, precinct & tile struct bytes  private:    int var_structure_bytes; // Bytes in block, precinct & tile structures  };  /* Notes:         The fields listed below `initialized' become valid only once     kdu_codestream::initialize has been called.  This is not true of the     parameters listed above `initialized'.         The `tile_refs' field points to an array of tile pointers all of which     are initially NULL. When a tile is first accessed, the relevant `kd_tile'     object is created and its pointer is inserted in this array.  When the     tile has expired, the pointer value is set to KD_EXPIRED_TILE, marking it     as unusable.  The array is organized in scan-line fashion based on the     original code-stream geometry (not the apparent geometry).         The `num_tparts_used' count does not include tiles which we skipped     over since they had no intersection with the region of interest. *//*****************************************************************************//*                                kd_tile                                    *//*****************************************************************************/#define KD_EXPIRED_TILE ((kd_tile *)(-1))struct kd_tile { // State structure for the "kdu_tile" interface  public: // Member functions    kd_tile(kd_codestream *codestream, int tnum);      /* Sets up only enough information for the tile to locate itself and         for a determination to be made as to whether the tile belongs to         a current region of interest. */    ~kd_tile();      /* Note that this function also detaches the tile object from the         codestream object which references it, replacing the pointer with         the special illegal value, KD_EXPIRED_TILE. */    void initialize();      /* Called immediately after a successful construction.  Builds all         subordinate structures and fills in all fields. */    void open();      /* Called by `kdu_codestream::open_tile' after the tile has been         constructed and initialized (if necessary).  The purpose of this         function is to mark the tile as open (until it is subsequently         closed) and to reflect any prevailing region of interest and         limitations on the number of resolution levels and/or image         components into the dependent structures.  This allows the appearance         of the image to be changed and then reflected into any desired         tile when it is re-opened -- this behaviour is supported only for         persistent input objects (see `kdu_codestream::set_persistent'). */    bool read_tile_part_header();      /* Returns false, if the code-stream source was exhausted before a         new tile-part header could be completely read (up to and including         the SOD marker).  Except in this event, the current tile become's         the codestream object's active tile upon return. */    void finished_reading();      /* This function may be called as soon as we can be sure that no more         information can be read for the tile.  When this happens, the tile         is marked as `exhausted' and a search is conducted to see if we can         destroy any precincts whose existence serves only to allow the parsing         of packet headers. */    int simulate_output(int &header_bytes,                        int layer_idx, kdu_uint16 slope_threshold,                        bool finalize_layer, bool last_layer,                        int max_bytes=INT_MAX, int *sloppy_bytes=NULL);      /* Implements the functionality of `kd_codestream::simulate_output'         for a single tile. */    int generate_tile_part(int max_layers, kdu_uint16 slope_thresholds[]);      /* If all packets for the tile have already been transferred, the         function does nothing and returns 0.  Otherwise, it generates the         next tile-part header and all packets for that tile-part, using the         packet sequencer to determine both the order of packets and the         number of packets which belong to this tile-part.  The function         returns the total number of bytes in the tile-part, including all         marker codes and segments.            The `max_layers' argument indicates the number of quality layers         for which rate allocation information is available in the         `slope_thresholds' array.  If the tile contains additional layers,         the corresponding packets are assign the special empty packet code,         occupying only a single byte. */  public: // Data    kd_codestream *codestream;    int tnum;    bool is_open;    bool closed; // Once closed, the tile may no longer be accessed.    kdu_dims dims; // Region occupied by the tile on the canvas    kdu_dims region; // Region of interest within tile.    bool initialized; // Fields below here are valid only once initialized    int num_components;    int first_apparent_component, num_apparent_components;    int num_tparts; // Zero if number of tile-parts unknown.    int next_tpart; // Index of next tile-part to be read or written.    bool use_sop, use_eph, use_ycc;    kdu_coords coding_origin;    int num_layers;    int num_apparent_layers;    kd_tile_comp *comps;    int total_precincts;    int total_packets;    int num_transferred_packets; // Incremented on reading/writing new packet.    bool skipping_to_sop; // True only if trying to recover from an error.    int next_sop_sequence_num; // Valid only if `skipping_to_sop' is true.    int saved_num_transferred_packets; // For "kdu_packet_sequencer::save_state".    bool exhausted; // True if no more tile-parts are available for this tile.    kd_packet_sequencer *sequencer;    kd_pph_input *packed_headers; // NULL unless tile has packed packet headers  };  /* Notes:        If `skipping_to_sop' is true, packets are automatically discarded     (this is a pseudo-transfer which leaves the packet empty) until one is     reached whose sequence number (same as `num_transferred_packets') agrees     with the value of `next_sop_sequence_num'. *//*****************************************************************************//*                              kd_tile_comp                                 *//*****************************************************************************/struct kd_tile_comp { // State structure for the "kdu_tile_comp" interface  public: // Member functions    kd_tile_comp()      { // We will be relying on all fields starting out as 0.        memset(this,0,sizeof(*this));      }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -