/* VC-2 13.5.5.2 - slice_band() */
static void encode_subband(VC2EncContext *s, PutBitContext *pb, int sx, int sy,
                           SubBand *b, int quant)
{
    int x, y;

    int left   = b->width  * (sx+0) / s->num_x;
    int right  = b->width  * (sx+1) / s->num_x;
    int top    = b->height * (sy+0) / s->num_y;
    int bottom = b->height * (sy+1) / s->num_y;

    int qfactor = ff_dirac_qscale_tab[quant];
    uint8_t  *len_lut = &s->coef_lut_len[2*quant*COEF_LUT_TAB + COEF_LUT_TAB];
    uint32_t *val_lut = &s->coef_lut_val[2*quant*COEF_LUT_TAB + COEF_LUT_TAB];

    dwtcoef *coeff = b->buf + top * b->stride;

    for (y = top; y < bottom; y++) {
        for (x = left; x < right; x++) {
            if (coeff[x] >= -COEF_LUT_TAB && coeff[x] < COEF_LUT_TAB)
                put_bits(pb, len_lut[coeff[x]], val_lut[coeff[x]]);
            else
                coeff_quantize_encode(pb, coeff[x], qfactor);
        }
        coeff += b->stride;
    }
 
static void encode_subband(VC2EncContext *s, PutBitContext *pb, int sx, int sy,
                           SubBand *b, int quant)
{
    int x, y;

    int left   = b->width  * (sx+0) / s->num_x;
    int right  = b->width  * (sx+1) / s->num_x;
    int top    = b->height * (sy+0) / s->num_y;
    int bottom = b->height * (sy+1) / s->num_y;

    int qfactor = ff_dirac_qscale_tab[quant];
    uint8_t  *len_lut = &s->coef_lut_len[2*quant*COEF_LUT_TAB + COEF_LUT_TAB];
    uint32_t *val_lut = &s->coef_lut_val[2*quant*COEF_LUT_TAB + COEF_LUT_TAB];

    dwtcoef *coeff = b->buf + top * b->stride;

    for (y = top; y < bottom; y++) {
        for (x = left; x < right; x++) {
            if (coeff[x] >= -COEF_LUT_TAB && coeff[x] < COEF_LUT_TAB)
                put_bits(pb, len_lut[coeff[x]], val_lut[coeff[x]]);
            else
                coeff_quantize_encode(pb, coeff[x], qfactor);
        }
        coeff += b->stride;
    }