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

int eps_read_block_header ( unsigned char *  buf,
int  buf_size,
eps_block_header hdr 
)

Read block header

This function performes a broad range of tasks:

  • Read and parse block header
  • Check header consistency
  • Check header and data CRC
  • Fill special eps_block_header structure with gathered information (it is worthwhile to mention that all decoding functions in the library rely on this structure)

The eps_block_header structure consists of two parts: general part and special part. The first one holds information that is common for all block types. The second one holds information that is specific for a particular block type.

Note:
The data buffer buf should hold whole block without markers.
Parameters:
bufData buffer
buf_sizeBuffer size
hdrBlock header
Returns:
The function returns either EPS_OK (the header is well-formed, the hdr structure is filled appropriately) or EPS_PARAM_ERROR (your should not get this error unless you pass a NULL pointer, negative buffer size or something like that) or EPS_FORMAT_ERROR (the header is malformed, block should be ignored).

Definition at line 495 of file libmain.c.

References eps_block_header_tag::block_type, EPS_FORMAT_ERROR, EPS_GRAYSCALE_BLOCK, EPS_OK, EPS_PARAM_ERROR, EPS_TRUECOLOR_BLOCK, read_gs_header(), read_tc_header(), terminate_header(), and unterminate_header().

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

    if (buf_size < 1) {
        return EPS_PARAM_ERROR;
    }

    /* Extract first header field: block type */
    if (terminate_header(buf, buf_size, 1) != EPS_OK) {
        return EPS_FORMAT_ERROR;
    }

    str = (char *) buf;

    /* Set block type */
    if ((strlen(str) == 7) && (strcmp(str, "type=gs") == 0)) {
        hdr->block_type = EPS_GRAYSCALE_BLOCK;
    } else if ((strlen(str) == 7) && (strcmp(str, "type=tc") == 0)) {
        hdr->block_type = EPS_TRUECOLOR_BLOCK;
    } else {
        unterminate_header(buf);
        return EPS_FORMAT_ERROR;
    }

    unterminate_header(buf);

    /* Process the block using appropriative function */
    switch (hdr->block_type) {
        case EPS_GRAYSCALE_BLOCK:
        {
            return read_gs_header(buf, buf_size, hdr);
            break;
        }

        case EPS_TRUECOLOR_BLOCK:
        {
            return read_tc_header(buf, buf_size, hdr);
            break;
        }

        default:
        {
            assert(0);
            break;
        }
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index