📄 hpbit_stream_out_local.h
字号:
/*****************************************************************************//* Copyright 1998, Hewlett-Packard Company *//* All rights reserved *//* File: "hpbit_stream_out_local.h" *//* Description: Private definitions for "hpbit_stream_out.c" *//* Author: David Taubman *//* Affiliation: Hewlett-Packard and *//* The University of New South Wales, Australia *//* Acknowledgements: Partly developed in collaboration with Salma Soudagar *//* of Motorola, Switzerland, and her colleagues *//* Version: VM6.0 *//* Last Revised: 19 January, 2000 *//*****************************************************************************//*****************************************************************************//* Modified by David Taubman to support interface modifications, arbitrary *//* changes in coding parameters from component to component and from tile *//* to tile, to support the full generality of PART-1 of the JPEG2000 *//* standard, and to support most anticipated generality of PART-2. Changes *//* are too numerous to flag individually within the code, which in some *//* places has been completely rewritten. All changes copyrighted by HP with *//* all rights reserved for the modified parts. *//*****************************************************************************/#ifndef HPBIT_STREAM_OUT_LOCAL_H#define HPBIT_STREAM_OUT_LOCAL_H#include <ifc.h>#include <stdio.h>#define HPBIT_MEM_KEY "STREAM IN/OUT OBJECT MEMORY"/*****************************************************************************//* hpbit_marker_elt *//*****************************************************************************/typedef struct hpbit_marker_elt { int marker_id; int element_id; char *description; int precision; int size; std_uint *buf; int *set_buf; struct hpbit_marker_elt *next; } hpbit_marker_elt, *hpbit_marker_elt_ptr; /* This structure is used to build a linked list of elements for each `hpbit_pre_marker' structure. These are the elements declared using the `stream_out__declare_marker_elt' interface function. The `marker_id' and `element_id' fields hold the value of the first and second byte in the element ID string passed across that interface function (see "ifc.h" for an explanation); these are 1-byte quantities. The `description' string is also derived from the element ID string; it is a pointer into the constant string resource supplied by the original caller and does not point to memory to be deallocated. The `precision' and `size' fields play identical roles to their namesakes in the `stream_out__declare_marker_elt' interface function. The `buf' field points to an array with `size' entries, which is dynamically allocated and hence must be deallocated upon termination. The `set_buf' field points to a dynamically allocated array with `size' entries, identifying the number of times the corresponding element in the `buf' array has been set by a call to `stream_out__set_marker_val'. Elements with a `size' of 0 have NULL `buf' and `set_buf' fields. *//*****************************************************************************//* hpbit_pre_marker *//*****************************************************************************/typedef struct hpbit_pre_marker { int id; int instance; hpbit_marker_elt_ptr elements; struct hpbit_pre_marker *link_prev, *link_next; int potentially_redundant; int translated; struct hpbit_pre_marker *prev, *next; } hpbit_pre_marker, *hpbit_pre_marker_ptr; /* This structure is used to build a linked list of so-called pre-markers; these contain the information delivered across the `stream_out__declare_marker_elt' and `stream_out__set_marker_val' interface functions. The actual codestream markers can be significantly different; it is the role of the `stream_out' object to provide translation between pre-markers and codestream markers. The `id' field is identical to the `marker_id' field of all elements in the list referenced by the `elements' field. The `potentially_redundant', `link_prev' and `link_next' fields are used together to determine whether or not a pre-marker or a collection of pre-markers which appear in a tile header are redundant because they do not convey any different information to that available from the global header. They work as follows: the `link_prev' and `link_next' fields are used to build a doubly linked list of pre-markers which must all be identical to a corresponding list of pre-markers in the global header for the collection of pre-markers in the tile-header to be considered redundant. The `potentially_redundant' flag indicates whether or not a particular pre-marker is identical to one with the same instance and marker ID in the global header. Detection and elimination of redundant markers proceeds in three phases. Pre-markers first inherit any elements from a corresponding global pre-marker which they do not have in common. Next, we identify the potentially redundant pre-markers by direct comparison. Finally, we scan the list of pre-markers for groups of dependent pre-markers which are entirely redundant, eliminating the entire group whenever this happens. *//*****************************************************************************//* hpbit_codestream_marker *//*****************************************************************************/typedef struct hpbit_codestream_marker { int instance; int num_bytes; std_byte *buf; struct hpbit_codestream_marker *next; } hpbit_codestream_marker, *hpbit_codestream_marker_ptr; /* This structure is used to manage a linked list of codestream markers. The codestream marker is actually written into the codestream as-is at the appropriate juncture. Specifically, the `buf' field contains `num_bytes' bytes which must simply be written to the codestream. The buffer is typically typecast from a meaningful structure whose entries define the marker contents. The first two bytes of the `buf' buffer always contain the marker code itself (i.e. an FF, followed by an identifying byte). The third and fourth bytes of the `buf' buffer usually contain the value of `num_bytes'-2 in Big Endian byte order. The `instance' field must be identical to the `instance' field of the corresponding pre-marker if any; if non-zero, it can be expected to be found somewhere in the marker bytes themselves, but explicit inclusion of this field simplifies testing for tile-header markers which do not differ from their counterparts in the global header. *//*****************************************************************************//* hpbit_component_params *//*****************************************************************************/typedef struct hpbit_component_params { int num_levels; int num_bands; } hpbit_component_params, *hpbit_component_params_ptr; /* This structure manages the limited set of component-specific coding parameters which are required for correct translation of markers. The `num_levels' field holds the number of decomposition levels available in the relevant tile-component. The `num_bands' field holds the total number of subbands, which is, of course, dependent upon the decomposition structure, as well as he number of decomposition levels. *//*****************************************************************************//* hpbit_params *//*****************************************************************************/typedef struct hpbit_params { int num_components; hpbit_component_params_ptr components; } hpbit_params, *hpbit_params_ptr; /* This structure maintains parameters which are needed to correctly translate codestream markers. These parameters are fairly limited and readily extracted from simple markers. Currently, we expect these parameters to be limited to the number of components, and the number of decomposition levels and the number of subbands in each component. A separate structure is managed within each `hpbit_markers' structure. *//*****************************************************************************//* hpbit_markers *//*****************************************************************************/typedef struct hpbit_markers { hpbit_pre_marker_ptr pre_markers; hpbit_codestream_marker_ptr codestream_markers; int total_codestream_bytes; int processed; hpbit_params params; } hpbit_markers, *hpbit_markers_ptr; /* This structure manages a complete set of marker information, corresponding to either the global header, or a tile header. Most markers start out on the `pre_marker' list, which is constructed from information delivered across the `stream_out__declare_marker_elt' and `stream_out__set_marker_val' interface functions. This information is then massaged and used to create the final codestream markers. The `total_codestream_bytes' field holds the sum of the `num_bytes' fields from all elements of the list referenced by the `codestream_markers' field, plus the number of bytes associated with the SOC or SOT/SOS markers which form part of the relevant scope (global markers or tile-specific markers), but are not explicitly included on the list of codestream markers for simplicity. The `processed' field indicates whether or not the codestream markers have been generated from the pre-markers. The `params' field manages the limited set of coding parameters which are required to translate codestream markers. *//*****************************************************************************//* hpbit_tile *//*****************************************************************************/typedef struct hpbit_tile { int tnum; hpbit_markers markers; int resync; int eph; struct hpbit_tile *next; } hpbit_tile, *hpbit_tile_ptr; /* This structure manages the header and other tile-specific information as necessary. It manages only the markers which must be included in the tile head. The `resync' flag indicates whether or not resync markers are to be used in the current tile. The `eph' flag indicates whether or not EPH markers are to be used in the current tile. *//*****************************************************************************//* hpbit_stream_out_obj *//*****************************************************************************/typedef struct hpbit_stream_out_obj { stream_out_obj base; FILE *fp; hpbit_markers global_markers; hpbit_tile_ptr tiles; int remaining_bytes; int global_resync, current_resync; int global_eph, current_eph; std_ushort packet_sequence_idx; int open_packet; int packet_bytes; int outstanding_head_bytes; int outstanding_body_bytes; int num_non_compliant_markers; int use_old_sot; } hpbit_stream_out_obj, *hpbit_stream_out_ref; /* This structure defines the augmented state of the `stream_out' object created by `create_reference_stream_out'. `fp' points to the open file associated with the bit-stream. `global_markers' contains all information concerning the markers which must be written to the global header of the codestream, i.e. before the first tile header. `tiles' points to a linked list of `hpbit_tile' structures for which any tile-specific information is available. The tiles are not guaranteed to appear in order within this list. `remaining_bytes' identifies the total number of bytes which can still be written to the output file, without violating the constraint established during the call to `stream_out__initialize'. This includes any marker codes which have not yet been output to the file, even the SOC marker. `global_resync' holds 1 or 0, depending upon whether resynchronization (SOP) markers are to be inserted before each packet as part of a global ERS style. The flag may be overridden in particular tiles, so the `current_resync' flag is provided to identify whether or not the current tile uses resync markers. `global_eph' holds 1 or 0, depending upon whether end-of-packet-head (EPH) markers are to be inserted immediately after the head of each packet as part of a global ERS style. The flag may be overridden in particular tiles, as the `current_eph' flag is provided to identify whether or not the current tile uses EPH markers. `packet_sequence_idx' holds the sequence index for the next packet's resynchronization marker, when `resync' is non-zero. The sequence index cycles through the range 0 to 2^16-1. `open_packet' is non-zero if a `start_packet' call has not been concluded by a matching `end_packet' call. The value is positive if the packet head and body bytes are to be sent directly to the output file. The value is negative, if the caller is simulating a packet output operation in order to determine the size of the packet. `packet_bytes' keeps track of the total number of bytes in the current packet, including resync markers and any extra bytes which must be stuffed to avoid misdetection of resync markers. `outstanding_head_bytes' and `outstanding_body_bytes' keep track of the number of head and body bytes declared in the most recent call to `start_packet' which have not yet been delivered via calls to `push_head_bytes' and `push_body_bytes', respectively. `num_non_compliant_markers' indicates the total number of codestream markers which the decompressor must understand to meaningfully decompress the codestream, yet which are not currently compliant with the standard. `use_old_sot' is a flag indicating whether or not the final `NTPsot' field in the SOT marker should be omitted. The decompressor figures this out based upon the SOT marker's length field. */#endif /* HPBIT_STREAM_OUT_LOCAL_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -