@@ -237,7 +237,7 @@ namespace ojph {
237237 tile_rect.org .x += index.x * sz.get_tile_size ().w ;
238238 t = tile_rect.org .x + sz.get_tile_size ().w ; // end of tile
239239 // restrict tile
240- tile_rect.org .x =ojph_max (tile_rect.org .x ,sz.get_image_offset ().x );
240+ tile_rect.org .x = ojph_max (tile_rect.org .x ,sz.get_image_offset ().x );
241241 tile_rect.siz .w = ojph_min (t, sz.get_image_extent ().x );
242242 tile_rect.siz .w -= tile_rect.org .x ;
243243
@@ -376,7 +376,7 @@ namespace ojph {
376376 if (!qcd.write (file))
377377 throw " Error writing to file" ;
378378
379- char buf[] = " OpenJPH Ver 0.1.0 " ;
379+ char buf[] = " OpenJPH Ver 0.1.1 " ;
380380 size_t len = strlen (buf);
381381 *(ui16*)buf = swap_byte (JP2K_MARKER::COM);
382382 *(ui16*)(buf + 2 ) = swap_byte ((ui16)(len - 2 ));
@@ -795,8 +795,7 @@ namespace ojph {
795795 comp_rects[i].siz .w = tcx1 - tcx0;
796796 comp_rects[i].siz .h = tcy1 - tcy0;
797797
798- comps[i].finalize_alloc (codestream, this , i, comp_rects[i],
799- tile_rect);
798+ comps[i].finalize_alloc (codestream, this , i, comp_rects[i]);
800799 width = ojph_max (width, comp_rects[i].siz .w );
801800
802801 num_bits[i] = sz.get_bit_depth (i);
@@ -1239,8 +1238,7 @@ namespace ojph {
12391238
12401239 // ////////////////////////////////////////////////////////////////////////
12411240 void tile_comp::finalize_alloc (codestream *codestream, tile *parent,
1242- int comp_num, const rect& comp_rect,
1243- const rect& tile_rect)
1241+ int comp_num, const rect& comp_rect)
12441242 {
12451243 mem_fixed_allocator* allocator = codestream->get_allocator ();
12461244
@@ -1256,7 +1254,7 @@ namespace ojph {
12561254 this ->comp_num = comp_num;
12571255 res = allocator->post_alloc_obj <resolution>(1 );
12581256 res->finalize_alloc (codestream, comp_rect, num_decomps, comp_downsamp,
1259- this , NULL , tile_rect );
1257+ this , NULL );
12601258 }
12611259
12621260 // ////////////////////////////////////////////////////////////////////////
@@ -1489,8 +1487,7 @@ namespace ojph {
14891487 const rect& res_rect, int res_num,
14901488 point comp_downsamp,
14911489 tile_comp *parent_tile,
1492- resolution *parent_res,
1493- const rect& tile_rect)
1490+ resolution *parent_res)
14941491 {
14951492 mem_fixed_allocator* allocator = codestream->get_allocator ();
14961493 elastic = codestream->get_elastic_alloc ();
@@ -1501,7 +1498,6 @@ namespace ojph {
15011498 this ->parent = parent_tile;
15021499 this ->parent_res = parent_res;
15031500 this ->res_rect = res_rect;
1504- this ->tile_rect = tile_rect;
15051501 this ->res_num = res_num;
15061502 // finalize next resolution
15071503 if (res_num > 0 )
@@ -1519,8 +1515,7 @@ namespace ojph {
15191515 next_res_rect.siz .h = try1 - try0;
15201516
15211517 child_res->finalize_alloc (codestream, next_res_rect, res_num - 1 ,
1522- comp_downsamp, parent_tile, this ,
1523- tile_rect);
1518+ comp_downsamp, parent_tile, this );
15241519 }
15251520 else
15261521 child_res = NULL ;
@@ -1555,7 +1550,7 @@ namespace ojph {
15551550 }
15561551
15571552 // finalize precincts
1558- size log_PP = cd.get_log_precinct_size (res_num);
1553+ log_PP = cd.get_log_precinct_size (res_num);
15591554 num_precincts.w = (trx1 + (1 <<log_PP.w ) - 1 ) >> log_PP.w ;
15601555 num_precincts.w -= trx0 >> log_PP.w ;
15611556 num_precincts.h = (try1 + (1 <<log_PP.h ) - 1 ) >> log_PP.h ;
@@ -1564,7 +1559,9 @@ namespace ojph {
15641559 memset (precincts, 0 , sizeof (precinct) * num_precincts.area ());
15651560
15661561 int x_lower_bound = (trx0 >> log_PP.w ) << log_PP.w ;
1567- int y_lower_bound = (try0 >> log_PP.w ) << log_PP.w ;
1562+ int y_lower_bound = (try0 >> log_PP.h ) << log_PP.h ;
1563+ bool test_x = x_lower_bound != trx0;
1564+ bool test_y = y_lower_bound != try0;
15681565
15691566 point proj_factor;
15701567 proj_factor.x = comp_downsamp.x * (1 <<(num_decomps - res_num));
@@ -1578,6 +1575,8 @@ namespace ojph {
15781575 int ppx0 = x_lower_bound + (x << log_PP.w );
15791576 pp->img_point .x = proj_factor.x * ppx0;
15801577 pp->img_point .y = proj_factor.y * ppy0;
1578+ pp->special_x = test_x && x == 0 ;
1579+ pp->special_y = test_y && y == 0 ;
15811580 pp->num_bands = num_bands;
15821581 pp->bands = bands;
15831582 }
@@ -2054,7 +2053,9 @@ namespace ojph {
20542053 int idx = cur_precinct_loc.x + cur_precinct_loc.y * num_precincts.w ;
20552054 if (idx < (int )num_precincts.area ())
20562055 {
2057- top_left = precincts[idx].img_point ;
2056+ point t = precincts[idx].img_point ;
2057+ top_left.x = precincts[idx].special_x ? 0 : t.x ;
2058+ top_left.y = precincts[idx].special_y ? 0 : t.y ;
20582059 return true ;
20592060 }
20602061 return false ;
@@ -2902,42 +2903,47 @@ namespace ojph {
29022903 num_blocks.h = (tby1 + (1 << ycb_prime) - 1 ) >> ycb_prime;
29032904 num_blocks.h -= tby0 >> ycb_prime;
29042905
2905- blocks = allocator->post_alloc_obj <codeblock>(num_blocks.w );
2906- // allocate codeblock headers
2907- coded_cb_header *cp = coded_cbs =
2908- allocator->post_alloc_obj <coded_cb_header>(num_blocks.area ());
2909- memset (coded_cbs, 0 , sizeof (coded_cb_header) * num_blocks.area ());
2910- for (int i = (int )num_blocks.area (); i > 0 ; --i, ++cp)
2911- cp->Kmax = K_max;
2912-
2913- int x_lower_bound = (tbx0 >> xcb_prime) << xcb_prime;
2914- int y_lower_bound = (tby0 >> ycb_prime) << ycb_prime;
2915-
2916- size cb_size;
2917- cb_size.h = ojph_min (tby1, y_lower_bound + nominal.h ) - tby0;
2918- cur_cb_height = cb_size.h ;
2919- int line_offset = 0 ;
2920- for (int i = 0 ; i < num_blocks.w ; ++i)
2906+ if (num_blocks.area ())
29212907 {
2922- int cbx0 = ojph_max (tbx0, x_lower_bound + i * nominal.w );
2923- int cbx1 = ojph_min (tbx1, x_lower_bound + (i + 1 ) * nominal.w );
2924- cb_size.w = cbx1 - cbx0;
2925- blocks[i].finalize_alloc (codestream, this , nominal, cb_size,
2926- coded_cbs + i, K_max, line_offset);
2927- line_offset += cb_size.w ;
2928- }
2908+ blocks = allocator->post_alloc_obj <codeblock>(num_blocks.w );
2909+ // allocate codeblock headers
2910+ coded_cb_header *cp = coded_cbs =
2911+ allocator->post_alloc_obj <coded_cb_header>(num_blocks.area ());
2912+ memset (coded_cbs, 0 , sizeof (coded_cb_header) * num_blocks.area ());
2913+ for (int i = (int )num_blocks.area (); i > 0 ; --i, ++cp)
2914+ cp->Kmax = K_max;
2915+
2916+ int x_lower_bound = (tbx0 >> xcb_prime) << xcb_prime;
2917+ int y_lower_bound = (tby0 >> ycb_prime) << ycb_prime;
2918+
2919+ size cb_size;
2920+ cb_size.h = ojph_min (tby1, y_lower_bound + nominal.h ) - tby0;
2921+ cur_cb_height = cb_size.h ;
2922+ int line_offset = 0 ;
2923+ for (int i = 0 ; i < num_blocks.w ; ++i)
2924+ {
2925+ int cbx0 = ojph_max (tbx0, x_lower_bound + i * nominal.w );
2926+ int cbx1 = ojph_min (tbx1, x_lower_bound + (i + 1 ) * nominal.w );
2927+ cb_size.w = cbx1 - cbx0;
2928+ blocks[i].finalize_alloc (codestream, this , nominal, cb_size,
2929+ coded_cbs + i, K_max, line_offset);
2930+ line_offset += cb_size.w ;
2931+ }
29292932
2930- // allocate lines
2931- lines = allocator->post_alloc_obj <line_buf>(1 );
2932- // allocate line_buf
2933- int width = band_rect.siz .w + 1 ;
2934- lines->wrap (allocator->post_alloc_data <si32>(width,1 ),width,1 );
2933+ // allocate lines
2934+ lines = allocator->post_alloc_obj <line_buf>(1 );
2935+ // allocate line_buf
2936+ int width = band_rect.siz .w + 1 ;
2937+ lines->wrap (allocator->post_alloc_data <si32>(width,1 ),width,1 );
2938+ }
29352939 }
29362940
29372941 // ////////////////////////////////////////////////////////////////////////
29382942 void subband::get_cb_indices (const size& num_precincts,
29392943 precinct *precincts)
29402944 {
2945+ if (num_precincts.area () == 0 )
2946+ return ;
29412947 rect res_rect = parent->get_rect ();
29422948 int trx0 = res_rect.org .x ;
29432949 int try0 = res_rect.org .y ;
0 commit comments