[trunk] Import rev 1103 into trunk.
[openjpeg.git] / applications / jpip / libopenjpip / cachemodel_manager.c
index d710e1492cd1d857a29a9950199dd37224d24392..70b58c878a10566362fd80f664d3d24434e74ef3 100644 (file)
@@ -55,7 +55,7 @@ cachemodellist_param_t * gene_cachemodellist()
   return cachemodellist;
 }
 
-cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target)
+cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, target_param_t *target, bool reqJPP)
 {
   cachemodel_param_t *cachemodel;
   faixbox_param_t *tilepart;
@@ -67,6 +67,19 @@ cachemodel_param_t * gene_cachemodel( cachemodellist_param_t *cachemodellist, ta
   cachemodel = (cachemodel_param_t *)malloc( sizeof(cachemodel_param_t));
 
   refer_target( target, &cachemodel->target);
+  
+  if( reqJPP){
+    if( target->jppstream)
+      cachemodel->jppstream = true;
+    else
+      cachemodel->jppstream = false;
+  } else{ // reqJPT
+    if( target->jptstream)
+      cachemodel->jppstream = false;
+    else
+      cachemodel->jppstream = true;
+  }
+
   cachemodel->mhead_model = false;
   
   tilepart = target->codeidx->tilepart;
@@ -171,9 +184,8 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
   free( (*cachemodel)->tp_model);
   free( (*cachemodel)->th_model);
   
-  if( (*cachemodel)->target->codeidx->SIZ.Csiz > 1)
-    for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
-      free( (*cachemodel)->pp_model[i]);
+  for( i=0; i<(*cachemodel)->target->codeidx->SIZ.Csiz; i++)
+    free( (*cachemodel)->pp_model[i]);
   free( (*cachemodel)->pp_model);
 
 #ifndef SERVER
@@ -181,3 +193,41 @@ void delete_cachemodel( cachemodel_param_t **cachemodel)
 #endif
   free( *cachemodel);
 }
+
+bool is_allsent( cachemodel_param_t cachemodel)
+{
+  target_param_t *target;
+  Byte8_t TPnum; // num of tile parts in each tile
+  Byte8_t Pmax; // max num of packets per tile
+  int i, j, k, n;
+
+  target = cachemodel.target;
+  
+  if( !cachemodel.mhead_model)
+    return false;
+
+  TPnum = get_nmax( target->codeidx->tilepart);
+
+  if( cachemodel.jppstream){
+    for( i=0; i<target->codeidx->SIZ.XTnum*target->codeidx->SIZ.YTnum; i++){
+      if( !cachemodel.th_model[i])
+       return false;
+      
+      for( j=0; j<target->codeidx->SIZ.Csiz; j++){
+       Pmax = get_nmax( target->codeidx->precpacket[j]);
+       for( k=0; k<Pmax; k++)
+         if( !cachemodel.pp_model[j][i*Pmax+k])
+           return false;
+      }
+    }
+    return true;
+  }
+  else{
+    for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++)
+      for( j=0; j<target->codeidx->SIZ.XTnum; j++)
+       for( k=0; k<TPnum; k++)
+         if( !cachemodel.tp_model[n++])
+           return false;
+    return true;
+  }
+}