OPJ_BOOL delete_session( session_param_t **session, sessionlist_param_t *sessionlist) { session_param_t *ptr; if( *session == NULL) return OPJ_FALSE; if( *session == sessionlist->first) sessionlist->first = (*session)->next; else{ ptr = sessionlist->first; while( ptr->next != *session) ptr = ptr->next; ptr->next = (*session)->next; if( *session == sessionlist->last) sessionlist->last = ptr; } delete_channellist( &((*session)->channellist)); delete_cachemodellist( &((*session)->cachemodellist)); #ifndef SERVER fprintf( logstream, "local log: session: %p deleted!\n", (void *)(*session)); #endif opj_free( *session); return OPJ_TRUE; }
int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio) { 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) 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; }
void opj_thread_join( opj_thread_t* thread ) { void* status; pthread_join( thread->thread, &status); opj_free(thread); }
static void opj_worker_thread_function(void* user_data) { opj_worker_thread_t* worker_thread; opj_thread_pool_t* tp; opj_tls_t* tls; OPJ_BOOL job_finished = OPJ_FALSE; worker_thread = (opj_worker_thread_t* ) user_data; tp = worker_thread->tp; tls = opj_tls_new(); while( OPJ_TRUE ) { opj_worker_thread_job_t* job = opj_thread_pool_get_next_job(tp, worker_thread, job_finished); if( job == NULL ) break; if( job->job_fn ) { job->job_fn(job->user_data, tls); } opj_free(job); job_finished = OPJ_TRUE; } opj_tls_destroy(tls); }
void opj_thread_join( opj_thread_t* thread ) { WaitForSingleObject(thread->hThread, INFINITE); CloseHandle( thread->hThread ); opj_free(thread); }
void opj_cond_destroy(opj_cond_t* cond) { if( !cond ) return; opj_mutex_destroy(cond->internal_mutex); assert(cond->waiter_list == NULL); opj_free(cond); }
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) { if (cstr_info) { if ((*cstr_info)->m_default_tile_info.tccp_info) { opj_free((*cstr_info)->m_default_tile_info.tccp_info); } if ((*cstr_info)->tile_info) { /* FIXME not used for the moment*/ } opj_free((*cstr_info)); (*cstr_info) = NULL; } }
void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) { int i; if(volume) { if(volume->comps) { /* volume components */ for(i = 0; i < volume->numcomps; i++) { opj_volume_comp_t *volume_comp = &volume->comps[i]; if(volume_comp->data) { opj_free(volume_comp->data); } } opj_free(volume->comps); } opj_free(volume); } }
OPJ_BOOL OPJ_CALLCONV fwrite_jp2k( const char fname[], jpip_dec_param_t *dec) { int outfd; #ifdef _WIN32 if(( outfd = open( fname, O_WRONLY|O_CREAT, _S_IREAD | _S_IWRITE)) == -1){ #else if(( outfd = open( fname, O_WRONLY|O_CREAT, S_IRWXU|S_IRWXG)) == -1){ #endif fprintf( stderr, "file %s open error\n", fname); return OPJ_FALSE; } if( write( outfd, dec->jp2kstream, dec->jp2klen) != (int)dec->jp2klen) fprintf( stderr, "j2k file write error\n"); close(outfd); return OPJ_TRUE; } void OPJ_CALLCONV output_log( OPJ_BOOL messages, OPJ_BOOL metadata, OPJ_BOOL ihdrbox, jpip_dec_param_t *dec) { if( messages) print_msgqueue( dec->msgqueue); if( metadata) print_allmetadata( dec->metadatalist); if( ihdrbox){ printf("W*H: %d*%d\n", dec->ihdrbox->height, dec->ihdrbox->width); printf("NC: %d, bpc: %d\n", dec->ihdrbox->nc, dec->ihdrbox->bpc); } } void OPJ_CALLCONV destroy_jpipdecoder( jpip_dec_param_t **dec) { opj_free( (*dec)->jpipstream); delete_msgqueue( &(*dec)->msgqueue); if( (*dec)->metadatalist){ delete_metadatalist( &(*dec)->metadatalist); opj_free( (*dec)->ihdrbox); } opj_free( (*dec)->jp2kstream); opj_free( *dec); }
void end_QRprocess( server_record_t *rec, QR_t **qr) { /* TODO: record client preferences if necessary*/ (void)rec; /* unused */ delete_query( &((*qr)->query)); delete_msgqueue( &((*qr)->msgqueue)); opj_free( *qr); }
void terminate_JPIPserver( server_record_t **rec) { delete_sessionlist( &(*rec)->sessionlist); delete_targetlist( &(*rec)->targetlist); close_aux_transport( (*rec)->auxtrans); opj_free( *rec); }
/** * Destroys a Tier 2 handle. * * @param p_t2 the Tier 2 handle to destroy */ void t2_destroy(opj_t2_t *p_t2) { if (p_t2) { opj_free(p_t2); } }
OPJ_BOOL set_cidxdata( box_param_t *cidx_box, index_param_t *jp2idx) { box_param_t *manf_box; manfbox_param_t *manf; codestream_param_t codestream; set_cptrdata( cidx_box, jp2idx); codestream = set_codestream( cidx_box->fd, jp2idx->offset, jp2idx->length); manf_box = gene_boxbyType( cidx_box->fd, get_DBoxoff( cidx_box), get_DBoxlen( cidx_box), "manf"); manf = gene_manfbox( manf_box); if( !search_boxheader( "mhix", manf)){ fprintf( FCGI_stderr, "Error: mhix box not present in manfbox\n"); opj_free(jp2idx); return OPJ_FALSE; } set_mainmhixdata( cidx_box, codestream, jp2idx); if( !search_boxheader( "tpix", manf)){ fprintf( FCGI_stderr, "Error: tpix box not present in manfbox\n"); opj_free(jp2idx); return OPJ_FALSE; } set_tpixdata( cidx_box, jp2idx); if( !search_boxheader( "thix", manf)){ fprintf( FCGI_stderr, "Error: thix box not present in manfbox\n"); opj_free(jp2idx); return OPJ_FALSE; } set_thixdata( cidx_box, jp2idx); if( !search_boxheader( "ppix", manf)){ fprintf( FCGI_stderr, "Error: ppix box not present in manfbox\n"); opj_free(jp2idx); return OPJ_FALSE; } set_ppixdata( cidx_box, jp2idx); delete_manfbox( &manf); opj_free( manf_box); return OPJ_TRUE; }
int open_jp2file( const char filepath[], char tmpfname[]) { int fd; char *data; /* download remote target file to local storage*/ if( strncmp( filepath, "http://", 7) == 0){ if( (fd = open_remotefile( filepath, tmpfname)) == -1) return -1; } else{ tmpfname[0] = 0; if( (fd = open( filepath, O_RDONLY)) == -1){ fprintf( FCGI_stdout, "Reason: Target %s not found\r\n", filepath); return -1; } } /* Check resource is a JP family file.*/ if( lseek( fd, 0, SEEK_SET)==-1){ close(fd); fprintf( FCGI_stdout, "Reason: Target %s broken (lseek error)\r\n", filepath); return -1; } data = (char *)opj_malloc( 12); /* size of header*/ if( read( fd, data, 12) != 12){ opj_free( data); close(fd); fprintf( FCGI_stdout, "Reason: Target %s broken (read error)\r\n", filepath); return -1; } if( *data || *(data + 1) || *(data + 2) || *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){ opj_free( data); close(fd); fprintf( FCGI_stdout, "Reason: No JPEG 2000 Signature box in target %s\r\n", filepath); return -1; } opj_free( data); return fd; }
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { opj_cp_t *cp = NULL; opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); if(!cio) return NULL; cio->cinfo = cinfo; if(buffer && length) { /* wrap a user buffer containing the encoded image */ cio->openmode = OPJ_STREAM_READ; cio->buffer = buffer; cio->length = length; } else if(!buffer && !length && cinfo) { /* allocate a buffer for the encoded image */ cio->openmode = OPJ_STREAM_WRITE; switch(cinfo->codec_format) { case CODEC_J2K: cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp; break; case CODEC_JP2: cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp; break; default: opj_free(cio); return NULL; } cio->length = (unsigned int) (0.1625 * cp->img_size + 2000); /* 0.1625 = 1.3/8 and 2000 bytes as a minimum for headers */ cio->buffer = (unsigned char *)opj_malloc(cio->length); if(!cio->buffer) { opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n"); opj_free(cio); return NULL; } } else { opj_free(cio); return NULL; } /* Initialize byte IO */ cio->start = cio->buffer; cio->end = cio->buffer + cio->length; cio->bp = cio->buffer; return cio; }
void delete_cachemodel( cachemodel_param_t **cachemodel) { int i; unrefer_target( (*cachemodel)->target); opj_free( (*cachemodel)->tp_model); opj_free( (*cachemodel)->th_model); for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++) opj_free( (*cachemodel)->pp_model[i]); opj_free( (*cachemodel)->pp_model); #ifndef SERVER fprintf( logstream, "local log: cachemodel deleted\n"); #endif opj_free( *cachemodel); }
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; }
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { opj_cp_t *cp = NULL; opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); if(!cio) return NULL; cio->cinfo = cinfo; if(buffer && length) { /* wrap a user buffer containing the encoded image */ cio->openmode = OPJ_STREAM_READ; cio->buffer = buffer; cio->length = length; } else if(!buffer && !length && cinfo) { /* allocate a buffer for the encoded image */ cio->openmode = OPJ_STREAM_WRITE; switch(cinfo->codec_format) { case CODEC_J2K: cp = ((opj_j2k_t*)cinfo->j2k_handle)->cp; break; case CODEC_JP2: cp = ((opj_jp2_t*)cinfo->jp2_handle)->j2k->cp; break; default: opj_free(cio); return NULL; } cio->length = cp->tdx * cp->tdy * cp->tw * cp->th * 4; cio->buffer = (unsigned char *)opj_malloc(cio->length); if(!cio->buffer) { opj_free(cio); return NULL; } } else { opj_free(cio); return NULL; } /* Initialize byte IO */ cio->start = cio->buffer; cio->end = cio->buffer + cio->length; cio->bp = cio->buffer; return cio; }
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { if(dinfo) { /* destroy the codec */ if(dinfo->codec_format != CODEC_UNKNOWN) { j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle); } /* destroy the decompressor */ opj_free(dinfo); } }
opj_cond_t* opj_cond_create(void) { opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t)); if( !cond ) return NULL; /* Make sure that the TLS key is allocated in a thread-safe way */ /* We cannot use a global mutex/critical section since its creation itself would not be */ /* thread-safe, so use InterlockedCompareExchange trick */ while( OPJ_TRUE ) { #if HAVE_INTERLOCKED_COMPARE_EXCHANGE if( InterlockedCompareExchange(&inTLSLockedSection, 1, 0) == 0 ) #endif { if( !TLSKeyInit ) { TLSKey = TlsAlloc(); TLSKeyInit = OPJ_TRUE; } #if HAVE_INTERLOCKED_COMPARE_EXCHANGE InterlockedCompareExchange(&inTLSLockedSection, 0, 1); #endif break; } } if( TLSKey == TLS_OUT_OF_INDEXES ) { opj_free(cond); return NULL; } cond->internal_mutex = opj_mutex_create(); if (cond->internal_mutex == NULL) { opj_free(cond); return NULL; } cond->waiter_list = NULL; return cond; }
void tcd_free_encode(opj_tcd_t *tcd) { int tileno, compno, resno, bandno, precno; for (tileno = 0; tileno < 1; tileno++) { opj_tcd_tile_t *tile = tcd->tcd_image->tiles; for (compno = 0; compno < tile->numcomps; compno++) { opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; for (resno = 0; resno < tilec->numresolutions; resno++) { opj_tcd_resolution_t *res = &tilec->resolutions[resno]; for (bandno = 0; bandno < res->numbands; bandno++) { opj_tcd_band_t *band = &res->bands[bandno]; for (precno = 0; precno < res->pw * res->ph; precno++) { opj_tcd_precinct_t *prc = &band->precincts[precno]; if (prc->incltree != NULL) { tgt_destroy(prc->incltree); prc->incltree = NULL; } if (prc->imsbtree != NULL) { tgt_destroy(prc->imsbtree); prc->imsbtree = NULL; } opj_free(prc->cblks); prc->cblks = NULL; } /* for (precno */ opj_free(band->precincts); band->precincts = NULL; } /* for (bandno */ } /* for (resno */ opj_free(tilec->resolutions); tilec->resolutions = NULL; } /* for (compno */ opj_free(tile->comps); tile->comps = NULL; } /* for (tileno */ opj_free(tcd->tcd_image->tiles); tcd->tcd_image->tiles = NULL; }
void delete_index( index_param_t **index) { int i; delete_metadatalist( &((*index)->metadatalist)); delete_COD( (*index)->COD); delete_faixbox( &((*index)->tilepart)); for( i=0; i< (int)((*index)->SIZ.XTnum*(*index)->SIZ.YTnum);i++) delete_mhixbox( &((*index)->tileheader[i])); opj_free( (*index)->tileheader); for( i=0; i<(*index)->SIZ.Csiz; i++) delete_faixbox( &((*index)->precpacket[i])); opj_free( (*index)->precpacket); opj_free(*index); }
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; }
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; }
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { OPJ_UINT32 i; if (image) { if (image->comps) { /* image components */ for(i = 0; i < image->numcomps; i++) { opj_image_comp_t *image_comp = &image->comps[i]; if(image_comp->data) { opj_free(image_comp->data); } } opj_free(image->comps); } opj_free(image); } }
void delete_targetlist(targetlist_param_t **targetlist) { target_param_t *targetPtr, *targetNext; targetPtr = (*targetlist)->first; while( targetPtr != NULL){ targetNext=targetPtr->next; delete_target( &targetPtr); targetPtr=targetNext; } opj_free( *targetlist); }
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { int compno, pino; opj_tcp_t *tcp = &cp->tcps[tileno]; if(pi) { for (pino = 0; pino < tcp->numpocs + 1; pino++) { if(pi[pino].comps) { for (compno = 0; compno < pi->numcomps; compno++) { opj_pi_comp_t *comp = &pi[pino].comps[compno]; if(comp->resolutions) { opj_free(comp->resolutions); } } opj_free(pi[pino].comps); } } if(pi->include) { opj_free(pi->include); } opj_free(pi); } }
opj_cond_t* opj_cond_create(void) { opj_cond_t* cond = (opj_cond_t*) opj_malloc(sizeof(opj_cond_t)); if( !cond ) return NULL; if( pthread_cond_init(&(cond->cond), NULL) != 0 ) { opj_free(cond); return NULL; } return cond; }
void delete_cachemodellist( cachemodellist_param_t **cachemodellist) { cachemodel_param_t *cachemodelPtr, *cachemodelNext; cachemodelPtr = (*cachemodellist)->first; while( cachemodelPtr != NULL){ cachemodelNext=cachemodelPtr->next; delete_cachemodel( &cachemodelPtr); cachemodelPtr=cachemodelNext; } opj_free(*cachemodellist); }
void delete_target( target_param_t **target) { close( (*target)->fd); #ifdef SERVER if( (*target)->tmpfname){ fprintf( FCGI_stderr, "Temporal file %s is deleted\n", (*target)->tmpfname); remove( (*target)->tmpfname); } #endif if( (*target)->codeidx) delete_index ( &(*target)->codeidx); #ifndef SERVER fprintf( logstream, "local log: target: %s deleted\n", (*target)->targetname); #endif opj_free( (*target)->targetname); opj_free(*target); }