Added option for Digital cinema profile compliant codestream. This can be chosen...
[openjpeg.git] / libopenjpeg / tcd.c
index c0c4c52f9288b829433a031ecbdf2aeefb7314aa..89658ce70b99650a4143d0428c94913a2ec852c0 100644 (file)
@@ -1,9 +1,10 @@
 /*
+ * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
+ * Copyright (c) 2002-2007, Professor Benoit Macq
  * Copyright (c) 2001-2003, David Janssens
  * Copyright (c) 2002-2003, Yannick Verschueren
- * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
- * Copyright (c) 2005, Herv� Drolon, FreeImage Team
- * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
+ * Copyright (c) 2003-2007, Francois-Olivier Devaux and Antonin Descampe
+ * Copyright (c) 2005, Herve Drolon, FreeImage Team
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -1020,7 +1021,7 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
                double hi = max;
                int success = 0;
                /* TODO: remove maxlen */
-               int maxlen = tcd_tcp->rates[layno] ? (tcd_tcp->rates[layno] < len ? tcd_tcp->rates[layno] : len) : len;
+               int maxlen = tcd_tcp->rates[layno] ? int_min(((int) ceil(tcd_tcp->rates[layno])), len) : len;
                double goodthresh = 0;
                int i;
                double distotarget;             /* fixed_quality */
@@ -1039,13 +1040,29 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_image_in
                                tcd_makelayer(tcd, layno, thresh, 0);
                                
                                if (cp->fixed_quality) {        /* fixed_quality */
-                                       distoachieved = (layno == 0) ? 
-                                               tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
-                                       if (distoachieved < distotarget) {
-                                               hi = thresh;
-                                               continue;
+                                       if(cp->cinema){
+                                               l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info);
+                                               if (l == -999) {
+                                                       lo = thresh;
+                                                       continue;
+                                               }else{
+                       distoachieved = layno == 0 ? 
+                                                       tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
+                                                       if (distoachieved < distotarget) {
+                                                               hi=thresh; continue;
+                                                       }else{
+                                                               lo=thresh;
+                                                       }
+                                               }
+                                       }else{
+                                               distoachieved = (layno == 0) ? 
+                                                       tcd_tile->distolayer[0] : (cumdisto[layno - 1] + tcd_tile->distolayer[layno]);
+                                               if (distoachieved < distotarget) {
+                                                       hi = thresh;
+                                                       continue;
+                                               }
+                                               lo = thresh;
                                        }
-                                       lo = thresh;
                                } else {
                                        l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, image_info);
                                        /* TODO: what to do with l ??? seek / tell ??? */