avcodec/j2k: rename J2K_ constants to JPEG2000_

This should simplify merging the 2 decoders

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-05-21 21:27:56 +02:00
parent 0ab0ed2b86
commit 78c7bff04a
4 changed files with 133 additions and 133 deletions

View File

@ -109,16 +109,16 @@ static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol)
{
int h, v, d;
h = ((flag & J2K_T1_SIG_E) ? 1:0)+
((flag & J2K_T1_SIG_W) ? 1:0);
v = ((flag & J2K_T1_SIG_N) ? 1:0);
h = ((flag & JPEG2000_T1_SIG_E) ? 1:0)+
((flag & JPEG2000_T1_SIG_W) ? 1:0);
v = ((flag & JPEG2000_T1_SIG_N) ? 1:0);
if (!vert_causal_ctx_csty_symbol)
v = v + ((flag & J2K_T1_SIG_S) ? 1:0);
d = ((flag & J2K_T1_SIG_NE) ? 1:0)+
((flag & J2K_T1_SIG_NW) ? 1:0);
v = v + ((flag & JPEG2000_T1_SIG_S) ? 1:0);
d = ((flag & JPEG2000_T1_SIG_NE) ? 1:0)+
((flag & JPEG2000_T1_SIG_NW) ? 1:0);
if (!vert_causal_ctx_csty_symbol)
d = d + ((flag & J2K_T1_SIG_SE) ? 1:0)+
((flag & J2K_T1_SIG_SW) ? 1:0);
d = d + ((flag & JPEG2000_T1_SIG_SE) ? 1:0)+
((flag & JPEG2000_T1_SIG_SW) ? 1:0);
if (bandno < 3){
if (bandno == 1)
FFSWAP(int, h, v);
@ -159,10 +159,10 @@ static int getsgnctxno(int flag, uint8_t *xorbit)
static const int ctxlbltab[3][3] = {{13, 12, 11}, {10, 9, 10}, {11, 12, 13}};
static const int xorbittab[3][3] = {{1, 1, 1,}, {1, 0, 0}, {0, 0, 0}};
hcontrib = contribtab[flag & J2K_T1_SIG_E ? flag & J2K_T1_SGN_E ? 1:2:0]
[flag & J2K_T1_SIG_W ? flag & J2K_T1_SGN_W ? 1:2:0]+1;
vcontrib = contribtab[flag & J2K_T1_SIG_S ? flag & J2K_T1_SGN_S ? 1:2:0]
[flag & J2K_T1_SIG_N ? flag & J2K_T1_SGN_N ? 1:2:0]+1;
hcontrib = contribtab[flag & JPEG2000_T1_SIG_E ? flag & JPEG2000_T1_SGN_E ? 1:2:0]
[flag & JPEG2000_T1_SIG_W ? flag & JPEG2000_T1_SGN_W ? 1:2:0]+1;
vcontrib = contribtab[flag & JPEG2000_T1_SIG_S ? flag & JPEG2000_T1_SGN_S ? 1:2:0]
[flag & JPEG2000_T1_SIG_N ? flag & JPEG2000_T1_SGN_N ? 1:2:0]+1;
*xorbit = xorbittab[hcontrib][vcontrib];
return ctxlbltab[hcontrib][vcontrib];
}
@ -181,22 +181,22 @@ void ff_j2k_init_tier1_luts(void)
void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative)
{
x++; y++;
t1->flags[y][x] |= J2K_T1_SIG;
t1->flags[y][x] |= JPEG2000_T1_SIG;
if (negative){
t1->flags[y][x+1] |= J2K_T1_SIG_W | J2K_T1_SGN_W;
t1->flags[y][x-1] |= J2K_T1_SIG_E | J2K_T1_SGN_E;
t1->flags[y+1][x] |= J2K_T1_SIG_N | J2K_T1_SGN_N;
t1->flags[y-1][x] |= J2K_T1_SIG_S | J2K_T1_SGN_S;
t1->flags[y][x+1] |= JPEG2000_T1_SIG_W | JPEG2000_T1_SGN_W;
t1->flags[y][x-1] |= JPEG2000_T1_SIG_E | JPEG2000_T1_SGN_E;
t1->flags[y+1][x] |= JPEG2000_T1_SIG_N | JPEG2000_T1_SGN_N;
t1->flags[y-1][x] |= JPEG2000_T1_SIG_S | JPEG2000_T1_SGN_S;
} else{
t1->flags[y][x+1] |= J2K_T1_SIG_W;
t1->flags[y][x-1] |= J2K_T1_SIG_E;
t1->flags[y+1][x] |= J2K_T1_SIG_N;
t1->flags[y-1][x] |= J2K_T1_SIG_S;
t1->flags[y][x+1] |= JPEG2000_T1_SIG_W;
t1->flags[y][x-1] |= JPEG2000_T1_SIG_E;
t1->flags[y+1][x] |= JPEG2000_T1_SIG_N;
t1->flags[y-1][x] |= JPEG2000_T1_SIG_S;
}
t1->flags[y+1][x+1] |= J2K_T1_SIG_NW;
t1->flags[y+1][x-1] |= J2K_T1_SIG_NE;
t1->flags[y-1][x+1] |= J2K_T1_SIG_SW;
t1->flags[y-1][x-1] |= J2K_T1_SIG_SE;
t1->flags[y+1][x+1] |= JPEG2000_T1_SIG_NW;
t1->flags[y+1][x-1] |= JPEG2000_T1_SIG_NE;
t1->flags[y-1][x+1] |= JPEG2000_T1_SIG_SW;
t1->flags[y-1][x-1] |= JPEG2000_T1_SIG_SE;
}
int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty, Jpeg2000QuantStyle *qntsty, int cbps, int dx, int dy)
@ -251,7 +251,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
int xi0, yi0, xi1, yi1;
int cblkperprecw, cblkperprech;
if (qntsty->quantsty != J2K_QSTY_NONE){
if (qntsty->quantsty != JPEG2000_QSTY_NONE){
static const uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}};
int numbps;

View File

@ -32,77 +32,77 @@
#include "j2k_dwt.h"
enum Jpeg2000Markers{
J2K_SOC = 0xff4f, ///< start of codestream
J2K_SIZ = 0xff51, ///< image and tile size
J2K_COD, ///< coding style default
J2K_COC, ///< coding style component
J2K_TLM = 0xff55, ///< packed packet headers, tile-part header
J2K_PLM = 0xff57, ///< tile-part lengths
J2K_PLT, ///< packet length, main header
J2K_QCD = 0xff5c, ///< quantization default
J2K_QCC, ///< quantization component
J2K_RGN, ///< region of interest
J2K_POC, ///< progression order change
J2K_PPM, ///< packet length, tile-part header
J2K_PPT, ///< packed packet headers, main header
J2K_CRG = 0xff63, ///< component registration
J2K_COM, ///< comment
J2K_SOT = 0xff90, ///< start of tile-part
J2K_SOP, ///< start of packet
J2K_EPH, ///< end of packet header
J2K_SOD, ///< start of data
J2K_EOC = 0xffd9, ///< end of codestream
JPEG2000_SOC = 0xff4f, ///< start of codestream
JPEG2000_SIZ = 0xff51, ///< image and tile size
JPEG2000_COD, ///< coding style default
JPEG2000_COC, ///< coding style component
JPEG2000_TLM = 0xff55, ///< packed packet headers, tile-part header
JPEG2000_PLM = 0xff57, ///< tile-part lengths
JPEG2000_PLT, ///< packet length, main header
JPEG2000_QCD = 0xff5c, ///< quantization default
JPEG2000_QCC, ///< quantization component
JPEG2000_RGN, ///< region of interest
JPEG2000_POC, ///< progression order change
JPEG2000_PPM, ///< packet length, tile-part header
JPEG2000_PPT, ///< packed packet headers, main header
JPEG2000_CRG = 0xff63, ///< component registration
JPEG2000_COM, ///< comment
JPEG2000_SOT = 0xff90, ///< start of tile-part
JPEG2000_SOP, ///< start of packet
JPEG2000_EPH, ///< end of packet header
JPEG2000_SOD, ///< start of data
JPEG2000_EOC = 0xffd9, ///< end of codestream
};
enum Jpeg2000Quantsty{ ///< quantization style
J2K_QSTY_NONE, ///< no quantization
J2K_QSTY_SI, ///< scalar derived
J2K_QSTY_SE ///< scalar expoounded
JPEG2000_QSTY_NONE, ///< no quantization
JPEG2000_QSTY_SI, ///< scalar derived
JPEG2000_QSTY_SE ///< scalar expoounded
};
#define J2K_MAX_CBLKW 64
#define J2K_MAX_CBLKH 64
#define JPEG2000_MAX_CBLKW 64
#define JPEG2000_MAX_CBLKH 64
// T1 flags
// flags determining significance of neighbour coefficients
#define J2K_T1_SIG_N 0x0001
#define J2K_T1_SIG_E 0x0002
#define J2K_T1_SIG_W 0x0004
#define J2K_T1_SIG_S 0x0008
#define J2K_T1_SIG_NE 0x0010
#define J2K_T1_SIG_NW 0x0020
#define J2K_T1_SIG_SE 0x0040
#define J2K_T1_SIG_SW 0x0080
#define J2K_T1_SIG_NB (J2K_T1_SIG_N | J2K_T1_SIG_E | J2K_T1_SIG_S | J2K_T1_SIG_W \
|J2K_T1_SIG_NE | J2K_T1_SIG_NW | J2K_T1_SIG_SE | J2K_T1_SIG_SW)
#define JPEG2000_T1_SIG_N 0x0001
#define JPEG2000_T1_SIG_E 0x0002
#define JPEG2000_T1_SIG_W 0x0004
#define JPEG2000_T1_SIG_S 0x0008
#define JPEG2000_T1_SIG_NE 0x0010
#define JPEG2000_T1_SIG_NW 0x0020
#define JPEG2000_T1_SIG_SE 0x0040
#define JPEG2000_T1_SIG_SW 0x0080
#define JPEG2000_T1_SIG_NB (JPEG2000_T1_SIG_N | JPEG2000_T1_SIG_E | JPEG2000_T1_SIG_S | JPEG2000_T1_SIG_W \
|JPEG2000_T1_SIG_NE | JPEG2000_T1_SIG_NW | JPEG2000_T1_SIG_SE | JPEG2000_T1_SIG_SW)
// flags determining sign bit of neighbour coefficients
#define J2K_T1_SGN_N 0x0100
#define J2K_T1_SGN_S 0x0200
#define J2K_T1_SGN_W 0x0400
#define J2K_T1_SGN_E 0x0800
#define JPEG2000_T1_SGN_N 0x0100
#define JPEG2000_T1_SGN_S 0x0200
#define JPEG2000_T1_SGN_W 0x0400
#define JPEG2000_T1_SGN_E 0x0800
#define J2K_T1_VIS 0x1000
#define J2K_T1_SIG 0x2000
#define J2K_T1_REF 0x4000
#define JPEG2000_T1_VIS 0x1000
#define JPEG2000_T1_SIG 0x2000
#define JPEG2000_T1_REF 0x4000
#define J2K_T1_SGN 0x8000
#define JPEG2000_T1_SGN 0x8000
// Codeblock coding styles
#define J2K_CBLK_BYPASS 0x01 // Selective arithmetic coding bypass
#define J2K_CBLK_RESET 0x02 // Reset context probabilities
#define J2K_CBLK_TERMALL 0x04 // Terminate after each coding pass
#define J2K_CBLK_VSC 0x08 // Vertical stripe causal context formation
#define J2K_CBLK_PREDTERM 0x10 // Predictable termination
#define J2K_CBLK_SEGSYM 0x20 // Segmentation symbols present
#define JPEG2000_CBLK_BYPASS 0x01 // Selective arithmetic coding bypass
#define JPEG2000_CBLK_RESET 0x02 // Reset context probabilities
#define JPEG2000_CBLK_TERMALL 0x04 // Terminate after each coding pass
#define JPEG2000_CBLK_VSC 0x08 // Vertical stripe causal context formation
#define JPEG2000_CBLK_PREDTERM 0x10 // Predictable termination
#define JPEG2000_CBLK_SEGSYM 0x20 // Segmentation symbols present
// Coding styles
#define J2K_CSTY_PREC 0x01 // Precincts defined in coding style
#define J2K_CSTY_SOP 0x02 // SOP marker present
#define J2K_CSTY_EPH 0x04 // EPH marker present
#define JPEG2000_CSTY_PREC 0x01 // Precincts defined in coding style
#define JPEG2000_CSTY_SOP 0x02 // SOP marker present
#define JPEG2000_CSTY_EPH 0x04 // EPH marker present
typedef struct {
int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH];
int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2];
int data[JPEG2000_MAX_CBLKW][JPEG2000_MAX_CBLKH];
int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2];
MqcState mqc;
} Jpeg2000T1Context;

View File

@ -307,7 +307,7 @@ static int get_cox(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *c)
av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style);
}
c->transform = bytestream2_get_byteu(&s->g); // transformation
if (c->csty & J2K_CSTY_PREC) {
if (c->csty & JPEG2000_CSTY_PREC) {
int i;
for (i = 0; i < c->nreslevels; i++)
@ -377,13 +377,13 @@ static int get_qcx(Jpeg2000DecoderContext *s, int n, Jpeg2000QuantStyle *q)
q->nguardbits = x >> 5;
q->quantsty = x & 0x1f;
if (q->quantsty == J2K_QSTY_NONE){
if (q->quantsty == JPEG2000_QSTY_NONE){
n -= 3;
if (bytestream2_get_bytes_left(&s->g) < n || 32*3 < n)
return AVERROR(EINVAL);
for (i = 0; i < n; i++)
q->expn[i] = bytestream2_get_byteu(&s->g) >> 3;
} else if (q->quantsty == J2K_QSTY_SI){
} else if (q->quantsty == JPEG2000_QSTY_SI){
if (bytestream2_get_bytes_left(&s->g) < 2)
return AVERROR(EINVAL);
x = bytestream2_get_be16u(&s->g);
@ -562,8 +562,8 @@ static int decode_packet(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty,
}
j2k_flush(s);
if (codsty->csty & J2K_CSTY_EPH) {
if (bytestream2_peek_be16(&s->g) == J2K_EPH) {
if (codsty->csty & JPEG2000_CSTY_EPH) {
if (bytestream2_peek_be16(&s->g) == JPEG2000_EPH) {
bytestream2_skip(&s->g, 2);
} else {
av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n");
@ -623,8 +623,8 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0+4; y++){
if ((t1->flags[y+1][x+1] & J2K_T1_SIG_NB)
&& !(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
if ((t1->flags[y+1][x+1] & JPEG2000_T1_SIG_NB)
&& !(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){
int vert_causal_ctx_csty_loc_symbol = vert_causal_ctx_csty_symbol && (x == 3 && y == 3);
if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno,
vert_causal_ctx_csty_loc_symbol))){
@ -637,7 +637,7 @@ static void decode_sigpass(Jpeg2000T1Context *t1, int width, int height, int bpn
ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
}
t1->flags[y+1][x+1] |= J2K_T1_VIS;
t1->flags[y+1][x+1] |= JPEG2000_T1_VIS;
}
}
}
@ -653,11 +653,11 @@ static void decode_refpass(Jpeg2000T1Context *t1, int width, int height, int bpn
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0+4; y++){
if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
if ((t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG){
int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf;
t1->data[y][x] += t1->data[y][x] < 0 ? -r : r;
t1->flags[y+1][x+1] |= J2K_T1_REF;
t1->flags[y+1][x+1] |= JPEG2000_T1_REF;
}
}
}
@ -670,10 +670,10 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
for (y0 = 0; y0 < height; y0 += 4) {
for (x = 0; x < width; x++){
if (y0 + 3 < height && !(
(t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)))){
(t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+2][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+3][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+4][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)))){
if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL))
continue;
runlen = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
@ -686,7 +686,7 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
for (y = y0 + runlen; y < y0 + 4 && y < height; y++){
if (!dec){
if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)))
if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)))
dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1],
bandno, 0));
}
@ -696,7 +696,7 @@ static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1, int
ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0);
}
dec = 0;
t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;
}
}
}
@ -716,8 +716,8 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, J
int width, int height, int bandpos)
{
int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0;
int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style;
int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style;
int bpass_csty_symbol = JPEG2000_CBLK_BYPASS & codsty->cblk_style;
int vert_causal_ctx_csty_symbol = JPEG2000_CBLK_VSC & codsty->cblk_style;
for (y = 0; y < height+2; y++)
memset(t1->flags[y], 0, (width+2)*sizeof(int));
@ -739,7 +739,7 @@ static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle *codsty, J
ff_mqc_initdec(&t1->mqc, cblk->data);
break;
case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos,
codsty->cblk_style & J2K_CBLK_SEGSYM);
codsty->cblk_style & JPEG2000_CBLK_SEGSYM);
clnpass_cnt = clnpass_cnt + 1;
if (bpass_csty_symbol && clnpass_cnt >= 4)
ff_mqc_initdec(&t1->mqc, cblk->data);
@ -936,7 +936,7 @@ static int decode_codestream(Jpeg2000DecoderContext *s)
av_dlog(s->avctx, "marker 0x%.4X at pos 0x%x\n", marker, bytestream2_tell(&s->g) - 4);
oldpos = bytestream2_tell(&s->g);
if (marker == J2K_SOD){
if (marker == JPEG2000_SOD){
Jpeg2000Tile *tile = s->tile + s->curtileno;
if (ret = init_tile(s, s->curtileno)) {
av_log(s->avctx, AV_LOG_ERROR, "tile initialization failed\n");
@ -948,36 +948,36 @@ static int decode_codestream(Jpeg2000DecoderContext *s)
}
continue;
}
if (marker == J2K_EOC)
if (marker == JPEG2000_EOC)
break;
if (bytestream2_get_bytes_left(&s->g) < 2)
return AVERROR(EINVAL);
len = bytestream2_get_be16u(&s->g);
switch (marker){
case J2K_SIZ:
case JPEG2000_SIZ:
ret = get_siz(s);
break;
case J2K_COC:
case JPEG2000_COC:
ret = get_coc(s, codsty, properties);
break;
case J2K_COD:
case JPEG2000_COD:
ret = get_cod(s, codsty, properties);
break;
case J2K_QCC:
case JPEG2000_QCC:
ret = get_qcc(s, len, qntsty, properties);
break;
case J2K_QCD:
case JPEG2000_QCD:
ret = get_qcd(s, len, qntsty, properties);
break;
case J2K_SOT:
case JPEG2000_SOT:
if (!(ret = get_sot(s))){
codsty = s->tile[s->curtileno].codsty;
qntsty = s->tile[s->curtileno].qntsty;
properties = s->tile[s->curtileno].properties;
}
break;
case J2K_COM:
case JPEG2000_COM:
// the comment is ignored
bytestream2_skip(&s->g, len - 2);
break;
@ -1049,7 +1049,7 @@ static int decode_frame(AVCodecContext *avctx,
bytestream2_seek(&s->g, 0, SEEK_SET);
}
if (bytestream2_get_be16u(&s->g) != J2K_SOC){
if (bytestream2_get_be16u(&s->g) != JPEG2000_SOC){
av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n");
ret = -1;
goto err_out;

View File

@ -235,7 +235,7 @@ static int put_siz(Jpeg2000EncoderContext *s)
if (s->buf_end - s->buf < 40 + 3 * s->ncomponents)
return -1;
bytestream_put_be16(&s->buf, J2K_SIZ);
bytestream_put_be16(&s->buf, JPEG2000_SIZ);
bytestream_put_be16(&s->buf, 38 + 3 * s->ncomponents); // Lsiz
bytestream_put_be16(&s->buf, 0); // Rsiz
bytestream_put_be32(&s->buf, s->width); // width
@ -264,7 +264,7 @@ static int put_cod(Jpeg2000EncoderContext *s)
if (s->buf_end - s->buf < 14)
return -1;
bytestream_put_be16(&s->buf, J2K_COD);
bytestream_put_be16(&s->buf, JPEG2000_COD);
bytestream_put_be16(&s->buf, 12); // Lcod
bytestream_put_byte(&s->buf, 0); // Scod
// SGcod
@ -290,7 +290,7 @@ static int put_qcd(Jpeg2000EncoderContext *s, int compno)
Jpeg2000CodingStyle *codsty = &s->codsty;
Jpeg2000QuantStyle *qntsty = &s->qntsty;
if (qntsty->quantsty == J2K_QSTY_NONE)
if (qntsty->quantsty == JPEG2000_QSTY_NONE)
size = 4 + 3 * (codsty->nreslevels-1);
else // QSTY_SE
size = 5 + 6 * (codsty->nreslevels-1);
@ -298,10 +298,10 @@ static int put_qcd(Jpeg2000EncoderContext *s, int compno)
if (s->buf_end - s->buf < size + 2)
return -1;
bytestream_put_be16(&s->buf, J2K_QCD);
bytestream_put_be16(&s->buf, JPEG2000_QCD);
bytestream_put_be16(&s->buf, size); // LQcd
bytestream_put_byte(&s->buf, (qntsty->nguardbits << 5) | qntsty->quantsty); // Sqcd
if (qntsty->quantsty == J2K_QSTY_NONE)
if (qntsty->quantsty == JPEG2000_QSTY_NONE)
for (i = 0; i < codsty->nreslevels * 3 - 2; i++)
bytestream_put_byte(&s->buf, qntsty->expn[i] << 3);
else // QSTY_SE
@ -317,7 +317,7 @@ static uint8_t *put_sot(Jpeg2000EncoderContext *s, int tileno)
if (s->buf_end - s->buf < 12)
return NULL;
bytestream_put_be16(&s->buf, J2K_SOT);
bytestream_put_be16(&s->buf, JPEG2000_SOT);
bytestream_put_be16(&s->buf, 10); // Lsot
bytestream_put_be16(&s->buf, tileno); // Isot
@ -480,7 +480,7 @@ static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int ban
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0+4; y++){
if (!(t1->flags[y+1][x+1] & J2K_T1_SIG) && (t1->flags[y+1][x+1] & J2K_T1_SIG_NB)){
if (!(t1->flags[y+1][x+1] & JPEG2000_T1_SIG) && (t1->flags[y+1][x+1] & JPEG2000_T1_SIG_NB)){
int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol),
bit = t1->data[y][x] & mask ? 1 : 0;
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, bit);
@ -491,7 +491,7 @@ static void encode_sigpass(Jpeg2000T1Context *t1, int width, int height, int ban
*nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
}
t1->flags[y+1][x+1] |= J2K_T1_VIS;
t1->flags[y+1][x+1] |= JPEG2000_T1_VIS;
}
}
}
@ -502,11 +502,11 @@ static void encode_refpass(Jpeg2000T1Context *t1, int width, int height, int *nm
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++)
for (y = y0; y < height && y < y0+4; y++)
if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){
if ((t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS)) == JPEG2000_T1_SIG){
int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]);
*nmsedec += getnmsedec_ref(t1->data[y][x], bpno + NMSEDEC_FRACBITS);
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
t1->flags[y+1][x+1] |= J2K_T1_REF;
t1->flags[y+1][x+1] |= JPEG2000_T1_REF;
}
}
@ -517,10 +517,10 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
for (y0 = 0; y0 < height; y0 += 4)
for (x = 0; x < width; x++){
if (y0 + 3 < height && !(
(t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) ||
(t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG))))
(t1->flags[y0+1][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+2][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+3][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG)) ||
(t1->flags[y0+4][x+1] & (JPEG2000_T1_SIG_NB | JPEG2000_T1_VIS | JPEG2000_T1_SIG))))
{
// aggregation mode
int rlen;
@ -533,7 +533,7 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen >> 1);
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen & 1);
for (y = y0 + rlen; y < y0 + 4; y++){
if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){
int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol);
if (y > y0 + rlen)
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
@ -545,11 +545,11 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
}
}
t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;
}
} else{
for (y = y0; y < y0 + 4 && y < height; y++){
if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){
if (!(t1->flags[y+1][x+1] & (JPEG2000_T1_SIG | JPEG2000_T1_VIS))){
int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol);
ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0);
if (t1->data[y][x] & mask){ // newly significant
@ -560,7 +560,7 @@ static void encode_clnpass(Jpeg2000T1Context *t1, int width, int height, int ban
ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15);
}
}
t1->flags[y+1][x+1] &= ~J2K_T1_VIS;
t1->flags[y+1][x+1] &= ~JPEG2000_T1_VIS;
}
}
}
@ -578,7 +578,7 @@ static void encode_cblk(Jpeg2000EncoderContext *s, Jpeg2000T1Context *t1, Jpeg20
for (y = 0; y < height; y++){
for (x = 0; x < width; x++){
if (t1->data[y][x] < 0){
t1->flags[y+1][x+1] |= J2K_T1_SGN;
t1->flags[y+1][x+1] |= JPEG2000_T1_SGN;
t1->data[y][x] = -t1->data[y][x];
}
max = FFMAX(max, t1->data[y][x]);
@ -928,7 +928,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
if (s->buf_end - s->buf < 2)
return -1;
bytestream_put_be16(&s->buf, J2K_SOC);
bytestream_put_be16(&s->buf, JPEG2000_SOC);
if (ret = put_siz(s))
return ret;
if (ret = put_cod(s))
@ -942,14 +942,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
return -1;
if (s->buf_end - s->buf < 2)
return -1;
bytestream_put_be16(&s->buf, J2K_SOD);
bytestream_put_be16(&s->buf, JPEG2000_SOD);
if (ret = encode_tile(s, s->tile + tileno, tileno))
return ret;
bytestream_put_be32(&psotptr, s->buf - psotptr + 6);
}
if (s->buf_end - s->buf < 2)
return -1;
bytestream_put_be16(&s->buf, J2K_EOC);
bytestream_put_be16(&s->buf, JPEG2000_EOC);
av_log(s->avctx, AV_LOG_DEBUG, "end\n");
pkt->size = s->buf - s->buf_start;
@ -984,9 +984,9 @@ static av_cold int j2kenc_init(AVCodecContext *avctx)
s->tile_height = 256;
if (codsty->transform == FF_DWT53)
qntsty->quantsty = J2K_QSTY_NONE;
qntsty->quantsty = JPEG2000_QSTY_NONE;
else
qntsty->quantsty = J2K_QSTY_SE;
qntsty->quantsty = JPEG2000_QSTY_SE;
s->width = avctx->width;
s->height = avctx->height;