Bug with tk->imagefile pointer fixed
authorFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Thu, 9 Sep 2004 13:34:20 +0000 (13:34 +0000)
committerFrancois-Olivier Devaux <fodevaux@users.noreply.github.com>
Thu, 9 Sep 2004 13:34:20 +0000 (13:34 +0000)
mj2/mj2.c

index 1d7706795121db286a26d1a966e7af0826677ca9..dea20bb47d91e9233939e54d5914398008f37ca4 100644 (file)
--- a/mj2/mj2.c
+++ b/mj2/mj2.c
@@ -581,16 +581,14 @@ int mj2_read_mdat(mj2_movie_t * movie, unsigned char *src, char *outfile)
   fclose(f);
 
   for (track_nb = 0; track_nb < movie->next_tk_id - 1; track_nb++) {
-    if ((movie->tk->imagefile != (char *) 0xcdcdcdcd)
-       && (movie->tk->imagefile != NULL)) {
+    if (movie->tk[track_nb].imagefile != NULL) {
       fprintf(stderr, "%s", movie->tk[track_nb].imagefile);
 
-      f = fopen(movie->tk->imagefile, "w");    /* Erase content of file if it already exists */
+      f = fopen(movie->tk[track_nb].imagefile, "w");   // Erase content of file if it already exists 
       fclose(f);
     }
   }
 
-
   for (track_nb = 0;
        track_nb < movie->num_htk + movie->num_stk + movie->num_vtk;
        track_nb++) {
@@ -602,10 +600,11 @@ int mj2_read_mdat(mj2_movie_t * movie, unsigned char *src, char *outfile)
       fprintf(stderr, "Track %d: Width=%d Height=%d\n", track_nb,
              tk->w, tk->h);
       fprintf(stderr, "%d Samples\n", tk->num_samples);
-      if ((tk->imagefile == (char *) 0xcdcdcdcd)
-         || (movie->tk->imagefile == NULL)) {
+
+      if (tk->imagefile == NULL) {
        tk->imagefile = outfile;
       }
+
       for (i = 0; i < tk->num_samples; i++) {
 
        mj2_sample_t *sample = &tk->sample[i];
@@ -613,7 +612,7 @@ int mj2_read_mdat(mj2_movie_t * movie, unsigned char *src, char *outfile)
        j2k_cp_t cp;
        unsigned char *pos;
 
-       fprintf(stderr, "Frame %d: \n", i);
+       fprintf(stderr, "Frame %d / %d: \n", i+1, tk->num_samples);
 
        cio_init(src + sample->offset, 8);
 
@@ -2813,6 +2812,9 @@ int mj2_read_moov(mj2_movie_t * movie, j2k_image_t * img)
   movie->tk =
     (mj2_tk_t *) malloc((movie->next_tk_id - 1) * sizeof(mj2_tk_t));
 
+  for (i=0; i < (unsigned int)movie->next_tk_id - 1; i++)
+    movie->tk[i].imagefile = NULL;
+
   for (i = 0; cio_tell() - box.init_pos < box.length; i++) {
     mj2_read_boxhdr(&box2);
     if (box2.type == MJ2_TRAK) {