📄 ref_forward_roi.c
字号:
}
/* Now parse the command-line arguments to initialize the remaining
tile-specific fields. */
global_rgn_params = NULL;
global_max_shift_params = NULL;
if ((p = cmdl->extract(cmdl,"-Rrgn",-1,¶ms)) >= 0)
global_rgn_params = params;
if ((p = cmdl->extract(cmdl,"-Rmax_shift",-1,¶ms)) >= 0)
global_max_shift_params = NULL;
for (tnum=0; tnum < num_tiles; tnum++)
get_tile_specific_args(self->num_components,self->components,cmdl,
tnum,global_rgn_params,global_max_shift_params);
/* Now write the relevant codestream markers. */
if (!self->block_aligned)
{
for (c=0; c < num_components; c++)
{
comp_info = self->components + c;
tile = NULL;
for (tnum=0; tnum < comp_info->num_tiles; tnum++)
{
tile = comp_info->tiles + tnum;
if (!tile->tile_specific_params)
break;
}
if (tile != NULL)
save_tile_component_marker(tile,c,-1,stream); /* Global marker */
for (tnum=0; tnum < comp_info->num_tiles; tnum++)
{
tile = comp_info->tiles + tnum;
if (tile->tile_specific_params)
save_tile_component_marker(tile,c,tnum,stream);
}
}
}
/* Finally, start the first tile. */
start_tile(self);
}
/*****************************************************************************/
/* STATIC __get_usage */
/*****************************************************************************/
static char **
__get_usage(forward_roi_ref base)
{
static char *args[] =
{"-Rrgn[+<tnum>] <boost> [R <y> <x> <ht> <wd>]|[C <y> <x> <rad>] [*] ...",
"This argument may appear only once, but it can take a potentially "
"very large number of parameters. The argument specifies boost and "
"geometric information for one or more regions, which may be "
"customized on a component basis. Moreover, like most command-line "
"arguments, the tile-specific form may be used to override default "
"region configurations. The argument consists of one or more "
"parameter sets, which may be interspersed with `*' characters if "
"separate parameter sets are to be specified for different "
"components. Each parameter set commences with a `boost' value which "
"must be a positive integer indicating the amount by which sample "
"values are effectively shifted up above the background, if they "
"contribute to the region of interest. The parameter set then "
"contains either an `R' or a `C' character, depending upon whether "
"a rectangular or a circular geometry is to be specified. Rectangular "
"geometries are specified with four parameters corresponding to the "
"y- and x-coordinates of the upper left hand corner and the height "
"and width of the rectangular region, respectively; all parameters "
"are specified relative to the dimensions of the location and size "
"of the relevant image component on the canvas, as parameters in the "
"range 0 to 1. Circular regions are specified via the y- and x-"
"coordinates of the centre, followed by the radius; again, all "
"coordinates are specified relative to the location and size of "
"the relevant image component, with the radius specified relative to "
"the maximum of the two dimensions. Any number of regions may be "
"specified via consecutive parameter sets. If a `*' character is "
"encountered between parameter sets then the ensuing parameter "
"sets are deemed to apply to the next image component in sequence. "
"All parameter sets after the last `*' character, if any, are deemed "
"to apply to all remaining image components.",
"-Ralign",
"This flag forces the use of a single homogeneous boost value "
"within each code-block. In this case, no ROI geometry or boost "
"information must be specified at all and the ROI machinery is "
"simply being used to generate region-specific differentiation in the "
"distortion metric applied to the different code-blocks for the "
"purpose of quality layer generation in the EBCOT algorithm.",
"-Rmax_shift[+<tnum>] [Y|N [Y|N [...]]] (default = explicit regions)",
"This flag is used to specify whether or not the "
"region of interest geometries should be determined implicitly by"
"the decompressor using the `max-shift' method. By default, all "
"geometry information is signalled explicitly through the codestream. "
"The argument takes one or more parameters, each of which must consist "
"of a single character, either `Y' (use `max-shift') or `N' (do not "
"use `max-shift' method). The first character refers to the first "
"component; the second character refers to the second component and so "
"forth; the last parameter is applied to any remaining components. "
"Like most arguments, this argument has a tile-specific form, which "
"can be used to override the signalling mode in specific tiles. Note "
"that the `max-shift' method requires that all regions of interest "
"for the relevant tile have identical boost values and that these "
"boost values be sufficiently large. Violation of these conditions "
"in any tile will generate an error; to remedy the error, the "
"`max-shift' method must be explicitly disabled in the affected tiles.",
/* Begin ROIrect */
"-Rno_rect",
"This flag forces the use of the generic ROI mask generation "
"implementation, rather than the fast rectangular mask generation. "
"The flag has no affect unless all ROI regions in some tile-component "
"have rectangular geometries, since this is the condition under which "
"the specific implementation for rectangular geometries will normally "
"be used.",
/* End ROIrect */
NULL};
return(args);
}
/*****************************************************************************/
/* STATIC __next_tile */
/*****************************************************************************/
static void
__next_tile(forward_roi_ref base)
{
ref_forward_roi_ref self = (ref_forward_roi_ref) base;
roi_component_info_ptr comp;
int c;
for (c=0; c < self->num_components; c++)
{
comp = self->components + c;
ref_roi_terminate_component(comp);
comp->tiles[comp->current_tile_idx].regions = NULL;
comp->current_tile_idx++;
assert(comp->current_tile_idx < comp->num_tiles);
}
start_tile(self);
}
/*****************************************************************************/
/* STATIC __get_max_boost */
/*****************************************************************************/
static int
__get_max_boost(forward_roi_ref base, int component_idx, int level_idx,
int band_idx, int *block_aligned, int *mask_implicit)
{
ref_forward_roi_ref self = (ref_forward_roi_ref) base;
roi_component_info_ptr comp_info;
roi_level_info_ptr lev;
assert(component_idx < self->num_components);
comp_info = self->components + component_idx;
assert(level_idx <= comp_info->num_levels);
lev = comp_info->levels + level_idx;
if (block_aligned != NULL)
*block_aligned = lev->block_aligned;
if (mask_implicit != NULL)
*mask_implicit = comp_info->implicit_partition;
return(comp_info->max_boost);
}
/*****************************************************************************/
/* STATIC __check_roi */
/*****************************************************************************/
static int
__check_roi(forward_roi_ref base, int component_idx, int level_idx,
int band_idx, int block_rows, int block_cols, int top_row,
int left_col, int *min_boost, std_byte *mask[])
{
ref_forward_roi_ref self = (ref_forward_roi_ref) base;
roi_component_info_ptr comp_info;
roi_level_info_ptr lev;
roi_band_ref band;
std_byte *mp, **mpp, min, max;
int r, c;
assert(component_idx < self->num_components);
comp_info = self->components + component_idx;
if (comp_info->max_boost == 0)
{
*min_boost = 0;
return(0);
}
assert(level_idx <= comp_info->num_levels);
lev = comp_info->levels + level_idx;
assert((band_idx >= lev->min_band) && (band_idx <= lev->max_band));
band = lev->bands[band_idx];
ref_roi_get_band_mask(band,block_rows,block_cols,top_row,left_col,mask,
comp_info); /* ROIrect */
/* Determine min and max boost. */
min = max = *(mask[0]);
for (mpp=mask, r=block_rows; r > 0; r--, mpp++)
for (mp=*mpp, c=block_cols; c > 0; c--, mp++)
if (*mp < min)
min = *mp;
else if (*mp > max)
max = *mp;
/* Now prepare the result. */
if (lev->block_aligned)
{
*min_boost = (int) max;
return(0);
}
*min_boost = (int) min;
if (min)
for (mpp=mask, r=block_rows; r > 0; r--, mpp++)
for (mp=*mpp, c=block_cols; c > 0; c--, mp++)
*mp -= min;
return((int)(max-min));
}
/*****************************************************************************/
/* STATIC __terminate */
/*****************************************************************************/
static void
__terminate(forward_roi_ref base)
{
ref_forward_roi_ref self = (ref_forward_roi_ref) base;
roi_component_info_ptr comp_info;
roi_tile_ptr tile;
roi_region_ptr reg;
int c, t;
if (self->components != NULL)
{
for (c=0; c < self->num_components; c++)
{
comp_info = self->components + c;
ref_roi_terminate_component(comp_info);
assert(comp_info->current_tile_idx < comp_info->num_tiles);
comp_info->tiles[comp_info->current_tile_idx].regions = NULL;
for (t=0; t < comp_info->num_tiles; t++)
{
tile = comp_info->tiles + t;
while ((reg = tile->regions) != NULL)
{
tile->regions = reg->next;
local_free(reg);
}
}
local_free(comp_info->tiles);
}
local_free(self->components);
}
local_free(self);
}
/*****************************************************************************/
/* EXTERN create_reference_forward_roi */
/*****************************************************************************/
forward_roi_ref
create_reference_forward_roi(void)
{
ref_forward_roi_ref result;
result = (ref_forward_roi_ref)
local_malloc(ROI_MEM_KEY,sizeof(ref_forward_roi_obj));
result->base.initialize = __initialize;
result->base.get_usage = __get_usage;
result->base.get_max_boost = __get_max_boost;
result->base.check_roi = __check_roi;
result->base.next_tile = __next_tile;
result->base.terminate = __terminate;
return((forward_roi_ref) result);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -