📄 hpbit_stream_in.c
字号:
hpbit_marker_elt_ptr elt;
std_byte *bp;
assert(cp->accesses == 0);
bp = cp->buf;
copy_from_big_endian(bp,&(cod.COD),2,2); bp += 2*2;
cod.Scod = *(bp++);
cod.prog = *(bp++);
copy_from_big_endian(bp,&(cod.layers),1,2); bp += 1*2;
cod.cxform = *(bp++);
cod.level = *(bp++);
cod.xcb = *(bp++);
cod.ycb = *(bp++);
cod.mod = *(bp++);
cod.rev = *(bp++);
if((cod.cxform == 1) && (cod.rev == 0)) cod.cxform = 2;
if (cod.Scod & 1) {
for(i=0;i<cod.level + 1;i++){
ppxy = *(bp++);
cod_ppx[i] = (ppxy & 0x0f);
cod_ppy[i] = (ppxy >> 4);
}
}
pm = (hpbit_pre_marker_ptr)
local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker));
pm->next = markers->pre_markers;
markers->pre_markers = pm;
pm->id = MARKER_COD & 0x00FF;
pm->instance = 0;
elt = add_elt(pm,MARKER_COD_PROG,1); elt->buf[0] = cod.prog;
elt = add_elt(pm,MARKER_COD_LAYERS,1); elt->buf[0] = cod.layers;
elt = add_elt(pm,MARKER_COD_SOP,1); elt->buf[0] = (cod.Scod&2)?1:0;
elt = add_elt(pm,MARKER_COD_EPH,1); elt->buf[0] = (cod.Scod&4)?1:0;
elt = add_elt(pm,MARKER_COD_CXFORM,1); elt->buf[0] = cod.cxform;
cp->accesses = 1;
break;
}
self->failed_marker_translations += failure;
if (cp==NULL) /* No COD found */
return(0);
if (failure)
return(0);
/* Now for each component either read a COC, or if none
create a COC from the COD, and add the pre-marker */
failure = 0;
for (comp=0; comp < markers->params.num_components; comp++)
{
for (cp=markers->codestream_markers; cp != NULL; cp=cp->next)
if (cp->buf[1] == (MARKER_COC & 0x00FF))
{
if ((markers->params.num_components < 256) &&
(cp->buf[4] != comp))
continue;
if ((markers->params.num_components >=256) &&
((cp->buf[4] << 8) + cp->buf[5] != comp))
continue;
assert(cp->accesses == 0);
bp = cp->buf;
copy_from_big_endian(bp,&(coc.COC),2,2); bp += 2*2;
coc.Ccoc = *(bp++);
if (markers->params.num_components >= 256) /* J. Kasner fix */
coc.Ccoc = (coc.Ccoc << 8) + *(bp++);
assert(coc.COC == MARKER_COC);
coc.Scoc = *(bp++);
coc.level = *(bp++);
coc.xcb = *(bp++);
coc.ycb = *(bp++);
coc.mod = *(bp++);
coc.rev = *(bp++);
if (coc.Scoc & 1) {
for(i=0;i<coc.level + 1;i++){
ppxy = *(bp++);
coc_ppx[i] = (ppxy & 0x0f);
coc_ppy[i] = (ppxy >> 4);
}
}
cp->accesses = 1;
break;
}
self->failed_marker_translations += failure;
if (cp == NULL) /* Didn't find marker */
{
/* Note: this code doesn't work if COD is a marker, but */
/* COC is premarker, but only the VM writes pre-markers and */
/* it either writes both COD and COC as markers or as premarkers */
/* copy from cod */
coc.Ccoc = comp;
coc.Scoc = cod.Scod;
coc.level = cod.level;
coc.xcb = cod.xcb;
coc.ycb = cod.ycb;
coc.mod = cod.mod;
coc.rev = cod.rev;
for(i=0;i<coc.level + 1;i++){
coc_ppx[i] = cod_ppx[i];
coc_ppy[i] = cod_ppy[i];
}
}
pm = (hpbit_pre_marker_ptr)
local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker));
pm->next = markers->pre_markers;
markers->pre_markers = pm;
pm->id = MARKER_COC & 0x00FF;
pm->instance = coc.Ccoc;
elt = add_elt(pm,MARKER_COC_LEVELS,1); elt->buf[0] = coc.level;
elt = add_elt(pm,MARKER_COC_REV,1); elt->buf[0] = coc.rev;
elt = add_elt(pm,MARKER_COC_XCB,1); elt->buf[0] = coc.xcb;
elt = add_elt(pm,MARKER_COC_YCB,1); elt->buf[0] = coc.ycb;
if (coc.Scoc & 1) {
ppx = add_elt(pm,MARKER_COC_PPX,coc.level+1);
ppy = add_elt(pm,MARKER_COC_PPY,coc.level+1);
/* Found Bug by Sony Corp.!! 00.10.27 */
/*
for(i=0;i<cod.level + 1;i++){ */
for(i=0;i<coc.level + 1;i++){
ppx->buf[i] = coc_ppx[i];
ppy->buf[i] = coc_ppy[i];
}
}
elt = add_elt(pm,MARKER_COC_MOD,1); elt->buf[0] = coc.mod;
}
return(1);
}
/*****************************************************************************/
/* STATIC translate_qcd_qcc_markers */
/*****************************************************************************/
static int
translate_qcd_qcc_markers(hpbit_stream_in_ref self,
hpbit_markers_ptr markers)
/* Looks for QCD and QCC markers in the `markers->codestream_markers' list
and uses these to construct the COD and COC pre-markers, putting them
on the `markers->pre_markers' list. If no QCD marker can be found, the
function returns 0. Otherwise, the function returns 1. The function
should not raise asserts or terminate the program abnormally. If marker
translation fails, `self->failed_marker_translations' should be
incremented instead.
Note: all coding parameters collected in `markers->params' are accurate
and available for error checking and codestream marker formation. There
should be no need to store further coding parameters. */
{
qcc_marker qcd,qcc;
hpbit_pre_marker_ptr pm;
hpbit_codestream_marker_ptr cp;
hpbit_marker_elt_ptr elt, elt2;
std_byte *bp;
int comp;
int data_size;
int failure = 0;
memset(&qcd,0,sizeof(qcd));
memset(&qcc,0,sizeof(qcc));
/* First find a QCD and pass the WHICH up */
for (cp=markers->codestream_markers; cp != NULL; cp=cp->next)
if (cp->buf[1] == (MARKER_QCD & 0x00FF))
{
assert(cp->accesses == 0);
bp = cp->buf;
copy_from_big_endian(bp,&(qcd.QCC),2,2); bp += 2*2;
qcd.Cqcc = -1; /* no component number */
qcd.Sqcc = *(bp++);
if ((qcd.Sqcc & 0x1F) > 5)
failure = 1;
qcd.data = bp;
break;
}
self->failed_marker_translations += failure;
if (cp==NULL) /* No COD found */
return(0);
if (failure)
return(0);
pm = (hpbit_pre_marker_ptr)
local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker));
pm->next = markers->pre_markers;
markers->pre_markers = pm;
pm->id = MARKER_QCD & 0x00FF;
pm->instance = 0;
/* MARKER_QCD_WHICH is not directly related to syntax, for
Part I, it is always 0 */
elt = add_elt(pm,MARKER_QCD_WHICH,1); elt->buf[0] = 0;
cp->accesses = 1;
/* Now for each component find the QCC or use the QCD */
failure = 0;
for (comp=0; comp < markers->params.num_components; comp++)
{
for (cp=markers->codestream_markers; cp != NULL; cp=cp->next)
if (cp->buf[1] == (MARKER_QCC & 0x00FF))
{
if ((markers->params.num_components < 256) &&
(cp->buf[4] != comp))
continue;
if ((markers->params.num_components >=256) &&
((cp->buf[4] << 8) + cp->buf[5] != comp))
continue;
bp = cp->buf;
copy_from_big_endian(bp,&(qcc.QCC),2,2); bp += 2*2;
qcc.Cqcc = *(bp++);
if (markers->params.num_components >=256)
qcc.Cqcc = (qcc.Cqcc << 8) + *(bp++);
qcc.Sqcc = *(bp++);
qcc.data = bp;
assert(qcc.QCC == MARKER_QCC);
cp->accesses = 1;
break;
}
self->failed_marker_translations += failure;
if (cp == NULL) /* Didn't find marker */
{
/* Note: this code doesn't work if QCD is a marker, but */
/* QCC is premarker, but only the VM writes pre-markers and */
/* it either writes both QCD and QCC as markers or as premarkers */
/* copy from qcd */
qcc.Lqcc = qcd.Lqcc + 1; /* component # */
qcc.Cqcc = comp;
qcc.Sqcc = qcd.Sqcc;
qcc.data = qcd.data;
}
data_size = qcc.Lqcc - 4;/* length, component, selector */
pm = (hpbit_pre_marker_ptr)
local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker));
pm->next = markers->pre_markers;
markers->pre_markers = pm;
pm->id = MARKER_QCC & 0x00FF;
pm->instance = comp;
elt = add_elt(pm,MARKER_QCC_GUARD,1); elt->buf[0] = qcc.Sqcc >> 5;
elt = add_elt(pm,MARKER_QCC_TYPE,1); elt->buf[0] = qcc.Sqcc & 0x1F;
if ((qcc.Sqcc & 0x1F) ==0) {
/* REV */
int i;
elt = add_elt(pm,MARKER_QCC_REV,data_size);
for(i=0; i<data_size; i++)
elt->buf[i] = (std_int) qcc.data[i] >> 3;
} else {
/* STEP */
int i, j;
if ((qcc.Sqcc & 0x1F) < 3) {
elt = add_elt(pm,MARKER_QCC_STEP,data_size/2);
for(i=0, j=0; j<data_size; i++, j+=2) {
elt->buf[i] = (std_int) qcc.data[j] << 8;
elt->buf[i] |= (std_int) qcc.data[j+1];
}
} else if ((qcc.Sqcc & 0x1F) == 3) {
elt = add_elt(pm,MARKER_QCC_STEP,1);
elt2 = add_elt(pm,MARKER_QCC_NZ,1);
for(i=0, j=0; j<data_size; i++, j+=4) {
elt2->buf[i] = (std_int) qcc.data[j] << 8;
elt2->buf[i] |= (std_int) qcc.data[j+1];
elt->buf[i] = (std_int) qcc.data[j+2] << 8;
elt->buf[i] |= (std_int) qcc.data[j+3];
}
} else if ((qcc.Sqcc & 0x1F) == 5) {
elt = add_elt(pm,MARKER_QCC_STEP,data_size/4);
elt2 = add_elt(pm,MARKER_QCC_NZ,data_size/4);
for(i=0, j=0; j<data_size; i++, j+=4) {
elt2->buf[i] = (std_int) qcc.data[j] << 8;
elt2->buf[i] |= (std_int) qcc.data[j+1];
elt->buf[i] = (std_int) qcc.data[j+2] << 8;
elt->buf[i] |= (std_int) qcc.data[j+3];
}
} else if ((qcc.Sqcc & 0x1F) == 4) {
elt2 = add_elt(pm,MARKER_QCC_NZ,1);
elt = add_elt(pm,MARKER_QCC_STEP,data_size/2-1);
elt2->buf[0] = (std_int) qcc.data[0] << 8;
elt2->buf[0] |= (std_int) qcc.data[1];
for(i=0, j=2; j<data_size; i++, j+=2) {
elt->buf[i] = (std_int) qcc.data[j] << 8;
elt->buf[i] |= (std_int) qcc.data[j+1];
}
}
}
}
return(1);
}
/*****************************************************************************/
/* STATIC siz_to_pre_marker */
/*****************************************************************************/
static int
siz_to_pre_marker(hpbit_stream_in_ref self,
hpbit_markers_ptr markers,
hpbit_codestream_marker_ptr cp)
/* Returns 1 if successful in translating marker; 0 otherwise. */
{
siz_marker siz;
hpbit_pre_marker_ptr pm;
hpbit_marker_elt_ptr elt, Ssiz, XRsiz, YRsiz;
std_byte *bp;
int comps, c;
if (markers != &(self->global_markers))
return(0);
assert(cp->accesses == 0);
bp = cp->buf;
copy_from_big_endian(bp,&(siz.SIZ),3,2); bp += 3*2;
copy_from_big_endian(bp,&(siz.Xsiz),8,4); bp += 8*4;
copy_from_big_endian(bp,&(siz.Csiz),1,2); bp += 1*2;
assert(siz.SIZ == MARKER_SIZ);
comps = siz.Csiz;
pm = (hpbit_pre_marker_ptr)
local_malloc(HPBIT_MEM_KEY,sizeof(hpbit_pre_marker));
pm->next = markers->pre_markers;
markers->pre_markers = pm;
pm->id = MARKER_SIZ & 0x00FF;
pm->instance = 0;
elt = add_elt(pm,MARKER_SIZ_X,1); elt->buf[0] = siz.Xsiz;
elt = add_elt(pm,MARKER_SIZ_Y,1); elt->buf[0] = siz.Ysiz;
elt = add_elt(pm,MARKER_SIZ_XO,1); elt->buf[0] = siz.XOsiz;
elt = add_elt(pm,MARKER_SIZ_YO,1); elt->buf[0] = siz.YOsiz;
elt = add_elt(pm,MARKER_SIZ_XT,1); elt->buf[0] = siz.XTsiz;
elt = add_elt(pm,MARKER_SIZ_YT,1); elt->buf[0] = siz.YTsiz;
elt = add_elt(pm,MARKER_SIZ_XTO,1); elt->buf[0] = siz.XTOsiz;
elt = add_elt(pm,MARKER_SIZ_YTO,1); elt->buf[0] = siz.YTOsiz;
elt = add_elt(pm,MARKER_SIZ_C,1); elt->buf[0] = siz.Csiz;
Ssiz = add_elt(pm,MARKER_SIZ_S,comps);
XRsiz = add_elt(pm,MARKER_SIZ_XR,comps);
YRsiz = add_elt(pm,MARKER_SIZ_YR,comps);
for (c=0; c < comps; c++)
{
Ssiz->buf[c] = *(bp++) + 1;
XRsiz->buf[c] = *(bp++);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -