Commit 53ec1c81 authored by Michael Niedermayer's avatar Michael Niedermayer

j2k: merge cosmetics and non functional changes from jpeg2000

Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent e5c7bafb
......@@ -114,7 +114,7 @@ static int getsigctxno(int flag, int bandno)
if (v == 1) return 3;
if (d >= 2) return 2;
if (d == 1) return 1;
} else{
} else {
if (d >= 3) return 8;
if (d == 2) {
if (h+v >= 1) return 7;
......@@ -172,7 +172,10 @@ void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y,
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)
int ff_j2k_init_component(Jpeg2000Component *comp,
Jpeg2000CodingStyle *codsty,
Jpeg2000QuantStyle *qntsty,
int cbps, int dx, int dy)
{
uint8_t log2_band_prec_width, log2_band_prec_height;
int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1;
......@@ -182,16 +185,20 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
for (i = 0; i < 2; i++)
csize *= comp->coord[i][1] - comp->coord[i][0];
comp->data = av_malloc_array(csize, sizeof(int));
comp->data = av_malloc_array(csize, sizeof(*comp->data));
if (!comp->data)
return AVERROR(ENOMEM);
comp->reslevel = av_malloc_array(codsty->nreslevels, sizeof(*comp->reslevel));
if (!comp->reslevel)
return AVERROR(ENOMEM);
/* LOOP on resolution levels */
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
int declvl = codsty->nreslevels - reslevelno;
int declvl = codsty->nreslevels - reslevelno; // N_L -r see ISO/IEC 15444-1:2002 B.5
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
/* Compute borders for each resolution level.
* Computation of trx_0, trx_1, try_0 and try_1.
* see ISO/IEC 15444-1:2002 eq. B.5 and B-14 */
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
reslevel->coord[i][j] =
......@@ -200,22 +207,34 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
reslevel->log2_prec_width = codsty->log2_prec_widths[reslevelno];
reslevel->log2_prec_height = codsty->log2_prec_heights[reslevelno];
/* Number of bands for each resolution level */
if (reslevelno == 0)
reslevel->nbands = 1;
else
reslevel->nbands = 3;
/* Number of precincts wich span the tile for resolution level reslevelno
* see B.6 in ISO/IEC 15444-1:2002 eq. B-16
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -| - (trx_0 / 2 ^ log2_prec_width)
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| - (try_0 / 2 ^ log2_prec_width)
* for Dcinema profiles in JPEG 2000
* num_precincts_x = |- trx_1 / 2 ^ log2_prec_width) -|
* num_precincts_y = |- try_1 / 2 ^ log2_prec_width) -| */
if (reslevel->coord[0][1] == reslevel->coord[0][0])
reslevel->num_precincts_x = 0;
else
reslevel->num_precincts_x = ff_jpeg2000_ceildivpow2(reslevel->coord[0][1], reslevel->log2_prec_width)
- (reslevel->coord[0][0] >> reslevel->log2_prec_width);
reslevel->num_precincts_x =
ff_jpeg2000_ceildivpow2(reslevel->coord[0][1],
reslevel->log2_prec_width) -
(reslevel->coord[0][0] >> reslevel->log2_prec_width);
if (reslevel->coord[1][1] == reslevel->coord[1][0])
reslevel->num_precincts_y = 0;
else
reslevel->num_precincts_y = ff_jpeg2000_ceildivpow2(reslevel->coord[1][1], reslevel->log2_prec_height)
- (reslevel->coord[1][0] >> reslevel->log2_prec_height);
reslevel->num_precincts_y =
ff_jpeg2000_ceildivpow2(reslevel->coord[1][1],
reslevel->log2_prec_height) -
(reslevel->coord[1][0] >> reslevel->log2_prec_height);
reslevel->band = av_malloc_array(reslevel->nbands, sizeof(*reslevel->band));
if (!reslevel->band)
......@@ -252,7 +271,7 @@ int ff_j2k_init_component(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty,
reslevel->log2_prec_width);
band->log2_cblk_height = FFMIN(codsty->log2_cblk_height,
reslevel->log2_prec_height);
} else{
} else {
/* 3 bands x0_b = 1 y0_b = 0; x0_b = 0 y0_b = 1; x0_b = y0_b = 1 */
/* x0_b and y0_b are computed with ((bandno + 1 >> i) & 1) */
for (i = 0; i < 2; i++)
......@@ -376,7 +395,7 @@ void ff_j2k_cleanup(Jpeg2000Component *comp, Jpeg2000CodingStyle *codsty)
for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++) {
Jpeg2000ResLevel *reslevel = comp->reslevel + reslevelno;
for (bandno = 0; bandno < reslevel->nbands ; bandno++) {
for (bandno = 0; bandno < reslevel->nbands; bandno++) {
Jpeg2000Band *band = reslevel->band + bandno;
for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++) {
Jpeg2000Prec *prec = band->prec + precno;
......
......@@ -24,11 +24,14 @@
#define AVCODEC_J2K_H
/**
* JPEG2000 tables
* @file
* @author Kamil Nowosad
* JPEG 2000 structures and defines common
* to encoder and decoder
*/
#include <stdint.h>
#include "avcodec.h"
#include "mqc.h"
#include "j2k_dwt.h"
......@@ -114,7 +117,7 @@ enum Jpeg2000Quantsty { // quantization style
typedef struct Jpeg2000T1Context {
int data[JPEG2000_MAX_CBLKW][JPEG2000_MAX_CBLKH];
int flags[JPEG2000_MAX_CBLKW+2][JPEG2000_MAX_CBLKH+2];
int flags[JPEG2000_MAX_CBLKW + 2][JPEG2000_MAX_CBLKH + 2];
MqcState mqc;
} Jpeg2000T1Context;
......@@ -139,10 +142,10 @@ typedef struct Jpeg2000CodingStyle {
} Jpeg2000CodingStyle;
typedef struct Jpeg2000QuantStyle {
uint8_t expn[32 * 3]; // quantization exponent
uint8_t expn[32 * 3]; // quantization exponent
uint16_t mant[32 * 3]; // quantization mantissa
uint8_t quantsty; // quantization style
uint8_t nguardbits; // number of guard bits
uint8_t quantsty; // quantization style
uint8_t nguardbits; // number of guard bits
} Jpeg2000QuantStyle;
typedef struct Jpeg2000Pass {
......@@ -150,7 +153,7 @@ typedef struct Jpeg2000Pass {
int64_t disto;
} Jpeg2000Pass;
typedef struct Jpeg2000Cblk {
typedef struct Jpeg2000Cblk {
uint8_t npasses;
uint8_t ninclpasses; // number coding of passes included in codestream
uint8_t nonzerobits;
......@@ -179,7 +182,7 @@ typedef struct Jpeg2000Band {
typedef struct Jpeg2000ResLevel {
uint8_t nbands;
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
uint16_t num_precincts_x, num_precincts_y; // number of precincts in x/y direction
uint8_t log2_prec_width, log2_prec_height; // exponent of precinct size
Jpeg2000Band *band;
......@@ -189,7 +192,7 @@ typedef struct Jpeg2000Component {
Jpeg2000ResLevel *reslevel;
DWTContext dwt;
int *data;
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
uint16_t coord[2][2]; // border coordinates {{x0, x1}, {y0, y1}}
} Jpeg2000Component;
/* misc tools */
......@@ -207,9 +210,14 @@ static inline int ff_jpeg2000_ceildiv(int a, int b)
Jpeg2000TgtNode *ff_j2k_tag_tree_init(int w, int h);
/* TIER-1 routines */
/* Set up lookup tables used in TIER-1. */
void ff_jpeg2000_init_tier1_luts(void);
void ff_j2k_set_significant(Jpeg2000T1Context *t1, int x, int y, int negative);
/* Update significance of a coefficient at current position (x,y) and
* for neighbors. */
void ff_j2k_set_significant(Jpeg2000T1Context *t1,
int x, int y, int negative);
extern uint8_t ff_jpeg2000_sigctxno_lut[256][4];
......@@ -220,11 +228,12 @@ static inline int ff_jpeg2000_getsigctxno(int flag, int bandno)
return ff_jpeg2000_sigctxno_lut[flag & 255][bandno];
}
static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } };
/* Get context label (number in range[14..16]) of a coefficient for magnitude
* refinement pass. */
static inline int ff_jpeg2000_getrefctxno(int flag)
{
static const uint8_t refctxno_lut[2][2] = { { 14, 15 }, { 16, 16 } };
return refctxno_lut[(flag >> 14) & 1][(flag & 255) != 0];
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment