Logo Search packages:      
Sourcecode: librasterlite version File versions  Download package

int eps_decode_grayscale_block ( unsigned char **  block,
unsigned char *  buf,
eps_block_header hdr 
)

Decode a GRAYSCALE block

This function decodes a GRAYSCALE image block from the buf. Block and image dimensions as well as other necessary information is taken from the hdr structure filled by the eps_read_block_header function beforehand.

Note:
The caller should not invoke this function if the buf contains no data, i.e. eps_block_header::data_size = 0.
The caller should allocate an image block beforehand. Block dimensions as well as other information is available in the hdr structure.
Parameters:
blockImage block
bufBuffer
hdrBlock header
Returns:
The function returns either EPS_OK (the block is successfully decoded), or EPS_PARAM_ERROR (one or more parameters are incorrect) or EPS_UNSUPPORTED_FB (filterbank used by encoder not found).

Definition at line 761 of file libmain.c.

References copy_channel(), eps_block_header_tag::data_size, gs_hdr_tag::dc, dc_level_unshift(), EPS_OK, EPS_PARAM_ERROR, EPS_UNSUPPORTED_FB, extract_channel(), gs_hdr_tag::fb_id, free_2D(), get_block_size(), get_fb(), eps_block_header_tag::gs, gs_hdr_tag::h, eps_block_header_tag::hdr_size, malloc_2D(), gs_hdr_tag::mode, reset_Y(), speck_decode(), synthesis_2D(), unstuff_data(), gs_hdr_tag::w, and xmalloc().

{
    filterbank_t *fb;

    unsigned char *unstuff_buf;
    int unstuff_bytes;

    int **int_block;
    coeff_t **dwt_block;
    coeff_t **pad_block;

    unsigned char dc_int;
    int block_size;

    /* Sanity checks */
    if (!block || !buf || !hdr) {
        return EPS_PARAM_ERROR;
    }

    if (hdr->data_size < 1) {
        return EPS_PARAM_ERROR;
    }

    if (!hdr->gs.fb_id) {
        return EPS_UNSUPPORTED_FB;
    }

    /* Reset Y channel */
    reset_Y(block, hdr->gs.w, hdr->gs.h);

    /* Find filterbank from id */
    fb = get_fb(hdr->gs.fb_id);
    assert(fb);

    /* Unstuff data */
    unstuff_buf = (unsigned char *) xmalloc(hdr->data_size *
        sizeof(unsigned char));

    unstuff_bytes = unstuff_data(buf + hdr->hdr_size, unstuff_buf,
        hdr->data_size, hdr->data_size);

    if (unstuff_bytes == 0) {
        unstuff_buf[0] = 0;
        unstuff_bytes = 1;
    }

    /* Compute block size */
    block_size = get_block_size(hdr->gs.w, hdr->gs.h, hdr->gs.mode, 2);

    /* Decode coefficients */
    int_block = (int **) malloc_2D(block_size, block_size, sizeof(int));
    speck_decode(unstuff_buf, unstuff_bytes, int_block, block_size);
    free(unstuff_buf);

    /* Extend values from int to coeff_t */
    dwt_block = (coeff_t **) malloc_2D(block_size, block_size, sizeof(coeff_t));
    copy_channel(int_block, dwt_block, block_size);
    free_2D((void *) int_block, block_size, block_size);

    /* Inverse wavelet transform */
    pad_block = (coeff_t **) malloc_2D(block_size, block_size, sizeof(coeff_t));
    synthesis_2D(dwt_block, pad_block, block_size, hdr->gs.mode, fb);
    free_2D((void *) dwt_block, block_size, block_size);

    dc_int = (unsigned char) hdr->gs.dc;

    /* DC level unshift */
    dc_level_unshift(pad_block, (coeff_t) dc_int,
        block_size, block_size);

    /* Extract original data */
    extract_channel(pad_block, block, block_size, block_size,
        hdr->gs.w, hdr->gs.h);

    free_2D((void *) pad_block, block_size, block_size);

    return EPS_OK;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index