Esempio n. 1
0
opj_sparse_array_int32_t* opj_sparse_array_int32_create(OPJ_UINT32 width,
        OPJ_UINT32 height,
        OPJ_UINT32 block_width,
        OPJ_UINT32 block_height)
{
    opj_sparse_array_int32_t* sa;

    if (width == 0 || height == 0 || block_width == 0 || block_height == 0) {
        return NULL;
    }
    if (block_width > ((OPJ_UINT32)~0U) / block_height / sizeof(OPJ_INT32)) {
        return NULL;
    }

    sa = opj_calloc(1, sizeof(opj_sparse_array_int32_t));
    sa->width = width;
    sa->height = height;
    sa->block_width = block_width;
    sa->block_height = block_height;
    sa->block_count_hor = opj_uint_ceildiv(width, block_width);
    sa->block_count_ver = opj_uint_ceildiv(height, block_height);
    if (sa->block_count_hor > ((OPJ_UINT32)~0U) / sa->block_count_ver) {
        opj_free(sa);
        return NULL;
    }
    sa->data_blocks = opj_calloc(sizeof(OPJ_INT32*),
                                 sa->block_count_hor * sa->block_count_ver);
    if (sa->data_blocks == NULL) {
        opj_free(sa);
        return NULL;
    }

    return sa;
}
Esempio n. 2
0
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
	OPJ_UINT32 compno;
	opj_image_t *image = 00;

	image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
	if (image)
	{
		
		image->color_space = clrspc;
		image->numcomps = numcmpts;
		
		/* allocate memory for the per-component information */
		image->comps = (opj_image_comp_t*)opj_calloc(image->numcomps, sizeof(opj_image_comp_t));
		if (!image->comps) {
			opj_image_destroy(image);
			return 00;
		}
		
		/* create the individual image components */
		for(compno = 0; compno < numcmpts; compno++) {
			opj_image_comp_t *comp = &image->comps[compno];
			comp->dx = cmptparms[compno].dx;
			comp->dy = cmptparms[compno].dy;
			comp->w = cmptparms[compno].w;
			comp->h = cmptparms[compno].h;
			comp->x0 = cmptparms[compno].x0;
			comp->y0 = cmptparms[compno].y0;
			comp->prec = cmptparms[compno].prec;
			comp->sgnd = cmptparms[compno].sgnd;
			comp->data = 0;
		}
	}

	return image;
}
cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target, OPJ_BOOL reqJPP)
{
  cachemodel_param_t *cachemodel;
  faixbox_param_t *tilepart;
  faixbox_param_t *precpacket;
  size_t numOfelem;
  Byte8_t numOftiles;
  int i;

  cachemodel = (cachemodel_param_t *)opj_malloc( sizeof(cachemodel_param_t));

  refer_target( target, &cachemodel->target);
  
  if( reqJPP){
    if( target->jppstream)
      cachemodel->jppstream = OPJ_TRUE;
    else
      cachemodel->jppstream = OPJ_FALSE;
  } else{ /* reqJPT */
    if( target->jptstream)
      cachemodel->jppstream = OPJ_FALSE;
    else
      cachemodel->jppstream = OPJ_TRUE;
  }

  cachemodel->mhead_model = OPJ_FALSE;
  
  tilepart = target->codeidx->tilepart;
  numOftiles = get_m( tilepart);
  numOfelem = get_nmax( tilepart)*numOftiles;
  cachemodel->tp_model = (OPJ_BOOL *)opj_calloc( 1, numOfelem*sizeof(OPJ_BOOL));
  cachemodel->th_model = (OPJ_BOOL *)opj_calloc( 1, numOftiles*sizeof(OPJ_BOOL));
  cachemodel->pp_model = (OPJ_BOOL **)opj_malloc( target->codeidx->SIZ.Csiz*sizeof(OPJ_BOOL *));
  for( i=0; i<target->codeidx->SIZ.Csiz; i++){
    precpacket = target->codeidx->precpacket[i];
    cachemodel->pp_model[i] = (OPJ_BOOL *)opj_calloc( 1, get_nmax(precpacket)*get_m(precpacket)*sizeof(OPJ_BOOL));
  }
  cachemodel->next = NULL;
  
  if( cachemodellist){
    if( cachemodellist->first) /* there are one or more entries */
      cachemodellist->last->next = cachemodel;
    else                   /* first entry */
      cachemodellist->first = cachemodel;
    cachemodellist->last = cachemodel;
  }

#ifndef SERVER
  fprintf( logstream, "local log: cachemodel generated\n");
#endif

  return cachemodel; 
}
Esempio n. 4
0
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
	opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_calloc(1, sizeof(opj_cinfo_t));
	if(!cinfo) return NULL;
	cinfo->is_decompressor = OPJ_FALSE;
	switch(format) {
		case CODEC_J2K:
			/* get a J2K coder handle */
			cinfo->j2k_handle = (void*)j2k_create_compress((opj_common_ptr)cinfo);
			if(!cinfo->j2k_handle) {
				opj_free(cinfo);
				return NULL;
			}
			break;
		case CODEC_JP2:
			/* get a JP2 coder handle */
			cinfo->jp2_handle = (void*)jp2_create_compress((opj_common_ptr)cinfo);
			if(!cinfo->jp2_handle) {
				opj_free(cinfo);
				return NULL;
			}
			break;
		case CODEC_JPT:
		case CODEC_UNKNOWN:
		default:
			opj_free(cinfo);
			return NULL;
	}

	cinfo->codec_format = format;

	return cinfo;
}
Esempio n. 5
0
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
	opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
	if(!dinfo) return NULL;
	dinfo->is_decompressor = OPJ_TRUE;
	switch(format) {
		case CODEC_J2K:
		case CODEC_JPT:
			/* get a J2K decoder handle */
			dinfo->j2k_handle = (void*)j2k_create_decompress((opj_common_ptr)dinfo);
			if(!dinfo->j2k_handle) {
				opj_free(dinfo);
				return NULL;
			}
			break;
		case CODEC_JP2:
			/* get a JP2 decoder handle */
			dinfo->jp2_handle = (void*)jp2_create_decompress((opj_common_ptr)dinfo);
			if(!dinfo->jp2_handle) {
				opj_free(dinfo);
				return NULL;
			}
			break;
		case CODEC_UNKNOWN:
		default:
			opj_free(dinfo);
			return NULL;
	}

	dinfo->codec_format = format;

	return dinfo;
}
int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
{
    int len, lenp, compno, i;
    opj_jp2_box_t *box;

    /*  printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */

    lenp = -1;
    box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));

    for (i=0; i<2; i++) {
        if (i) cio_seek( cio, lenp);

        lenp = cio_tell( cio);
        cio_skip( cio, 4);              /* L [at the end] */
        cio_write( cio, JPIP_PPIX, 4);  /* PPIX           */

        write_manf( i, cstr_info.numcomps, box, cio);

        for (compno=0; compno<cstr_info.numcomps; compno++) {
            box[compno].length = write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio);
            box[compno].type = JPIP_FAIX;
        }

        len = cio_tell( cio)-lenp;
        cio_seek( cio, lenp);
        cio_write( cio, len, 4);        /* L              */
        cio_seek( cio, lenp+len);
    }

    opj_free(box);

    return len;
}
Esempio n. 7
0
opj_codec_t* OPJ_CALLCONV opj_jpip_create_compress(OPJ_CODEC_FORMAT p_format)
{
	opj_codec_private_t *l_codec = 00;

	l_codec = (opj_codec_private_t*)opj_calloc(1, sizeof(opj_codec_private_t));
	if (!l_codec) {
		return 00;
	}
	memset(l_codec, 0, sizeof(opj_codec_private_t));
	
	l_codec->is_decompressor = 0;

	switch(p_format) {
		case CODEC_JP2:
			/* get a JP2 decoder handle */
			l_codec->m_codec_data.m_compression.opj_encode = (opj_bool (*) (void *,
																			struct opj_stream_private *,
																			struct opj_event_mgr * )) opj_jp2_encode;

			l_codec->m_codec_data.m_compression.opj_end_compress = (opj_bool (*) (	void *,
																					struct opj_stream_private *,
																					struct opj_event_mgr *)) opj_jpip_end_compress;

			l_codec->m_codec_data.m_compression.opj_start_compress = (opj_bool (*) (void *,
																					struct opj_stream_private *,
																					struct opj_image * ,
																					struct opj_event_mgr *))  opj_jpip_start_compress;

			l_codec->m_codec_data.m_compression.opj_write_tile = (opj_bool (*) (void *,
																				OPJ_UINT32,
																				OPJ_BYTE*,
																				OPJ_UINT32,
																				struct opj_stream_private *,
																				struct opj_event_mgr *)) opj_jp2_write_tile;

			l_codec->m_codec_data.m_compression.opj_destroy = (void (*) (void *)) opj_jp2_destroy;

			l_codec->m_codec_data.m_compression.opj_setup_encoder = (void (*) (	void *,
																				opj_cparameters_t *,
																				struct opj_image *,
																				struct opj_event_mgr * )) opj_jp2_setup_encoder;

			l_codec->m_codec = opj_jp2_create(OPJ_FALSE);
			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return 00;
			}

			break;

		case CODEC_UNKNOWN:
		case CODEC_JPT:
		default:
			opj_free(l_codec);
			return 00;
	}

	opj_set_default_event_handler(&(l_codec->m_event_mgr));
	return (opj_codec_t*) l_codec;
}
opj_procedure_list_t *  opj_procedure_list_create()
{
    /* memory allocation */
    opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
    if (! l_validation) {
        return 00;
    }
    /* initialization */
    l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
    l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
    if (! l_validation->m_procedures) {
        opj_free(l_validation);
        return 00;
    }
    return l_validation;
}
Esempio n. 9
0
size_t write_thix( size_t coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
{
  size_t len, lenp;
  int i;
  int tileno;
  opj_jp2_box_t *box;

  lenp = 0;
  box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));

  for ( i = 0; i < 2 ; i++ ){
    if (i)
      cio_seek( cio, lenp);

    lenp = cio_tell( cio);
    cio_skip( cio, 4);              /* L [at the end] */
    cio_write( cio, JPIP_THIX, 4);  /* THIX           */
    write_manf( i, cstr_info.tw*cstr_info.th, box, cio);
    
    for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
      box[tileno].length = write_tilemhix( coff, cstr_info, tileno, cio);
      box[tileno].type = JPIP_MHIX;
    }
 
    len = cio_tell( cio)-lenp;
    cio_seek( cio, lenp);
    cio_write( cio, len, 4);        /* L              */
    cio_seek( cio, lenp+len);
  }

  opj_free(box);

  return len;
}
Esempio n. 10
0
opj_thread_pool_t* opj_thread_pool_create(int num_threads)
{
    opj_thread_pool_t* tp;

    tp = (opj_thread_pool_t*) opj_calloc(1, sizeof(opj_thread_pool_t));
    if( !tp )
        return NULL;
    tp->state = OPJWTS_OK;

    if( num_threads <= 0 )
    {
        tp->tls = opj_tls_new();
        if( !tp->tls )
        {
            opj_free(tp);
            tp = NULL;
        }
        return tp;
    }

    tp->mutex = opj_mutex_create();
    if( !tp->mutex )
    {
        opj_free(tp);
        return NULL;
    }
    if( !opj_thread_pool_setup(tp, num_threads) )
    {
        opj_thread_pool_destroy(tp);
        return NULL;
    }
    return tp;
}
Esempio n. 11
0
int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen)
{
  int len, i, lenp;
  opj_jp2_box_t *box;
  int num_box = 0;
  opj_bool  EPHused;
  (void)image; /* unused ? */

  lenp = -1;
  box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));

  for (i=0;i<2;i++){
  
    if(i)
      cio_seek( cio, lenp);

    lenp = cio_tell( cio);

    cio_skip( cio, 4);              /* L [at the end] */
    cio_write( cio, JPIP_CIDX, 4);  /* CIDX           */
    write_cptr( offset, cstr_info.codestream_size, cio);

    write_manf( i, num_box, box, cio);
    
    num_box = 0;
    box[num_box].length = write_mainmhix( offset, cstr_info, cio);
    box[num_box].type = JPIP_MHIX;
    num_box++;

    box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio);
    box[num_box].type = JPIP_TPIX;
    num_box++;
      
    box[num_box].length = write_thix( offset, cstr_info, cio);
    box[num_box].type = JPIP_THIX;
    num_box++;

    EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio);
      
    box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio);
    box[num_box].type = JPIP_PPIX;
    num_box++;
    
    box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio);
    box[num_box].type = JPIP_PHIX;
    num_box++;
      
    len = cio_tell( cio)-lenp;
    cio_seek( cio, lenp);
    cio_write( cio, len, 4);        /* L             */
    cio_seek( cio, lenp+len);
  }

  opj_free( box);
  
  return len;
}
Esempio n. 12
0
int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
              opj_event_mgr_t * p_manager )
{
  OPJ_BYTE l_data_header [4];
  int len, lenp, i;
  int tileno;
  opj_jp2_box_t *box;

  lenp = 0;
  box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));

  for ( i = 0; i < 2 ; i++ ){
    if (i)
#if 0
      cio_seek( cio, lenp);
#else
      opj_stream_seek( cio, lenp, p_manager);
#endif

#if 0
    lenp = cio_tell( cio);
    cio_skip( cio, 4);              /* L [at the end] */
    cio_write( cio, JPIP_THIX, 4);  /* THIX           */
#else
    lenp = opj_stream_tell(cio);
    opj_stream_skip(cio, 4, p_manager);             /* L [at the end] */
    opj_write_bytes(l_data_header,JPIP_THIX,4); /* THIX */
    opj_stream_write_data(cio,l_data_header,4,p_manager);
#endif
    write_manf_v2( i, cstr_info.tw*cstr_info.th, box, cio);
    
    for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
      box[tileno].length = write_tilemhix_v2( coff, cstr_info, tileno, cio);
      box[tileno].type = JPIP_MHIX;
    }
 
#if 0
    len = cio_tell( cio)-lenp;
    cio_seek( cio, lenp);
    cio_write( cio, len, 4);        /* L              */
    cio_seek( cio, lenp+len);
#else
    len = opj_stream_tell(cio)-lenp;
    opj_stream_seek(cio, lenp, p_manager);
    opj_write_bytes(l_data_header,len,4); /* L              */
    opj_stream_write_data(cio,l_data_header,4,p_manager);
    opj_stream_seek( cio, lenp+len,p_manager);
#endif
  }

  opj_free(box);

  return len;
}
Esempio n. 13
0
opj_mutex_t* opj_mutex_create(void)
{
    opj_mutex_t* mutex = (opj_mutex_t*) opj_calloc(1U, sizeof(opj_mutex_t));
    if( mutex != NULL ) {
        if ( pthread_mutex_init(&mutex->mutex, NULL) != 0) {
            opj_free(mutex);
            mutex = NULL;
        }
    }
    return mutex;
}
Esempio n. 14
0
jpip_dec_param_t * OPJ_CALLCONV init_jpipdecoder( OPJ_BOOL jp2)
{
  jpip_dec_param_t *dec;
  
  dec = (jpip_dec_param_t *)opj_calloc( 1, sizeof(jpip_dec_param_t));

  dec->msgqueue = gene_msgqueue( OPJ_TRUE, NULL);
  
  if( jp2)
    dec->metadatalist = gene_metadatalist();

  return dec;
}
Esempio n. 15
0
opj_jp2_t* jp2_create_decompress(opj_common_ptr cinfo) {
	opj_jp2_t *jp2 = (opj_jp2_t*) opj_calloc(1, sizeof(opj_jp2_t));
	if(jp2) {
		jp2->cinfo = cinfo;
		/* create the J2K codec */
		jp2->j2k = j2k_create_decompress(cinfo);
		if(jp2->j2k == NULL) {
			jp2_destroy_decompress(jp2);
			return NULL;
		}
	}
	return jp2;
}
Esempio n. 16
0
opj_image_t* OPJ_CALLCONV opj_image_create(int numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) {
	int compno;
	opj_image_t *image = NULL;

	image = (opj_image_t*) opj_calloc(1, sizeof(opj_image_t));
	if(image) {
		image->color_space = clrspc;
		image->numcomps = numcmpts;
		/* allocate memory for the per-component information */
		image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t));
		if(!image->comps) {
			fprintf(stderr,"Unable to allocate memory for image.\n");
			opj_image_destroy(image);
			return NULL;
		}
		/* create the individual image components */
		for(compno = 0; compno < numcmpts; compno++) {
			opj_image_comp_t *comp = &image->comps[compno];
			comp->dx = cmptparms[compno].dx;
			comp->dy = cmptparms[compno].dy;
			comp->w = cmptparms[compno].w;
			comp->h = cmptparms[compno].h;
			comp->x0 = cmptparms[compno].x0;
			comp->y0 = cmptparms[compno].y0;
			comp->prec = cmptparms[compno].prec;
			comp->bpp = cmptparms[compno].bpp;
			comp->sgnd = cmptparms[compno].sgnd;
			comp->data = (int*) opj_calloc(comp->w * comp->h, sizeof(int));
			if(!comp->data) {
				fprintf(stderr,"Unable to allocate memory for image.\n");
				opj_image_destroy(image);
				return NULL;
			}
		}
	}

	return image;
}
Esempio n. 17
0
/**
* Creates a new Tier 1 handle
* and initializes the look-up tables of the Tier-1 coder/decoder
* @return a new T1 handle if successful, returns NULL otherwise
*/
opj_t1_opt_t* opj_t1_opt_create(bool isEncoder)
{
    opj_t1_opt_t *l_t1 = 00;

    l_t1 = (opj_t1_opt_t*)opj_calloc(1, sizeof(opj_t1_opt_t));
    if (!l_t1) {
        return 00;
    }

    /* create MQC handles */
    l_t1->mqc = opj_mqc_create();
    if (!l_t1->mqc) {
        opj_t1_opt_destroy(l_t1);
        return 00;
    }

    l_t1->encoder = isEncoder;

    return l_t1;
}
Esempio n. 18
0
int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio,
              opj_event_mgr_t * p_manager )
{
  OPJ_BYTE l_data_header [8];
  OPJ_UINT32 len, compno, i;
  opj_jp2_box_t *box;
  OPJ_OFF_T lenp = 0;

  box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
  
  for( i=0;i<2;i++){
    if (i)
      opj_stream_seek( cio, lenp, p_manager);
      
    lenp = opj_stream_tell(cio);
    opj_stream_skip(cio, 4, p_manager);         /* L [at the end]      */
    opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
    opj_stream_write_data(cio,l_data_header,4,p_manager);
      
    opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager );

    for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++){       
      box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager);
      box[compno].type = JPIP_FAIX;
    }

    len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
    opj_stream_seek(cio, 4, p_manager);
    opj_write_bytes(l_data_header,len,4);/* L              */
    opj_stream_write_data(cio,l_data_header,4,p_manager);
    opj_stream_seek( cio, lenp+len,p_manager);
  }

  opj_free(box);

  return (int)len;
}
Esempio n. 19
0
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) {
        OPJ_INT32 nplh[32];
        OPJ_INT32 nplv[32];
        opj_tgt_node_t *node = 00;
        opj_tgt_node_t *l_parent_node = 00;
        opj_tgt_node_t *l_parent_node0 = 00;
        opj_tgt_tree_t *tree = 00;
        OPJ_UINT32 i;
        OPJ_INT32  j,k;
        OPJ_UINT32 numlvls;
        OPJ_UINT32 n;

        tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
        if(!tree) {
                fprintf(stderr, "ERROR in tgt_create while allocating tree\n");
                return 00;
        }
        memset(tree,0,sizeof(opj_tgt_tree_t));

        tree->numleafsh = numleafsh;
        tree->numleafsv = numleafsv;

        numlvls = 0;
        nplh[0] = (OPJ_INT32)numleafsh;
        nplv[0] = (OPJ_INT32)numleafsv;
        tree->numnodes = 0;
        do {
                n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]);
                nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
                nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
                tree->numnodes += n;
                ++numlvls;
        } while (n > 1);

        /* ADD */
        if (tree->numnodes == 0) {
                opj_free(tree);
                fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no tree created.\n");
                return 00;
        }

        tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
        if(!tree->nodes) {
                fprintf(stderr, "ERROR in tgt_create while allocating node of the tree\n");
                opj_free(tree);
                return 00;
        }
        memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t));
        tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t);

        node = tree->nodes;
        l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv];
        l_parent_node0 = l_parent_node;

        for (i = 0; i < numlvls - 1; ++i) {
                for (j = 0; j < nplv[i]; ++j) {
                        k = nplh[i];
                        while (--k >= 0) {
                                node->parent = l_parent_node;
                                ++node;
                                if (--k >= 0) {
                                        node->parent = l_parent_node;
                                        ++node;
                                }
                                ++l_parent_node;
                        }
                        if ((j & 1) || j == nplv[i] - 1) {
                                l_parent_node0 = l_parent_node;
                        } else {
                                l_parent_node = l_parent_node0;
                                l_parent_node0 += nplh[i];
                        }
                }
        }
        node->parent = 0;
        opj_tgt_reset(tree);
        return tree;
}
Esempio n. 20
0
opj_image_t* opj_image_create0(void) {
	opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
	return image;
}
Esempio n. 21
0
static OPJ_BOOL opj_thread_pool_setup(opj_thread_pool_t* tp, int num_threads)
{
    int i;
    OPJ_BOOL bRet = OPJ_TRUE;

    assert( num_threads > 0 );

    tp->cond = opj_cond_create();
    if( tp->cond == NULL )
        return OPJ_FALSE;

    tp->worker_threads = (opj_worker_thread_t*) opj_calloc( (size_t)num_threads,
                                                        sizeof(opj_worker_thread_t) );
    if( tp->worker_threads == NULL )
        return OPJ_FALSE;
    tp->worker_threads_count = num_threads;

    for(i=0;i<num_threads;i++)
    {
        tp->worker_threads[i].tp = tp;

        tp->worker_threads[i].mutex = opj_mutex_create();
        if( tp->worker_threads[i].mutex == NULL )
        {
            tp->worker_threads_count = i;
            bRet = OPJ_FALSE;
            break;
        }

        tp->worker_threads[i].cond = opj_cond_create();
        if( tp->worker_threads[i].cond == NULL )
        {
            opj_mutex_destroy(tp->worker_threads[i].mutex);
            tp->worker_threads_count = i;
            bRet = OPJ_FALSE;
            break;
        }

        tp->worker_threads[i].marked_as_waiting = OPJ_FALSE;

        tp->worker_threads[i].thread = opj_thread_create(opj_worker_thread_function,
                                                         &(tp->worker_threads[i]));
        if( tp->worker_threads[i].thread == NULL )
        {
            tp->worker_threads_count = i;
            bRet = OPJ_FALSE;
            break;
        }
    }

    /* Wait all threads to be started */
    /* printf("waiting for all threads to be started\n"); */
    opj_mutex_lock(tp->mutex);
    while( tp->waiting_worker_thread_count < num_threads )
    {
        opj_cond_wait(tp->cond, tp->mutex);
    }
    opj_mutex_unlock(tp->mutex);
    /* printf("all threads started\n"); */

    if( tp->state == OPJWTS_ERROR )
        bRet = OPJ_FALSE;

    return bRet;
}
Esempio n. 22
0
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
              opj_event_mgr_t * p_manager )
{
  int i;
  OPJ_OFF_T lenp;
  OPJ_UINT32 len;
  opj_jp2_box_t *box;
  int num_box = 0;
  OPJ_BOOL  EPHused;
  OPJ_BYTE l_data_header [4];

  lenp = -1;
  box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
  if(box == NULL){
	return 0;
  }
  for (i=0;i<2;i++){
  
    if(i)
      opj_stream_seek(cio,lenp,p_manager);


    lenp = opj_stream_tell (cio);

    opj_stream_skip(cio, 4, p_manager); /* L [at the end] */

    opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
    opj_stream_write_data(cio,l_data_header,4,p_manager);

    opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);

    opj_write_manf( i, num_box, box, cio,p_manager);
    
    num_box = 0;
    box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager);
    box[num_box].type = JPIP_MHIX;
    num_box++;

    box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
    box[num_box].type = JPIP_TPIX;
    num_box++;
      
    box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager);
    box[num_box].type = JPIP_THIX;
    num_box++;

    EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
      
    box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
    box[num_box].type = JPIP_PPIX;
    num_box++;
    
    box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
    box[num_box].type = JPIP_PHIX;
    num_box++;
      
    len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
    opj_stream_seek(cio, lenp,p_manager);
    opj_write_bytes(l_data_header,len,4);/* L  */
    opj_stream_write_data(cio,l_data_header,4,p_manager);
    opj_stream_seek(cio, lenp+len,p_manager);
  }

  opj_free( box);
  
  return (int)len;
}
Esempio n. 23
0
static OPJ_BOOL opj_sparse_array_int32_read_or_write(
    const opj_sparse_array_int32_t* sa,
    OPJ_UINT32 x0,
    OPJ_UINT32 y0,
    OPJ_UINT32 x1,
    OPJ_UINT32 y1,
    OPJ_INT32* buf,
    OPJ_UINT32 buf_col_stride,
    OPJ_UINT32 buf_line_stride,
    OPJ_BOOL forgiving,
    OPJ_BOOL is_read_op)
{
    OPJ_UINT32 y, block_y;
    OPJ_UINT32 y_incr = 0;
    const OPJ_UINT32 block_width = sa->block_width;

    if (!opj_sparse_array_is_region_valid(sa, x0, y0, x1, y1)) {
        return forgiving;
    }

    block_y = y0 / sa->block_height;
    for (y = y0; y < y1; block_y ++, y += y_incr) {
        OPJ_UINT32 x, block_x;
        OPJ_UINT32 x_incr = 0;
        OPJ_UINT32 block_y_offset;
        y_incr = (y == y0) ? sa->block_height - (y0 % sa->block_height) :
                 sa->block_height;
        block_y_offset = sa->block_height - y_incr;
        y_incr = opj_uint_min(y_incr, y1 - y);
        block_x = x0 / block_width;
        for (x = x0; x < x1; block_x ++, x += x_incr) {
            OPJ_UINT32 j;
            OPJ_UINT32 block_x_offset;
            OPJ_INT32* src_block;
            x_incr = (x == x0) ? block_width - (x0 % block_width) : block_width;
            block_x_offset = block_width - x_incr;
            x_incr = opj_uint_min(x_incr, x1 - x);
            src_block = sa->data_blocks[block_y * sa->block_count_hor + block_x];
            if (is_read_op) {
                if (src_block == NULL) {
                    if (buf_col_stride == 1) {
                        OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride +
                                              (x - x0) * buf_col_stride;
                        for (j = 0; j < y_incr; j++) {
                            memset(dest_ptr, 0, sizeof(OPJ_INT32) * x_incr);
                            dest_ptr += buf_line_stride;
                        }
                    } else {
                        OPJ_INT32* dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride +
                                              (x - x0) * buf_col_stride;
                        for (j = 0; j < y_incr; j++) {
                            OPJ_UINT32 k;
                            for (k = 0; k < x_incr; k++) {
                                dest_ptr[k * buf_col_stride] = 0;
                            }
                            dest_ptr += buf_line_stride;
                        }
                    }
                } else {
                    const OPJ_INT32* OPJ_RESTRICT src_ptr = src_block + block_y_offset *
                                                            (OPJ_SIZE_T)block_width + block_x_offset;
                    if (buf_col_stride == 1) {
                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride
                                                           +
                                                           (x - x0) * buf_col_stride;
                        if (x_incr == 4) {
                            // Same code as general branch, but the compiler
                            // can have an efficient memcpy()
                            for (j = 0; j < y_incr; j++) {
                                memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                                dest_ptr += buf_line_stride;
                                src_ptr += block_width;
                            }
                        } else {
                            for (j = 0; j < y_incr; j++) {
                                memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                                dest_ptr += buf_line_stride;
                                src_ptr += block_width;
                            }
                        }
                    } else {
                        OPJ_INT32* OPJ_RESTRICT dest_ptr = buf + (y - y0) * (OPJ_SIZE_T)buf_line_stride
                                                           +
                                                           (x - x0) * buf_col_stride;
                        if (x_incr == 1) {
                            for (j = 0; j < y_incr; j++) {
                                *dest_ptr = *src_ptr;
                                dest_ptr += buf_line_stride;
                                src_ptr += block_width;
                            }
                        } else if (y_incr == 1 && buf_col_stride == 2) {
                            OPJ_UINT32 k;
                            for (k = 0; k < (x_incr & ~3U); k += 4) {
                                dest_ptr[k * buf_col_stride] = src_ptr[k];
                                dest_ptr[(k + 1) * buf_col_stride] = src_ptr[k + 1];
                                dest_ptr[(k + 2) * buf_col_stride] = src_ptr[k + 2];
                                dest_ptr[(k + 3) * buf_col_stride] = src_ptr[k + 3];
                            }
                            for (; k < x_incr; k++) {
                                dest_ptr[k * buf_col_stride] = src_ptr[k];
                            }
                        } else if (x_incr >= 8 && buf_col_stride == 8) {
                            for (j = 0; j < y_incr; j++) {
                                OPJ_UINT32 k;
                                for (k = 0; k < (x_incr & ~3U); k += 4) {
                                    dest_ptr[k * buf_col_stride] = src_ptr[k];
                                    dest_ptr[(k + 1) * buf_col_stride] = src_ptr[k + 1];
                                    dest_ptr[(k + 2) * buf_col_stride] = src_ptr[k + 2];
                                    dest_ptr[(k + 3) * buf_col_stride] = src_ptr[k + 3];
                                }
                                for (; k < x_incr; k++) {
                                    dest_ptr[k * buf_col_stride] = src_ptr[k];
                                }
                                dest_ptr += buf_line_stride;
                                src_ptr += block_width;
                            }
                        } else {
                            /* General case */
                            for (j = 0; j < y_incr; j++) {
                                OPJ_UINT32 k;
                                for (k = 0; k < x_incr; k++) {
                                    dest_ptr[k * buf_col_stride] = src_ptr[k];
                                }
                                dest_ptr += buf_line_stride;
                                src_ptr += block_width;
                            }
                        }
                    }
                }
            } else {
                if (src_block == NULL) {
                    src_block = opj_calloc(1,
                                           sa->block_width * sa->block_height * sizeof(OPJ_INT32));
                    if (src_block == NULL) {
                        return OPJ_FALSE;
                    }
                    sa->data_blocks[block_y * sa->block_count_hor + block_x] = src_block;
                }

                if (buf_col_stride == 1) {
                    OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset *
                                                       (OPJ_SIZE_T)block_width + block_x_offset;
                    const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) *
                                                            (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride;
                    if (x_incr == 4) {
                        // Same code as general branch, but the compiler
                        // can have an efficient memcpy()
                        for (j = 0; j < y_incr; j++) {
                            memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                            dest_ptr += block_width;
                            src_ptr += buf_line_stride;
                        }
                    } else {
                        for (j = 0; j < y_incr; j++) {
                            memcpy(dest_ptr, src_ptr, sizeof(OPJ_INT32) * x_incr);
                            dest_ptr += block_width;
                            src_ptr += buf_line_stride;
                        }
                    }
                } else {
                    OPJ_INT32* OPJ_RESTRICT dest_ptr = src_block + block_y_offset *
                                                       (OPJ_SIZE_T)block_width + block_x_offset;
                    const OPJ_INT32* OPJ_RESTRICT src_ptr = buf + (y - y0) *
                                                            (OPJ_SIZE_T)buf_line_stride + (x - x0) * buf_col_stride;
                    if (x_incr == 1) {
                        for (j = 0; j < y_incr; j++) {
                            *dest_ptr = *src_ptr;
                            src_ptr += buf_line_stride;
                            dest_ptr += block_width;
                        }
                    } else if (x_incr >= 8 && buf_col_stride == 8) {
                        for (j = 0; j < y_incr; j++) {
                            OPJ_UINT32 k;
                            for (k = 0; k < (x_incr & ~3U); k += 4) {
                                dest_ptr[k] = src_ptr[k * buf_col_stride];
                                dest_ptr[k + 1] = src_ptr[(k + 1) * buf_col_stride];
                                dest_ptr[k + 2] = src_ptr[(k + 2) * buf_col_stride];
                                dest_ptr[k + 3] = src_ptr[(k + 3) * buf_col_stride];
                            }
                            for (; k < x_incr; k++) {
                                dest_ptr[k] = src_ptr[k * buf_col_stride];
                            }
                            src_ptr += buf_line_stride;
                            dest_ptr += block_width;
                        }
                    } else {
                        /* General case */
                        for (j = 0; j < y_incr; j++) {
                            OPJ_UINT32 k;
                            for (k = 0; k < x_incr; k++) {
                                dest_ptr[k] = src_ptr[k * buf_col_stride];
                            }
                            src_ptr += buf_line_stride;
                            dest_ptr += block_width;
                        }
                    }
                }
            }
Esempio n. 24
0
opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
{
  opj_codec_private_t *l_info = 00;

  l_info = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
  if
    (!l_info)
  {
    return 00;
  }
  memset(l_info, 0, sizeof(opj_codec_private_t));
  l_info->is_decompressor = 1;
  switch
    (p_format)
  {
    case CODEC_J2K:
      l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode;
      l_info->m_codec_data.m_decompression.opj_end_decompress =  (bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress;
      l_info->m_codec_data.m_decompression.opj_read_header =  (bool (*) (
        void *,
        opj_image_t **,
        OPJ_INT32 * ,
        OPJ_INT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        struct opj_stream_private *,
        struct opj_event_mgr * )) j2k_read_header;
      l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
      l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder;
      l_info->m_codec_data.m_decompression.opj_read_tile_header = (bool (*) (
        void *,
        OPJ_UINT32*,
        OPJ_UINT32*,
        OPJ_INT32 * ,
        OPJ_INT32 * ,
        OPJ_INT32 * ,
        OPJ_INT32 * ,
        OPJ_UINT32 * ,
        bool *,
        struct opj_stream_private *,
        struct opj_event_mgr * )) j2k_read_tile_header;
        l_info->m_codec_data.m_decompression.opj_decode_tile_data = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *,  struct opj_event_mgr * )) j2k_decode_tile;
      l_info->m_codec_data.m_decompression.opj_set_decode_area = (bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) j2k_set_decode_area;
      l_info->m_codec = j2k_create_decompress();
      if
        (! l_info->m_codec)
      {
        opj_free(l_info);
        return 00;
      }
      break;

    case CODEC_JP2:
      /* get a JP2 decoder handle */
      l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))jp2_decode;
      l_info->m_codec_data.m_decompression.opj_end_decompress =  (bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
      l_info->m_codec_data.m_decompression.opj_read_header =  (bool (*) (
        void *,
        opj_image_t **,

        OPJ_INT32 * ,
        OPJ_INT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        OPJ_UINT32 * ,
        struct opj_stream_private *,
        struct opj_event_mgr * )) jp2_read_header;

      l_info->m_codec_data.m_decompression.opj_read_tile_header = (
        bool (*) (
          void *,
          OPJ_UINT32*,
          OPJ_UINT32*,
          OPJ_INT32*,
          OPJ_INT32*,
          OPJ_INT32 * ,
          OPJ_INT32 * ,
          OPJ_UINT32 * ,
          bool *,
          struct opj_stream_private *,
          struct opj_event_mgr * )) jp2_read_tile_header;

      l_info->m_codec_data.m_decompression.opj_decode_tile_data = (bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *,  struct opj_event_mgr * )) jp2_decode_tile;

      l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
      l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder;
      l_info->m_codec_data.m_decompression.opj_set_decode_area = (bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;


      l_info->m_codec = jp2_create(true);
      if
        (! l_info->m_codec)
      {
        opj_free(l_info);
        return 00;
      }
      break;
    case CODEC_UNKNOWN:
    case CODEC_JPT:
    default:
      opj_free(l_info);
      return 00;
  }
  set_default_event_handler(&(l_info->m_event_mgr));
  return (opj_codec_t*) l_info;
}
Esempio n. 25
0
/*
Create region manager.

Note: because this method uses a tcd struct, and we can't forward declare the struct
in region_mgr.h header file, this method's declaration can be found in the tcd.h
header file.

*/
bool opj_tile_buf_create_component(opj_tcd_tilecomp_t* tilec,
                                   bool irreversible,
                                   uint32_t cblkw,
                                   uint32_t cblkh,
                                   opj_image_t* output_image,
                                   uint32_t dx,
                                   uint32_t dy)
{
    int32_t resno = 0;
    opj_rect_t	component_output_rect;
    opj_tile_buf_component_t* comp = NULL;

    if (!tilec)
        return false;

    /* create region component struct*/
	comp = new opj_tile_buf_component_t();
    if (!comp) {
        return false;
    }
	comp->data = NULL;

    opj_rect_init(&comp->tile_dim,
                  tilec->x0,
                  tilec->y0,
                  tilec->x1,
                  tilec->y1);

    if (output_image) {
        opj_rect_init(&comp->dim,
                      opj_uint_ceildiv(output_image->x0,dx),
                      opj_uint_ceildiv(output_image->y0,dy),
                      opj_uint_ceildiv(output_image->x1,dx),
                      opj_uint_ceildiv(output_image->y1,dy));

        /* clip output image to tile */
        opj_rect_clip(&comp->tile_dim, &comp->dim, &comp->dim);

    } else {
        comp->dim = comp->tile_dim;
    }


    /* for encode, we don't need to allocate resolutions */
    if (!output_image) {
        opj_tile_buf_destroy_component(tilec->buf);
        tilec->buf = comp;
        return true;
    }


    component_output_rect = comp->dim;


    /* fill resolutions vector */
    for (resno = (int32_t)(tilec->numresolutions-1); resno >= 0; --resno) {
        uint32_t bandno;
        opj_tcd_resolution_t*  tcd_res = tilec->resolutions + resno;
        opj_tile_buf_resolution_t* res = (opj_tile_buf_resolution_t*)opj_calloc(1, sizeof(opj_tile_buf_resolution_t));
        if (!res) {
            opj_tile_buf_destroy_component(comp);
            return false;
        }

        res->bounds.x = tcd_res->x1 - tcd_res->x0;
        res->bounds.y = tcd_res->y1 - tcd_res->y0;
        res->origin.x = tcd_res->x0;
        res->origin.y = tcd_res->y0;

        for (bandno = 0; bandno < tcd_res->numbands; ++bandno) {
            opj_tcd_band_t* band = tcd_res->bands + bandno;
            opj_rect_t  band_rect;
            opj_rect_init(&band_rect,
                          band->x0,
                          band->y0,
                          band->x1,
                          band->y1
                         );

            res->band_region[bandno].dim = component_output_rect;
            if (resno > 0) {

                /*For next level down, E' = ceil((E-b)/2) where b in {0,1} identifies band  */
                opj_pt_t shift;
                shift.x = band->bandno & 1;
                shift.y = band->bandno & 2;

                opj_rect_pan(&res->band_region[bandno].dim, &shift);
                opj_rect_ceildivpow2(&res->band_region[bandno].dim, 1);

                /* boundary padding */
                opj_rect_grow(&res->band_region[bandno].dim, irreversible ? 3 : 2);

            }

            /* add code block padding around region */
            (res->band_region + bandno)->data_dim = (res->band_region + bandno)->dim;
            opj_rect_grow2(&(res->band_region + bandno)->data_dim, cblkw, cblkh);

        }
        component_output_rect = res->band_region[0].dim;
        res->num_bands = tcd_res->numbands;
        comp->resolutions.push_back(res);
    }

    opj_tile_buf_destroy_component(tilec->buf);
    tilec->buf = comp;

    return true;
}
Esempio n. 26
0
static opj_tls_t* opj_tls_new(void)
{
    return (opj_tls_t*) opj_calloc(1, sizeof(opj_tls_t));
}
Esempio n. 27
0
opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
{
	opj_codec_private_t *l_codec = 00;

	l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
	if (!l_codec){
		return 00;
	}
	memset(l_codec, 0, sizeof(opj_codec_private_t));

	l_codec->is_decompressor = 1;

	switch (p_format) {
		case OPJ_CODEC_J2K:
			l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) j2k_dump;

			l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) j2k_get_cstr_info;

			l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;

			l_codec->m_codec_data.m_decompression.opj_decode =
					(OPJ_BOOL (*) (	void *,
									struct opj_stream_private *,
									opj_image_t*, struct opj_event_mgr * )) opj_j2k_decode;

			l_codec->m_codec_data.m_decompression.opj_end_decompress =
					(OPJ_BOOL (*) (	void *,
									struct opj_stream_private *,
									struct opj_event_mgr *)) opj_j2k_end_decompress;

			l_codec->m_codec_data.m_decompression.opj_read_header =
					(OPJ_BOOL (*) (	struct opj_stream_private *,
									void *,
									opj_image_t **,
									struct opj_event_mgr * )) opj_j2k_read_header;

			l_codec->m_codec_data.m_decompression.opj_destroy =
					(void (*) (void *))opj_j2k_destroy;

			l_codec->m_codec_data.m_decompression.opj_setup_decoder =
					(void (*) (void * , opj_dparameters_t * )) opj_j2k_setup_decoder;

			l_codec->m_codec_data.m_decompression.opj_read_tile_header =
					(OPJ_BOOL (*) (	void *,
									OPJ_UINT32*,
									OPJ_UINT32*,
									OPJ_INT32*, OPJ_INT32*,
									OPJ_INT32*, OPJ_INT32*,
									OPJ_UINT32*,
									OPJ_BOOL*,
									struct opj_stream_private *,
									struct opj_event_mgr * )) opj_j2k_read_tile_header;

			l_codec->m_codec_data.m_decompression.opj_decode_tile_data =
					(OPJ_BOOL (*) ( void *, 
                                    OPJ_UINT32, 
                                    OPJ_BYTE*, 
                                    OPJ_UINT32, 
                                    struct opj_stream_private *,
                                    struct opj_event_mgr *)) opj_j2k_decode_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decode_area =
					(OPJ_BOOL (*) ( void *, 
                                    opj_image_t*, 
                                    OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, 
                                    struct opj_event_mgr *)) opj_j2k_set_decode_area;

			l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = 
                    (OPJ_BOOL (*) ( void *p_codec,
								    opj_stream_private_t *p_cio,
								    opj_image_t *p_image,
								    struct opj_event_mgr * p_manager,
								    OPJ_UINT32 tile_index)) opj_j2k_get_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = 
                    (OPJ_BOOL (*) ( void * p_codec,
									OPJ_UINT32 res_factor,
									struct opj_event_mgr * p_manager)) opj_j2k_set_decoded_resolution_factor;

			l_codec->m_codec = opj_j2k_create_decompress();

			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return NULL;
			}

			break;

		case OPJ_CODEC_JP2:
			/* get a JP2 decoder handle */
			l_codec->opj_dump_codec = (void (*) (void*, OPJ_INT32, FILE*)) jp2_dump;

			l_codec->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) jp2_get_cstr_info;

			l_codec->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) jp2_get_cstr_index;

			l_codec->m_codec_data.m_decompression.opj_decode =
					(OPJ_BOOL (*) (	void *,
									struct opj_stream_private *,
									opj_image_t*,
									struct opj_event_mgr * )) opj_jp2_decode;

			l_codec->m_codec_data.m_decompression.opj_end_decompress =  
                    (OPJ_BOOL (*) ( void *,
                                    struct opj_stream_private *,
                                    struct opj_event_mgr *)) opj_jp2_end_decompress;

			l_codec->m_codec_data.m_decompression.opj_read_header =  
                    (OPJ_BOOL (*) ( struct opj_stream_private *,
					                void *,
					                opj_image_t **,
					                struct opj_event_mgr * )) opj_jp2_read_header;

			l_codec->m_codec_data.m_decompression.opj_read_tile_header = 
                    (OPJ_BOOL (*) ( void *,
					                OPJ_UINT32*,
					                OPJ_UINT32*,
					                OPJ_INT32*,
					                OPJ_INT32*,
					                OPJ_INT32 * ,
					                OPJ_INT32 * ,
					                OPJ_UINT32 * ,
					                OPJ_BOOL *,
					                struct opj_stream_private *,
					                struct opj_event_mgr * )) opj_jp2_read_tile_header;

			l_codec->m_codec_data.m_decompression.opj_decode_tile_data = 
                    (OPJ_BOOL (*) ( void *,
                                    OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,
                                    struct opj_stream_private *,
                                    struct opj_event_mgr * )) opj_jp2_decode_tile;

			l_codec->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))opj_jp2_destroy;

			l_codec->m_codec_data.m_decompression.opj_setup_decoder = 
                    (void (*) (void * ,opj_dparameters_t * )) opj_jp2_setup_decoder;

			l_codec->m_codec_data.m_decompression.opj_set_decode_area = 
                    (OPJ_BOOL (*) ( void *,
                                    opj_image_t*, 
                                    OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32,
                                    struct opj_event_mgr * )) opj_jp2_set_decode_area;

			l_codec->m_codec_data.m_decompression.opj_get_decoded_tile = 
                    (OPJ_BOOL (*) ( void *p_codec,
									opj_stream_private_t *p_cio,
									opj_image_t *p_image,
									struct opj_event_mgr * p_manager,
									OPJ_UINT32 tile_index)) opj_jp2_get_tile;

			l_codec->m_codec_data.m_decompression.opj_set_decoded_resolution_factor = 
                    (OPJ_BOOL (*) ( void * p_codec,
						    		OPJ_UINT32 res_factor,
							    	opj_event_mgr_t * p_manager)) opj_jp2_set_decoded_resolution_factor;

			l_codec->m_codec = opj_jp2_create(OPJ_TRUE);

			if (! l_codec->m_codec) {
				opj_free(l_codec);
				return 00;
			}

			break;
		case OPJ_CODEC_UNKNOWN:
		case OPJ_CODEC_JPT:
		default:
			opj_free(l_codec);
			return 00;
	}

	opj_set_default_event_handler(&(l_codec->m_event_mgr));
	return (opj_codec_t*) l_codec;
}
Esempio n. 28
0
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv) {
	int nplh[32];
	int nplv[32];
	opj_tgt_node_t *node = NULL;
	opj_tgt_node_t *parentnode = NULL;
	opj_tgt_node_t *parentnode0 = NULL;
	opj_tgt_tree_t *tree = NULL;
	int i, j, k;
	int numlvls;
	int n;

	tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t));
	if(!tree) return NULL;
	tree->numleafsh = numleafsh;
	tree->numleafsv = numleafsv;

	numlvls = 0;
	nplh[0] = numleafsh;
	nplv[0] = numleafsv;
	tree->numnodes = 0;
	do {
		n = nplh[numlvls] * nplv[numlvls];
		nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2;
		nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2;
		tree->numnodes += n;
		++numlvls;
	} while (n > 1);
	
	/* ADD */
	if (tree->numnodes == 0) {
		opj_free(tree);
		return NULL;
	}

	tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t));
	if(!tree->nodes) {
		opj_free(tree);
		return NULL;
	}

	node = tree->nodes;
	parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv];
	parentnode0 = parentnode;
	
	for (i = 0; i < numlvls - 1; ++i) {
		for (j = 0; j < nplv[i]; ++j) {
			k = nplh[i];
			while (--k >= 0) {
				node->parent = parentnode;
				++node;
				if (--k >= 0) {
					node->parent = parentnode;
					++node;
				}
				++parentnode;
			}
			if ((j & 1) || j == nplv[i] - 1) {
				parentnode0 = parentnode;
			} else {
				parentnode = parentnode0;
				parentnode0 += nplh[i];
			}
		}
	}
	node->parent = 0;
	
	tgt_reset(tree);
	
	return tree;
}
Esempio n. 29
0
opj_pi_iterator_t *pi_initialise_encode(opj_image_t *image, opj_cp_t *cp, int tileno, J2K_T2_MODE t2_mode){ 
	int p, q, pino;
	int compno, resno;
	int maxres = 0;
	int maxprec = 0;
	opj_pi_iterator_t *pi = NULL;
	opj_tcp_t *tcp = NULL;
	opj_tccp_t *tccp = NULL;
	
	tcp = &cp->tcps[tileno];

	pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
	if(!pi) {	return NULL;}
	pi->tp_on = cp->tp_on;

	for(pino = 0;pino < tcp->numpocs+1 ; pino ++){
		p = tileno % cp->tw;
		q = tileno / cp->tw;

		pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
		pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
		pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
		pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
		pi[pino].numcomps = image->numcomps;
		
		pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
		if(!pi[pino].comps) {
			pi_destroy(pi, cp, tileno);
			return NULL;
		}
		
		for (compno = 0; compno < pi[pino].numcomps; compno++) {
			int tcx0, tcy0, tcx1, tcy1;
			opj_pi_comp_t *comp = &pi[pino].comps[compno];
			tccp = &tcp->tccps[compno];
			comp->dx = image->comps[compno].dx;
			comp->dy = image->comps[compno].dy;
			comp->numresolutions = tccp->numresolutions;

			comp->resolutions = (opj_pi_resolution_t*) opj_malloc(comp->numresolutions * sizeof(opj_pi_resolution_t));
			if(!comp->resolutions) {
				pi_destroy(pi, cp, tileno);
				return NULL;
			}

			tcx0 = int_ceildiv(pi[pino].tx0, comp->dx);
			tcy0 = int_ceildiv(pi[pino].ty0, comp->dy);
			tcx1 = int_ceildiv(pi[pino].tx1, comp->dx);
			tcy1 = int_ceildiv(pi[pino].ty1, comp->dy);
			if (comp->numresolutions > maxres) {
				maxres = comp->numresolutions;
			}

			for (resno = 0; resno < comp->numresolutions; resno++) {
				int levelno;
				int rx0, ry0, rx1, ry1;
				int px0, py0, px1, py1;
				opj_pi_resolution_t *res = &comp->resolutions[resno];
				if (tccp->csty & J2K_CCP_CSTY_PRT) {
					res->pdx = tccp->prcw[resno];
					res->pdy = tccp->prch[resno];
				} else {
					res->pdx = 15;
					res->pdy = 15;
				}
				levelno = comp->numresolutions - 1 - resno;
				rx0 = int_ceildivpow2(tcx0, levelno);
				ry0 = int_ceildivpow2(tcy0, levelno);
				rx1 = int_ceildivpow2(tcx1, levelno);
				ry1 = int_ceildivpow2(tcy1, levelno);
				px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
				py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
				px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
				py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
				res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
				res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);

				if (res->pw*res->ph > maxprec) {
					maxprec = res->pw * res->ph;
				}
			}
		}
		
		tccp = &tcp->tccps[0];
		pi[pino].step_p = 1;
		pi[pino].step_c = maxprec * pi[pino].step_p;
		pi[pino].step_r = image->numcomps * pi[pino].step_c;
		pi[pino].step_l = maxres * pi[pino].step_r;
		
		for (compno = 0; compno < pi->numcomps; compno++) {
			opj_pi_comp_t *comp = &pi->comps[compno];
			for (resno = 0; resno < comp->numresolutions; resno++) {
				int dx, dy;
				opj_pi_resolution_t *res = &comp->resolutions[resno];
				dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno));
				dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno));
				pi[pino].dx = !pi->dx ? dx : int_min(pi->dx, dx);
				pi[pino].dy = !pi->dy ? dy : int_min(pi->dy, dy);
			}
		}

		if (pino == 0) {
			pi[pino].include = (short int*) opj_calloc(tcp->numlayers * pi[pino].step_l, sizeof(short int));
			if(!pi[pino].include) {
				pi_destroy(pi, cp, tileno);
				return NULL;
			}
		}
		else {
			pi[pino].include = pi[pino - 1].include;
		}
		
		/* Generation of boundaries for each prog flag*/
			if(tcp->POC && ( cp->cinema || ((!cp->cinema) && (t2_mode == FINAL_PASS)))){
				tcp->pocs[pino].compS= tcp->pocs[pino].compno0;
				tcp->pocs[pino].compE= tcp->pocs[pino].compno1;
				tcp->pocs[pino].resS = tcp->pocs[pino].resno0;
				tcp->pocs[pino].resE = tcp->pocs[pino].resno1;
				tcp->pocs[pino].layE = tcp->pocs[pino].layno1;
				tcp->pocs[pino].prg  = tcp->pocs[pino].prg1;
				if (pino > 0)
					tcp->pocs[pino].layS = (tcp->pocs[pino].layE > tcp->pocs[pino - 1].layE) ? tcp->pocs[pino - 1].layE : 0;
			}else {
				tcp->pocs[pino].compS= 0;
				tcp->pocs[pino].compE= image->numcomps;
				tcp->pocs[pino].resS = 0;
				tcp->pocs[pino].resE = maxres;
				tcp->pocs[pino].layS = 0;
				tcp->pocs[pino].layE = tcp->numlayers;
				tcp->pocs[pino].prg  = tcp->prg;
			}
			tcp->pocs[pino].prcS = 0;
			tcp->pocs[pino].prcE = maxprec;;
			tcp->pocs[pino].txS = pi[pino].tx0;
			tcp->pocs[pino].txE = pi[pino].tx1;
			tcp->pocs[pino].tyS = pi[pino].ty0;
			tcp->pocs[pino].tyE = pi[pino].ty1;
			tcp->pocs[pino].dx = pi[pino].dx;
			tcp->pocs[pino].dy = pi[pino].dy;
		}
			return pi;
	}
Esempio n. 30
0
opj_pi_iterator_t *pi_create_decode(opj_image_t *image, opj_cp_t *cp, int tileno) {
	int p, q;
	int compno, resno, pino;
	opj_pi_iterator_t *pi = NULL;
	opj_tcp_t *tcp = NULL;
	opj_tccp_t *tccp = NULL;

	tcp = &cp->tcps[tileno];

	pi = (opj_pi_iterator_t*) opj_calloc((tcp->numpocs + 1), sizeof(opj_pi_iterator_t));
	if(!pi) {
		/* TODO: throw an error */
		return NULL;
	}

	for (pino = 0; pino < tcp->numpocs + 1; pino++) {	/* change */
		int maxres = 0;
		int maxprec = 0;
		p = tileno % cp->tw;
		q = tileno / cp->tw;

		pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, image->x0);
		pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, image->y0);
		pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, image->x1);
		pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, image->y1);
		pi[pino].numcomps = image->numcomps;

		pi[pino].comps = (opj_pi_comp_t*) opj_calloc(image->numcomps, sizeof(opj_pi_comp_t));
		if(!pi[pino].comps) {
			/* TODO: throw an error */
			pi_destroy(pi, cp, tileno);
			return NULL;
		}
		
		for (compno = 0; compno < pi->numcomps; compno++) {
			int tcx0, tcy0, tcx1, tcy1;
			opj_pi_comp_t *comp = &pi[pino].comps[compno];
			tccp = &tcp->tccps[compno];
			comp->dx = image->comps[compno].dx;
			comp->dy = image->comps[compno].dy;
			comp->numresolutions = tccp->numresolutions;

			comp->resolutions = (opj_pi_resolution_t*) opj_calloc(comp->numresolutions, sizeof(opj_pi_resolution_t));
			if(!comp->resolutions) {
				/* TODO: throw an error */
				pi_destroy(pi, cp, tileno);
				return NULL;
			}

			tcx0 = int_ceildiv(pi->tx0, comp->dx);
			tcy0 = int_ceildiv(pi->ty0, comp->dy);
			tcx1 = int_ceildiv(pi->tx1, comp->dx);
			tcy1 = int_ceildiv(pi->ty1, comp->dy);
			if (comp->numresolutions > maxres) {
				maxres = comp->numresolutions;
			}

			for (resno = 0; resno < comp->numresolutions; resno++) {
				int levelno;
				int rx0, ry0, rx1, ry1;
				int px0, py0, px1, py1;
				opj_pi_resolution_t *res = &comp->resolutions[resno];
				if (tccp->csty & J2K_CCP_CSTY_PRT) {
					res->pdx = tccp->prcw[resno];
					res->pdy = tccp->prch[resno];
				} else {
					res->pdx = 15;
					res->pdy = 15;
				}
				levelno = comp->numresolutions - 1 - resno;
				rx0 = int_ceildivpow2(tcx0, levelno);
				ry0 = int_ceildivpow2(tcy0, levelno);
				rx1 = int_ceildivpow2(tcx1, levelno);
				ry1 = int_ceildivpow2(tcy1, levelno);
				px0 = int_floordivpow2(rx0, res->pdx) << res->pdx;
				py0 = int_floordivpow2(ry0, res->pdy) << res->pdy;
				px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx;
				py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy;
				res->pw = (rx0==rx1)?0:((px1 - px0) >> res->pdx);
				res->ph = (ry0==ry1)?0:((py1 - py0) >> res->pdy);
				
				if (res->pw*res->ph > maxprec) {
					maxprec = res->pw*res->ph;
				}
				
			}
		}
		
		tccp = &tcp->tccps[0];
		pi[pino].step_p = 1;
		pi[pino].step_c = maxprec * pi[pino].step_p;
		pi[pino].step_r = image->numcomps * pi[pino].step_c;
		pi[pino].step_l = maxres * pi[pino].step_r;
		
		if (pino == 0) {
			pi[pino].include = (short int*) opj_calloc(image->numcomps * maxres * tcp->numlayers * maxprec, sizeof(short int));
			if(!pi[pino].include) {
				/* TODO: throw an error */
				pi_destroy(pi, cp, tileno);
				return NULL;
			}
		}
		else {
			pi[pino].include = pi[pino - 1].include;
		}
		
		if (tcp->POC == 0) {
			pi[pino].first = 1;
			pi[pino].poc.resno0 = 0;
			pi[pino].poc.compno0 = 0;
			pi[pino].poc.layno1 = tcp->numlayers;
			pi[pino].poc.resno1 = maxres;
			pi[pino].poc.compno1 = image->numcomps;
			pi[pino].poc.prg = tcp->prg;
		} else {
			pi[pino].first = 1;
			pi[pino].poc.resno0 = tcp->pocs[pino].resno0;
			pi[pino].poc.compno0 = tcp->pocs[pino].compno0;
			pi[pino].poc.layno1 = tcp->pocs[pino].layno1;
			pi[pino].poc.resno1 = tcp->pocs[pino].resno1;
			pi[pino].poc.compno1 = tcp->pocs[pino].compno1;
			pi[pino].poc.prg = tcp->pocs[pino].prg;
		}
		pi[pino].poc.layno0  = 0;
		pi[pino].poc.precno0 = 0; 
		pi[pino].poc.precno1 = maxprec;
			
	}
	
	return pi;
}