On Fri, Mar 15, 2013 at 03:35:14PM +0100, Nicolas Bertrand wrote:
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2561,6 +2561,12 @@ typedef struct AVCodecContext {
>  #define FF_PROFILE_MPEG4_SIMPLE_STUDIO             14
>  #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE           15
>  
> +#define FF_PROFILE_JPEG2000_CSTRM_RSTRCTN_0         0
> +#define FF_PROFILE_JPEG2000_CSTRM_RSTRCTN_1         1
> +#define FF_PROFILE_JPEG2000_CSTRM_NO_RSTRCTN        2
> +#define FF_PROFILE_JPEG2000_DCINEMA_2K              3
> +#define FF_PROFILE_JPEG2000_DCINEMA_4K              4

Don't we have a way to export these per-codec?  Anton?

> --- /dev/null
> +++ b/libavcodec/jpeg2000.c
> @@ -0,0 +1,475 @@
> +
> +/* allocate the memory for tag tree */
> +static int32_t tag_tree_size(uint16_t w, uint16_t h)
> +{
> +    uint32_t res = 0;
> +    while (w > 1 || h > 1) {
> +        res += w * h;
> +        if ( (res + 1) >= INT32_MAX)

stray space inside (), pointless ()

> +    static const int contribtab[3][3] = { { 0, -1, 1 }, { -1, -1, 0 }, { 1, 
> 0, 1 } };
> +    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 } };

Vertical alignment could make these more readable.

> +                log2_band_prec_width = reslevel->log2_prec_width - 1;
> +                log2_band_prec_height = reslevel->log2_prec_height - 1;

align

> --- /dev/null
> +++ b/libavcodec/jpeg2000.h
> @@ -0,0 +1,256 @@
> +
> +/* TODO: data can be float of integer depending of reversible/irreversible
> + * transformation.

or?

> --- /dev/null
> +++ b/libavcodec/jpeg2000dec.c
> @@ -0,0 +1,1253 @@
> +static int get_siz(Jpeg2000DecoderContext *s)
> +
> +    s->avctx->profile = bytestream_get_be16(&s->buf); // Rsiz
> +    s->width  = bytestream_get_be32(&s->buf);         // width
> +    s->height = bytestream_get_be32(&s->buf);         // height
> +    s->image_offset_x = bytestream_get_be32(&s->buf); // X0Siz
> +    s->image_offset_y = bytestream_get_be32(&s->buf); // Y0Siz

align

> +                        // check if a precinct exist

exist_S_

> +                        prcx = ff_jpeg2000_ceildivpow2(x,reducedresno) >> 
> rlevel->log2_prec_width;
> +                        prcy = ff_jpeg2000_ceildivpow2(y,reducedresno) >> 
> rlevel->log2_prec_height;
> +                        precno = prcx + rlevel->num_precincts_x * prcy;
> +                        for (layno = 0; layno < tile->codsty[0].nlayers; 
> layno++) {
> +                            if (jpeg2000_decode_packet( s,
> +                                                        codsty, rlevel,
> +                                                        precno, layno,
> +                                                        qntsty->expn + 
> (reslevelno ? 3 * (reslevelno - 1) + 1 : 0),
> +                                                        qntsty->nguardbits)
> +                                                        )

Ugh, no, that's ugly formatting.

> +static void decode_clnpass(Jpeg2000DecoderContext *s, Jpeg2000T1Context *t1,
> +                           int width, int height, int bpno, int bandno,
> +                           int seg_symbols)
> +{
> +    if (seg_symbols) {
> +        int val;
> +        val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI);
> +        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + 
> MQC_CX_UNI);
> +        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + 
> MQC_CX_UNI);
> +        val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + 
> MQC_CX_UNI);
> +        if (val != 0xa) {
> +            av_log(s->avctx, AV_LOG_ERROR, "Segmentation symbol value 
> incorrect\n");
> +        }

nit: pointless {}

> +static int decode_cblk(Jpeg2000DecoderContext *s, Jpeg2000CodingStyle 
> *codsty,
> +                       Jpeg2000T1Context *t1, Jpeg2000Cblk *cblk,
> +                       int width, int height, int bandpos)
> +{
> +    int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y;
> +
> +    for (y = 0; y < height + 2; y++)
> +        memset(t1->flags[y], 0, (width + 2) * sizeof(int));
> +
> +    for (y = 0; y < height; y++)
> +        memset(t1->data[y], 0, width * sizeof(int));

Please replace sizeof(type) by sizeof(*var) - here and everywhere else.

> +static int jpeg2000_decode_tile(Jpeg2000DecoderContext *s, Jpeg2000Tile 
> *tile, AVFrame *picture)
> +{
> +                        /* TODO: only the case or irreversible transform is 
> implemented (float)
> +                         * comp->data can be float or int regarding the type 
> of transformation
> +                         * see ISO/IEC 15444-1:2002 §A.6.1
> +                         *
> +                         */

nit: Skip the two empty lines.

> +static int jpeg2000_decode_frame(AVCodecContext *avctx, void *data,
> +                                 int *got_frame, AVPacket *avpkt)
> +{
> +    s->avctx = avctx;
> +    // init
> +    s->buf       = s->buf_start = avpkt->data;
> +    s->buf_end   = s->buf_start + avpkt->size;

pointless comment

> +    // FIXME: add verficiation accodeing number of resolution levels
> +    s->reduction_factor = s->lowres;

multiple typos

> --- /dev/null
> +++ b/libavcodec/jpeg2000dwt.c
> @@ -0,0 +1,250 @@
> +    if (type == FF_DWT97)
> +        s->linebuf = av_malloc((maxlen + 12) * sizeof(float));
> +    else if (type == FF_DWT53)
> +        s->linebuf = av_malloc((maxlen + 6) * sizeof(int));
> +    else
> +        return -1;

switch/case?

> --- /dev/null
> +++ b/libavcodec/jpeg2000dwt.h
> @@ -0,0 +1,62 @@
> +
> +#include "avcodec.h"

Just stdint.h should be enough.

> +typedef struct {
> +    /// line lengths { horizontal, vertical } in consecutive decomposition 
> levels
> +    uint16_t linelen[FF_DWT_MAX_DECLVLS][2];
> +    uint8_t mod[FF_DWT_MAX_DECLVLS][2];  ///< coordinates (x0, y0) of 
> decomp. levels mod 2
> +    uint8_t ndeclevels;                  ///< number of decomposition levels
> +    uint8_t type;                        ///< 0 for 9/7; 1 for 5/3
> +    void *linebuf;                       ///< buffer used by transform (int 
> or float)
> +} DWTContext;

no anonymous structs (in headers)

> +/**
> + * initialize DWT

Capitalize and end in a period.

> + * @param s DWT context
> + * @param border coordinates of transformed region {{x0, x1}, {y0, y1}}
> + * @param decomp_levels number of decomposition levels
> + * @param type 0 for DWT 9/7; 1 for DWT 5/3

Please vertically align the parameter descriptions.

> --- /dev/null
> +++ b/libavcodec/mqc.c
> @@ -0,0 +1,111 @@
> +
> +typedef struct {
> +        uint16_t qe;
> +        uint8_t  nmps;
> +        uint8_t  nlps;
> +        uint8_t  sw;
> +} MqcCxState;

no anonymous structs please

> --- /dev/null
> +++ b/libavcodec/mqc.h
> @@ -0,0 +1,61 @@
> +
> +#include "avcodec.h"

stdint.h, rather

> +extern uint16_t  ff_mqc_qe[2*47];
> +extern uint8_t ff_mqc_nlps[2*47];
> +extern uint8_t ff_mqc_nmps[2*47];

spaces around *

> +typedef struct {
> +    uint8_t *bp, *bpstart;
> +    unsigned int a;
> +    unsigned int c;
> +    unsigned int ct;
> +    uint8_t cx_states[19];
> +} MqcState;

no anonymous structs (in headers)

> +/* decoder */
> +
> +/** initialize the decoder */
> +void ff_mqc_initdec(MqcState *mqc, uint8_t *bp);
> +
> +/* common */
> +
> +/** initialize the contexts */
> +void ff_mqc_init_contexts(MqcState *mqc);

These are pointless comments, Doxygen to boot.

> --- /dev/null
> +++ b/libavcodec/mqcdec.c
> @@ -0,0 +1,93 @@
> +
> +#include "mqc.h"
> +
> +static void bytein(MqcState *mqc)
> +{
> +    if (*mqc->bp == 0xff){
> +        if (*(mqc->bp+1) > 0x8f)

spaces around +

> +static int exchange(MqcState *mqc, uint8_t *cxstate, int lps)
> +{
> +    } else{

space before {

> +    // renormd:

What?

> +    do{

space before {

> +void ff_mqc_initdec(MqcState *mqc, uint8_t *bp)
> +{
> +    ff_mqc_init_contexts(mqc);
> +    mqc->bp = bp;
> +    mqc->c = (*mqc->bp ^ 0xff) << 16;

align

> --- a/libavformat/img2.c
> +++ b/libavformat/img2.c
> @@ -62,6 +62,7 @@ static const IdStrMap img_tags[] = {
>      { AV_CODEC_ID_SUNRAST,    "sunras"   },
>      { AV_CODEC_ID_JPEG2000,   "jp2"      },
>      { AV_CODEC_ID_JPEG2000,   "jpc"      },
> +    { AV_CODEC_ID_JPEG2000,   "j2k"      },
>      { AV_CODEC_ID_DPX,        "dpx"      },
>      { AV_CODEC_ID_PICTOR,     "pic"      },
>      { AV_CODEC_ID_XBM,        "xbm"      },

This could probably go in separately, right away.

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to