示例#1
0
/*--------------------------------------------------------------------------
 NAME
    HCIcszip_encode -- Encode data from a buffer into SZIP compressed data

 USAGE
    int32 HCIcszip_encode(info,length,buf)
    compinfo_t *info;   IN: the info about the compressed element
    int32 length;       IN: number of bytes to store from the buffer
    const uint8 *buf;         OUT: buffer to get the bytes from

 RETURNS
    Returns SUCCEED or FAIL

 DESCRIPTION
    Common code called to encode SZIP data into a file.

 GLOBAL VARIABLES
 COMMENTS, BUGS, ASSUMPTIONS
 EXAMPLES
 REVISION LOG
--------------------------------------------------------------------------*/
PRIVATE int32
HCIcszip_encode(compinfo_t * info, int32 length, const uint8 *buf)
{
    CONSTR(FUNC, "HCIcszip_encode");
#ifdef H4_HAVE_SZIP_ENCODER
    int bytes_per_pixel;
    comp_coder_szip_info_t *szip_info;    /* ptr to SZIP info */
    int32 buffer_size;

    if (SZ_encoder_enabled() == 0) 
        HRETURN_ERROR(DFE_NOENCODER, FAIL);

    szip_info = &(info->cinfo.coder_info.szip_info);
    if (szip_info->szip_state == SZIP_INIT) {
	/* Need to initialize */
	bytes_per_pixel = (szip_info->bits_per_pixel + 7) >> 3;
	if (bytes_per_pixel == 3)
		bytes_per_pixel = 4;

	buffer_size = szip_info->pixels * bytes_per_pixel;
	if ((szip_info->buffer = HDmalloc(buffer_size)) == NULL)
			HRETURN_ERROR(DFE_NOSPACE, FAIL);
	
	szip_info->buffer_size = buffer_size;
	szip_info->buffer_pos = 0;
	szip_info->szip_state = SZIP_RUN;
    }
示例#2
0
int set_szip( int   pixels_per_block, /*in */
              int   compression_mode, /* in */
              comp_info *c_info/*out*/)
{
#ifdef H4_HAVE_LIBSZ
    
    int   ppb=pixels_per_block;
    
    if (SZ_encoder_enabled() == 0) {
        printf("Warning: SZIP encoder is not enabled\n");
        return -1;
    }
    
    if ( (compression_mode!=NN_MODE) && (compression_mode!=EC_MODE))
    {
        printf("SZIP compression mode must be NN_MODE or EC_MODE");
        return -1;
    }
    
    /* 
    pixels_per_block must be an even number, and <= pixels_per_scanline 
    and <= SZ_MAX_PIXELS_PER_BLOCK
    */
    
    if (pixels_per_block & 1)
    {
        printf("Pixels per block must be even.\n");
        return -1;
    }
    if (ppb < 2 || ppb > 32) {
        printf("Pixels per block must be 2-32.\n");
        return -1;
    }
    c_info->szip.pixels_per_block = ppb;
    
    /* set according to input value */
    c_info->szip.options_mask = SZ_EC_OPTION_MASK;
    if (compression_mode == EC_MODE) {
        c_info->szip.options_mask = SZ_EC_OPTION_MASK;
    } else if (compression_mode == NN_MODE) {
        c_info->szip.options_mask = SZ_NN_OPTION_MASK;
    }
    c_info->szip.options_mask |= SZ_RAW_OPTION_MASK;
    
    return 0;
#else
    printf("Warning: SZIP compression is not available\n");
    return -1;
#endif
    
}