Example #1
0
/**
 * Updates the components characteristics of the image from the coding parameters.
 *
 * @param p_image_header	the image header to update.
 * @param p_cp				the coding parameters from which to update the image.
 */
void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj_cp * p_cp)
{
	OPJ_UINT32 i, l_width, l_height;
	OPJ_INT32 l_x0, l_y0, l_x1, l_y1;
	OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1;
	opj_image_comp_t* l_img_comp = NULL;

	l_x0 = opj_int_max((OPJ_INT32)p_cp->tx0 , (OPJ_INT32)p_image_header->x0);
	l_y0 = opj_int_max((OPJ_INT32)p_cp->ty0 , (OPJ_INT32)p_image_header->y0);
	l_x1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + p_cp->tw * p_cp->tdx), (OPJ_INT32)p_image_header->x1);
	l_y1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + p_cp->th * p_cp->tdy), (OPJ_INT32)p_image_header->y1);

	l_img_comp = p_image_header->comps;
	for	(i = 0; i < p_image_header->numcomps; ++i) {
		l_comp_x0 = opj_int_ceildiv(l_x0, (OPJ_INT32)l_img_comp->dx);
		l_comp_y0 = opj_int_ceildiv(l_y0, (OPJ_INT32)l_img_comp->dy);
		l_comp_x1 = opj_int_ceildiv(l_x1, (OPJ_INT32)l_img_comp->dx);
		l_comp_y1 = opj_int_ceildiv(l_y1, (OPJ_INT32)l_img_comp->dy);
		l_width = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, (OPJ_INT32)l_img_comp->factor);
		l_height = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, (OPJ_INT32)l_img_comp->factor);
		l_img_comp->w = l_width;
		l_img_comp->h = l_height;
		l_img_comp->x0 = (OPJ_UINT32)l_comp_x0/*l_x0*/;
		l_img_comp->y0 = (OPJ_UINT32)l_comp_y0/*l_y0*/;
		++l_img_comp;
	}
}
Example #2
0
opj_pt_t opj_tile_buf_get_interleaved_range(opj_tile_buf_component_t* comp,
        uint32_t resno,
        bool is_horizontal)
{
    opj_pt_t rc;
    opj_pt_t even;
    opj_pt_t odd;
    opj_tile_buf_resolution_t* res = NULL;
    memset(&rc, 0, sizeof(opj_pt_t));
    if (!comp)
        return rc;

    res = comp->resolutions[comp->resolutions.size()- 1 - resno];
    if (!res)
        return rc;

    even = opj_tile_buf_get_uninterleaved_range(comp, resno, true, is_horizontal);
    odd = opj_tile_buf_get_uninterleaved_range(comp, resno, false, is_horizontal);

    rc.x = opj_int_min( (even.x <<1), (odd.x << 1) + 1 );
    rc.y = opj_int_max( (even.y<< 1),  (odd.y << 1) + 1);

    /* clip to resolution bounds */
    rc.x = opj_int_max(0, rc.x);
    rc.y = opj_int_min(rc.y, is_horizontal ? res->bounds.x : res->bounds.y);
    return rc;
}
Example #3
0
int32_t opj_tile_buf_get_max_interleaved_range(opj_tile_buf_component_t* comp)
{
    opj_pt_t even, odd;
    if (!comp || comp->resolutions.empty())
        return 0;
    even = opj_tile_buf_get_interleaved_range(comp, (uint32_t)comp->resolutions.size() - 1, true);
    odd = opj_tile_buf_get_interleaved_range(comp, (uint32_t)comp->resolutions.size() - 1, false);

    return opj_int_max(even.y - even.x, odd.y - odd.x);
}
Example #4
0
opj_pt_t opj_tile_buf_get_uninterleaved_range(opj_tile_buf_component_t* comp,
        uint32_t resno,
        bool is_even,
        bool is_horizontal)
{
    opj_pt_t rc;
    opj_tile_buf_resolution_t* res= NULL;
    opj_tile_buf_resolution_t* prev_res = NULL;
    opj_tile_buf_band_t *band= NULL;
    memset(&rc, 0, sizeof(opj_pt_t));
    if (!comp)
        return rc;

    res = comp->resolutions[comp->resolutions.size() - 1 - resno];
    if (!res)
        return rc;

    prev_res = comp->resolutions[comp->resolutions.size() - 1 - resno+1];

    if (resno == 0) {
        band = res->band_region;
    } else {
        if (!is_even) {
            band = res->band_region + 2;
        } else {
            band = is_horizontal ? res->band_region + 1 : res->band_region;
        }
    }

    if (is_horizontal) {
        rc.x = band->dim.x0 - prev_res->origin.x;
        rc.y = band->dim.x1 - prev_res->origin.x;
    } else {
        rc.x = band->dim.y0 - prev_res->origin.y;
        rc.y = band->dim.y1 - prev_res->origin.y;
    }

    /* clip */
    rc.x = opj_int_max(0, rc.x);

    /* if resno == 0, then prev_res is null */
    if (resno == 0) {
        rc.y = opj_int_min(rc.y, is_horizontal ? res->bounds.x : res->bounds.y);
    } else {
        if (is_even)
            rc.y = opj_int_min(rc.y, is_horizontal ? prev_res->bounds.x : prev_res->bounds.y);
        else
            rc.y = opj_int_min(rc.y,
                               is_horizontal ? res->bounds.x - prev_res->bounds.x : res->bounds.y - prev_res->bounds.y);

    }

    return rc;

}
Example #5
0
int main(int argc, char **argv)
{
    int i, j;
    double u, v, t;

    int lut_ctxno_zc[1024];
    int lut_ctxno_zc_opt[2048];
    int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS];
    int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
    int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
    int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
    (void)argc;
    (void)argv;

    printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");

    /* lut_ctxno_zc */
    for (j = 0; j < 4; ++j) {
        for (i = 0; i < 256; ++i) {
            int orient = j;
            if (orient == 2) {
                orient = 1;
            } else if (orient == 1) {
                orient = 2;
            }
            lut_ctxno_zc[(orient << 8) | i] = t1_init_ctxno_zc(i, j);
        }
    }

    printf("static uint8_t lut_ctxno_zc[1024] = {\n  ");
    for (i = 0; i < 1023; ++i) {
        printf("%i, ", lut_ctxno_zc[i]);
        if(!((i+1)&0x1f))
            printf("\n  ");
    }
    printf("%i\n};\n\n", lut_ctxno_zc[1023]);

    /* lut_ctxno_zc_opt */
    for (j = 0; j < 4; ++j) {
        for (i = 0; i < 512; ++i) {
            int orient = j;
            if (orient == 2) {
                orient = 1;
            } else if (orient == 1) {
                orient = 2;
            }
            lut_ctxno_zc_opt[(orient << 9) | i] = t1_init_ctxno_zc_opt(i, j);
        }
    }

    printf("static uint8_t lut_ctxno_zc_opt[2048] = {\n  ");
    for (i = 0; i < 2047; ++i) {
        printf("%i, ", lut_ctxno_zc_opt[i]);
        if (!((i + 1) & 0x1f))
            printf("\n  ");
    }
    printf("%i\n};\n\n", lut_ctxno_zc_opt[2047]);

    /* lut_ctxno_sc */
    printf("static uint8_t lut_ctxno_sc[256] = {\n  ");
    for (i = 0; i < 255; ++i) {
        printf("0x%x, ", t1_init_ctxno_sc(i << 4));
        if(!((i+1)&0xf))
            printf("\n  ");
    }
    printf("0x%x\n};\n\n", t1_init_ctxno_sc(255 << 4));


    /* lut_ctxno_sc_opt */
    printf("static uint8_t lut_ctxno_sc_opt[256] = {\n  ");
    for (i = 0; i < 255; ++i) {
        printf("0x%x, ", t1_init_ctxno_sc_opt(i));
        if (!((i + 1) & 0xf))
            printf("\n  ");
    }
    printf("0x%x\n};\n\n", t1_init_ctxno_sc_opt(255));


    /* lut_spb */
    printf("static uint8_t lut_spb[256] = {\n  ");
    for (i = 0; i < 255; ++i) {
        printf("%i, ", t1_init_spb(i << 4));
        if(!((i+1)&0x1f))
            printf("\n  ");
    }
    printf("%i\n};\n\n", t1_init_spb(255 << 4));


    /* lut_spb_opt */
    printf("static uint8_t lut_spb_opt[256] = {\n  ");
    for (i = 0; i < 255; ++i) {
        printf("%i, ", t1_init_spb_opt(i));
        if (!((i + 1) & 0x1f))
            printf("\n  ");
    }
    printf("%i\n};\n\n", t1_init_spb_opt(255));

    /* FIXME FIXME FIXME */
    /* fprintf(stdout,"nmsedec luts:\n"); */
    for (i = 0; i < (1 << T1_NMSEDEC_BITS); ++i) {
        t = i / pow(2, T1_NMSEDEC_FRACBITS);
        u = t;
        v = t - 1.5;
        lut_nmsedec_sig[i] =
            opj_int_max(0,
                        (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
        lut_nmsedec_sig0[i] =
            opj_int_max(0,
                        (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
        u = t - 1.0;
        if (i & (1 << (T1_NMSEDEC_BITS - 1))) {
            v = t - 1.5;
        } else {
            v = t - 0.5;
        }
        lut_nmsedec_ref[i] =
            opj_int_max(0,
                        (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
        lut_nmsedec_ref0[i] =
            opj_int_max(0,
                        (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0));
    }

    printf("static int16_t lut_nmsedec_sig[1 << T1_NMSEDEC_BITS] = {\n  ");
    dump_array16(lut_nmsedec_sig, 1 << T1_NMSEDEC_BITS);

    printf("static int16_t lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS] = {\n  ");
    dump_array16(lut_nmsedec_sig0, 1 << T1_NMSEDEC_BITS);

    printf("static int16_t lut_nmsedec_ref[1 << T1_NMSEDEC_BITS] = {\n  ");
    dump_array16(lut_nmsedec_ref, 1 << T1_NMSEDEC_BITS);

    printf("static int16_t lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS] = {\n  ");
    dump_array16(lut_nmsedec_ref0, 1 << T1_NMSEDEC_BITS);

    return 0;
}