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

int eps_truncate_block ( unsigned char *  buf_in,
unsigned char *  buf_out,
eps_block_header hdr,
int *  truncate_size 
)

Truncate block

This function truncates already encoded GRAYSCALE or TRUECOLOR block. Due to embedded encoding truncation is equivalent to block re-compression.

Parameters:
buf_inInput buffer
buf_outOutput buffer
hdrBlock header
truncate_sizeDesired truncated block size
Note:
On successful return, the value pointed by the truncate_size parameter will be overwritten with a real amount of bytes used in the buf_out (it will be less then or equal to the original truncate_size value).
Minimal value for the truncate_size parameter can be calculated as MAX(EPS_MIN_GRAYSCALE_BUF, EPS_MIN_TRUECOLOR_BUF).
Returns:
The function returns either EPS_OK (the block is successfully truncated), or EPS_PARAM_ERROR (one or more parameters are incorrect).

Definition at line 1533 of file libmain.c.

References eps_block_header_tag::data_size, EPS_MIN_GRAYSCALE_BUF, EPS_MIN_TRUECOLOR_BUF, EPS_OK, EPS_PARAM_ERROR, eps_block_header_tag::hdr_size, MAX, and MIN.

{
    crc32_t data_crc;

    /* Sanity checks */
    if (!buf_in || !buf_out || !hdr) {
        return EPS_PARAM_ERROR;
    }

    if (*truncate_size < MAX(EPS_MIN_GRAYSCALE_BUF, EPS_MIN_TRUECOLOR_BUF)) {
        return EPS_PARAM_ERROR;
    }

    /* Copy data */
    *truncate_size = MIN(*truncate_size, hdr->hdr_size + hdr->data_size);
    memcpy(buf_out, buf_in, *truncate_size);

    /* Recompute data CRC */
    data_crc = epsilon_crc32(buf_out + hdr->hdr_size, *truncate_size - hdr->hdr_size);
    snprintf((char *) (buf_out + hdr->hdr_size - 9), 9, "%08x", data_crc);
    *(buf_out + hdr->hdr_size - 1) = ';';

    return EPS_OK;
}

Generated by  Doxygen 1.6.0   Back to index