[trunk] WIP: add output elements about decoding of jp2 files with last tile part...
[openjpeg.git] / libopenjpeg / j2k.c
index 6d5b24e8659ab2492c9f0a1819676884d4cae4a8..4bd37eac4ed55fda4fa06f88ed73e52f76747861 100644 (file)
@@ -3350,8 +3350,11 @@ opj_bool j2k_read_sot_v2 (
        };
 #endif /* USE_JPWL */
 
+       /* Ref A.4.2: Psot could be equal zero if it is the last tile-part of the codestream.*/
        if (!l_tot_len) {
-               opj_event_msg_v2(p_manager, EVT_ERROR, "Cannot read data with no size known, giving up\n");
+               opj_event_msg_v2(p_manager, EVT_ERROR, "Psot value of the current tile-part is equal to zero, "
+                               "for the moment we couldn't manage this case (need to compute the number of byte left"
+                               " in the codestream).\n");
                return OPJ_FALSE;
        }
 
@@ -3362,6 +3365,16 @@ opj_bool j2k_read_sot_v2 (
        ++p_header_data;
 
        if (l_num_parts != 0) { /* Number of tile-part header is provided by this tile-part header */
+               /* Useful to manage the case of textGBR.jp2 file because two values of TNSot are allowed: the correct numbers of
+                * tile-parts for that tile and zero (A.4.2 of 15444-1 : 2002). */
+               if (l_tcp->m_nb_tile_parts) {
+                       if (l_current_part >= l_tcp->m_nb_tile_parts){
+                               opj_event_msg_v2(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current "
+                                               "number of tile-part (%d), giving up\n", l_current_part, l_tcp->m_nb_tile_parts );
+                               p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1;
+                               return OPJ_FALSE;
+                       }
+               }
                l_tcp->m_nb_tile_parts = l_num_parts;
        }
 
@@ -3372,8 +3385,15 @@ opj_bool j2k_read_sot_v2 (
                }
        }
 
-       /* Keep the size of data to skip after this marker */
-       p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; /* SOT_marker_size = 12 */
+       if (!p_j2k->m_specific_param.m_decoder.m_last_tile_part){
+               /* Keep the size of data to skip after this marker */
+               p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; /* SOT_marker_size = 12 */
+       }
+       else {
+               /* FIXME: need to be computed from the number of bytes remaining in the codestream */
+               p_j2k->m_specific_param.m_decoder.m_sot_length = 0;
+       }
+
        p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPH;
 
        /* Check if the current tile is outside the area we want decode (in tile index)*/
@@ -5709,7 +5729,7 @@ opj_bool j2k_read_tile_header(    opj_j2k_v2_t * p_j2k,
 
                        /* Read the marker segment with the correct marker handler */
                        if (! (*(l_marker_handler->handler))(p_j2k,p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size,p_manager)) {
-                               opj_event_msg_v2(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
+                               opj_event_msg_v2(p_manager, EVT_ERROR, "Fail to read the current marker segment (%#x)\n", l_current_marker);
                                return OPJ_FALSE;
                        }
 
@@ -6088,7 +6108,7 @@ opj_bool j2k_set_decode_area(     opj_j2k_v2_t *p_j2k,
        if (p_end_y < l_cp->ty0) {
                opj_event_msg_v2(p_manager, EVT_ERROR,
                        "Right position of the decoded area (ROI_y1=%d) is outside the tile area (YTOsiz=%d).\n",
-                       p_end_x, l_cp->ty0);
+                       p_end_y, l_cp->ty0);
                return OPJ_FALSE;
        }
        if (p_end_y > l_cp->ty0 + l_cp->th * l_cp->tdy){