📄 hpbit_stream_out.c
字号:
{ hpbit_stream_out_ref self = (hpbit_stream_out_ref) base; int p, min_tnum, tnum; char **params; self->fp = fopen(filename,"wb"); if (self->fp == NULL) local_error("Unable to open output bit-stream file, \"%s\"!",filename); if ((p = cmdl->extract(cmdl,"-Bcomment",-1,¶ms)) >= 0) { int siz; if (p != 1) local_error("The `-Bcomment' argument requires a single string " "parameter!"); siz = strlen(params[0]); base->set_main_cmetag(base,CME_COMMENT,siz,(std_byte *)(params[0])); } self->remaining_bytes = max_bytes; if ((p = cmdl->extract(cmdl,"-Bold_sot",-1,¶ms)) >= 0) { if (p != 0) local_error("The `-Bold_sot' argument takes no parameters!"); self->use_old_sot = 1; } /* Now determine how resync markers should be used globally and in each tile. Note that at this stage we have no idea how many tiles there are, so we set the ERS_SOP marker element for each tile for which a tile-specific `-Bresync' argument is found. */ if ((p = cmdl->extract(cmdl,"-Bresync",-1,¶ms)) >= 0) { if (p == 0) self->global_resync = 1; else if (p == 1) { if (*(params[0]) == 'Y') self->global_resync = 1; else if (*(params[0]) == 'N') self->global_resync = 0; else local_error("The `-Bresync' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } else local_error("The `-Bresync' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } base->declare_marker_elt(base,-1,MARKER_ERS_SOP,0,1,1); base->set_marker_val(base,-1,MARKER_ERS_SOP,0,(std_uint) (self->global_resync),0); min_tnum = 0; while ((p = cmdl->extract_next(cmdl,"-Bresync",min_tnum,&tnum,¶ms)) >= 0) { int resync; hpbit_tile_ptr tile; min_tnum = tnum+1; if (p == 0) resync = 1; else if (p == 1) { if (*(params[0]) == 'Y') resync = 1; else if (*(params[0]) == 'N') resync = 0; else local_error("The `-Bresync' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } else local_error("The `-Bresync' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); base->declare_marker_elt(base,tnum,MARKER_ERS_SOP,0,1,1); base->set_marker_val(base,tnum,MARKER_ERS_SOP,0,(std_uint) resync,0); for (tile=self->tiles; tile != NULL; tile=tile->next) if (tile->tnum == tnum) break; assert((tile != NULL) && (tile->resync == self->global_resync)); tile->resync = resync; } /* Process the `-Beph' argument in the same way. */ if ((p = cmdl->extract(cmdl,"-Beph",-1,¶ms)) >= 0) { if (p == 0) self->global_eph = 1; else if (p == 1) { if (*(params[0]) == 'Y') self->global_eph = 1; else if (*(params[0]) == 'N') self->global_eph = 0; else local_error("The `-Beph' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } else local_error("The `-Beph' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } base->declare_marker_elt(base,-1,MARKER_ERS_EPH,0,1,1); base->set_marker_val(base,-1,MARKER_ERS_EPH,0,(std_uint) (self->global_eph),0); min_tnum = 0; while ((p = cmdl->extract_next(cmdl,"-Beph",min_tnum,&tnum,¶ms)) >= 0) { int eph; hpbit_tile_ptr tile; min_tnum = tnum+1; if (p == 0) eph = 1; else if (p == 1) { if (*(params[0]) == 'Y') eph = 1; else if (*(params[0]) == 'N') eph = 0; else local_error("The `-Beph' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); } else local_error("The `-Beph' argument takes either no parameters " "or a single parameter consisting of one of the " "characters, `N' or `Y'!"); base->declare_marker_elt(base,tnum,MARKER_ERS_EPH,0,1,1); base->set_marker_val(base,tnum,MARKER_ERS_EPH,0,(std_uint) eph,0); for (tile=self->tiles; tile != NULL; tile=tile->next) if (tile->tnum == tnum) break; assert((tile != NULL) && (tile->eph == self->global_eph)); tile->eph = eph; }}/*****************************************************************************//* STATIC __get_usage *//*****************************************************************************/static char ** __get_usage(stream_out_ref base){ static char *args[] = {"-Bresync[+<tnum>] [Y|N]", "Insert resync markers on packet boundaries. The optional parameter, " "`Y' or `N' may be used to explicitly state whether the argument is " "turning resync markers on or off, which can be useful when " "overriding global settings in specific tiles.", "-Beph[+<tnum>] [Y|N]", "Insert End-Of-Packet-Head (EPH) markers on packet boundaries. The " "optional parameter, `Y' or `N' may be used to explicitly state " "whether the argument is turning resync markers on or off, which can " "be useful when overriding global settings in specific tiles. Note " "that the EPH marker is not currently defined; it is included in the " "VM because of its tremendous usefulness (almost to the point of " "being essential) in creating codestreams which are easily " "reorganized; most importantly, the EPH marker is invaluable in " "creating codestreams to which packet packet head (PPT/PPM) markers " "can be added and manipulated by an external superficial codestream " "parser, such as \"j2g_fiddle\".", "-Bold_sot", "This flag forces the compressor to use the old SOT marker style, " "omitting the final byte which normally indicates the total number " "of tile-parts in the tile to minimize resource consumption during " "decompression.", "-Bcomment comment", "Place a comment in the compressed file (use quotes for multiple" " words).", NULL}; return(args);}/*****************************************************************************//* STATIC __set_main_cmetag *//*****************************************************************************/static void __set_main_cmetag(stream_out_ref base, std_ushort Rcme, int size, std_byte *data){ hpbit_stream_out_ref self = (hpbit_stream_out_ref) base; int length; cme_marker cme; std_byte *bp, *buf; if ((Rcme & 0xFF00) == 0xFF00) local_error("Real CME markers may not use Rcme codes in the range " "FF00 through FFFF; the current implementation uses these " "codes to pack generic marker segments for which a conversion " "to final codestream markers has not yet been implemented!"); length = 6 + size; cme.CME = MARKER_CME; cme.Lcme = length-2; cme.Rcme = (std_ushort) Rcme; bp = buf = (std_byte *) local_malloc(HPBIT_MEM_KEY,length); copy_to_big_endian(&cme,bp,3,2); bp += 6; while (size--) *(bp++) = *(data++); add_codestream_marker(&(self->global_markers),buf,length,0,1);}/*****************************************************************************//* STATIC __declare_marker_elt *//*****************************************************************************/static void __declare_marker_elt(stream_out_ref base, int tnum, const char *elt_id, int instance, int precision, int size){ hpbit_stream_out_ref self = (hpbit_stream_out_ref) base; hpbit_tile_ptr tile; hpbit_markers_ptr markers; hpbit_pre_marker_ptr pm; hpbit_marker_elt_ptr elt; int marker_id, element_id; char *description; marker_id = elt_id[0]; element_id = elt_id[1]; description = (char *)(elt_id + 2); if (tnum < 0) markers = &(self->global_markers); else { for (tile=self->tiles; tile != NULL; tile=tile->next) if (tile->tnum == tnum) break; if (tile == NULL) tile = add_tile(self,tnum); markers = &(tile->markers); } if (markers->processed) local_error("Attempting to declare a marker element in the global " "header or a tile header, which has already been written " "to the codestream! The marker element has the " "description \"%s\"!",description); assert(element_id == (element_id & 0x3F)); /* Must leave 2 free MSB's. */ for (pm=markers->pre_markers; pm != NULL; pm = pm->next) if ((pm->id == marker_id) && (pm->instance == instance)) break; if (pm == NULL) { pm = (hpbit_pre_marker_ptr) local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker)); pm->next = markers->pre_markers; markers->pre_markers = pm; pm->prev = NULL; if (pm->next != NULL) pm->next->prev = pm; pm->id = marker_id; pm->instance = instance; } for (elt=pm->elements; elt != NULL; elt = elt->next) if (elt->element_id == element_id) local_error("Attempting to declare the marker element \"%s\" " "multiple times with the same instance and scope!", description); elt = (hpbit_marker_elt_ptr) local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_marker_elt)); elt->marker_id = marker_id; elt->element_id = element_id; elt->description = description; elt->precision = precision; assert((precision >= 1) && (precision <= 32) && (size >= 0)); elt->size = size; if (size > 0) { elt->buf = (std_uint *) local_malloc(HPBIT_MEM_KEY,size*sizeof(std_uint)); elt->set_buf = (int *) local_malloc(HPBIT_MEM_KEY,size*sizeof(int)); } insert_pre_marker_element(elt,pm);}/*****************************************************************************//* STATIC __size_marker_elt *//*****************************************************************************/static int __size_marker_elt(stream_out_ref base, int tnum, const char *elt_id, int instance){ hpbit_stream_out_ref self = (hpbit_stream_out_ref) base; hpbit_tile_ptr tile; hpbit_pre_marker_ptr pm; hpbit_marker_elt_ptr elt; pm = NULL; if (tnum >= 0) { for (tile=self->tiles; tile != NULL; tile=tile->next) if (tile->tnum == tnum) break; if (tile != NULL) for (pm=tile->markers.pre_markers; pm != NULL; pm=pm->next) if ((pm->id == (int)(elt_id[0])) && (pm->instance == instance)) break; if (pm != NULL) for (elt=pm->elements; elt != NULL; elt=elt->next) if (elt->element_id == (int)(elt_id[1])) return(elt->size); } for (pm=self->global_markers.pre_markers; pm != NULL; pm=pm->next) if ((pm->id == (int)(elt_id[0])) && (pm->instance == instance)) break; if (pm != NULL) for (elt=pm->elements; elt != NULL; elt=elt->next) if (elt->element_id == (int)(elt_id[1])) return(elt->size); return(0);}/*****************************************************************************//* STATIC __get_marker_val *//*****************************************************************************/static std_uint __get_marker_val(stream_out_ref base, int tnum, const char *elt_id, int instance, int idx){ hpbit_stream_out_ref self = (hpbit_stream_out_ref) base; hpbit_tile_ptr tile; hpbit_pre_marker_ptr pm; hpbit_marker_elt_ptr elt; int marker_id, element_id; char *description; marker_id = elt_id[0]; element_id = elt_id[1]; description = (char *)(elt_id + 2); elt = NULL; if (tnum >= 0) { for (tile=self->tiles; tile != NULL; tile=tile->next) if (tile->tnum == tnum) break; if (tile != NULL) for (pm=tile->markers.pre_markers; pm != NULL; pm=pm->next) if ((pm->instance == instance) && (pm->id == marker_id)) break; if (pm != NULL) for (elt=pm->elements; elt != NULL; elt=elt->next) if (elt->element_id == element_id) break; } if (elt == NULL) { for (pm=self->global_markers.pre_markers; pm != NULL; pm=pm->next) if ((pm->instance == instance) && (pm->id == marker_id)) break; if (pm != NULL) for (elt=pm->elements; elt != NULL; elt=elt->next) if (elt->element_id == element_id) break; } if ((elt == NULL) || (idx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -