📄 compressed_local.h
字号:
/*****************************************************************************/// File: compressed_local.h [scope = CORESYS/COMPRESSED]// Version: Kakadu, V2.2// Author: David Taubman// Last Revised: 20 June, 2001/*****************************************************************************/// Copyright 2001, David Taubman, The University of New South Wales (UNSW)// The copyright owner is Unisearch Ltd, Australia (commercial arm of UNSW)// Neither this copyright statement, nor the licensing details below// may be removed from this file or dissociated from its contents./*****************************************************************************/// Licensee: Book Owner// License number: 99999// The Licensee has been granted a NON-COMMERCIAL license to the contents of// this source file, said Licensee being the owner of a copy of the book,// "JPEG2000: Image Compression Fundamentals, Standards and Practice," by// Taubman and Marcellin (Kluwer Academic Publishers, 2001). A brief summary// of the license appears below. This summary is not to be relied upon in// preference to the full text of the license agreement, which was accepted// upon breaking the seal of the compact disc accompanying the above-mentioned// book.// 1. The Licensee has the right to Non-Commercial Use of the Kakadu software,// Version 2.2, including distribution of one or more Applications built// using the software, provided such distribution is not for financial// return.// 2. The Licensee has the right to personal use of the Kakadu software,// Version 2.2.// 3. The Licensee has the right to distribute Reusable Code (including// source code and dynamically or statically linked libraries) to a Third// Party, provided the Third Party possesses a license to use the Kakadu// software, Version 2.2, and provided such distribution is not for// financial return./******************************************************************************Description: Local definitions employed by the machinery behind the interfaces definedin "kdu_compressed.h". These definitions should not be included from anyother scope. They are for use only in implementing the compressed datamanagement machinery. As a general rule, we use the prefix "kd_" for internal classes andstructures, for which a "kdu_" prefixed interface class exists in thecommon scope header file, "kdu_compressed.h".******************************************************************************/#ifndef COMPRESSED_LOCAL_H#define COMPRESSED_LOCAL_H#include <time.h>#include <string.h>#include <assert.h>#include "kdu_params.h"#include "kdu_compressed.h"// The following classes and structures are all defined here:struct kd_code_buffer;struct kd_code_alloc;class kd_buf_server;class kd_compressed_output;class kd_input;class kd_compressed_input;class kd_pph_input;class kd_marker;class kd_pp_marker_list;class kd_pp_markers;class kd_packet_sequencer;class kd_header_in;class kd_header_out;class kd_block;struct kd_codestream;struct kd_tile;struct kd_tile_comp;struct kd_resolution;struct kd_subband;struct kd_precinct;struct kd_precinct_band;/* ========================================================================= *//* Input Exception Codes *//* ========================================================================= */#define KDU_EXCEPTION_PRECISION ((kdu_uint16) 13) /* Thrown when a packet specifies quantities too large to represent within the constraints defined by the current implementation. This is almost certainly due to an erroneously constructed code-stream and will be treated as such if the resilient mode is enabled. */#define KDU_EXCEPTION_ILLEGAL_LAYER ((kdu_uint16) 21) /* Thrown when the inclusion tag tree attains an illegal state while decoding a packet header. Illegal states can occur only when one or more packets from the same precinct have had their empty packet bit set to 0 (i.e. the packet was skipped). Since no code-block can contribute to such packets, the index of the layer in which the block is first included cannot be equal to the index of a packet marked as empty. If the inclusion tag tree decodes such a layer index, an error must have occurred and this exception is thrown. */ /* Notes: The above exceptions may be thrown during packet header decoding. In addition, if an illegal marker code is encountered while reading any portion of a packet, an exception of type "kdu_uint16" will also be thrown, having the value of the illegal marker code. Marker exception throwing may not occur unless neither the "fussy" or the "resilient" mode is enabled, since watching for in-packet markers is a little time-consuming. *//* ========================================================================= *//* External Functions *//* ========================================================================= */extern void print_marker_code(kdu_uint16 code, std::ostream &out);/* ========================================================================= *//* Class/Struct Definitions *//* ========================================================================= *//*****************************************************************************//* kd_code_buffer *//*****************************************************************************/#define KD_CODE_BUFFER_LEN 28 // May not exceed 255 under any conditions.struct kd_code_buffer { // Chunks code bytes to minimize heap transactions kd_code_buffer *next; kdu_byte buf[KD_CODE_BUFFER_LEN]; };/*****************************************************************************//* kd_code_alloc *//*****************************************************************************/#define KD_CODE_ALLOC_NUM 200struct kd_code_alloc { kd_code_alloc *next; kd_code_buffer bufs[KD_CODE_ALLOC_NUM]; };/*****************************************************************************//* kd_buf_server *//*****************************************************************************/class kd_buf_server { public: // Member functions kd_buf_server() { alloc = NULL; free = NULL; total_buffers = num_allocated_buffers = peak_allocated_buffers = 0; num_users=0; } ~kd_buf_server(); // First call `can_destroy' to see if you can destroy it. bool can_destroy() { return (num_users == 0); } void attach() { num_users++; } void detach() { assert(num_users > 0); num_users--; } kd_code_buffer *get(); /* Returns a new code buffer, with its `next' pointer set to NULL. */ void release(kd_code_buffer *buf); /* Recycles a previously acquired code buffer. */ int get_peak_bytes() { /* Returns the maximum number of bytes ever actually allocated by the server. */ return peak_allocated_buffers * sizeof(kd_code_buffer); } private: // Data kd_code_alloc *alloc; kd_code_buffer *free; int total_buffers; int num_allocated_buffers; int peak_allocated_buffers; int num_users; // Number of users currently sharing the object. };/*****************************************************************************//* kd_compressed_output *//*****************************************************************************/class kd_compressed_output : public kdu_output { public: // Member functions kd_compressed_output(kdu_compressed_target *target) { this->target=target; flushed_bytes = 0; } virtual ~kd_compressed_output() { flush_buf(); } int get_bytes_written() { return flushed_bytes + (next_buf-buffer); } protected: // Virtual functions which implement required services. virtual void flush_buf() { if (next_buf > buffer) target->write(buffer,(next_buf-buffer)); flushed_bytes += next_buf - buffer; next_buf = buffer; } private: // Data kdu_compressed_target *target; int flushed_bytes; };/*****************************************************************************//* kd_input *//*****************************************************************************/#define KD_IBUF_SIZE 512#define KD_IBUF_PUTBACK 6 // Maximum number of bytes you can put back.class kd_input { /* This abstract base class must be derived to construct meaningful input devices. Currently, we have two derived classes in mind: one for reading from the code-stream and one for recovering packet headers from PPM or PPT markers. Since there may be many low level byte-oriented transactions, we emphasize efficiency for such transactions. */ public: // Member functions kd_input() { first_unread = first_unwritten = buffer+KD_IBUF_PUTBACK; exhausted = false; throw_markers=false; } virtual ~kd_input() { return; } void enable_marker_throwing(bool reject_all=false) { /* If `reject_all' is false, subsequent reads will throw an exception if a bona fide SOP or SOT marker is found. In this case, the function will check to make sure that the length field is correct, putting the length field and marker code bytes back to the source before throwing the exception, so that the catch statement can read them again. If `reject_all' is true, subsequent reads will throw an exception if any marker code in the range FF90 to FFFF is found. Again, the marker code itself is put back onto the stream before throwing the exception. Marker throwing is disabled before throwing an exception for either of the above reasons. Note that code-stream reading may be slowed down when this marker throwing is enabled. For this reason, the capability is best used only when error resilience or error detection capabilities are required. */ this->reject_all = reject_all; throw_markers = true; have_FF = false; } bool disable_marker_throwing() { /* Disable marker exception throwing. Returns true unless the last byte which was read was an FF, in which case the function returns false. This allows the caller to catch markers which were partially read. Any code-stream segment which is not permitted to contain a marker code in the range FF90 through FFFF is also not permitted to terminate with an FF. */ if (!throw_markers) return true; throw_markers = false; // Must not touch `reject_all' here. if (exhausted) have_FF = false; return !have_FF; } bool failed()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -