Skip to content

Commit 4ce4d5e

Browse files
committed
for J2C->EXR decoding, write only 1 scanline at a time instead of the whole image
1 parent 634028a commit 4ce4d5e

File tree

2 files changed

+54
-29
lines changed

2 files changed

+54
-29
lines changed

src/apps/common/ojph_img_io.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -919,15 +919,16 @@ namespace ojph {
919919
bit_depth[i] = 0;
920920
is_signed[i] = false;
921921
}
922+
rgba_output_file = NULL;
922923
is_use_Rgba_interface = false;
924+
925+
this->data_window.makeEmpty();
923926

924927
is_open = false;
925928
}
926929
virtual ~exr_out()
927930
{
928931
close();
929-
if(true == is_use_Rgba_interface )
930-
pixels.resizeErase(0, 0);
931932
}
932933

933934
void open(const char* filename);
@@ -946,9 +947,12 @@ namespace ojph {
946947
ui32 bit_depth[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
947948
bool is_signed[MAXIMUM_NUMBER_OF_COMPONENTS_EXR_OUT];
948949

950+
Imf::RgbaOutputFile* rgba_output_file;
949951
Imf::Array2D<Imf::Rgba> pixels;
950952
bool is_use_Rgba_interface;
951953

954+
Imath::Box2i data_window;
955+
952956
ui32 cur_line;
953957
};
954958
#endif /* OJPH_ENABLE_OPENEXR_SUPPORT */

src/apps/others/ojph_img_io.cpp

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,13 +2308,6 @@ namespace ojph {
23082308
}
23092309
}
23102310

2311-
if (bit_depth[comp_num] != 16)
2312-
{
2313-
fprintf(stderr, "ERROR in file %s on line %d in function %s:\n bit_depth[%d] = %d, this software currently only supports reading 16-bit files\n",
2314-
__FILE__, __LINE__, __FUNCTION__, comp_num, bit_depth[comp_num]);
2315-
return 0;
2316-
}
2317-
23182311
switch (comp_num)
23192312
{
23202313
case 0:
@@ -2362,8 +2355,31 @@ namespace ojph {
23622355
{
23632356
fname = filename;
23642357
cur_line = 0;
2365-
// allocate a framebuffer to hold decoded data
2366-
pixels.resizeErase(height, width);
2358+
if (true == is_use_Rgba_interface)
2359+
{
2360+
// allocate a scanline to hold a line of decoded data
2361+
pixels.resizeErase(1, width);
2362+
2363+
Imath::Box2i display_window(Imath::V2i(0, 0), Imath::V2i(width - 1, height - 1));
2364+
data_window.min.x = 0;
2365+
data_window.min.y = 0;
2366+
data_window.max.x = width - 1;
2367+
data_window.max.y = height - 1;
2368+
if (num_components == 4)
2369+
{
2370+
rgba_output_file = new Imf::RgbaOutputFile(fname, display_window, data_window, Imf::WRITE_RGBA);
2371+
}
2372+
else if (num_components == 3)
2373+
{
2374+
rgba_output_file = new Imf::RgbaOutputFile(fname, display_window, data_window, Imf::WRITE_RGB);
2375+
}
2376+
else
2377+
{
2378+
fprintf(stderr, "this software currently only supports writing EXR files with 3 or 4 components\n");
2379+
exit(-1);
2380+
}
2381+
}
2382+
23672383
is_open = true;
23682384
return;
23692385
}
@@ -2403,37 +2419,45 @@ namespace ojph {
24032419
fprintf(stderr, "not using RGBA interface\n");
24042420
}
24052421

2422+
2423+
24062424
return;
24072425
}
24082426

24092427
ui32 exr_out::write(const line_buf* line, ui32 comp_num)
24102428
{
24112429
if (true == this->is_use_Rgba_interface)
24122430
{
2431+
// set framebuffer for first component
2432+
if (0 == comp_num)
2433+
{
2434+
rgba_output_file->setFrameBuffer(&pixels[0][0] - data_window.min.x - data_window.min.y * width, 1, width);
2435+
}
2436+
24132437
switch (comp_num)
24142438
{
24152439
case 0:
24162440
for (ui32 i = 0; i < width; i++)
24172441
{
2418-
pixels[cur_line][i].r.setBits((si16)line->i32[i]);
2442+
pixels[0][i].r.setBits((si16)line->i32[i]);
24192443
}
24202444
break;
24212445
case 1:
24222446
for (ui32 i = 0; i < width; i++)
24232447
{
2424-
pixels[cur_line][i].g.setBits((si16)line->i32[i]);
2448+
pixels[0][i].g.setBits((si16)line->i32[i]);
24252449
}
24262450
break;
24272451
case 2:
24282452
for (ui32 i = 0; i < width; i++)
24292453
{
2430-
pixels[cur_line][i].b.setBits((si16)line->i32[i]);
2454+
pixels[0][i].b.setBits((si16)line->i32[i]);
24312455
}
24322456
break;
24332457
case 3:
24342458
for (ui32 i = 0; i < width; i++)
24352459
{
2436-
pixels[cur_line][i].a.setBits((si16)line->i32[i]);
2460+
pixels[0][i].a.setBits((si16)line->i32[i]);
24372461
}
24382462
break;
24392463
default:
@@ -2442,6 +2466,14 @@ namespace ojph {
24422466
return 0;
24432467
break;
24442468
}
2469+
2470+
// write to file after last component has been populated in this line
2471+
if (comp_num == num_components - 1)
2472+
{
2473+
rgba_output_file->writePixels(1);
2474+
data_window.min.y++;
2475+
}
2476+
24452477
}
24462478
else
24472479
{
@@ -2460,21 +2492,10 @@ namespace ojph {
24602492
{
24612493
if (true == is_use_Rgba_interface)
24622494
{
2463-
Imf::RgbaOutputFile* file = NULL;
2464-
if (num_components == 4)
2465-
file = new Imf::RgbaOutputFile(fname, width, height, Imf::WRITE_RGBA);
2466-
else if (num_components == 3)
2467-
file = new Imf::RgbaOutputFile(fname, width, height, Imf::WRITE_RGB);
2468-
else
2469-
{
2470-
fprintf(stderr, "this software currently only supports writing EXR files with 3 or 4 components\n");
2471-
exit(-1);
2472-
}
2473-
file->setFrameBuffer(&pixels[0][0], 1, width);
2474-
file->writePixels(height);
2495+
pixels.resizeErase(0, 0);
24752496

2476-
if (NULL != file)
2477-
delete file;
2497+
if (NULL != rgba_output_file)
2498+
delete rgba_output_file;
24782499
}
24792500
else
24802501
{

0 commit comments

Comments
 (0)